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 21:52:22 +0200

Benjamin Fleckenstein <address@hidden> ha escrit:

> Unfortunately there is a problem with the patch.

Ah, yes.  It was made against CVS, which is quite ahead of 4.0.  Here is
the patch reduced for that version:

diff -pur anubis-4.0/src/tunnel.c anubis-4.0-mod/src/tunnel.c
--- anubis-4.0/src/tunnel.c     2004-12-17 18:52:01.000000000 +0200
+++ anubis-4.0-mod/src/tunnel.c 2007-10-30 21:47:04.000000000 +0200
@@ -403,12 +403,21 @@ smtp_session (void)
   THE MAIL COMMANDS
 *********************/
 
+int
+anubis_assoc_cmp (void *item, void *data)
+{
+  ASSOC *p = item;
+  return strcmp (p->key, data);
+}
+
+
 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++)
     ;
 
@@ -418,26 +427,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

Regards,
Sergey




reply via email to

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