Browse Source

refactor sendmail script and fix forwarding mail from non-members to organizers

Pi 1 year ago
parent
commit
d238a805c5
4 changed files with 33 additions and 31 deletions
  1. 1 0
      cropswap-resendmail.sh
  2. 29 29
      cropswap-sendmail.sh
  3. 2 2
      filters/cropswap@shandan.one
  4. 1 0
      maildroprc

+ 1 - 0
cropswap-resendmail.sh

@@ -7,6 +7,7 @@ TO="$4"        # to e-mail
 SUBJECT="$5"   # subject flag [SUBJECT]
 MLIST="$6"     # members list
 SLIST="$7"     # subscription list
+REPLYTO="${8:-}" # from e-mail (non-member)
 
 DEBUGMAIL=$(readlink -f "${BASH_SOURCE[0]%/*}/cropswap-debug.sh")
 DEBUG="${DEBUG:=0}"

+ 29 - 29
cropswap-sendmail.sh

@@ -8,16 +8,6 @@ trap cleanup EXIT
 
 cd "${WD}"
 
-declare -A GROUPALIASES=(
-	["cropswap@shandan.one"]="Crop Swap Notices"
-	["cropswap-members@shandan.one"]="Crop Swap Members"
-)
-in_group_aliases(){
-	for key in "${!GROUPALIASES[@]}"; do
-		[ "${key}" == "${1}" ] && return 0
-	done
-	return 1
-}
 CROPSWAPARCHIVE=cropswap-archive@shandan.one
 ITER_SUBS=/opt/cropswap/gdbm-iter-subscriptions.py
 MIME_INJECT=/opt/cropswap/mime-inject.py
@@ -28,30 +18,40 @@ if ((DEBUG != 0)); then
 fi
 
 mk_subject(){
-	subject="$(cat subject)"
+	subject="$(reformail -c -x "Subject:")"
 	if [ "${subject/\[${SUBJECT}\]/}" == "${subject}" ]; then
 		subject="[${SUBJECT}] ${subject## }"
 	fi
 	echo "${subject}"
 }
-
-tee >(reformail -c -x "Subject:" >subject) original | "${MIME_INJECT}" "${MAILGROUP}" | reformime -s1 -e > body
-reformail \
-	-X "Date:" \
-	-X "MIME-Version:" \
-	-X "Subject:" \
-	-X "Content-Type:" \
-< original | reformail \
-	-U "MIME-Version:" \
-	-U "Content-Type:" | reformail \
-	-I "Subject: $(mk_subject)" \
-| if in_group_aliases "${MAILGROUP}"; then reformail \
-	-I "List-Id: $MAILGROUP" \
-	-I "List-Unsubscribe: <mailto:$MAILGROUP?subject=[UNSUBSCRIBE]>" \
-	-I "List-Subscribe: <mailto:$MAILGROUP?subject=[SUBSCRIBE]>" \
-	-I "List-Post: <mailto:$MAILGROUP>" \
-	-I "List-Unsubscribe-Post: List-Unsubscribe=One-Click"
-else cat -; fi | cat - body > mail
+mk_headers(){
+	subject="$(reformail \
+		-X "Date:" \
+		-X "MIME-Version:" \
+		-X "Subject:" \
+		-X "Content-Type:" \
+	| tee >(
+		reformail \
+			-U "MIME-Version:" \
+			-U "Content-Type:" \
+		| mk_list_headers > headers
+	) | mk_subject)"
+	reformail -I "Subject: $subject" < headers
+}
+mk_list_headers(){
+	if [ -n "$REPLYTO" ]; then 
+		reformail -I "Reply-To: $REPLYTO"
+		return
+	fi
+	reformail \
+		-I "List-Id: $MAILGROUP" \
+		-I "List-Unsubscribe: <mailto:$MAILGROUP?subject=[UNSUBSCRIBE]>" \
+		-I "List-Subscribe: <mailto:$MAILGROUP?subject=[SUBSCRIBE]>" \
+		-I "List-Post: <mailto:$MAILGROUP>" \
+		-I "List-Unsubscribe-Post: List-Unsubscribe=One-Click"
+}
+tee >(mk_headers > mail) | "${MIME_INJECT}" "${REPLYTO:-$MAILGROUP}" | reformime -s1 -e > body
+cat body >> mail
 
 declare -A SUBSCRIBED
 declare -a actions

+ 2 - 2
filters/cropswap@shandan.one

@@ -25,7 +25,7 @@ if ($DISPATCH)
       # TODO: test this works at all
       # should at least drop list headers
       SLIST="$LISTDIR/alist"
-      MAILGROUP=$FROM
+      REPLYTO=$FROM
       if (/^From:\s*("(.*)"|(.*))\s*\<.*\>$/)
       {
          ALIAS="$MATCH2$MATCH3"
@@ -50,7 +50,7 @@ if ($DISPATCH)
       # TODO: test this works at all
       # should at least drop list headers
       SLIST="$LISTDIR/alist"
-      MAILGROUP=$FROM
+      REPLYTO=$FROM
       FROM=$ALIAS
       to "!"
    }

+ 1 - 0
maildroprc

@@ -24,6 +24,7 @@ UNREGISTERED=3
 UNSUBSCRIBED=2
 FATAL=1
 
+REPLYTO=""
 MAILGROUP=""
 MAILGROUPALIAS=""