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;
 }
 
