diff options
author | Not Zed <NotZed@HelixCode.com> | 2000-08-11 00:35:28 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2000-08-11 00:35:28 +0800 |
commit | 690509bf826bc02af09cbec064f1f34c48dd9b0c (patch) | |
tree | 41580cd68f0f3e0dc297f11e34e237c37b2dc09e /camel/providers/mbox/camel-mbox-summary.c | |
parent | 544eb3c3493bfa25d6a3a82d1c18805174c37eb9 (diff) | |
download | gsoc2013-evolution-690509bf826bc02af09cbec064f1f34c48dd9b0c.tar gsoc2013-evolution-690509bf826bc02af09cbec064f1f34c48dd9b0c.tar.gz gsoc2013-evolution-690509bf826bc02af09cbec064f1f34c48dd9b0c.tar.bz2 gsoc2013-evolution-690509bf826bc02af09cbec064f1f34c48dd9b0c.tar.lz gsoc2013-evolution-690509bf826bc02af09cbec064f1f34c48dd9b0c.tar.xz gsoc2013-evolution-690509bf826bc02af09cbec064f1f34c48dd9b0c.tar.zst gsoc2013-evolution-690509bf826bc02af09cbec064f1f34c48dd9b0c.zip |
A better way to compress leading whitespace. The code is probably invalid
2000-08-11 Not Zed <NotZed@HelixCode.com>
* camel-mime-parser.c (folder_scan_header): A better way to
compress leading whitespace. The code is probably invalid anyway,
I dont think it will work across buffer boundaries.
* providers/mbox/camel-mbox-folder.c (mbox_append_message): And
write out proper format From lines here too.
* providers/mbox/camel-mbox-summary.c
(camel_mbox_summary_build_from): New function to build a more
compatible mbox "From " line.
(camel_mbox_summary_sync): Write From lines in the proper format.
2000-08-10 Not Zed <NotZed@HelixCode.com>
* providers/mh/camel-mh-store.c (get_folder): Remove warnin g.
* providers/mbox/camel-mbox-store.c (xrename): Kill some warnings
with constification.
* providers/imap/camel-imap-folder.c (imap_append_message): Fixed
for append api change. Eek this routine seriously wastes memory.
* providers/mh/camel-mh-folder.c (mh_search_free): Impelemnt.
(mh_append_message): Fix for api change, and include user flags
and tags in new message.
* providers/vee/camel-vee-folder.c (vee_search_by_expression): Fix
for search api change.
* camel-folder.c (camel_folder_search_free): New function for
freeing search results.
(search_free): Changed my mind, implement a default that actually
does something. Free as to the old interface.
(camel_folder_append_message): Changed to accept a
camelmessageinfo rather than flags, which just doesn't have enough
info in it.
(copy_message_to): Change for append_message api change.
(move_message_to): Likewise.
* providers/mbox/camel-mbox-folder.c (mbox_search_free):
Implement.
(mbox_append_message): Fix for api change, and also copy user
flags/tags across to new summary.
* camel-folder-search.c (search_user_tag): A search expression
that returns the current use flag by name.
(camel_folder_search_free_result): New function to free the result
of a search.
* camel-folder-summary.c: Bump summary version.
(message_info_new):
(message_info_load):
(message_info_save):
(camel_message_info_dup_to):
(camel_message_info_free): Added support for arbitrary tag/value
pairs (CamelTag's).
(camel_tag_get):
(camel_tag_set):
(camel_tag_list_size):
(camel_tag_list_free): Operations for working with CamelTags.
svn path=/trunk/; revision=4683
Diffstat (limited to 'camel/providers/mbox/camel-mbox-summary.c')
-rw-r--r-- | camel/providers/mbox/camel-mbox-summary.c | 676 |
1 files changed, 366 insertions, 310 deletions
diff --git a/camel/providers/mbox/camel-mbox-summary.c b/camel/providers/mbox/camel-mbox-summary.c index 4c826dbc28..fc1eacafe7 100644 --- a/camel/providers/mbox/camel-mbox-summary.c +++ b/camel/providers/mbox/camel-mbox-summary.c @@ -40,18 +40,19 @@ struct _CamelMboxSummaryPrivate { #define _PRIVATE(o) (((CamelMboxSummary *)(o))->priv) -static int summary_header_load (CamelFolderSummary *, FILE *); -static int summary_header_save (CamelFolderSummary *, FILE *); +static int summary_header_load(CamelFolderSummary *, FILE *); +static int summary_header_save(CamelFolderSummary *, FILE *); + +static CamelMessageInfo *message_info_new(CamelFolderSummary *, struct _header_raw *); +static CamelMessageInfo *message_info_new_from_parser(CamelFolderSummary *, CamelMimeParser *); +static CamelMessageInfo *message_info_load(CamelFolderSummary *, FILE *); +static int message_info_save(CamelFolderSummary *, FILE *, CamelMessageInfo *); -static CamelMessageInfo * message_info_new (CamelFolderSummary *, struct _header_raw *); -static CamelMessageInfo * message_info_new_from_parser (CamelFolderSummary *, CamelMimeParser *); -static CamelMessageInfo * message_info_load (CamelFolderSummary *, FILE *); -static int message_info_save (CamelFolderSummary *, FILE *, CamelMessageInfo *); /*static void message_info_free (CamelFolderSummary *, CamelMessageInfo *);*/ -static void camel_mbox_summary_class_init (CamelMboxSummaryClass *klass); -static void camel_mbox_summary_init (CamelMboxSummary *obj); -static void camel_mbox_summary_finalise (GtkObject *obj); +static void camel_mbox_summary_class_init(CamelMboxSummaryClass * klass); +static void camel_mbox_summary_init(CamelMboxSummary *obj); +static void camel_mbox_summary_finalise(GtkObject * obj); static CamelFolderSummaryClass *camel_mbox_summary_parent; @@ -61,52 +62,51 @@ enum SIGNALS { static guint signals[LAST_SIGNAL] = { 0 }; -guint -camel_mbox_summary_get_type (void) +guint camel_mbox_summary_get_type(void) { static guint type = 0; - + if (!type) { GtkTypeInfo type_info = { "CamelMboxSummary", - sizeof (CamelMboxSummary), - sizeof (CamelMboxSummaryClass), + sizeof(CamelMboxSummary), + sizeof(CamelMboxSummaryClass), (GtkClassInitFunc) camel_mbox_summary_class_init, (GtkObjectInitFunc) camel_mbox_summary_init, (GtkArgSetFunc) NULL, (GtkArgGetFunc) NULL }; - - type = gtk_type_unique (camel_folder_summary_get_type (), &type_info); + + type = gtk_type_unique(camel_folder_summary_get_type(), &type_info); } - + return type; } static void -camel_mbox_summary_class_init (CamelMboxSummaryClass *klass) +camel_mbox_summary_class_init(CamelMboxSummaryClass * klass) { GtkObjectClass *object_class = (GtkObjectClass *) klass; CamelFolderSummaryClass *sklass = (CamelFolderSummaryClass *) klass; - - camel_mbox_summary_parent = gtk_type_class (camel_folder_summary_get_type ()); + + camel_mbox_summary_parent = gtk_type_class(camel_folder_summary_get_type()); object_class->finalize = camel_mbox_summary_finalise; sklass->summary_header_load = summary_header_load; sklass->summary_header_save = summary_header_save; - sklass->message_info_new = message_info_new; + sklass->message_info_new = message_info_new; sklass->message_info_new_from_parser = message_info_new_from_parser; sklass->message_info_load = message_info_load; sklass->message_info_save = message_info_save; - /*sklass->message_info_free = message_info_free;*/ + /*sklass->message_info_free = message_info_free; */ - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); + gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL); } static void -camel_mbox_summary_init (CamelMboxSummary *obj) +camel_mbox_summary_init(CamelMboxSummary *obj) { struct _CamelMboxSummaryPrivate *p; struct _CamelFolderSummary *s = (CamelFolderSummary *)obj; @@ -122,13 +122,13 @@ camel_mbox_summary_init (CamelMboxSummary *obj) } static void -camel_mbox_summary_finalise (GtkObject *obj) +camel_mbox_summary_finalise(GtkObject * obj) { - CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (obj); + CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(obj); - g_free (mbs->folder_path); + g_free(mbs->folder_path); - ((GtkObjectClass *)(camel_mbox_summary_parent))->finalize(GTK_OBJECT (obj)); + ((GtkObjectClass *) (camel_mbox_summary_parent))->finalize(GTK_OBJECT(obj)); } /** @@ -139,204 +139,203 @@ camel_mbox_summary_finalise (GtkObject *obj) * Return value: A new CamelMboxSummary widget. **/ CamelMboxSummary * -camel_mbox_summary_new (const char *filename, const char *mbox_name, ibex *index) +camel_mbox_summary_new(const char *filename, const char *mbox_name, ibex * index) { - CamelMboxSummary *new = CAMEL_MBOX_SUMMARY (gtk_type_new (camel_mbox_summary_get_type ())); - + CamelMboxSummary *new = CAMEL_MBOX_SUMMARY(gtk_type_new(camel_mbox_summary_get_type())); + if (new) { /* ?? */ - camel_folder_summary_set_build_content (CAMEL_FOLDER_SUMMARY (new), TRUE); - camel_folder_summary_set_filename (CAMEL_FOLDER_SUMMARY (new), filename); - new->folder_path = g_strdup (mbox_name); + camel_folder_summary_set_build_content(CAMEL_FOLDER_SUMMARY(new), TRUE); + camel_folder_summary_set_filename(CAMEL_FOLDER_SUMMARY(new), filename); + new->folder_path = g_strdup(mbox_name); new->index = index; } return new; } static int -summary_header_load (CamelFolderSummary *s, FILE *in) +summary_header_load(CamelFolderSummary *s, FILE * in) { - CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (s); + CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(s); - if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_load (s, in) == -1) + if (((CamelFolderSummaryClass *) camel_mbox_summary_parent)->summary_header_load(s, in) == -1) return -1; - return camel_folder_summary_decode_uint32 (in, &mbs->folder_size); + return camel_folder_summary_decode_uint32(in, &mbs->folder_size); } static int -summary_header_save (CamelFolderSummary *s, FILE *out) +summary_header_save(CamelFolderSummary *s, FILE * out) { - CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (s); + CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(s); - if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_save (s, out) == -1) + if (((CamelFolderSummaryClass *) camel_mbox_summary_parent)->summary_header_save(s, out) == -1) return -1; - return camel_folder_summary_encode_uint32 (out, mbs->folder_size); + return camel_folder_summary_encode_uint32(out, mbs->folder_size); } static int -header_evolution_decode (const char *in, guint32 *uid, guint32 *flags) +header_evolution_decode(const char *in, guint32 * uid, guint32 * flags) { - char *header; - - if (in && (header = header_token_decode(in))) { - if (strlen (header) == strlen ("00000000-0000") - && sscanf (header, "%08x-%04x", uid, flags) == 2) { - g_free (header); - return *uid; - } - g_free (header); - } - - return -1; + char *header; + + if (in && (header = header_token_decode(in))) { + if (strlen(header) == strlen("00000000-0000") + && sscanf(header, "%08x-%04x", uid, flags) == 2) { + g_free(header); + return *uid; + } + g_free(header); + } + + return -1; } static char * -header_evolution_encode (guint32 uid, guint32 flags) +header_evolution_encode(guint32 uid, guint32 flags) { - return g_strdup_printf ("%08x-%04x", uid, flags & 0xffff); + return g_strdup_printf("%08x-%04x", uid, flags & 0xffff); } static CamelMessageInfo * -message_info_new (CamelFolderSummary *s, struct _header_raw *h) +message_info_new(CamelFolderSummary *s, struct _header_raw *h) { CamelMessageInfo *mi; - mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new (s, h); + mi = ((CamelFolderSummaryClass *) camel_mbox_summary_parent)->message_info_new(s, h); if (mi) { const char *xev; guint32 uid, flags; - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; + CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *) mi; - xev = header_raw_find (&h, "X-Evolution", NULL); + xev = header_raw_find(&h, "X-Evolution", NULL); if (xev && header_evolution_decode(xev, &uid, &flags) != -1) { - g_free (mi->uid); - mi->uid = g_strdup_printf ("%u", uid); + g_free(mi->uid); + mi->uid = g_strdup_printf("%u", uid); mi->flags = flags; } else { /* to indicate it has no xev header? */ mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED | CAMEL_MESSAGE_FOLDER_NOXEV; - mi->uid = g_strdup_printf ("%u", camel_folder_summary_next_uid (s)); + mi->uid = g_strdup_printf("%u", camel_folder_summary_next_uid(s)); } mbi->frompos = -1; } - + return mi; } static CamelMessageInfo * -message_info_new_from_parser (CamelFolderSummary *s, CamelMimeParser *mp) +message_info_new_from_parser(CamelFolderSummary *s, CamelMimeParser * mp) { CamelMessageInfo *mi; - CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (s); + CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(s); - mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new_from_parser (s, mp); + mi = ((CamelFolderSummaryClass *) camel_mbox_summary_parent)->message_info_new_from_parser(s, mp); if (mi) { - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; + CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *) mi; - mbi->frompos = camel_mime_parser_tell_start_from (mp); + mbi->frompos = camel_mime_parser_tell_start_from(mp); /* do we want to index this message as we add it, as well? */ - if (mbs->index_force - || (mi->flags & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0 + if (mbs->index_force || (mi->flags & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0 || !ibex_contains_name(mbs->index, mi->uid)) { - - camel_folder_summary_set_index (s, mbs->index); + camel_folder_summary_set_index(s, mbs->index); } else { - camel_folder_summary_set_index (s, NULL); + camel_folder_summary_set_index(s, NULL); } } - + return mi; } static CamelMessageInfo * -message_info_load (CamelFolderSummary *s, FILE *in) +message_info_load(CamelFolderSummary *s, FILE * in) { CamelMessageInfo *mi; - io (printf ("loading mbox message info\n")); + io(printf("loading mbox message info\n")); - mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_load (s, in); + mi = ((CamelFolderSummaryClass *) camel_mbox_summary_parent)->message_info_load(s, in); if (mi) { - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; + CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *) mi; - camel_folder_summary_decode_uint32 (in, &mbi->frompos); + camel_folder_summary_decode_uint32(in, &mbi->frompos); } - + return mi; } static int -message_info_save (CamelFolderSummary *s, FILE *out, CamelMessageInfo *mi) +message_info_save(CamelFolderSummary *s, FILE * out, CamelMessageInfo * mi) { - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; + CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *) mi; - io (printf ("saving mbox message info\n")); + io(printf("saving mbox message info\n")); - ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_save (s, out, mi); + ((CamelFolderSummaryClass *) camel_mbox_summary_parent)->message_info_save(s, out, mi); - return camel_folder_summary_encode_uint32 (out, mbi->frompos); + return camel_folder_summary_encode_uint32(out, mbi->frompos); } static int -summary_rebuild (CamelMboxSummary *mbs, off_t offset) +summary_rebuild(CamelMboxSummary *mbs, off_t offset) { - CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY (mbs); + CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY(mbs); CamelMimeParser *mp; int fd; int ok = 0; - fd = open (mbs->folder_path, O_RDONLY); + fd = open(mbs->folder_path, O_RDONLY); if (fd == -1) { - printf ("%s failed to open: %s", mbs->folder_path, strerror (errno)); + printf("%s failed to open: %s", mbs->folder_path, strerror(errno)); return -1; } - - mp = camel_mime_parser_new (); - camel_mime_parser_init_with_fd (mp, fd); - camel_mime_parser_scan_from (mp, TRUE); - camel_mime_parser_seek (mp, offset, SEEK_SET); + + mp = camel_mime_parser_new(); + camel_mime_parser_init_with_fd(mp, fd); + camel_mime_parser_scan_from(mp, TRUE); + camel_mime_parser_seek(mp, offset, SEEK_SET); if (offset > 0) { - if (camel_mime_parser_step (mp, NULL, NULL) == HSCAN_FROM) { - if (camel_mime_parser_tell_start_from (mp) != offset) { - g_warning ("The next message didn't start where I expected\nbuilding summary from start"); - camel_mime_parser_drop_step (mp); + if (camel_mime_parser_step(mp, NULL, NULL) == HSCAN_FROM) { + if (camel_mime_parser_tell_start_from(mp) != offset) { + g_warning + ("The next message didn't start where I expected\nbuilding summary from start"); + camel_mime_parser_drop_step(mp); offset = 0; - camel_mime_parser_seek (mp, offset, SEEK_SET); - camel_folder_summary_clear (CAMEL_FOLDER_SUMMARY (mbs)); + camel_mime_parser_seek(mp, offset, SEEK_SET); + camel_folder_summary_clear(CAMEL_FOLDER_SUMMARY(mbs)); } else { - camel_mime_parser_unstep (mp); + camel_mime_parser_unstep(mp); } } else { - gtk_object_unref (GTK_OBJECT (mp)); + gtk_object_unref(GTK_OBJECT(mp)); /* end of file - no content? */ return -1; } } - while (camel_mime_parser_step (mp, NULL, NULL) == HSCAN_FROM) { + while (camel_mime_parser_step(mp, NULL, NULL) == HSCAN_FROM) { CamelMessageInfo *info; - info = camel_folder_summary_add_from_parser (CAMEL_FOLDER_SUMMARY (mbs), mp); + info = camel_folder_summary_add_from_parser(CAMEL_FOLDER_SUMMARY(mbs), mp); if (info == NULL) { - printf ("Could not build info from file?\n"); + printf("Could not build info from file?\n"); ok = -1; break; } - g_assert (camel_mime_parser_step (mp, NULL, NULL) == HSCAN_FROM_END); + g_assert(camel_mime_parser_step(mp, NULL, NULL) == HSCAN_FROM_END); } - gtk_object_unref (GTK_OBJECT (mp)); - + gtk_object_unref(GTK_OBJECT(mp)); + /* update the file size/mtime in the summary */ if (ok != -1) { struct stat st; - if (stat (mbs->folder_path, &st) == 0) { + if (stat(mbs->folder_path, &st) == 0) { mbs->folder_size = st.st_size; s->time = st.st_mtime; } @@ -346,12 +345,12 @@ summary_rebuild (CamelMboxSummary *mbs, off_t offset) } int -camel_mbox_summary_update (CamelMboxSummary *mbs, off_t offset) +camel_mbox_summary_update(CamelMboxSummary *mbs, off_t offset) { int ret; mbs->index_force = FALSE; - ret = summary_rebuild (mbs, offset); + ret = summary_rebuild(mbs, offset); #if 0 #warning "Saving full summary and index after every summarisation is slow ..." @@ -366,9 +365,9 @@ camel_mbox_summary_update (CamelMboxSummary *mbs, off_t offset) } int -camel_mbox_summary_load (CamelMboxSummary *mbs, int forceindex) +camel_mbox_summary_load(CamelMboxSummary *mbs, int forceindex) { - CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY (mbs); + CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY(mbs); struct stat st; int ret = 0; off_t minstart; @@ -376,15 +375,15 @@ camel_mbox_summary_load (CamelMboxSummary *mbs, int forceindex) mbs->index_force = forceindex; /* is the summary out of date? */ - if (stat (mbs->folder_path, &st) == -1) { - camel_folder_summary_clear (s); - printf ("Cannot summarise folder: '%s': %s\n", mbs->folder_path, strerror(errno)); + if (stat(mbs->folder_path, &st) == -1) { + camel_folder_summary_clear(s); + printf("Cannot summarise folder: '%s': %s\n", mbs->folder_path, strerror(errno)); return -1; } - if (forceindex || camel_folder_summary_load (s) == -1) { - camel_folder_summary_clear (s); - ret = summary_rebuild (mbs, 0); + if (forceindex || camel_folder_summary_load(s) == -1) { + camel_folder_summary_clear(s); + ret = summary_rebuild(mbs, 0); } else { minstart = st.st_size; #if 0 @@ -392,10 +391,11 @@ camel_mbox_summary_load (CamelMboxSummary *mbs, int forceindex) /* TODO: For this to work, it has to check that the message is indexable, and contains content ... maybe it cannot be done properly? */ - for (i=0;i<camel_folder_summary_count(s);i++) { + for (i = 0; i < camel_folder_summary_count(s); i++) { CamelMessageInfo *mi = camel_folder_summary_index(s, i); + if (!ibex_contains_name(mbs->index, mi->uid)) { - minstart = ((CamelMboxMessageInfo *)mi)->frompos; + minstart = ((CamelMboxMessageInfo *) mi)->frompos; printf("Found unindexed message: %s\n", mi->uid); break; } @@ -405,28 +405,28 @@ camel_mbox_summary_load (CamelMboxSummary *mbs, int forceindex) if (st.st_size == mbs->folder_size && st.st_mtime == s->time) { if (minstart < st.st_size) { /* FIXME: Only clear the messages and reindex from this point forward */ - camel_folder_summary_clear (s); - ret = summary_rebuild (mbs, 0); + camel_folder_summary_clear(s); + ret = summary_rebuild(mbs, 0); } } else { if (mbs->folder_size < st.st_size) { if (minstart < mbs->folder_size) { /* FIXME: only make it rebuild as necessary */ - camel_folder_summary_clear (s); - ret = summary_rebuild (mbs, 0); + camel_folder_summary_clear(s); + ret = summary_rebuild(mbs, 0); } else { - ret = summary_rebuild (mbs, mbs->folder_size); + ret = summary_rebuild(mbs, mbs->folder_size); /* If that fails, it might be because a message was changed * rather than appended... so try again from the beginning. */ if (ret == -1) { - camel_folder_summary_clear (s); - ret = summary_rebuild (mbs, 0); + camel_folder_summary_clear(s); + ret = summary_rebuild(mbs, 0); } } } else { - camel_folder_summary_clear (s); - ret = summary_rebuild (mbs, 0); + camel_folder_summary_clear(s); + ret = summary_rebuild(mbs, 0); } } } @@ -434,53 +434,53 @@ camel_mbox_summary_load (CamelMboxSummary *mbs, int forceindex) if (ret != -1) { mbs->folder_size = st.st_size; s->time = st.st_mtime; - if (camel_folder_summary_save (s) == -1) - g_warning("Could not save summary: %s", strerror (errno)); + if (camel_folder_summary_save(s) == -1) + g_warning("Could not save summary: %s", strerror(errno)); if (mbs->index) - ibex_save (mbs->index); + ibex_save(mbs->index); } return ret; } static int -header_write (int fd, struct _header_raw *header, char *xevline) +header_write(int fd, struct _header_raw *header, char *xevline) { - struct iovec iv[4]; - int outlen = 0, len; + struct iovec iv[4]; + int outlen = 0, len; - iv[1].iov_base = ":"; - iv[1].iov_len = 1; - iv[3].iov_base = "\n"; - iv[3].iov_len = 1; + iv[1].iov_base = ":"; + iv[1].iov_len = 1; + iv[3].iov_base = "\n"; + iv[3].iov_len = 1; - while (header) { - if (strcasecmp (header->name, "X-Evolution")) { + while (header) { + if (strcasecmp(header->name, "X-Evolution")) { iv[0].iov_base = header->name; iv[0].iov_len = strlen(header->name); iv[2].iov_base = header->value; iv[2].iov_len = strlen(header->value); - + do { len = writev(fd, iv, 4); } while (len == -1 && errno == EINTR); - + if (len == -1) return -1; outlen += len; } - header = header->next; - } + header = header->next; + } - iv[0].iov_base = "X-Evolution: "; - iv[0].iov_len = strlen (iv[0].iov_base); - iv[1].iov_base = xevline; - iv[1].iov_len = strlen (xevline); - iv[2].iov_base = "\n\n"; - iv[2].iov_len = 2; + iv[0].iov_base = "X-Evolution: "; + iv[0].iov_len = strlen(iv[0].iov_base); + iv[1].iov_base = xevline; + iv[1].iov_len = strlen(xevline); + iv[2].iov_base = "\n\n"; + iv[2].iov_len = 2; do { - len = writev (fd, iv, 3); + len = writev(fd, iv, 3); } while (len == -1 && errno == EINTR); if (len == -1) @@ -488,66 +488,133 @@ header_write (int fd, struct _header_raw *header, char *xevline) outlen += 1; - d(printf ("Wrote %d bytes of headers\n", outlen)); + d(printf("Wrote %d bytes of headers\n", outlen)); - return outlen; + return outlen; } static int copy_block(int fromfd, int tofd, off_t start, size_t bytes) { - char buffer[4096]; - int written = 0; + char buffer[4096]; + int written = 0; - d(printf ("writing %d bytes ... ", bytes)); + d(printf("writing %d bytes ... ", bytes)); if (lseek(fromfd, start, SEEK_SET) != start) return -1; - while (bytes > 0) { - int toread, towrite; + while (bytes > 0) { + int toread, towrite; - toread = bytes; - if (bytes > 4096) - toread = 4096; - else - toread = bytes; + toread = bytes; + if (bytes > 4096) + toread = 4096; + else + toread = bytes; do { - towrite = read (fromfd, buffer, toread); + towrite = read(fromfd, buffer, toread); } while (towrite == -1 && errno == EINTR); if (towrite == -1) return -1; - /* check for 'end of file' */ - if (towrite == 0) { - d(printf ("end of file?\n")); - break; + /* check for 'end of file' */ + if (towrite == 0) { + d(printf("end of file?\n")); + break; } do { - toread = write (tofd, buffer, towrite); + toread = write(tofd, buffer, towrite); } while (toread == -1 && errno == EINTR); if (toread == -1) return -1; - written += toread; - bytes -= toread; - } + written += toread; + bytes -= toread; + } - d(printf ("written %d bytes\n", written)); + d(printf("written %d bytes\n", written)); - return written; + return written; +} + +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)); + + g_string_sprintfa(out, " %s %s %d %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; } int -camel_mbox_summary_sync (CamelMboxSummary *mbs, gboolean expunge, CamelException *ex) +camel_mbox_summary_sync(CamelMboxSummary *mbs, gboolean expunge, CamelException *ex) { CamelMimeParser *mp = NULL; int i, count; CamelMboxMessageInfo *info; - CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY (mbs); + CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY(mbs); int fd = -1, fdout = -1; off_t offset = 0; char *tmpname = NULL; @@ -557,260 +624,249 @@ camel_mbox_summary_sync (CamelMboxSummary *mbs, gboolean expunge, CamelException guint32 uid, flags; int quick = TRUE, work = FALSE; struct stat st; + char *fromline; /* make sure we're in sync */ - count = camel_folder_summary_count (s); + count = camel_folder_summary_count(s); if (count > 0) { - CamelMessageInfo *mi = camel_folder_summary_index (s, count - 1); - camel_mbox_summary_update (mbs, mi->content->endpos); + CamelMessageInfo *mi = camel_folder_summary_index(s, count - 1); + + camel_mbox_summary_update(mbs, mi->content->endpos); } else { - camel_mbox_summary_update (mbs, 0); + camel_mbox_summary_update(mbs, 0); } /* check if we have any work to do */ - d(printf ("Performing sync, %d messages in inbox\n", count)); + d(printf("Performing sync, %d messages in inbox\n", count)); for (i = 0; quick && i < count; i++) { - info = (CamelMboxMessageInfo *)camel_folder_summary_index (s, i); - if ((expunge && (info->info.flags & CAMEL_MESSAGE_DELETED)) || - (info->info.flags & CAMEL_MESSAGE_FOLDER_NOXEV)) + info = (CamelMboxMessageInfo *) camel_folder_summary_index(s, i); + if ((expunge && (info->info.flags & CAMEL_MESSAGE_DELETED)) + || (info->info.flags & CAMEL_MESSAGE_FOLDER_NOXEV)) quick = FALSE; else work |= (info->info.flags & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0; } - d(printf ("Options: %s %s %s\n", expunge ? "expunge" : "", quick ? "quick" : "", work ? "Work" : "")); + d(printf("Options: %s %s %s\n", expunge ? "expunge" : "", quick ? "quick" : "", work ? "Work" : "")); if (quick && !work) return 0; - fd = open (mbs->folder_path, O_RDWR); + fd = open(mbs->folder_path, O_RDWR); if (fd == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not open summary %s", mbs->folder_path); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "Could not open summary %s", mbs->folder_path); return -1; } - mp = camel_mime_parser_new (); - camel_mime_parser_scan_from (mp, TRUE); - camel_mime_parser_init_with_fd (mp, fd); + mp = camel_mime_parser_new(); + camel_mime_parser_scan_from(mp, TRUE); + camel_mime_parser_init_with_fd(mp, fd); if (!quick) { - tmpname = alloca (strlen (mbs->folder_path) + 5); - sprintf (tmpname, "%s.tmp", mbs->folder_path); - d(printf ("Writing tmp file to %s\n", tmpname)); - retry_out: - fdout = open (tmpname, O_WRONLY | O_CREAT | O_EXCL, 0600); + tmpname = alloca(strlen(mbs->folder_path) + 5); + sprintf(tmpname, "%s.tmp", mbs->folder_path); + d(printf("Writing tmp file to %s\n", tmpname)); + retry_out: + fdout = open(tmpname, O_WRONLY | O_CREAT | O_EXCL, 0600); if (fdout == -1) { if (errno == EEXIST) if (unlink(tmpname) != -1) goto retry_out; - - free (tmpname); + + free(tmpname); tmpname = NULL; - g_warning ("Something failed (yo!)"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot open temporary mailbox: %s", strerror (errno)); + g_warning("Something failed (yo!)"); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "Cannot open temporary mailbox: %s", + strerror(errno)); goto error; } } for (i = 0; i < count; i++) { off_t frompos, bodypos, lastpos; + /* This has to be an int, not an off_t, because that's * what camel_mime_parser_header returns... FIXME. */ int xevoffset; - info = (CamelMboxMessageInfo *)camel_folder_summary_index(s, i); + info = (CamelMboxMessageInfo *) camel_folder_summary_index(s, i); - g_assert (info); + g_assert(info); - d(printf ("Looking at message %s\n", info->info.uid)); + d(printf("Looking at message %s\n", info->info.uid)); if (expunge && info->info.flags & CAMEL_MESSAGE_DELETED) { - d(printf ("Deleting %s\n", info->info.uid)); + d(printf("Deleting %s\n", info->info.uid)); - g_assert (!quick); + g_assert(!quick); offset -= (info->info.content->endpos - info->frompos); if (mbs->index) - ibex_unindex (mbs->index, info->info.uid); - camel_folder_summary_remove (s, (CamelMessageInfo *)info); + ibex_unindex(mbs->index, info->info.uid); + camel_folder_summary_remove(s, (CamelMessageInfo *) info); count--; i--; info = NULL; } else if (info->info.flags & (CAMEL_MESSAGE_FOLDER_NOXEV | CAMEL_MESSAGE_FOLDER_FLAGGED)) { int xevok = FALSE; - d(printf ("Updating header for %s flags = %08x\n", info->info.uid, info->info.flags)); + d(printf("Updating header for %s flags = %08x\n", info->info.uid, info->info.flags)); /* find the next message, header parts */ - camel_mime_parser_seek (mp, info->frompos, SEEK_SET); - if (camel_mime_parser_step (mp, &buffer, &len) != HSCAN_FROM) { - g_warning ("camel_mime_parser_step failed (1)"); + camel_mime_parser_seek(mp, info->frompos, SEEK_SET); + if (camel_mime_parser_step(mp, &buffer, &len) != HSCAN_FROM) { + g_warning("camel_mime_parser_step failed (1)"); goto error; } - if (camel_mime_parser_tell_start_from (mp) != info->frompos) { - g_warning ("Summary/mbox mismatch, aborting sync"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Summary mismatch, aborting sync"); + if (camel_mime_parser_tell_start_from(mp) != info->frompos) { + g_warning("Summary/mbox mismatch, aborting sync"); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "Summary mismatch, aborting sync"); goto error; } - - if (camel_mime_parser_step (mp, &buffer, &len) == HSCAN_FROM_END) { - g_warning ("camel_mime_parser_step failed (2)"); + + if (camel_mime_parser_step(mp, &buffer, &len) == HSCAN_FROM_END) { + g_warning("camel_mime_parser_step failed (2)"); goto error; } /* Check if the X-Evolution header is valid. */ - xev = camel_mime_parser_header (mp, "X-Evolution", &xevoffset); - if (xev && header_evolution_decode (xev, &uid, &flags) != -1) + xev = camel_mime_parser_header(mp, "X-Evolution", &xevoffset); + if (xev && header_evolution_decode(xev, &uid, &flags) != -1) xevok = TRUE; - xevnew = header_evolution_encode (strtoul (info->info.uid, NULL, 10), info->info.flags & 0xffff); + xevnew = header_evolution_encode(strtoul(info->info.uid, NULL, 10), info->info.flags & 0xffff); if (quick) { if (!xevok) { - g_warning ("The summary told me I had an X-Evolution header, but i dont!"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Summary mismatch, X-Evolution header missing"); + g_warning("The summary told me I had an X-Evolution header, but i dont!"); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + "Summary mismatch, X-Evolution header missing"); goto error; } - buffer = g_strdup_printf ("X-Evolution: %s", xevnew); - lastpos = lseek (fd, 0, SEEK_CUR); - lseek (fd, xevoffset, SEEK_SET); + buffer = g_strdup_printf("X-Evolution: %s", xevnew); + lastpos = lseek(fd, 0, SEEK_CUR); + lseek(fd, xevoffset, SEEK_SET); do { - len = write (fd, buffer, strlen (buffer)); + len = write(fd, buffer, strlen(buffer)); } while (len == -1 && errno == EINTR); - lseek (fd, lastpos, SEEK_SET); - g_free (buffer); + lseek(fd, lastpos, SEEK_SET); + g_free(buffer); if (len == -1) { - g_warning ("Yahoo! len == -1"); + g_warning("Yahoo! len == -1"); goto error; } } else { - frompos = lseek (fdout, 0, SEEK_CUR); - write (fdout, "From -\n", strlen("From -\n")); - if (header_write (fdout, camel_mime_parser_headers_raw (mp), xevnew) == -1) { - d(printf ("Error writing to tmp mailbox\n")); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Error writing to temp mailbox: %s", - strerror (errno)); + frompos = lseek(fdout, 0, SEEK_CUR); + fromline = camel_mbox_summary_build_from(camel_mime_parser_headers_raw(mp)); + write(fdout, fromline, strlen(fromline)); + g_free(fromline); + if (header_write(fdout, camel_mime_parser_headers_raw(mp), xevnew) == -1) { + d(printf("Error writing to tmp mailbox\n")); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + "Error writing to temp mailbox: %s", strerror(errno)); goto error; } - bodypos = lseek (fdout, 0, SEEK_CUR); - d(printf ("pos = %d, endpos = %d, bodypos = %d\n", - (int) info->info.content->pos, - (int) info->info.content->endpos, - (int) info->info.content->bodypos)); - if (copy_block (fd, fdout, info->info.content->bodypos, - info->info.content->endpos - info->info.content->bodypos) == -1) { - g_warning ("Cannot copy data to output fd"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot copy data to output fd: %s", - strerror (errno)); + bodypos = lseek(fdout, 0, SEEK_CUR); + d(printf("pos = %d, endpos = %d, bodypos = %d\n", + (int)info->info.content->pos, + (int)info->info.content->endpos, + (int)info->info.content->bodypos)); + if (copy_block(fd, fdout, info->info.content->bodypos, + info->info.content->endpos - info->info.content->bodypos) == -1) { + g_warning("Cannot copy data to output fd"); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + "Cannot copy data to output fd: %s", strerror(errno)); goto error; } info->frompos = frompos; offset = bodypos - info->info.content->bodypos; } info->info.flags &= 0xffff; - g_free (xevnew); + g_free(xevnew); xevnew = NULL; - camel_mime_parser_drop_step (mp); - camel_mime_parser_drop_step (mp); + camel_mime_parser_drop_step(mp); + camel_mime_parser_drop_step(mp); } else { if (!quick) { - if (copy_block (fd, fdout, info->frompos, - info->info.content->endpos - info->frompos) == -1) { - g_warning ("Cannot copy data to output fd"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot copy data to output fd: %s", - strerror (errno)); + if (copy_block(fd, fdout, info->frompos, info->info.content->endpos - info->frompos) == -1) { + g_warning("Cannot copy data to output fd"); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + "Cannot copy data to output fd: %s", strerror(errno)); goto error; } /* update from pos here? */ info->frompos += offset; } else { - d(printf ("Nothing to do for this message\n")); + d(printf("Nothing to do for this message\n")); } } if (!quick && info != NULL && offset != 0) { - d(printf ("offsetting content: %d\n", (int) offset)); - camel_folder_summary_offset_content (info->info.content, offset); - d(printf ("pos = %d, endpos = %d, bodypos = %d\n", - (int) info->info.content->pos, - (int) info->info.content->endpos, - (int) info->info.content->bodypos)); + d(printf("offsetting content: %d\n", (int)offset)); + camel_folder_summary_offset_content(info->info.content, offset); + d(printf("pos = %d, endpos = %d, bodypos = %d\n", + (int)info->info.content->pos, + (int)info->info.content->endpos, + (int)info->info.content->bodypos)); } } - d(printf ("Closing folders\n")); + d(printf("Closing folders\n")); - if (close (fd) == -1) { - g_warning ("Cannot close source folder: %s", strerror (errno)); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not close source folder %s: %s", - mbs->folder_path, strerror (errno)); + if (close(fd) == -1) { + g_warning("Cannot close source folder: %s", strerror(errno)); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "Could not close source folder %s: %s", + mbs->folder_path, strerror(errno)); goto error; } if (!quick) { - if (close (fdout) == -1) { - g_warning ("Cannot close tmp folder: %s", strerror (errno)); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not close temp folder: %s", - strerror (errno)); + if (close(fdout) == -1) { + g_warning("Cannot close tmp folder: %s", strerror(errno)); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "Could not close temp folder: %s", + strerror(errno)); goto error; } - if (rename (tmpname, mbs->folder_path) == -1) { - g_warning ("Cannot rename folder: %s", strerror (errno)); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not rename folder: %s", - strerror (errno)); + if (rename(tmpname, mbs->folder_path) == -1) { + g_warning("Cannot rename folder: %s", strerror(errno)); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "Could not rename folder: %s", + strerror(errno)); goto error; } tmpname = NULL; if (mbs->index) - ibex_save (mbs->index); + ibex_save(mbs->index); } - if (stat (mbs->folder_path, &st) == -1) { - g_warning ("Hmm... stat(mbs->folder_path, &st) == -1"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Unknown error: %s", - strerror (errno)); + if (stat(mbs->folder_path, &st) == -1) { + g_warning("Hmm... stat(mbs->folder_path, &st) == -1"); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "Unknown error: %s", strerror(errno)); goto error; } - camel_folder_summary_touch (s); + camel_folder_summary_touch(s); s->time = st.st_mtime; mbs->folder_size = st.st_size; - camel_folder_summary_save (s); + camel_folder_summary_save(s); + + gtk_object_unref(GTK_OBJECT(mp)); - gtk_object_unref (GTK_OBJECT (mp)); - return 0; - error: + error: if (fd != -1) - close (fd); - + close(fd); + if (fdout != -1) - close (fdout); - - g_free (xevnew); - + close(fdout); + + g_free(xevnew); + if (tmpname) - unlink (tmpname); + unlink(tmpname); if (mp) - gtk_object_unref (GTK_OBJECT (mp)); + gtk_object_unref(GTK_OBJECT(mp)); return -1; } - - - - - |