*snip*

Fixed infinite loop where sender = recipient

Eric
diff -Naur dbmail-1.2.8a/pipe.c dbmail-1.2.8a-efung/pipe.c
--- dbmail-1.2.8a/pipe.c        2004-06-09 00:01:35.000000000 +1000
+++ dbmail-1.2.8a-efung/pipe.c  2004-06-11 15:01:07.000000000 +1000
@@ -150,6 +150,8 @@
   char *reply_body, *notify_address;
   FILE *instream = stdin;
   field_t val;
+  struct mime_record *delivered_to;
+  struct element *delivered_to_el;
 
   /* step 1.
      inserting first message
@@ -468,7 +470,56 @@
                        trace(TRACE_DEBUG, "insert_messages(): no reply body 
specified, skipping auto-reply");
                      else
                        {
+                         /*
+                          *   Requires:
+                          *      userid = full realm email address
+                          *  
+                          *   Assumptions:
+                          *      MIME_VALUE_MAX > column size of users.userid
+                          *
+                          *   Thoughts:
+                          *      Added Delivered-To Mime block into mime list 
as a temporary fix for
+                          *      missing Auto Reply From: Fields
+                          *      Delivered-to: header should be supplied by 
MDA which this is
+                          *      There isn't an easy way to do this in the 
current architecture
+                          *      As Alias->Username is many-to-one
+                          *      No memory is non fatal for this code.
+                          *
+                          *   Suggested Future Implementation:
+                          *      Add Delivered-To for each message inserted
+                          *      However this will probably require a re-write 
of insert-messages()
+                          *      Due to alias information being lost during 
insertion of each message
+                          *      Then re-read each message header to 
regenerate headerfields
+                          */
+                         delivered_to  = (struct mime_record 
*)my_malloc(sizeof(struct mime_record));
+
+                         if (!delivered_to)
+                            {
+                               trace(TRACE_ERROR, "insert_messages(): out of 
memory for delivered-to\n");
+                            }
+                         else
+                            {
+                               strcpy(delivered_to->field, "Delivered-To");
+                               strcpy(delivered_to->value, 
auth_get_userid(&bounce_userid));
+                               if ( 
!list_nodeadd(headerfields,delivered_to,sizeof (*delivered_to)))
+                                  {
+                                     trace(TRACE_ERROR, "insert_messages(): 
cannot add element to list\n");
+                                     my_free(delivered_to);
+                                     delivered_to      = NULL;
+                                  }
+                            }
                          send_reply(headerfields, reply_body);
+
+                         if (!delivered_to)
+                            {
+                               delivered_to_el = list_nodepop(headerfields);
+                               delivered_to    = delivered_to_el->data;
+                               my_free(delivered_to);
+                               delivered_to    = NULL;
+                               my_free(delivered_to_el);
+                               delivered_to_el = NULL;
+                            }
+
                          my_free(reply_body);
                        }
                    }
@@ -649,7 +700,19 @@
          subject = record->value;
          trace(TRACE_DEBUG, "send_reply(): found SUBJECT [%s]", subject);
        }
-      else if  (strcasecmp(record->field, "deliver-to") == 0)
+      /*
+       *   Multiple Delivered-To Headers
+       *   If a Delivered-To address is already in place, ignore.
+       *   Internal mime record will always be popped first
+       *   But old record kept in place in case of non-fatal error adding
+       *   Internal record
+       */
+      else if  (strcasecmp(record->field, "delivered-to") == 0 && to == NULL)
+       {
+         to = record->value;
+         trace(TRACE_DEBUG, "send_reply(): found DELIVERED-TO [%s]", to);
+       }
+      else if  (strcasecmp(record->field, "deliver-to") == 0 && to == NULL)
        {
          to = record->value;
          trace(TRACE_DEBUG, "send_reply(): found TO [%s]", to);
@@ -664,6 +727,11 @@
       my_free(sendmail);
       return 0;
     }
+  else if ( (replyto && strcasecmp(replyto, to) == 0) || (from && 
strcasecmp(from, to) == 0) )
+    {
+      trace(TRACE_DEBUG, "send_reply(): recipient is the same as sender, 
aborting");
+      return 0;
+    }
 
   
   trace(TRACE_DEBUG, "send_reply(): header fields scanned; opening pipe to 
sendmail");

Reply via email to