X-Git-Url: https://git.madduck.net/etc/mailfilter.git/blobdiff_plain/4ba2f39737ab0344a5b1d0ab05dd1743a3f98dd0..b9d8d8cd7d90da7e14d72ed0bf6d1054f2ce3f5c:/procmail/get-msgid

diff --git a/procmail/get-msgid b/procmail/get-msgid
index 3639f51..02b10b1 100644
--- a/procmail/get-msgid
+++ b/procmail/get-msgid
@@ -1,25 +1,34 @@
 :0
-* ^Message-Id:[ 	]*\/[^ 	]+
+*$ ^Message-Id:$RE_SPACE*\/$RE_NOT_SPACE+
 { MSGID="$MATCH" }
 
 :0
-* MSGID ?? ^[ 	]*$|^<>$
+*$ MSGID ?? ^$RE_SPACE*$|^<>$
 {
-  TMPFILE="`tempfile -p msgid`"
-  LOG="get-msgid:   LACKING MSGID header, DUMPING to $TMPFILE (@$OURDATE)$NL"
+  :0
+  *$ ^Resent-Message-Id:$RE_SPACE*\/$RE_NOT_SPACE+
+  {
+    LOGLATER="get-msgid:   lacking message-id, using resent-message-id...$NL"
+    :0 fw
+    |$FORMAIL -R Resent-Message-ID Message-ID
+  }
 
-  :0 ifw
-  |cat > $TMPFILE
+  :0 E
+  {
+    LOGLATER="get-msgid:   lacking message-id, generating one...$NL"
+    :0 fw
+    |$FORMAIL -a Message-ID:
+  }
 
-  EX_DEFER=75
-  EXITCODE=$EX_DEFER
-  HOST
+  :0
+  *$ ^Message-Id:$RE_EXTRACT_HEADER_VALUE
+  { MSGID="$MATCH" }
 }
 
 :0
 * ! MSGID ?? ^<[^>]+>$
 {
-  LOG="get-msgid:   message-id '$MSGID' not enclosed in <>, fixing it...$NL"
+  LOGLATER="get-msgid:   message-id '$MSGID' not enclosed in <>, fixing it...$NL"
   MSGID="<$MSGID>"
 }
 
@@ -27,13 +36,8 @@
 *$ MSGID ?? .+@$RE_MAILRELAYS>
 *$ !^Return-Path: .+@$RE_MAILRELAYS\>
 *$ !^Received: by $RE_MAILRELAYS \(postfix, from userid
+* MSGID ?? ^<\/[^>]+
 {
-  LOG="get-msgid:   missing message ID added by one of our mail relays$NL"
-
-  :0 fw
-  |$SED -re "s/^([Mm]essage-[Ii][Dd]:[^@]+@$RE_MAILRELAYS)\>/\1.MSGID-ADDED/"
-
-  :0
-  * ^Message-Id:[ 	]*\/[^ 	]+
-  { MSGID="$MATCH" }
+  LOGLATER="get-msgid:   missing message ID added by one of our mail relays$NL"
+  MSGID="<${MATCH}.MSGID-ADDED>"
 }