bug-anubis
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-anubis] Howto get all RCPT TO values?


From: Sergey Poznyakoff
Subject: Re: [bug-anubis] Howto get all RCPT TO values?
Date: Tue, 30 Oct 2007 20:50:49 +0200

Benjamin Fleckenstein <address@hidden> ha escrit:

> But it seems that I do only geht the first address of RCPT TO, even when
> I send the mail to multiple recepients.

Yes, it is a known bug of Anubis 4.0.  Technically speaking,the reason
for this behavior is that commands are kept internally in an associative
array, and the search in this array terminates when the first matching
entry is found.  It was made on the assumption that any meaningful two-
part SMTP command is issued once.  However, RCPT TO is just the command
that can lawfully be issued multiple times, and this breaks the logics.

Attached is a patch that I have in my local tree for months.  With this
patch, all RCPT TO values are stored internally as a single
comma-separated string (much like To: or Cc: headers).  So, the effect
of your rule will be:

address@hidden,address@hidden,address@hidden,address@hidden

Hope this will help.

Regards,
Sergey

Index: src/tunnel.c
===================================================================
RCS file: /cvsroot/anubis/anubis/src/tunnel.c,v
retrieving revision 1.51
diff -p -u -r1.51 tunnel.c
--- src/tunnel.c        6 Aug 2007 15:29:24 -0000       1.51
+++ src/tunnel.c        30 Oct 2007 18:37:01 -0000
@@ -412,9 +412,10 @@ smtp_session (void)
 static void
 save_command (MESSAGE * msg, char *line)
 {
-  int i;
-  ASSOC *asc = xmalloc (sizeof (*asc));
-
+  int i, j;
+  ASSOC *asc;
+  int rcpt_to = -1;
+  
   for (i = 0; line[i] && !isspace ((u_char) line[i]); i++)
     ;
 
@@ -424,26 +425,49 @@ save_command (MESSAGE * msg, char *line)
       if (memcmp (line, "mail", 4) == 0)
        expect = " from:";
       else if (memcmp (line, "rcpt", 4) == 0)
-       expect = " to:";
+       {
+         rcpt_to++;
+         expect = " to:";
+       }
+      
       if (expect)
        {
          int n = strlen (expect);
          if (strncmp (&line[i], expect, n) == 0)
-           i += n;
+           {
+             rcpt_to++;
+             i += n;
+           }
        }
     }
 
-  asc->key = xmalloc (i + 1);
-  memcpy (asc->key, line, i);
-  asc->key[i] = 0;
-  for (; line[i] && isspace ((u_char) line[i]); i++)
+  for (j = i; line[j] && isspace ((u_char) line[j]); j++)
     ;
 
-  if (line[i])
-    asc->value = strdup (&line[i]);
+  if (rcpt_to > 0
+      && (asc = list_locate (msg->commands, "rcpt to:", anubis_assoc_cmp)))
+    {
+      size_t vlen = strlen (asc->value);
+      size_t alen = strlen (line + j);
+      size_t len = vlen + 1 + alen;
+      asc->value = xrealloc (asc->value, len + 1);
+      asc->value[vlen++] = ',';
+      memcpy (asc->value + vlen, line + j, alen);
+      asc->value[len] = 0;
+    }
   else
-    asc->value = NULL;
-  list_append (msg->commands, asc);
+    {
+      asc = xmalloc (sizeof (*asc));
+      asc->key = xmalloc (i + 1);
+      memcpy (asc->key, line, i);
+      asc->key[i] = 0;
+      if (line[j])
+       asc->value = strdup (&line[j]);
+      else
+       asc->value = NULL;
+      list_append (msg->commands, asc);
+    }
+  
 }
 
 static int

reply via email to

[Prev in Thread] Current Thread [Next in Thread]