diff options
-rw-r--r-- | camel/ChangeLog | 30 | ||||
-rw-r--r-- | camel/camel-folder-summary.c | 16 | ||||
-rw-r--r-- | camel/camel-internet-address.c | 2 | ||||
-rw-r--r-- | camel/camel-mime-message.c | 65 | ||||
-rw-r--r-- | camel/camel-mime-message.h | 2 | ||||
-rw-r--r-- | camel/camel-mime-utils.c | 22 | ||||
-rw-r--r-- | camel/camel-mime-utils.h | 4 | ||||
-rw-r--r-- | camel/providers/local/camel-mbox-folder.c | 2 | ||||
-rw-r--r-- | camel/providers/local/camel-mbox-summary.c | 70 | ||||
-rw-r--r-- | camel/providers/local/camel-mbox-summary.h | 3 | ||||
-rw-r--r-- | camel/providers/local/camel-spool-summary.h | 2 |
11 files changed, 120 insertions, 98 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 6ffac9feee..6eb8942efe 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,33 @@ +2003-03-20 Dan Winship <danw@ximian.com> + + Handle raw 8-bit From data "correctly". (The same way we handle + raw 8-bit Subject data.) + + * camel-mime-utils.c (header_decode_mailbox): Take a charset arg + and pass it to header_decode_string. + (header_decode_address): Take a charset arg and pass it to + header_decode_mailbox. + (header_mailbox_decode): Likewise. + (header_address_decode): Take a charset arg and pass it to + header_decode_address. + + * camel-folder-summary.c (summary_format_address): Take a charset + arg and pass to header_address_decode. + (message_info_new, camel_message_info_new_from_header): Pass + charset to summary_format_address + + * camel-internet-address.c (internet_decode): Update for + header_address_decode change. (Unfortunately we don't have a + charset to pass here.) + + * camel-mime-message.c (camel_mime_message_build_mbox_from): Move + this here from camel-mbox-summary since the same functionality is + needed by evolution-mail too (and update for header_address_decode + change) + + * providers/local/camel-mbox-summary.c + (camel_mbox_summary_build_from): Moved to CamelMimeMessage + 2003-03-17 Jeffrey Stedfast <fejj@ximian.com> * camel-mime-part.c (process_header): Removed unused variable left diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c index b9645754cb..a66026f0ab 100644 --- a/camel/camel-folder-summary.c +++ b/camel/camel-folder-summary.c @@ -1467,14 +1467,14 @@ static CamelMessageContentInfo * content_info_new_from_message(CamelFolderSummar } static char * -summary_format_address(struct _header_raw *h, const char *name) +summary_format_address(struct _header_raw *h, const char *name, const char *charset) { struct _header_address *addr; const char *text; char *ret; text = header_raw_find (&h, name, NULL); - addr = header_address_decode (text); + addr = header_address_decode (text, charset); if (addr) { ret = header_address_list_format (addr); header_address_list_clear (&addr); @@ -1579,9 +1579,9 @@ message_info_new(CamelFolderSummary *s, struct _header_raw *h) charset = charset ? e_iconv_charset_name (charset) : NULL; subject = summary_format_string(h, "subject", charset); - from = summary_format_address(h, "from"); - to = summary_format_address(h, "to"); - cc = summary_format_address(h, "cc"); + from = summary_format_address(h, "from", charset); + to = summary_format_address(h, "to", charset); + cc = summary_format_address(h, "cc", charset); mlist = header_raw_check_mailing_list(&h); if (ct) @@ -2566,9 +2566,9 @@ camel_message_info_new_from_header (struct _header_raw *header) charset = charset ? e_iconv_charset_name (charset) : NULL; subject = summary_format_string(header, "subject", charset); - from = summary_format_address(header, "from"); - to = summary_format_address(header, "to"); - cc = summary_format_address(header, "cc"); + from = summary_format_address(header, "from", charset); + to = summary_format_address(header, "to", charset); + cc = summary_format_address(header, "cc", charset); date = header_raw_find(&header, "date", NULL); mlist = header_raw_check_mailing_list(&header); diff --git a/camel/camel-internet-address.c b/camel/camel-internet-address.c index 5b741c61ca..80b68ab053 100644 --- a/camel/camel-internet-address.c +++ b/camel/camel-internet-address.c @@ -88,7 +88,7 @@ internet_decode (CamelAddress *a, const char *raw) int count = a->addresses->len; /* Should probably use its own decoder or something */ - ha = header_address_decode(raw); + ha = header_address_decode(raw, NULL); if (ha) { n = ha; while (n) { diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c index aa15eeec5f..5108670104 100644 --- a/camel/camel-mime-message.c +++ b/camel/camel-mime-message.c @@ -901,3 +901,68 @@ camel_mime_message_get_part_by_content_id (CamelMimeMessage *message, const char return check.part; } + +static char *tz_months[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +static char *tz_days[] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" +}; + +char * +camel_mime_message_build_mbox_from (CamelMimeMessage *message) +{ + struct _header_raw *header = ((CamelMimePart *)message)->headers; + GString *out = g_string_new("From "); + char *ret; + const char *tmp; + time_t thetime; + int offset; + struct tm tm; + + tmp = header_raw_find (&header, "Sender", NULL); + if (tmp == NULL) + tmp = header_raw_find (&header, "From", NULL); + if (tmp != NULL) { + struct _header_address *addr = header_address_decode (tmp, NULL); + + tmp = NULL; + if (addr) { + if (addr->type == HEADER_ADDRESS_NAME) { + g_string_append (out, addr->v.addr); + tmp = ""; + } + header_address_unref (addr); + } + } + + if (tmp == NULL) + g_string_append (out, "unknown@nodomain.now.au"); + + /* try use the received header to get the date */ + tmp = header_raw_find (&header, "Received", NULL); + if (tmp) { + tmp = strrchr(tmp, ';'); + if (tmp) + tmp++; + } + + /* if there isn't one, try the Date field */ + if (tmp == NULL) + tmp = header_raw_find (&header, "Date", NULL); + + thetime = header_decode_date (tmp, &offset); + thetime += ((offset / 100) * (60 * 60)) + (offset % 100) * 60; + gmtime_r (&thetime, &tm); + g_string_append_printf (out, " %s %s %2d %02d:%02d:%02d %4d\n", + tz_days[tm.tm_wday], tz_months[tm.tm_mon], + tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, + tm.tm_year + 1900); + + ret = out->str; + g_string_free (out, FALSE); + + return ret; +} diff --git a/camel/camel-mime-message.h b/camel/camel-mime-message.h index 7735cc1775..c1149d5ef5 100644 --- a/camel/camel-mime-message.h +++ b/camel/camel-mime-message.h @@ -131,6 +131,8 @@ void camel_mime_message_encode_8bit_parts (CamelMimeMess CamelMimePart *camel_mime_message_get_part_by_content_id (CamelMimeMessage *message, const char *content_id); +char *camel_mime_message_build_mbox_from (CamelMimeMessage *mime_message); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index 64f28a254f..04fa0e6f90 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -2334,7 +2334,7 @@ header_decode_addrspec(const char **in) */ static struct _header_address * -header_decode_mailbox(const char **in) +header_decode_mailbox(const char **in, const char *charset) { const char *inptr = *in; char *pre; @@ -2356,7 +2356,7 @@ header_decode_mailbox(const char **in) char *text, *last; /* perform internationalised decoding, and append */ - text = header_decode_string (pre, NULL); + text = header_decode_string (pre, charset); g_string_append (name, text); last = pre; g_free(text); @@ -2458,7 +2458,7 @@ header_decode_mailbox(const char **in) g_string_append_c(addr, *inptr); /* check for address is encoded word ... */ - text = header_decode_string(addr->str, NULL); + text = header_decode_string(addr->str, charset); if (name == NULL) { name = addr; addr = g_string_new(""); @@ -2514,7 +2514,7 @@ header_decode_mailbox(const char **in) if (comend > comstart) { d(printf(" looking at subset '%.*s'\n", comend-comstart, comstart)); tmp = g_strndup (comstart, comend-comstart); - text = header_decode_string (tmp, NULL); + text = header_decode_string (tmp, charset); name = g_string_new (text); g_free (tmp); g_free (text); @@ -2537,7 +2537,7 @@ header_decode_mailbox(const char **in) } static struct _header_address * -header_decode_address(const char **in) +header_decode_address(const char **in, const char *charset) { const char *inptr = *in; char *pre; @@ -2562,7 +2562,7 @@ header_decode_address(const char **in) if (*inptr != ';') { int go = TRUE; do { - member = header_decode_mailbox(&inptr); + member = header_decode_mailbox(&inptr, charset); if (member) header_address_add_member(addr, member); header_decode_lwsp(&inptr); @@ -2581,7 +2581,7 @@ header_decode_address(const char **in) } *in = inptr; } else { - addr = header_decode_mailbox(in); + addr = header_decode_mailbox(in, charset); } g_string_free(group, TRUE); @@ -2807,16 +2807,16 @@ header_references_dup(const struct _header_references *list) } struct _header_address * -header_mailbox_decode(const char *in) +header_mailbox_decode(const char *in, const char *charset) { if (in == NULL) return NULL; - return header_decode_mailbox(&in); + return header_decode_mailbox(&in, charset); } struct _header_address * -header_address_decode(const char *in) +header_address_decode(const char *in, const char *charset) { const char *inptr = in, *last; struct _header_address *list = NULL, *addr; @@ -2832,7 +2832,7 @@ header_address_decode(const char *in) do { last = inptr; - addr = header_decode_address(&inptr); + addr = header_decode_address(&inptr, charset); if (addr) header_address_list_append(&list, addr); header_decode_lwsp(&inptr); diff --git a/camel/camel-mime-utils.h b/camel/camel-mime-utils.h index 303f29be07..b949ffcf98 100644 --- a/camel/camel-mime-utils.h +++ b/camel/camel-mime-utils.h @@ -111,8 +111,8 @@ void header_address_list_append_list(struct _header_address **l, struct _header_ void header_address_list_append(struct _header_address **, struct _header_address *); void header_address_list_clear(struct _header_address **); -struct _header_address *header_address_decode(const char *in); -struct _header_address *header_mailbox_decode(const char *in); +struct _header_address *header_address_decode(const char *in, const char *charset); +struct _header_address *header_mailbox_decode(const char *in, const char *charset); /* for mailing */ char *header_address_list_encode(struct _header_address *a); /* for display */ diff --git a/camel/providers/local/camel-mbox-folder.c b/camel/providers/local/camel-mbox-folder.c index e06a63fe47..f5332dc140 100644 --- a/camel/providers/local/camel-mbox-folder.c +++ b/camel/providers/local/camel-mbox-folder.c @@ -233,7 +233,7 @@ mbox_append_message(CamelFolder *folder, CamelMimeMessage * message, const Camel #endif /* we must write this to the non-filtered stream ... */ - fromline = camel_mbox_summary_build_from(((CamelMimePart *)message)->headers); + fromline = camel_mime_message_build_mbox_from(message); if (camel_stream_write(output_stream, fromline, strlen(fromline)) == -1) goto fail_write; diff --git a/camel/providers/local/camel-mbox-summary.c b/camel/providers/local/camel-mbox-summary.c index 42d26e8a5b..27c964f946 100644 --- a/camel/providers/local/camel-mbox-summary.c +++ b/camel/providers/local/camel-mbox-summary.c @@ -496,76 +496,6 @@ mbox_summary_check(CamelLocalSummary *cls, CamelFolderChangeInfo *changes, Camel return ret; } -static char *tz_months[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" -}; - -static char *tz_days[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" -}; - -/* tries to build a From line, based on message headers */ -char * -camel_mbox_summary_build_from(struct _header_raw *header) -{ - GString *out = g_string_new("From "); - char *ret; - const char *tmp; - time_t thetime; - int offset; - struct tm tm; - - tmp = header_raw_find(&header, "Sender", NULL); - if (tmp == NULL) - tmp = header_raw_find(&header, "From", NULL); - if (tmp != NULL) { - struct _header_address *addr = header_address_decode(tmp); - - tmp = NULL; - if (addr) { - if (addr->type == HEADER_ADDRESS_NAME) { - g_string_append(out, addr->v.addr); - tmp = ""; - } - header_address_unref(addr); - } - } - if (tmp == NULL) { - g_string_append(out, "unknown@nodomain.now.au"); - } - - /* try use the received header to get the date */ - tmp = header_raw_find(&header, "Received", NULL); - if (tmp) { - tmp = strrchr(tmp, ';'); - if (tmp) - tmp++; - } - - /* if there isn't one, try the Date field */ - if (tmp == NULL) - tmp = header_raw_find(&header, "Date", NULL); - - thetime = header_decode_date(tmp, &offset); - - thetime += ((offset / 100) * (60 * 60)) + (offset % 100) * 60; - - /* a pseudo, but still bogus attempt at thread safing the function */ - /*memcpy(&tm, gmtime(&thetime), sizeof(tm));*/ - gmtime_r (&thetime, &tm); - - g_string_append_printf (out, " %s %s %2d %02d:%02d:%02d %4d\n", - tz_days[tm.tm_wday], tz_months[tm.tm_mon], - tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, - tm.tm_year + 1900); - - ret = out->str; - g_string_free (out, FALSE); - - return ret; -} - /* perform a full sync */ static int mbox_summary_sync_full(CamelMboxSummary *mbs, gboolean expunge, CamelFolderChangeInfo *changeinfo, CamelException *ex) diff --git a/camel/providers/local/camel-mbox-summary.h b/camel/providers/local/camel-mbox-summary.h index 0588a9a81b..dc64aa23fa 100644 --- a/camel/providers/local/camel-mbox-summary.h +++ b/camel/providers/local/camel-mbox-summary.h @@ -68,9 +68,6 @@ CamelMboxSummary *camel_mbox_summary_new (const char *filename, const char /* do we honour/use xstatus headers, etc */ void camel_mbox_summary_xstatus(CamelMboxSummary *mbs, int state); -/* generate a From line from headers */ -char *camel_mbox_summary_build_from(struct _header_raw *header); - /* build a new mbox from an existing mbox storing summary information */ int camel_mbox_summary_sync_mbox(CamelMboxSummary *cls, guint32 flags, CamelFolderChangeInfo *changeinfo, int fd, int fdout, CamelException *ex); diff --git a/camel/providers/local/camel-spool-summary.h b/camel/providers/local/camel-spool-summary.h index eda6e64fab..7813243a69 100644 --- a/camel/providers/local/camel-spool-summary.h +++ b/camel/providers/local/camel-spool-summary.h @@ -64,8 +64,6 @@ int camel_spool_summary_decode_x_evolution(CamelSpoolSummary *cls, const char *x /* utility functions - write headers to a file with optional X-Evolution header */ int camel_spool_summary_write_headers(int fd, struct _header_raw *header, char *xevline); -/* build a from line: FIXME: remove, or move to common code */ -char *camel_spool_summary_build_from(struct _header_raw *header); #endif /* ! _CAMEL_SPOOL_SUMMARY_H */ |