home
readme
diff
tree
note
docs
0commit 2de932dc604111f2939384f40d6dae9331c98a80
1Author: Mason Wright <mason@lakefox.net>
2Date: Tue Nov 4 19:39:57 2025 -0700
3
4 Inital
5
6diff --git a/.index.html.swp b/.index.html.swp
7new file mode 100644
8index 0000000..be1d333
9Binary files /dev/null and b/.index.html.swp differ
10diff --git a/cgi-bin/mailto.awk b/cgi-bin/mailto.awk
11new file mode 100755
12index 0000000..28aa890
13--- /dev/null
14+++ b/cgi-bin/mailto.awk
15@@ -0,0 +1,227 @@
16+#!/usr/bin/awk -f
17+
18+# A list should be split by a /: grim/patches.txt
19+
20+BEGIN {
21+ if (ARGC == 4) {
22+ # getThreads( user, pass, imap-url, query )
23+ getThreads(ARGV[1], ARGV[2], ARGV[3], ARGV[4])
24+ exit
25+ }
26+
27+ referer = ENVIRON["HTTP_REFERER"]
28+
29+ list = ""
30+
31+ split(ENVIRON["QUERY_STRING"], pairs, "&")
32+ for (i in pairs) {
33+ split(pairs[i], kv, "=")
34+
35+ if (kv[1] == "action") {
36+ action = kv[2]
37+ } else if (kv[1] == "view") {
38+ view = kv[2]
39+ } else if (kv[1] == "email") {
40+ email = kv[2]
41+ gsub(/\%40/, "@", email)
42+ } else if (kv[1] == "list") {
43+ list = tolower(kv[2])
44+ gsub(/\%2f/, "/", list)
45+ }
46+ }
47+
48+ if (email != "") {
49+ if (action == "subscribe") {
50+ print email >> "/var/mailto/" list ".txt"
51+ } else if (action == "unsubscribe") {
52+ file = "/var/mailto/" list ".txt"
53+ tmp = file ".tmp"
54+
55+ while ((getline line < file) > 0) {
56+ if (line != email) # keep everything except the email
57+ print line > tmp
58+ }
59+ close(file)
60+ close(tmp)
61+ system("mv \"" tmp "\" \"" file "\"") # atomic replace
62+ }
63+
64+ redirect(referer)
65+ } else if (view != "") {
66+ openMail(list, view)
67+ } else {
68+ showLists(list)
69+ }
70+
71+ exit
72+}
73+
74+function redirect(url) {
75+ if (url == "") url = "/"
76+ print "Content-Type: text/html\r\n"
77+ print "<!DOCTYPE html>"
78+ print "<html><head>"
79+ print "<meta http-equiv=\"refresh\" content=\"0; url=" url "\">"
80+ print "<title>Redirecting…</title>"
81+ print "</head><body>"
82+ print "Redirecting to <a href=\"" url "\">" url "</a>..."
83+ print "</body></html>"
84+ exit
85+}
86+
87+function showLists(name) {
88+ split(name, parts, "/")
89+
90+ print "Content-Type: text/html\r\n"
91+ print "<!DOCTYPE html>"
92+ print "<html>"
93+ print "<head>"
94+ print "<title>MailTo: " name "</title>"
95+ print "</head>"
96+ print "<body>"
97+
98+ if (length(parts) == 1 || name == "") {
99+ # Print out all of the mailing lists
100+ cmd = "ls /var/mailto/" parts[1]
101+
102+ if (name != "") {
103+ name = name "/"
104+ print "<h1>MailTo:" name "</h1>"
105+ print "<p>Select a subject specific list to view or message.</p>"
106+ } else {
107+ print "<h1>MailTo</h1>"
108+ print "<p>MailTo is a stateless email mailing list manager and archiver. To include yourself in a mailing list go to a sites page and select a list you want to be included in. Then enter your email and select subscribe. To be taken off a list enter your email and select unsubscribe.</p>"
109+ print "<p>Select a site to view the site's lists.</p>"
110+ }
111+
112+ print "<ul>"
113+ while (cmd | getline file) {
114+ split(file, k, ".")
115+ print "<li><a href='/cgi-bin/mailto.awk?list=" name k[1] "'>/" k[1] "</a></li>"
116+ }
117+ print "</ul>"
118+ } else {
119+ print "<h1>MailTo:<a href='?list=" parts[1] "'>" parts[1] "/</a>" parts[2] "</h1>"
120+
121+ print "<form action='/cgi-bin/mailto.awk' method='get'>"
122+ print "<input type='email' name='email' placeholder='your@email.com' required>"
123+ print "<input type='text' name='list' value='" name "' hidden/>"
124+
125+ print "<button type='submit' name='action' value='subscribe'>Subscribe</button>"
126+ print "<button type='submit' name='action' value='unsubscribe'>Unsubscribe</button>"
127+ print "</form><br/>"
128+
129+ print "<a href='mailto:"
130+
131+ cmd = "cat /var/mailto/" parts[1] "/" parts[2] ".txt"
132+ while (cmd | getline address) {
133+ print address ","
134+ }
135+ close(cmd)
136+
137+ print "?subject=" name ": Your Title'>New</a>"
138+
139+ cmd = "ls -t -1 /var/mailto/.cache/" name
140+
141+ print "<ul>"
142+ while (cmd | getline line) {
143+ n = split(line, title, ".")
144+ formatted = ""
145+ for (i = 1; i < n; i++) {
146+ formatted = formatted title[i]
147+ }
148+ sub("<>","/", formatted)
149+ print "<li><a href='/cgi-bin/mailto.awk?list=" name "&view=" title[n] "'>" formatted "</a></li>"
150+ }
151+ print "</ul>"
152+ }
153+
154+ print "</body>"
155+ print "</html>"
156+}
157+
158+function openMail(folder, uid) {
159+ print "Content-Type: text/html\r\n"
160+ print "<!DOCTYPE html>"
161+ print "<html>"
162+ print "<head>"
163+ print "<title>MailTo: " name "</title>"
164+ print "</head>"
165+ print "<body>"
166+
167+ cmd = "cat /var/mailto/.cache/" folder "/*." uid
168+
169+ while (cmd | getline line) {
170+ print line
171+ }
172+
173+ print "</body>"
174+ print "</html>"
175+}
176+
177+# This function will keep all email's up to date
178+function getThreads(username, password, inbox, query) {
179+ cmd = "curl -s -u '" username ":" password "' '" inbox "' -X 'UID SEARCH SUBJECT " query "'"
180+ while ((cmd | getline res) > 0) { # collect last line
181+ split(res, a); # a[1]="*"; a[2]="SEARCH"; rest are UIDs
182+ n = 0
183+ for (i = 3; i <= length(a); i++) { # skip "* SEARCH"
184+ uids[++n] = a[i]
185+ }
186+ }
187+ close(cmd)
188+
189+ cmd = "ls /var/mailto/.cache/" query
190+ files = ""
191+
192+ while (cmd | getline line) {
193+ file = files line
194+ }
195+ close(cmd)
196+
197+
198+ for (i = 1; i <= n; i++) {
199+ uid = uids[i]
200+ sub("\r", "", uid)
201+
202+ if (index(files, uid) == 0) {
203+ cmd = "curl -s -u '" username ":" password "' '" inbox ";UID=" uid "'"
204+ subj = ""
205+ body = ""
206+ from = ""
207+ date = ""
208+ inBody = 0
209+ while ((cmd | getline line) > 0) {
210+ if (line == "\r") { # blank line → headers finished
211+ inBody = 1
212+ continue
213+ }
214+ if (!inBody) { # still in headers
215+ if (line ~ /^Subject:/)
216+ subj = substr(line, 10)
217+ else if (line ~ /^From:/)
218+ from = substr(line, 6)
219+ else if (line ~ /^Date:/)
220+ date = substr(line, 6)
221+ } else { # body lines
222+ body = body line "\n"
223+ }
224+ }
225+ close(cmd)
226+
227+ cleanSubj = subj
228+ sub("/", "<>", cleanSubj)
229+ sub("\r", "", cleanSubj)
230+
231+ if (system("test -e \"/var/mailto/.cache/" query "/" cleanSubj "." uid "\"") != 0) {
232+ file = "/var/mailto/.cache/" query "/" cleanSubj "." uid
233+ gsub("\r","</br>", body)
234+ print "<h1>" subj "</h1>" > file
235+ print "<h3>From: " from "</h3>" >> file
236+ print "<b>Date: " date "</b>" >> file
237+ print "<p>" body "</p>" >> file
238+ }
239+ }
240+ }
241+
242+}
243diff --git a/index.html b/index.html
244new file mode 100644
245index 0000000..4e047e7
246--- /dev/null
247+++ b/index.html
248@@ -0,0 +1,47 @@
249+<!DOCTYPE html>
250+<html>
251+ <head>
252+ <title>DECODE</title>
253+ <style>
254+ table,
255+ thead,
256+ tbody,
257+ th,
258+ td {
259+ border: 1px solid black;
260+ border-collapse: collapse;
261+ }
262+ </style>
263+ </head>
264+ <body>
265+ <h1>DECODE</h1>
266+ <a href="irc.decode.sh">#IRC</a> <a href="/cgi-bin/mailto.awk">Mailing Lists</a>
267+ <p>
268+ Decode is a project sharing website.
269+ </p>
270+
271+ <h2>Projects</h2>
272+ <table style="width: 90%; ">
273+ <thead>
274+ <th>Source</th>
275+ <th>About</th>
276+ <th>IRC</th>
277+ <th>Clone</th>
278+ </thead>
279+ <tbody>
280+ <tr>
281+ <td><a href="http://lakefox.net/grim">grim/</a></td>
282+ <td></td>
283+ <td><a href="irc.decode.sh/#grim">#grim</a></td>
284+ <td>http://lakefox.net/grim.git</td>
285+ </tr>
286+ <tr>
287+ <td><a href="http://lakefox.net/asftp">asftp/</a></td>
288+ <td></td>
289+ <td><a href="irc.decode.sh/#asftp">#asftp</a></td>
290+ <td>http://lakefox.net/asftp.git</td>
291+ </tr>
292+ </tbody>
293+ </div>
294+ </body>
295+</html>