Browse Source

remove subunsub script

Pi 1 year ago
parent
commit
3ebab3d00a

+ 4 - 9
cropswap-sendmail.sh

@@ -8,6 +8,7 @@ trap cleanup EXIT
 
 cd "${WD}"
 
+ITER_SUBS=/opt/cropswap/gdbm-iter-subscriptions.py
 MIME_INJECT=/opt/cropswap/mime-inject.py
 DELIVERED=false
 SENDMAIL="/usr/sbin/sendmail"
@@ -26,9 +27,6 @@ mk_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
-)" "$(cat <<EOF
-.banner{position:sticky;top:0;background-color:#00f;color:#fff;height:2em;width:100vw;text-align:center;padding:0.5em;box-sizing:border-box;text-transform:uppercase;}
-EOF
 )" | reformime -s1 -e > body
 reformail \
 	-X "Date:" \
@@ -46,7 +44,6 @@ reformail \
 	-I "List-Unsubscribe-Post: List-Unsubscribe=One-Click" \
 | cat - body > mail
 
-
 declare -A SUBSCRIBED
 declare -a actions
 update(){
@@ -54,11 +51,9 @@ update(){
 	email="${2}"
 	SUBSCRIBED["$email"]="$alias"
 }
-
-exec 4< "${SLIST}.txt"
-flock 4
-mapfile -t -c 2 -C update -u 4 actions
-flock -u 4
+mapfile -t -c 2 -C update actions <<EOF
+$("${ITER_SUBS}" "${MLIST}" "${SLIST}")
+EOF
 
 for email in "${!SUBSCRIBED[@]}"; do
 	if [ "${email,,}" == "${NOFORWARD,,}" ]; then

+ 2 - 0
filters/cropswap@shandan.one

@@ -62,6 +62,7 @@ if ($DISPATCH)
 
    if ($ORGANIZER eq "NONE" || $ORGANIZER eq "")
    {
+      MLIST="$LISTDIR/mlist"
       SLIST="$LISTDIR/alist"
       FROM=$ALIAS
       to "!"
@@ -69,6 +70,7 @@ if ($DISPATCH)
 
    #
    # Organizers only
+   MLIST="$LISTDIR/mlist"
    FROM=$ALIAS
    SUBJECT="Crop Swap Notice"
    SLIST="$LISTDIR/slist"

+ 0 - 1
filters/postmaster@localhost

@@ -71,7 +71,6 @@ if ($DISPATCH)
    {
       SUBSCRIBE="UNSUBSCRIBE"
    }
-   system "$SUBUNSUB '$SUBSCRIBE' '$KEY' '$FROM'"
    if ($EXITCODE)
    {
       cc "|$DEBUGMAIL 'auth-sub-fail'"

+ 0 - 1
filters/subscriptions

@@ -24,7 +24,6 @@ if ($DISPATCH)
          exit
       }
       gdbmclose
-      system "$SUBUNSUB '$SUBSCRIBE' '$ALIAS' '$FROM'"
       if ($NOREPLY)
       {
          exit

+ 34 - 0
gdbm-iter-subscribed.py

@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+# depends (debian) python3-gdbm
+import dbm
+import sys
+#mlist, alist, slist = sys.argv[1:4]
+mlist, slist = sys.argv[1:3]
+
+def gdbm_iter_keys(dbpath):
+    with dbm.open(dbpath, 'r') as db:
+        k = db.firstkey()
+        while k is not None:
+            yield k, db.get(k)
+            k = db.nextkey(k)
+
+#admins = filter(lambda x: x[1].lower() == 'admin', gdbm_iter_keys(alist) if alist else [])
+#subscribed = filter(lambda x: x[1].lower() == 'subscribe', gdbm_iter_keys(slist))
+
+SUBSCRIBED = {
+  'admin',
+  'subscribe',
+}
+
+members = filter(lambda x: x[1], gdbm_iter_keys(mlist))
+subscribed = set(map(lambda x: x[0], filter(
+    lambda x: x[1].decode('utf-8').lower() in SUBSCRIBED,
+    gdbm_iter_keys(slist)
+)))
+
+for email, alias in {
+    k: v for k,v in members if k in subscribed
+}.items():
+    print(alias.decode('utf-8'))
+    print(email.decode('utf-8'))
+

+ 0 - 1
maildroprc

@@ -7,7 +7,6 @@ import DEBUG
 import TEST
 SHELL="/bin/bash"
 SENDMAIL="/opt/cropswap/sendmail.sh"
-SUBUNSUB="/opt/cropswap/subunsub.sh"
 DEBUGMAIL="/opt/cropswap/debug.sh"
 MAILBOT="/opt/cropswap/mailbot.sh"
 FILTERDIR="/opt/cropswap/filters"

+ 23 - 19
mime-inject.py

@@ -1,35 +1,39 @@
 #!/usr/bin/env python3
 import sys
 import email
+
+txt, html = sys.argv[1:3]
+
 m = email.message_from_bytes(sys.stdin.buffer.read())
 
 INJECTED = {
-  'text/plain': False,
-  'text/html': False,
+    'text/plain': False,
+    'text/html': False,
 }
-txt, html, css = sys.argv[1:4]
+
 def inject(m):
-  c = m.get_content_type()
-  payload = m.get_payload()
-  if c == 'text/plain' and txt not in payload:
-    payload = payload + f"""
+    c = m.get_content_type()
+    payload = m.get_payload()
+    if c == 'text/plain' and txt not in payload:
+        payload = payload + f"""
 {txt}
 """
-  if c == 'text/html':
-    if '</body>' in payload and '</head>' in payload:
-      payload = payload.replace('</body>', f'{html}</body>').replace('</head>', f'<style>{css}</style></head>')
-    else:
-      payload = payload + f'<style>{css}</style>{html}'
-  m.set_payload(payload)
+    if c == 'text/html':
+        payload = payload.replace(html, '')
+        if '</body>' in payload:
+            payload = payload.replace('</body>', f'{html}</body>')
+        else:
+            payload += f'{html}'
+    m.set_payload(payload)
 
 def visit(m):
-  c = m.get_content_type()
-  if c in ('text/plain', 'text/html'):
-    if INJECTED[c]: return
-    inject(m)
-    INJECTED[c] = True
+    c = m.get_content_type()
+    if c in ('text/plain', 'text/html'):
+        if INJECTED[c]: return
+        inject(m)
+        INJECTED[c] = True
 
 for _m in m.walk():
-  visit(_m)
+     visit(_m)
 
 sys.stdout.buffer.write(m.as_bytes())

+ 0 - 15
subunsub.sh

@@ -1,15 +0,0 @@
-#!/bin/bash
-set -euo pipefail
-exec 4<>"${SLIST}.txt" 5>"${SLIST}.txt.new"
-flock -n 4
-flock -n 5
-{
-	grep -Fivx -e "${2}" -e "${3}" <&4 || :
-	if [ "${1}" == "SUBSCRIBE" ]; then
-		cat - <<-EOF
-		${2}
-		${3}
-		EOF
-	fi
-} >&5
-mv "${SLIST}.txt.new" "${SLIST}.txt"

+ 14 - 0
tests/test-signup.sh

@@ -30,6 +30,7 @@ EOF
 
 	grep 'You have been registered as a member' reply.out
 	#cat reply.err
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/alist" > "${group}/alist.txt"
 	ls ${group} ; cat ${group}/alist.txt
 	grep -Fx 'Admin' "${group}/alist.txt" #|| cat "${group}/alist.txt" && exit 1
 	grep -Fx 'admin@mail.com' "${group}/alist.txt"
@@ -37,6 +38,7 @@ EOF
 	${SCRIPTDIR}/cropswap-postmaster.sh SUBSCRIBE admin@mail.com <<-EOF 1> reply.out 2> reply.err #|| cat reply.err && exit 1
 	X-GROUP: $group
 	EOF
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep 'Your subscription status has been updated successfully' reply.out
 	grep -Fx 'Admin' "${group}/slist.txt"
 	grep -Fx 'admin@mail.com' "${group}/slist.txt"
@@ -51,6 +53,7 @@ EOF
 	X-GROUP: $group
 	EOF
 	grep 'Your subscription status has been updated successfully' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep -Fvx 'Admin' "${group}/slist.txt" || ! grep -Fxq 'Admin' "${group}/slist.txt"
 	grep -Fvx 'admin@mail.com' "${group}/slist.txt" || ! grep -Fxq 'admin@mail.com' "${group}/slist.txt"
 
@@ -66,6 +69,7 @@ EOF
 	Subject: [SUBSCRIBE]
 	EOF
 	grep 'Your subscription status has been updated successfully' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep -Fx 'Admin' "${group}/slist.txt"
 	grep -Fx 'admin@mail.com' "${group}/slist.txt"
 
@@ -75,6 +79,7 @@ EOF
 	Subject: [SUBSCRIBE]
 	EOF
 	grep 'Your subscription status has been updated successfully' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep -Fx 'Admin' "${group}/slist.txt"
 	grep -Fx 'admin@mail.com' "${group}/slist.txt"
 
@@ -84,6 +89,7 @@ EOF
 	Subject: [UNSUBSCRIBE]
 	EOF
 	grep 'Your subscription status has been updated successfully' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep -Fvx 'Admin' "${group}/slist.txt" || ! grep -Fxq 'Admin' "${group}/slist.txt"
 	grep -Fvx 'admin@mail.com' "${group}/slist.txt" || ! grep -Fxq 'admin@mail.com' "${group}/slist.txt"
 
@@ -93,6 +99,7 @@ EOF
 	Subject: [UNSUBSCRIBE]
 	EOF
 	grep 'Your subscription status has been updated successfully' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep -Fvx 'Admin' "${group}/slist.txt" || ! grep -Fxq 'Admin' "${group}/slist.txt"
 	grep -Fvx 'admin@mail.com' "${group}/slist.txt" || ! grep -Fxq 'admin@mail.com' "${group}/slist.txt"
 
@@ -102,6 +109,7 @@ EOF
 	X-GROUP: $group
 	EOF
 	grep 'You have been registered as a member' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/alist" > "${group}/alist.txt"
 	! grep -Fx 'Non-admin' "${group}/alist.txt"
 	! grep -Fx 'non-admin@mail.com' "${group}/alist.txt"
 
@@ -109,6 +117,7 @@ EOF
 	X-GROUP: $group
 	EOF
 	grep 'Your subscription status has been updated successfully' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep -Fx 'Non-admin' "${group}/slist.txt"
 	grep -Fx 'non-admin@mail.com' "${group}/slist.txt"
 
@@ -122,6 +131,7 @@ EOF
 	X-GROUP: $group
 	EOF
 	grep 'Your subscription status has been updated successfully' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep -Fvx 'Non-admin' "${group}/slist.txt" || ! grep -Fqx 'Non-admin' "${group}/slist.txt"
 	grep -Fvx 'non-admin@mail.com' "${group}/slist.txt" || ! grep -Fqx 'non-admin@mail.com' "${group}/slist.txt"
 
@@ -137,6 +147,7 @@ EOF
 	Subject: [SUBSCRIBE]
 	EOF
 	grep 'Your subscription status has been updated successfully' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep -Fx 'Non-admin' "${group}/slist.txt"
 	grep -Fx 'non-admin@mail.com' "${group}/slist.txt"
 
@@ -146,6 +157,7 @@ EOF
 	Subject: [SUBSCRIBE]
 	EOF
 	grep 'Your subscription status has been updated successfully' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep -Fx 'Non-admin' "${group}/slist.txt"
 	grep -Fx 'non-admin@mail.com' "${group}/slist.txt"
 
@@ -155,6 +167,7 @@ EOF
 	Subject: [UNSUBSCRIBE]
 	EOF
 	grep 'Your subscription status has been updated successfully' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep -Fvx 'Non-admin' "${group}/slist.txt" || ! grep -Fxq 'Non-admin' "${group}/slist.txt"
 	grep -Fvx 'non-admin@mail.com' "${group}/slist.txt" || ! grep -Fxq 'non-admin@mail.com' "${group}/slist.txt"
 
@@ -164,6 +177,7 @@ EOF
 	Subject: [UNSUBSCRIBE]
 	EOF
 	grep 'Your subscription status has been updated successfully' reply.out
+	${SCRIPTDIR}/gdbm-iter-subscribed.py "${group}/mlist" "${group}/slist" > "${group}/slist.txt"
 	grep -Fvx 'Non-admin' "${group}/slist.txt" || ! grep -Fxq 'Non-admin' "${group}/slist.txt"
 	grep -Fvx 'non-admin@mail.com' "${group}/slist.txt" || ! grep -Fxq 'non-admin@mail.com' "${group}/slist.txt"
 done