From 71619f80dc63e859203ae76af002cfea65016200 Mon Sep 17 00:00:00 2001 From: sl Date: Sat, 14 Jun 2025 23:48:50 +0000 Subject: [PATCH] add apps/mdir --- apps/mdir/TODO | 10 +++ apps/mdir/app.rc | 178 +++++++++++++++++++++++++++++++++++++++++++ apps/mdir/readme.txt | 11 +++ 3 files changed, 199 insertions(+) create mode 100644 apps/mdir/TODO create mode 100755 apps/mdir/app.rc create mode 100644 apps/mdir/readme.txt diff --git a/apps/mdir/TODO b/apps/mdir/TODO new file mode 100644 index 0000000..d1b1f3b --- /dev/null +++ b/apps/mdir/TODO @@ -0,0 +1,10 @@ +* unfuck quoted-printable crap +* more robust plaintext extraction from mime +* more efficient month sort in the year view + * I think sort(1) might have a bug with -M and pos1 + * or stupid awk can just produce an ordered list +* a lot of speedup + * this might mean an external index + * or it might just mean aggressive in-app cache +* do we want threading in the month views +* decode non-ascii header values (From: especially) diff --git a/apps/mdir/app.rc b/apps/mdir/app.rc new file mode 100755 index 0000000..b9f05c9 --- /dev/null +++ b/apps/mdir/app.rc @@ -0,0 +1,178 @@ +fn conf_enable_mdir { + mdir=`{pwd} + listbase=$conf_wd + listname=`{basename `{ basename -d $listbase}} + conf_enable_app mdir + dirfilter=$dirfilter' /mbox\/?$/d;' +} + + +fn mdir_init { + showmonth=`{echo $req_path | sed 's/.*[0-9][0-9][0-9][0-9]\/([A-Z][a-z][^\/]+).*/\1/'} + showyear=`{echo $req_path | sed 's/.*\/([0-9][0-9][0-9][0-9])\/.*/\1/'} + handler_body_main='mdir_index' + + if (~ $req_path $listbase[0-9][0-9][0-9][0-9]/[A-Z][a-z]*/[0-9]*) { + handler_body_main='message_display' + } + if not if (~ $req_path $listbase[0-9][0-9][0-9][0-9]/[A-Z][a-z]*) { + handler_body_main='month_display' + } + if not if(~ $req_path $listbase[0-9][0-9][0-9][0-9]*) { + handler_body_main='year_display' + } + + +} + +fn message_display { + message=`{basename $req_path} + echo '

'$listname' - '$showyear' - ' + echo ''$showmonth' -' + echo 'this message ' + approx=`{echo $"message | sed 's/(...).*/\1/' } + neighbors=`{ls -p $mdir/mbox/$approx^*} + prevmsg=`{echo $neighbors | tr '\012' ' ' | sed -n 's/.* ([^ ]+) '$message'.*/\1/p'} + nextmsg=`{echo $neighbors | tr '\012' ' ' | sed -n 's/.*'$message' ([^ ]+).*/\1/p'} + echo '

' + if (~ $#prevmsg 1 || ~ $#nextmsg 1) { echo '[ ' } + if (~ $#prevmsg 1) { echo 'previous' } + if (~ $#prevmsg 1 && ~ $#nextmsg 1) { echo ' , ' } + if (~ $#nextmsg 1) { echo 'next' } + if (~ $#prevmsg 1 || ~ $#nextmsg 1) { echo ' ]' } + echo '

' + awk ' + /^Subject:/ && (headersdone == 0) { subject=$0 } + /^From:/ && (headersdone == 0) { from=$0; gsub(//, "\\>", from); } + /^Date:/ && (headersdone == 0) { date=$0 } + /^$/ && (headersdone==0) { print "

" subject "

"; print from; print date; headersdone=1 }
+  (headersdone == 1) { exit }
+  ' $mdir/mbox/$message | sed 's/([^ @.]+)\@[^ @]+\.[^@ $][a-zA-Z]+/\1@[REDACTED]/g;' 
+
+	cat $mdir/mbox/$message | {
+		boundary=undef;
+		while (line=`{read}) {
+			if (~ $line Content-Type*multipart*) { # flag mimeshit boundary
+										multipart=1
+				boundary=`{echo $line | sed 's/^.*boundary=//; s/[  ].*$//'}
+										if (test -z $boundary) { boundary=undef; } # fucking header wrap
+			}
+						if (~ $multipart 1) {
+										if (~ $boundary undef) { # desperately try to identify a boundary
+					boundary=`{echo $line | sed 's/^.*boundary=//; s/[        ].*$//'}
+			 }
+			}
+
+			if (~ $"line '') { # note end of header section
+				endheaders = 1;
+			}
+
+			if (~ $boundary undef ) { # no boundary, headers over:  print message
+				if (~ $endheaders 1) {
+					echo $line
+				}
+			}
+			if not { # boundaries: print only text/plain
+				if (~ $line --$boundary) { # boundary found, toggle state
+					if (~ $inboundary 1) { 
+						inboundary=0
+					}
+					if not {
+						inboundary=1
+					}
+				}
+				if (~ $inboundary 1) { # we're in a text/plain part, print it
+					if (~ $textpart 1) {
+						echo $line
+					}
+				}
+				if (~ $line Content-Type*text*plain*) { # note advent of text/plain part
+					if (~ $inboundary 1) {
+						echo found text part
+						textpart=1
+					}
+				}
+			}
+		}
+	}
+
+  echo '
' +} + +fn mdir_index { + echo '

' $listname '

' + echo '' +} + +fn year_display { +echo '

'$listname' - '$showyear'

' +echo '' +} + +fn month_display { +echo '

'$listname' - '$showyear' - '$showmonth'

' +echo '' +} diff --git a/apps/mdir/readme.txt b/apps/mdir/readme.txt new file mode 100644 index 0000000..25ab886 --- /dev/null +++ b/apps/mdir/readme.txt @@ -0,0 +1,11 @@ +INSTALL: + +put this folder in e.g. /werc/apps/mdir + +put your mdir in e.g. /werc/sites/example.com/mail/ +(such that all the messages land in /werc/sites/example.com/mail/mbox/) + +mkdir /werc/sites/example.com/mail/_werc +echo "conf_enable_mdir" > /werc/sites/example.com/mail/_werc/config + +good luck.