diff options
Diffstat (limited to 'camel/camel-mime-utils.c')
-rw-r--r-- | camel/camel-mime-utils.c | 67 |
1 files changed, 67 insertions, 0 deletions
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) { |