Hooks to be used to receive/send emails.
Author: brian (git@myr.sh)
Date: Mon Jan 29 17:20:51 2024 -0300
Parent: 5a4cc86
Improved path handling - Added feed
diff --git a/receive-example.domain b/receive-example.domain index 34fe481..a750a5e 100755 --- a/receive-example.domain +++ b/receive-example.domain @@ -74,6 +74,7 @@ index() { <style>body{max-width:600px;padding:0 15px;margin:40px auto;font-family:sans-serif}a{color:#888}small{float:right}</style> <link rel="manifest" href="/assets/manifest.json"> <link rel="apple-touch-icon" sizes="200x200" href="/logo.png"> + <link rel="alternate" type="application/rss+xml" href="/feed.xml" title="your inbox"> </head> <body> <center> @@ -90,10 +91,10 @@ index() { ls -ogdt --time-style long-iso "$HOME/mail"/* | while read -r g x s d t f do - f="$(basename "$f" | cut -d ' ' -f -1)" + f="$(basename "$f")" cat <<- EOF <p> - <a href="$f/index.html">$f</a> + <a href="$f/index.html">$(printf "%s" "$f" | base64 -d)</a> <small>$t $d</small> </p> EOF @@ -115,21 +116,19 @@ inbox() { <meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="color-scheme" content="light dark"/> <style>body{max-width:600px;padding:0 15px;margin:40px auto;font-family:sans-serif}a{color:#888}small{float:right}</style> - <link rel="manifest" href="/assets/manifest.json"> - <link rel="apple-touch-icon" sizes="200x200" href="/logo.png"> </head> <body> <h1>$to</h1> <a href=/index.html>go back</a> EOF - ls -ogdt --time-style long-iso "$HOME/mail/$to"/* | while read -r g x s d t f + ls -ogdt --time-style long-iso "$HOME/mail/$toenc"/* | while read -r g x s d t f do f="$(basename "$f")" - qty="$(ls -1 "$HOME/mail/$to/$f" | wc -l)" + qty="$(ls -1 "$HOME/mail/$toenc/$f" | wc -l)" cat <<- EOF <p> - <a href="$f/index.html">$f</a> + <a href="$f/index.html">$(printf "%s" "$f" | base64 -d)</a> <small>$t $d</small><br> <i>$qty emails</i> </p> @@ -152,18 +151,16 @@ emails() { <meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="color-scheme" content="light dark"/> <style>body{max-width:600px;padding:0 15px;margin:40px auto;font-family:sans-serif}a{color:#888}small{float:right}</style> - <link rel="manifest" href="/assets/manifest.json"> - <link rel="apple-touch-icon" sizes="200x200" href="/logo.png"> </head> <body> - <h1>$subj</h1> - <a href="/$to/index.html">go back</a><br><br> + <h1>$(decode "$subj")</h1> + <a href="/$toenc/index.html">go back</a><br><br> EOF # print each email # TODO: read text part # TODO: decode quoted-pritable or base64 - ls -1rt "$HOME/mail/$to/$subj"/*.mbox | while read -r f + ls -1rt "$HOME/mail/$toenc/$subjenc"/*.mbox | while read -r f do { # print headers @@ -264,6 +261,22 @@ emails() { EOF } +genfeed() { + cat <<- EOF +<?xml version="1.0" encoding="UTF-8" ?> +<rss version="2.0"> +<channel> + <title>your emails</title> + <description>emails.</description> + <link>https://inbox.dovel.email</link> + <language>en-us</language> + <copyright>2024 dovel.email All rights reserved</copyright> + <lastBuildDate>$date</lastBuildDate> + <pubDate>$date</pubDate> + <ttl>180</ttl> + EOF +} + save() { log "parsing email" @@ -283,28 +296,49 @@ save() { done # adjust fields - to="$(decode "${to##* }" | tr -d '<>"')" - eid="$(printf "%s" "${eid:-$(date -Iseconds)}" | tr -d '<>"')" - subj="$(decode "$subj" | sed 's@/@/@g')" + toenc="$(printf "%s" "$to" | base64 -w 0)" + eidenc="$(printf "%s" "${eid:-$(date -Iseconds)}" | base64 -w 0)" + subjenc="$(decode "$subj" | base64 -w 0)" log "mail $eid to $to: $subj" # now the rest is a body cat > /dev/null # move temp file - mkdir -p "$HOME/mail/$to/$subj" - mv "$tmp" "$HOME/mail/$to/$subj/$eid.mbox" + mkdir -p "$HOME/mail/$toenc/$subjenc" + mv "$tmp" "$HOME/mail/$toenc/$subjenc/$eidenc.mbox" # create html pages log "building index page" - mkdir -p "$out/$to/$subj" + mkdir -p "$out/$toenc/$subjenc" index > "$out/index.html" log "building inbox page" - inbox > "$out/$to/index.html" + inbox > "$out/$toenc/index.html" log "building emails page" - emails > "$out/$to/$subj/index.html" + emails > "$out/$toenc/$subjenc/index.html" + + log "updating feed" + feed="$out/feed.xml" + [ -f "$feed" ] || genfeed > "$feed" + + tmpfeed="$(mktemp)" + head -n -2 "$feed" > "$tmpfeed" + + cat <<- EOF >> $tmpfeed + <item> + <title>mail from $from to $to</title> + <description>$subj</description> + <link>https://inbox.dovel.email/$toenc/$subjenc/$eidenc.html</link> + <guid>https://inbox.dovel.email/$toenc/$subjenc/$eidenc.html</guid> + <pubDate>$date</pubDate> + </item> + </channel> +</rss> + EOF + + mv "$tmpfeed" "$feed" } # copy to temp file