[PATCH] mime parsing

Paul Bagyenda <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
There is a need for a small change to the way multipart/related MIME  
messages are parsed. Attached patch should help take care of issues  
where the Content-ID for the start element is enclosed in '<' '>'

  Kindly review, etc.

Thanks

P.
mime.diff (application/octet-stream, 1 KB)
Index: gwlib/mime.c
===================================================================
RCS file: /home/cvs/gateway/gwlib/mime.c,v
retrieving revision 1.19
diff -u -r1.19 mime.c
--- gwlib/mime.c	8 Jan 2007 00:08:52 -0000	1.19
+++ gwlib/mime.c	11 Apr 2007 12:41:14 -0000
@@ -316,14 +316,27 @@
 static int cid_matches(List *headers, Octstr *start)
 {
      Octstr *cid = http_header_value(headers, octstr_imm("Content-ID"));
+     char *cid_str;
+     int cid_len;
      int ret;
+
+     if (cid == NULL) 
+         return 0;
+     
+     /* First, strip the <> if any. XXX some mime coders produce such messiness! */
+     cid_str = octstr_get_cstr(cid);
+     cid_len = octstr_len(cid);
+     if (cid_str[0] == '<') {
+         cid_str+=1;
+	 cid_len-=2;
+     }
      if (start != NULL && cid != NULL  && 
-	 octstr_compare(start, cid) == 0) 
+	 (octstr_compare(start, cid) == 0 || octstr_str_ncompare(start, cid_str, cid_len) == 0)) 
 	  ret = 1;
      else 
 	  ret = 0;
-     if (cid)
-	  octstr_destroy(cid);
+
+     octstr_destroy(cid);
      return ret;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.