<<< Date Index >>>     <<< Thread Index >>>

[PATCH] Adequately read mailboxes with s/@/ at / obfuscations



 from.c   |  28 ++++++++++++++++++++--------
 rfc822.c |   6 ++++++
 2 files changed, 26 insertions(+), 8 deletions(-)


# HG changeset patch
# User David Champion <dgc@xxxxxxxxxxxx>
# Date 1273031552 18000
# Branch HEAD
# Node ID 850072857e7c86e29a73efc3478b2feabbe01394
# Parent  4cd2daafd03bfe9d8af1fa543baf873cd94e144f
Adequately read mailboxes with s/@/ at / obfuscations.

This handles mbox From_ separators and rfc822 address parsing.

diff -r 4cd2daafd03b -r 850072857e7c from.c
--- a/from.c    Sat Apr 24 16:10:43 2010 -0700
+++ b/from.c    Tue May 04 22:52:32 2010 -0500
@@ -83,20 +83,32 @@
     const char *p;
     size_t len;
     short q = 0;
+    short at = 0;
 
-    for (p = s; *p && (q || !ISSPACE (*p)); p++)
+    p = s;
+    do
     {
-      if (*p == '\\')
+      for ( ; *p && (q || !ISSPACE (*p)); p++)
       {
-       if (*++p == '\0') 
-         return 0;
+        if (*p == '\\')
+        {
+         if (*++p == '\0') 
+           return 0;
+        }
+        else if (*p == '"')
+        {
+         q = !q;
+        }
       }
-      else if (*p == '"')
+
+      at = 0;
+      if (!strncasecmp(p, " at ", 4))
       {
-       q = !q;
+        at = 1;
+        p += 4;
       }
-    }
-    
+    } while (at);
+
     if (q || !*p) return 0;
     
     if (path)
diff -r 4cd2daafd03b -r 850072857e7c rfc822.c
--- a/rfc822.c  Sat Apr 24 16:10:43 2010 -0700
+++ b/rfc822.c  Tue May 04 22:52:32 2010 -0500
@@ -245,6 +245,12 @@
       ps = next_token (s, mailbox, mailboxlen, mailboxmax);
     if (!ps)
       return NULL;
+    if (!strncasecmp(ps, " at ", 4))
+    {
+      if (*mailboxlen < mailboxmax)
+        mailbox[(*mailboxlen)++] = '@';
+      ps += 4;
+    }
     s = ps;
   }