diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2003-03-15 01:44:20 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2003-03-15 01:44:20 +0800 |
commit | 1df1d4aead3ebacf457f637c6df2a5e8539b7fbf (patch) | |
tree | 0d31b8877fc39052b20abc8434018ecaa1ef63c9 | |
parent | 0b82cc7a34271a145a45ff7f296304e19a9315cc (diff) | |
download | gsoc2013-evolution-1df1d4aead3ebacf457f637c6df2a5e8539b7fbf.tar.gz gsoc2013-evolution-1df1d4aead3ebacf457f637c6df2a5e8539b7fbf.tar.zst gsoc2013-evolution-1df1d4aead3ebacf457f637c6df2a5e8539b7fbf.zip |
Use header_contentid_decode() as this new function should be safer than
2003-03-13 Jeffrey Stedfast <fejj@ximian.com>
* camel-mime-part.c (process_header): Use
header_contentid_decode() as this new function should be safer
than the hack that we had before.
* camel-mime-utils.c (header_contentid_decode): New function to
try and parse a content-id string in such a way as to work around
some of the known bugs in other MIME implementations. Try to be as
"safe" as we can - ie. don't allow for more than 1 @ (since the
mailer uses "@@@%d" as a fake content-id value for parts without
content-ids) and don't allow for invalid content-type chars.
svn path=/trunk/; revision=20295
-rw-r--r-- | camel/ChangeLog | 13 | ||||
-rw-r--r-- | camel/camel-mime-part.c | 16 | ||||
-rw-r--r-- | camel/camel-mime-utils.c | 67 | ||||
-rw-r--r-- | camel/camel-mime-utils.h | 1 |
4 files changed, 82 insertions, 15 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 9785e0dbcf..c94f27a563 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,5 +1,18 @@ 2003-03-13 Jeffrey Stedfast <fejj@ximian.com> + * camel-mime-part.c (process_header): Use + header_contentid_decode() as this new function should be safer + than the hack that we had before. + + * camel-mime-utils.c (header_contentid_decode): New function to + try and parse a content-id string in such a way as to work around + some of the known bugs in other MIME implementations. Try to be as + "safe" as we can - ie. don't allow for more than 1 @ (since the + mailer uses "@@@%d" as a fake content-id value for parts without + content-ids) and don't allow for invalid content-type chars. + +2003-03-13 Jeffrey Stedfast <fejj@ximian.com> + * camel-folder.c (get_uids): Don't add bogus uids to the uid array. Might fix bug #38868 (it's the only way I can figure that camel_folder_get_message_info() could possibly return NULL for the diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index 11a024218b..ad09728c5f 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -234,21 +234,7 @@ process_header(CamelMedium *medium, const char *header_name, const char *header_ break; case HEADER_CONTENT_ID: g_free (mime_part->content_id); - if (!(mime_part->content_id = header_msgid_decode (header_value))) { - while (*header_value && strchr (" \t\r\n", *header_value)) - header_value++; - if (*header_value == '<') { - p = header_value; - while (*p && *p != '>') - p++; - mime_part->content_id = g_strndup (header_value, p - header_value); - } else if (*header_value) { - mime_part->content_id = g_strdup (header_value); - } - - if (mime_part->content_id) - g_strstrip (mime_part->content_id); - } + mime_part->content_id = header_contentid_decode (header_value); break; case HEADER_ENCODING: text = header_token_decode (header_value); diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index 9513d920e3..64f28a254f 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -2629,6 +2629,73 @@ header_msgid_decode(const char *in) return header_msgid_decode_internal(&in); } +char * +header_contentid_decode (const char *in) +{ + const char *inptr = in; + gboolean at = FALSE; + GString *addr; + char *buf; + + d(printf("decoding Content-ID: '%s'\n", in)); + + header_decode_lwsp (&inptr); + + /* some lame mailers quote the Content-Id */ + if (*inptr == '"') + inptr++; + + /* make sure the content-id is not "" which can happen if we get a + * content-id such as <.@> (which Eudora likes to use...) */ + if ((buf = header_msgid_decode (inptr)) != NULL && *buf) + return buf; + + g_free (buf); + + /* ugh, not a valid msg-id - try to get something useful out of it then? */ + inptr = in; + header_decode_lwsp (&inptr); + if (*inptr == '<') { + inptr++; + header_decode_lwsp (&inptr); + } + + /* Eudora has been known to use <.@> as a content-id */ + if (!(buf = header_decode_word (&inptr)) && !strchr (".@", *inptr)) + return NULL; + + addr = g_string_new (""); + header_decode_lwsp (&inptr); + while (buf != NULL || *inptr == '.' || (*inptr == '@' && !at)) { + if (buf != NULL) { + g_string_append (addr, buf); + g_free (buf); + buf = NULL; + } + + if (!at) { + if (*inptr == '.') { + g_string_append_c (addr, *inptr++); + buf = header_decode_word (&inptr); + } else if (*inptr == '@') { + g_string_append_c (addr, *inptr++); + buf = header_decode_word (&inptr); + at = TRUE; + } + } else if (strchr (".[]", *inptr)) { + g_string_append_c (addr, *inptr++); + buf = header_decode_atom (&inptr); + } + + header_decode_lwsp (&inptr); + } + + buf = addr->str; + g_string_free (addr, FALSE); + + return buf; +} + void header_references_list_append_asis(struct _header_references **list, char *ref) { diff --git a/camel/camel-mime-utils.h b/camel/camel-mime-utils.h index 91d1d71553..303f29be07 100644 --- a/camel/camel-mime-utils.h +++ b/camel/camel-mime-utils.h @@ -184,6 +184,7 @@ char *header_format_date (time_t time, int offset); /* decode a message id */ char *header_msgid_decode (const char *in); +char *header_contentid_decode (const char *in); /* generate msg id */ char *header_msgid_generate (void); |