Browse Source

simplify some insanely overly complex logic

Pi 1 year ago
parent
commit
8bd0476291
3 changed files with 20 additions and 35 deletions
  1. 3 14
      cropswap-postmaster.sh
  2. 17 16
      filters/postmaster@localhost
  3. 0 5
      filters/subscriptions

+ 3 - 14
cropswap-postmaster.sh

@@ -3,27 +3,16 @@ set -euo pipefail
 ACTION="$1"
 FROM="$2"
 
-if [ "$ACTION" == "SIGNUP" ]; then
-	TO=postmaster@localhost
-	HEADER="$(cat <<EOF
-$(cat -)
-EOF
-)"
-else
-	TO=$(cat - | formail -X 'X-GROUP')
-	HEADER="X-IGNORED:"
-fi
-
 #
 # Ideally, FROM should be "postmaster" or "root" or something
-# but to keep the logic (at this time) simpler
+# but to keep the logic (at this time) simpler,
 # I impersonate the user
 #
 # However, the origin of these e-mails are still disambiguated
 # by the "From: " header
 maildrop -f "$FROM" <<EOF
 From: postmaster@localhost
-To: ${TO}
+To: postmaster@localhost
 Subject: [${ACTION}]
-${HEADER}
+$(cat -)
 EOF

+ 17 - 16
filters/postmaster@localhost

@@ -1,24 +1,25 @@
 SIGNUPRESP="/opt/cropswap/signup.eml"
 if (!$CONTINUE)
 {
-   if (/^Subject:\s*\[SIGNUP\]\s*$/)
+   if (/^X\-GROUP:\s*($ANYGROUPREGEX)\s*$/)
    {
-      TOPOSTMASTER=1
-      CONTINUE=1
-   }
-   if (/^X\-GROUP:\s*($ORGANIZERGROUPREGEX)\s*$/)
-   {
-      TOORGANIZER=1
-      MAILGROUP=$MATCH1
-   }
-   if (/^X\-GROUP:\s*($MEMBERGROUPREGEX)\s*$/)
-   {
-      TOMEMBER=1
       MAILGROUP=$MATCH1
-   }
-   if (/^X\-GROUP\-ALIAS:\s*(.*)\s*$/)
-   {
-      MAILGROUPALIAS=$MATCH1
+      if (/^Subject:\s*\[SIGNUP\]\s*$/)
+      {
+         if (/^X\-GROUP\-ALIAS:\s*(.*)\s*$/)
+         {
+            MAILGROUPALIAS=$MATCH1
+         }
+         TOPOSTMASTER=1
+         CONTINUE=1
+      }
+      elsif (/^Subject:\s*\[(SUBSCRIBE|UNSUBSCRIBE)\]\s*$/)
+      {
+         SUBSCRIBE=$MATCH1
+      }
+      TOORGANIZER=($TOORGANIZER || ($MAILGROUP eq $ORGANIZERGROUP))
+      TOMEMBER=($TOMEMBER || ($MAILGROUP eq $MEMBERGROUP))
+      CONTINUE=1
    }
 }
 elsif ($CONTINUE)

+ 0 - 5
filters/subscriptions

@@ -1,10 +1,5 @@
 SUBSCRIBERESP="/opt/cropswap/subunsub.eml"
 gdbmopen($SLIST, "C")
-if (/^Subject:\s*\[(SUBSCRIBE|UNSUBSCRIBE)\]\s*$/)
-{
-   SUBSCRIBE=$MATCH1
-}
-
 if ($SUBSCRIBE ne "")
 {
    if (gdbmstore(tolower($FROM), $SUBSCRIBE) == 0)