From 8ad855fef6632e32723242fda554fce04f025036 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 17 Jan 2001 00:27:19 +0000 Subject: Delayed loading of IMAP message parts. * camel-types.h: typedef CamelMessageInfo and CamelMessageContentInfo here * camel-folder-summary.h: Add a "size" field to CamelMessageContentInfo. * camel-folder-summary.c (camel_folder_summary_content_info_new, camel_folder_summary_content_info_free): Renamed and made non-static for providers that construct their own content info. (content_info_load, content_info_save): load/save size * camel-data-wrapper.c (camel_data_wrapper_is_offline): New function to return if a data wrapper's contents are "offline". (So that, for example, we don't make thumbnails of images that haven't been loaded off the IMAP server yet.) Defaults to FALSE. * providers/imap/camel-imap-folder.c (camel_imap_folder_selected): Fix a bug in re-selecting a folder when messages have been expunged from it by another client in the meantime. (imap_get_message): Rewrite. If the message is larger than a certain size, just create a skeleton message containing CamelImapWrappers that will read parts as needed. This way, large attachments only need to be downloaded if the user looks at them, and multipart/alternative alternatives that aren't used will never be downloaded at all. (imap_update_summary): Rewrite this a bunch too to make the parsing more robust. * providers/imap/camel-imap-summary.c (CAMEL_IMAP_SUMMARY_VERSION): bump. (camel_imap_summary_new): Set build_content to TRUE. (content_info_load, content_info_save): Only save/load the content for messages that have it. (The content info gets created as a side effect of imap_get_message.) * providers/imap/camel-imap-utils.c (imap_parse_body): New routine (and helpers) to parse an IMAP 'body' FETCH response and fill in a CamelMessageContentInfo from it. * providers/imap/Makefile.am (libcamelimap_la_SOURCES, libcamelimap_la_HEADERS): add camel-imap-wrapper. svn path=/trunk/; revision=7557 --- camel/camel-folder-summary.c | 53 ++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 17 deletions(-) (limited to 'camel/camel-folder-summary.c') diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c index 8cea0a4666..c948d6865f 100644 --- a/camel/camel-folder-summary.c +++ b/camel/camel-folder-summary.c @@ -807,8 +807,15 @@ CamelMessageInfo *camel_folder_summary_info_new_from_message(CamelFolderSummary return info; } -static void -perform_content_info_free(CamelFolderSummary *s, CamelMessageContentInfo *ci) +/** + * camel_folder_summary_content_info_free: + * @s: + * @ci: + * + * Free the content info @ci, and all associated memory. + **/ +void +camel_folder_summary_content_info_free(CamelFolderSummary *s, CamelMessageContentInfo *ci) { CamelMessageContentInfo *pw, *pn; @@ -816,7 +823,7 @@ perform_content_info_free(CamelFolderSummary *s, CamelMessageContentInfo *ci) ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_free(s, ci); while (pw) { pn = pw->next; - perform_content_info_free(s, pw); + camel_folder_summary_content_info_free(s, pw); pw = pn; } } @@ -851,7 +858,7 @@ void camel_folder_summary_info_free(CamelFolderSummary *s, CamelMessageInfo *mi) ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_free(s, mi); if (s->build_content && ci) { - perform_content_info_free(s, ci); + camel_folder_summary_content_info_free(s, ci); } } @@ -1596,8 +1603,17 @@ camel_folder_summary_info_new(CamelFolderSummary *s) return mi; } -static CamelMessageContentInfo * -content_info_alloc(CamelFolderSummary *s) +/** + * camel_folder_summary_content_info_new: + * @s: + * + * Allocate a new camel message content info, suitable for adding + * to this summary. + * + * Return value: + **/ +CamelMessageContentInfo * +camel_folder_summary_content_info_new(CamelFolderSummary *s) { CamelMessageContentInfo *ci; @@ -1831,7 +1847,7 @@ content_info_new(CamelFolderSummary *s, struct _header_raw *h) { CamelMessageContentInfo *ci; - ci = content_info_alloc(s); + ci = camel_folder_summary_content_info_new(s); ci->id = header_msgid_decode(header_raw_find(&h, "content-id", NULL)); ci->description = header_decode_string(header_raw_find(&h, "content-description", NULL)); @@ -1850,7 +1866,7 @@ content_info_load(CamelFolderSummary *s, FILE *in) io(printf("Loading content info\n")); - ci = content_info_alloc(s); + ci = camel_folder_summary_content_info_new(s); camel_folder_summary_decode_token(in, &type); camel_folder_summary_decode_token(in, &subtype); @@ -1873,6 +1889,8 @@ content_info_load(CamelFolderSummary *s, FILE *in) camel_folder_summary_decode_token(in, &ci->description); camel_folder_summary_decode_token(in, &ci->encoding); + camel_folder_summary_decode_uint32(in, &ci->size); + ci->childs = NULL; return ci; } @@ -1903,7 +1921,8 @@ content_info_save(CamelFolderSummary *s, FILE *out, CamelMessageContentInfo *ci) } camel_folder_summary_encode_token(out, ci->id); camel_folder_summary_encode_token(out, ci->description); - return camel_folder_summary_encode_token(out, ci->encoding); + camel_folder_summary_encode_token(out, ci->encoding); + return camel_folder_summary_encode_uint32(out, ci->size); } static void @@ -2563,10 +2582,10 @@ content_info_dump(CamelMessageContentInfo *ci, int depth) return; } - printf("%sconent-type: %s/%s\n", p, ci->type->type, ci->type->subtype); - printf("%sontent-transfer-encoding: %s\n", p, ci->encoding); + printf("%scontent-type: %s/%s\n", p, ci->type->type, ci->type->subtype); + printf("%scontent-transfer-encoding: %s\n", p, ci->encoding); printf("%scontent-description: %s\n", p, ci->description); - printf("%sbytes: %d %d %d\n", p, (int)ci->pos, (int)ci->bodypos, (int)ci->endpos); + printf("%ssize: %lu\n", p, (unsigned long)ci->size); ci = ci->childs; while (ci) { content_info_dump(ci, depth+1); @@ -2574,7 +2593,7 @@ content_info_dump(CamelMessageContentInfo *ci, int depth) } } -static void +void message_info_dump(CamelMessageInfo *mi) { if (mi == NULL) { @@ -2583,10 +2602,10 @@ message_info_dump(CamelMessageInfo *mi) } printf("Subject: %s\n", camel_message_info_subject(mi)); - printf("To: %s\n", camel_message_info_to(to)); - printf("Cc: %s\n", camel_message_info_cc(cc)); - printf("From: %s\n", camel_message_info_from(from)); - printf("UID: %s\n", camel_message_info_uid(uid)); + printf("To: %s\n", camel_message_info_to(mi)); + printf("Cc: %s\n", camel_message_info_cc(mi)); + printf("From: %s\n", camel_message_info_from(mi)); + printf("UID: %s\n", camel_message_info_uid(mi)); printf("Flags: %04x\n", mi->flags & 0xffff); content_info_dump(mi->content, 0); } -- cgit v1.2.3