Hooks to be used to receive/send emails.
Author: brian (git@myr.sh)
Date: Sun Jan 28 20:35:56 2024 -0300
Parent: 219ab33
Fixed empty to field
diff --git a/receive-example.domain b/receive-example.domain
index 1272426..4ca8eb3 100755
--- a/receive-example.domain
+++ b/receive-example.domain
@@ -1,5 +1,9 @@
#!/bin/sh
+log() {
+ printf "%s INFO %s\n" "$(date +'%Y/%m/%d %X')" "$*"
+}
+
decode() {
case "$1" in
"=?iso-8859-1?Q?"*)
@@ -49,6 +53,7 @@ decode() {
printf "%s" "$@" | sed -e 's/=?UTF-8?B?//Ig' \
-e 's/?=//g' | base64 -d
;;
+ *) printf "$s" "$@" ;;
esac
}
@@ -66,7 +71,7 @@ index() {
<link rel=icon href=/assets/favicon.ico>
<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>
+ <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>
@@ -80,8 +85,6 @@ index() {
\__,_/ \____/_____/ \___//_/
</pre>
</center>
- <a href=compose.html>compose</a> 
- <a href=logout.html>logout</a>
EOF
ls -ogdt --time-style long-iso "$HOME/mail"/* | while read -r g x s d t f
@@ -261,10 +264,11 @@ emails() {
}
save() {
- echo "parsing email"
+ log "parsing email"
# first line is From email date:
read -r foo from date
+ log "mail from $from"
# read headers
while read -r k v
@@ -276,10 +280,11 @@ save() {
"") break ;;
esac
done
+ log "mail to $to"
# adjust fields
to="$(decode "${to##* }" | tr -d '<>"')"
- eid="${eid:-$(date -Iseconds)}"
+ eid="$(printf "%s" "${eid:-$(date -Iseconds)}" | tr -d '<>"')"
subj="$(decode "$subj" | sed 's@/@/@g')"
# now the rest is a body
@@ -290,21 +295,21 @@ save() {
mv "$tmp" "$HOME/mail/$to/$subj/$eid.mbox"
# create html pages
- echo "building index page"
+ log "building index page"
mkdir -p "$out/$to/$subj"
index > "$out/index.html"
- echo "building inbox page"
+ log "building inbox page"
inbox > "$out/$to/index.html"
- echo "building emails page"
+ log "building emails page"
emails > "$out/$to/$subj/index.html"
}
# copy to temp file
-echo "[INFO] receive-example.domain started"
+log "receive-example.domain started"
out="$HOME/www/mail"
tmp="$(mktemp)"
tee "$tmp" | save
-echo "[INFO] script finished"
+log "script finished"