Problems with some MIME messages (cyrus-imapd-2.1.9)

Ralf Haferkamp rhafer at suse.de
Thu Nov 21 10:29:01 EST 2002


Hi,

we encountered problems with some multipart MIME mails. It seems, that
cyrus-imapd fails to correctly seperate the different parts of mail under
certain circumstances. This e.g. the case if one MIME part of the mail
contains a multipart/alternative part, that has a boundary which contains
the boundary of the enclousing MIME part as a substring. I guess I better
give an example here: ;)

Let's say the header contains this:

    Received: from localhost (localhost [127.0.0.1])
        by ************* (Postfix on SuSE Linux eMail Server 3.1)
    with ESMTP id B580FE2DC
        for ******************; Tue, 19 Nov 2002 10:42:50 +0100 (CET)
    Content-Type: multipart/mixed;
        boundary="=====================_9011728==_"
    Date: Tue, 19 Nov 2002 10:42:03 +0100
    From: ****************

And the first mime part looks like this:
    --=====================_9011728==_
    Content-Type: multipart/alternative;
        boundary="=====================_9011728==_.ALT"
    
    --=====================_9011728==_.ALT
    Content-Type: text/plain; charset="iso-8859-1"; format=flowed
    Content-Transfer-Encoding: quoted-printable
    ...
    --=====================_9011728==_.ALT
    Content-Type: text/html; charset="iso-8859-1"
    Content-Transfer-Encoding: quoted-printable
    ...
    --=====================_9011728==_.ALT--

And after that follows a second part:
    --=====================_9011728==_
    ...
    --=====================_9011728==_--

Because the boundary of the enclosed multipart/alternative part contains
the same string as the surrounding boundary (+ the string ".ALT")
cyrus-imapd is not able to correctly parse the mail. 

It seems that some versions of Eudora created such boundary strings.

The attached patch should fix this problem. BTW: is this the right list to
send patches to or does there exist a mailinglist better suited for this?

-- 
Ralf Haferkamp

SuSE Linux AG                                    - The Linux Experts -
Deutschherrnstrasse 15-19                         http://www.suse.com
D-90429 Nuernberg, Germany                        Tel: +49-911-74053-0
-------------- next part --------------
--- imap/message.c	2002/11/21 13:07:39	1.1
+++ imap/message.c	2002/11/21 13:11:04
@@ -1699,13 +1699,27 @@
 char **boundaries;
 int *boundaryct;
 {
-    int i, len;
-
+    int i, len,slen;
+    char *end;
+    
     if (s[0] != '-' || s[1] != '-') return(0);
     s+=2;
 
+    slen=0;
+    end = strchr(s, '\r');
+    if(end){
+        slen = end - s;
+	if( ( *(end-1) == '-') && (*(end-2) == '-')){
+	    slen -=2 ;
+	}
+    }
     for (i=0; i < *boundaryct; ++i) {
 	len = strlen(boundaries[i]);
+	/* s might contain a boundaries[i] as a substring. So use the 
+	   length of s if it is longer than len */
+	if (slen > len){
+	    len=slen;
+	}
         if (!strncmp(s, boundaries[i], len)) {
             if (s[len] == '-' && s[len+1] == '-') *boundaryct = i;
             return(1);


More information about the Info-cyrus mailing list