Browse Source

make autoreplies html with description of the group purpose

Pi 1 year ago
parent
commit
00a593661d

+ 11 - 0
cropswap-members@shandan.one/SUBSCRIBE.eml

@@ -0,0 +1,11 @@
+<html><head></head><body>
+<p>You have been successfully subscribed to the Taupiri Crop Members mailing list.
+<p>Email sent to <a href="mailto:cropswap-members@shandan.one">cropswap-members@shandan.one</a> will be forwarded to all other subscribed members.
+<p>When you reply to an email from the mailing list, only the sender will receive it.
+<p>If you would like to send an email to all the members, then start a new email thread addressed to: <a href="mailto:cropswap-members@shandan.one">cropswap-members@shandan.one</a>
+<p>To unsubscribe click <a href="mailto:cropswap-members@shandan.one?subject=[UNSUBSCRIBE]">here</a>.
+<p>You may unsubscribe from this list at any time by clicking the unsubscribe link at the bottom of any mail you receive, or by sending an email to <a href="mailto:cropswap-members@shandan.one">cropswap-members@shandan.one</a>, with [UNSUBSCRIBE] as the subject (square brackets included). For example:
+<p><pre>
+To:      cropswap-members@shandan.one
+Subject: [UNSUBSCRIBE]
+</pre></body></html>

+ 10 - 0
cropswap-members@shandan.one/UNSUBSCRIBE.eml

@@ -0,0 +1,10 @@
+<html><head></head><body>
+<p>You have been successfully unsubscribed from the Taupiri Crop Members mailing list.
+<p>You will no longer receive email from <a href="mailto:cropswap-members@shandan.one">cropswap-members@shandan.one</a>.
+<p>If you wish to continue receiveing messages from other members, then you may <a href="mailto:cropswap-members@shandan.one?subject=[SUBSCRIBE]">subscribe</a> at any time by sending an email to <a href="mailto:cropswap-members@shandan.one">cropswap-members@shandan.one</a>, with [SUBSCRIBE] as the subject (square brackets included). For example:
+<p><pre>
+To:      cropswap-members@shandan.one
+Subject: [SUBSCRIBE]
+</pre>
+<p>You may also contact the orgnizers for assistance by sending an e-mail to <a href="mailto:cropswap@shandan.one">cropswap@shandan.one</a>
+</body></html>

+ 0 - 0
signup.eml → cropswap-members@shandan.one/signup.eml


+ 47 - 0
cropswap-register-new.sh

@@ -0,0 +1,47 @@
+#!/bin/bash
+set -euo pipefail
+set -x
+WD=$(mktemp -d)
+cleanup (){
+  rm -rf "${WD}"
+}
+trap 'cleanup' EXIT
+form_dir="$1"
+
+SCRIPTDIR=$(readlink -f "${BASH_SOURCE[0]%/*}")
+
+declare -a contacts
+update_members(){
+	name="${contacts[$1-1]}"
+	email="${2}"
+	MEMBERS["$email"]="${name}"
+}
+update_signup(){
+	name="${contacts[$1-1]}"
+	email="${2}"
+	for key in "${!MEMBERS[@]}"; do
+		[ "${key}" == "${email}" ] && return
+	done
+	SIGNUP["$email"]="${name}"
+}
+for group in cropswap cropswap-members; do
+	declare -A MEMBERS=()
+	# Define an array of contacts (name and email pairs)
+	#
+	# Reads files in $form_dir with structure like
+	#
+	#  Name: Som E. Name
+	#  Email: address@example.com
+	mapfile -t -c 2 -C update_members contacts < <("${SCRIPTDIR}/gdbm-iter.py" "/var/mail/maildrop/${group}@shandan.one/mlist")
+	unset contacts
+
+	declare -A SIGNUP=()
+	mapfile -t -c 2 -C update_signup contacts < <(find ${form_dir} -type f -name "*.txt" -exec awk -F ":" '
+/Name:/ { print substr($2,2) OFS }
+/Email:/ { print substr($2,2) OFS }
+' {} \;)
+
+	for email in "${!SIGNUP[@]}"; do
+		echo "${SCRIPTDIR}/cropswap-register.sh" "${group}@shandan.one" "${SIGNUP["$email"]}" "$email" NONE
+	done
+done

+ 5 - 1
cropswap-reply.sh

@@ -3,7 +3,11 @@ SENDMAIL=/usr/sbin/sendmail
 if ((DEBUG != 0)); then
 	SENDMAIL="$DEBUGMAIL"
 fi
-/usr/bin/mailbot -N -t $RESP \
+#set -x
+	#-A "Content-Transfer-Encoding: 8bit" \
+/usr/bin/mailbot -N -c utf-8 -t "$RESP" \
+	-A "MIME-Version: 1.0" \
+	-A "Content-Type: text/html" \
 	-A "From: $MAILGROUPALIAS <$MAILGROUP>" \
 	-A "List-Id: $MAILGROUP" \
 	-A "List-Unsubscribe: <mailto:$MAILGROUP?subject=[UNSUBSCRIBE]>" \

+ 1 - 4
cropswap-sendmail.sh

@@ -24,10 +24,7 @@ mk_subject(){
 	echo "${subject}"
 }
 
-tee >(reformail -c -x "Subject:" >subject) original | "${MIME_INJECT}" "To unsubscribe, send an email to $MAILGROUP, with [UNSUBSCRIBE] as the subject (square brackets included)." "$(cat <<EOF
-<div class="banner" style="position:sticky;top:0;background-color:#00f;color:#fff;width:100%;text-align:center;padding:0.5em;box-sizing:border-box;"><span>To unsubscribe, click <a href="mailto:$MAILGROUP?subject=[UNSUBSCRIBE]">here</a> or send an email to $MAILGROUP, with [UNSUBSCRIBE] as the subject (square brackets included).</span></div>
-EOF
-)" | reformime -s1 -e > body
+tee >(reformail -c -x "Subject:" >subject) original | "${MIME_INJECT}" "${MAILGROUP}" | reformime -s1 -e > body
 reformail \
 	-X "Date:" \
 	-X "MIME-Version:" \

+ 11 - 0
cropswap@shandan.one/SUBSCRIBE.eml

@@ -0,0 +1,11 @@
+<html><head></head><body>
+<p>You have been successfully subscribed to the Taupiri Crop Swap Notices mailing list.
+<p>Email sent to <a href="mailto:cropswap@shandan.one">cropswap@shandan.one</a> will be forwarded to the organizers only.
+<p>When you reply to an email from the mailing list, only the sender will receive it.
+<p>If you would like to send an email to all the organizers, then start a new email thread addressed to: <a href="mailto:cropswap@shandan.one">cropswap@shandan.one</a>
+<p>To unsubscribe click <a href="mailto:cropswap@shandan.one?subject=[UNSUBSCRIBE]">here</a>.
+<p>You may also unsubscribe at any time by clicking the unsubscribe link at the bottom of any mail you receive, or by sending an email to <a href="mailto:cropswap@shandan.one">cropswap@shandan.one</a>, with [UNSUBSCRIBE] as the subject (square brackets included). For example:
+<p><pre>
+To:      cropswap@shandan.one
+Subject: [UNSUBSCRIBE]
+</pre></body></html>

+ 11 - 0
cropswap@shandan.one/UNSUBSCRIBE.eml

@@ -0,0 +1,11 @@
+<html><head></head><body>
+<p>You have been successfully unsubscribed from the Taupiri Crop Swap Notices mailing list.
+<p>You will no longer receive email from <a href="cropswap@shandan.one">cropswap@shandan.one</a>
+<p>This includes any notices, updates, and announcements from the Taupiri Crop Swap organizers.
+<p>If you wish to continue receiveing announcements or updates, then you may <a href="mailto:cropswap@shandan.one?subject=[SUBSCRIBE]">subscribe</a> again at any time by sending an email to <a href="mailto:cropswap@shandan.one">cropswap@shandan.one</a>, with [SUBSCRIBE] as the subject (square brackets included). For example:
+<p><pre>
+To:      cropswap@shandan.one
+Subject: [SUBSCRIBE]
+</pre>
+<p>You may also contact the orgnizers for assistance by sending an e-mail to <a href="mailto:cropswap@shandan.one">cropswap@shandan.one</a>
+</body></html>

+ 1 - 0
cropswap@shandan.one/signup.eml

@@ -0,0 +1 @@
+You have been registered as a member

+ 4 - 3
filters/postmaster@localhost

@@ -1,5 +1,5 @@
 POSTMASTERREGEX=escape($POSTMASTER)
-SIGNUPRESP="/opt/cropswap/signup.eml"
+SIGNUPRESPDIR="/opt/cropswap"
 foreach (tolower $ADDR) =~ /^$POSTMASTERREGEX$/
 {
    TOPOSTMASTER=1
@@ -80,6 +80,7 @@ if ($DISPATCH)
    {
       exit
    }
-   RESP=$SIGNUPRESP
-   to "|$MAILBOT"
+   #RESP="$SIGNUPRESPDIR/$MAILGROUP/signup.eml"
+   #to "|$MAILBOT"
+   exit
 }

+ 2 - 2
filters/subscriptions

@@ -1,4 +1,4 @@
-SUBSCRIBERESP="/opt/cropswap/subunsub.eml"
+SUBUNSUBRESPDIR="/opt/cropswap"
 if ($MAILGROUP ne "")
 {
    if (/^Subject:\s*\[(SUBSCRIBE|UNSUBSCRIBE)\]\s*$/)
@@ -28,7 +28,7 @@ if ($DISPATCH)
       {
          exit
       }
-      RESP=$SUBSCRIBERESP
+      RESP="$SUBUNSUBRESPDIR/$MAILGROUP/$SUBSCRIBE.eml"
       to "|$MAILBOT"
    }
 }

+ 1 - 1
maildroprc

@@ -71,7 +71,7 @@ MLIST="$LISTDIR/mlist"
 SLIST="$LISTDIR/slist"
 
 gdbmopen($MLIST, "R")
-TO=gdbmfetch($TOALIAS)
+TO=gdbmfetch(tolower($TOALIAS))
 gdbmclose
 DISPATCH=1
 if ($FORPOSTMASTER)

+ 19 - 3
mime-inject.py

@@ -2,7 +2,11 @@
 import sys
 import email
 
-txt, html = sys.argv[1:3]
+mailgroup = sys.argv[1]
+with open(f'/opt/cropswap/{mailgroup}/banner.html', 'rb') as f:
+    html = f.read().decode("utf-8")
+with open(f'/opt/cropswap/{mailgroup}/banner.txt', 'rb') as f:
+    txt = f.read().decode("utf-8")
 
 m = email.message_from_bytes(sys.stdin.buffer.read())
 
@@ -13,7 +17,8 @@ INJECTED = {
 
 def inject(m):
     c = m.get_content_type()
-    payload = m.get_payload()
+    e = m.get('Content-Transfer-Encoding','').lower()
+    payload = m.get_payload(decode=True).decode("utf-8")
     if c == 'text/plain' and txt not in payload:
         payload = payload + f"""
 {txt}
@@ -24,7 +29,18 @@ def inject(m):
             payload = payload.replace('</body>', f'{html}</body>')
         else:
             payload += f'{html}'
-    m.set_payload(payload)
+
+    if e == 'quoted-printable':
+        encode = email.encoders.encode_quopri
+    elif e in ('7bit', '8bit'):
+        encode = email.encoders.encode_7or8bit
+    elif e == 'base64':
+        encode = email.encoders.encode_base64
+    else:
+        encode = email.encoders.encode_noop
+    m.set_payload(payload.encode("utf-8"))
+    encode(m)
+    m.set_charset("utf-8")
 
 def visit(m):
     c = m.get_content_type()

+ 0 - 1
subunsub.eml

@@ -1 +0,0 @@
-Your subscription status has been updated successfully