fetchmail-friends
[Top] [All Lists]

[fetchmail] [PATCH] Bounce messages

2003-10-23 06:28:33
The attached patch for fetchmail-6.2.5 sends IMHO much better bounce
messages. Changes:

- The SMTP command "MAIL FROM: FETCHMAIL-DAEMON(_at_)(_dot_)(_dot_)(_dot_)" is 
changed to
  "MAIL FROM: <>" as required by RFC 2821

- Removed Return-path: header, as required by RFC 2821

- Changed From:, added Subject: header

- changed the human readable part to be more descriptive and detailed

-- 
Holger Mauermann                           GPG/PGP Key ID: 0x8EA8C301

--- sink.c.orig Sat Oct 11 00:06:36 2003
+++ sink.c      Thu Oct 23 08:55:58 2003
@@ -296,7 +296,7 @@
                           int nerrors, char *errors[])
 /* bounce back an error report a la RFC 1892 */
 {
-    char daemon_name[18 + HOSTLEN] = "FETCHMAIL-DAEMON@";
+    char daemon_name[15 + HOSTLEN] = "MAILER-DAEMON@";
     char boundary[BUFSIZ], *bounce_to;
     int sock;
     static char *fqdn_of_host = NULL;
@@ -329,7 +329,7 @@
     }
 
     if (SMTP_helo(sock, fetchmailhost) != SM_OK
-       || SMTP_from(sock, daemon_name, (char *)NULL) != SM_OK
+       || SMTP_from(sock, "<>", (char *)NULL) != SM_OK
        || SMTP_rcpt(sock, bounce_to) != SM_OK
        || SMTP_data(sock) != SM_OK) 
     {
@@ -351,12 +351,11 @@
        report(stdout, GT_("SMTP: (bounce-message body)\n"));
     else
        /* this will usually go to sylog... */
-       report(stderr, GT_("mail from %s bounced to %s\n"),
-              daemon_name, bounce_to);
+       report(stderr, GT_("mail bounced to %s\n"), bounce_to);
 
     /* bouncemail headers */
-    SockPrintf(sock, "Return-Path: <>\r\n");
-    SockPrintf(sock, "From: %s\r\n", daemon_name);
+    SockPrintf(sock, "Subject: Mail delivery failed: returning message to 
sender\r\n");
+    SockPrintf(sock, "From: Mail Delivery System <%s>\r\n", daemon_name);
     SockPrintf(sock, "To: %s\r\n", bounce_to);
     SockPrintf(sock, "MIME-Version: 1.0\r\n");
     SockPrintf(sock, "Content-Type: multipart/report; 
report-type=delivery-status;\r\n\tboundary=\"%s\"\r\n", boundary);
@@ -366,20 +365,41 @@
     SockPrintf(sock, "--%s\r\n", boundary); 
     SockPrintf(sock,"Content-Type: text/plain\r\n");
     SockPrintf(sock, "\r\n");
-    SockWrite(sock, message, strlen(message));
-    SockPrintf(sock, "\r\n");
+    SockPrintf(sock, "This message was created automatically by mail delivery 
software.\r\n\r\n");
+    SockPrintf(sock, "A message that you sent could not be delivered to one or 
more of its\r\n");
+    SockPrintf(sock, "recipients. This is a permanent error. The following 
address(es) failed:\r\n");
     SockPrintf(sock, "\r\n");
 
     if (nerrors)
     {
        struct idlist   *idp;
        int             nusers;
-       
+       
+        nusers = 0;
+        for (idp = msg->recipients; idp; idp = idp->next)
+        {
+            if (idp->val.status.mark == userclass)
+            {
+                char   *error;
+                SockPrintf(sock, "%s\r\n", rcpt_address (ctl, idp->id, 1));
+                
+                if (nerrors == 1) error = errors[0];
+                else if (nerrors <= nusers)
+                {
+                    SockPrintf(sock, "Internal error: SMTP error count doesn't 
match number of recipients.\r\n");
+                    break;
+                }
+                else error = errors[nusers++];
+                        
+                SockPrintf(sock, "   SMTP error: %s\r\n\r\n", error);
+            }
+        }
+    
        /* RFC1892 part 2 -- machine-readable responses */
        SockPrintf(sock, "--%s\r\n", boundary); 
        SockPrintf(sock,"Content-Type: message/delivery-status\r\n");
        SockPrintf(sock, "\r\n");
-       SockPrintf(sock, "Reporting-MTA: dns; %s\r\n", fetchmailhost);
+       SockPrintf(sock, "Reporting-MTA: dns; %s\r\n", fqdn_of_host);
 
        nusers = 0;
        for (idp = msg->recipients; idp; idp = idp->next)
<Prev in Thread] Current Thread [Next in Thread>
  • [fetchmail] [PATCH] Bounce messages, Holger Mauermann <=