diff options
author | Not Zed <NotZed@HelixCode.com> | 2000-09-28 19:31:29 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2000-09-28 19:31:29 +0800 |
commit | e71de4c02186efe577412709346154df96e35054 (patch) | |
tree | 125ad7e9d02cf42bf8acebefed08c39b8df675e5 /camel/providers | |
parent | 18579aa7e01b4d313d2cf05f355aa4698b99cf7d (diff) | |
download | gsoc2013-evolution-e71de4c02186efe577412709346154df96e35054.tar.gz gsoc2013-evolution-e71de4c02186efe577412709346154df96e35054.tar.zst gsoc2013-evolution-e71de4c02186efe577412709346154df96e35054.zip |
New function to fold headers.
2000-09-28 Not Zed <NotZed@HelixCode.com>
* camel-mime-utils.c (header_fold): New function to fold headers.
2000-09-27 Not Zed <NotZed@HelixCode.com>
* camel-mime-parser.c (folder_scan_header): If we had an empty
header, then it must be end of the headers too.
(folder_scan_init): No we dont need to init the outbuf with a nul
terminator.
* camel-folder-summary.c (camel_folder_summary_set_uid): New
function to reset the uid to a higher value.
* providers/mbox/camel-mbox-summary.c (camel_mbox_summary_sync):
"something failed (yo!)" what sort of crap is this? Fixed all the
indenting again, what wanker keeps running stuff through indent?
(message_info_new): Check the uid we loaded off the disk, if it
existed already, assign a new one. If it didn't then make sure
the nextuid is higher.
* camel-charset-map.c: New file, used to build a large unicode
decoding mapping table, and use it to determine what is the
lowest charset a given word can be encoded with. Uses tables from
libunicode's source.
* camel-internet-address.c (internet_encode): Use
header_phrase_encode to properly encode the fullname, as required.
refixed indenting. Who keeps doing that?
(camel_internet_address_find_address): Changed fatal return/warnings
into assertions.
* camel-mime-utils.c (header_raw_append_parse): Check : explicitly
(removed from is_fieldname() macro).
(camel_mime_special_table): Changed to short, so we can represent
more bit types.
(quoted_encode): Take a mask of the safe chars for this encoding.
(header_address_decode): Removed a #warning that makes no sense
anymore.
(header_decode_date): Fixed the 'broken date' parser code, if it
ever decoded it it just threw away the result.
(header_encode_string): Use better charset matching for encoding
strings as well.
2000-08-31 Not Zed <NotZed@HelixCode.com>
* providers/mh/camel-mh-summary.c (camel_mh_summary_sync): Save
the index if we do a sync.
(camel_mh_summary_check): Save the index here too. Probably.
svn path=/trunk/; revision=5615
Diffstat (limited to 'camel/providers')
-rw-r--r-- | camel/providers/mbox/camel-mbox-summary.c | 366 | ||||
-rw-r--r-- | camel/providers/mh/camel-mh-summary.c | 10 |
2 files changed, 195 insertions, 181 deletions
diff --git a/camel/providers/mbox/camel-mbox-summary.c b/camel/providers/mbox/camel-mbox-summary.c index adfad1312d..18d889ee84 100644 --- a/camel/providers/mbox/camel-mbox-summary.c +++ b/camel/providers/mbox/camel-mbox-summary.c @@ -56,29 +56,29 @@ static void camel_mbox_summary_finalise (CamelObject *obj); static CamelFolderSummaryClass *camel_mbox_summary_parent; CamelType -camel_mbox_summary_get_type (void) +camel_mbox_summary_get_type(void) { static CamelType type = CAMEL_INVALID_TYPE; if (type == CAMEL_INVALID_TYPE) { - type = camel_type_register (camel_folder_summary_get_type (), "CamelMboxSummary", - sizeof (CamelMboxSummary), - sizeof (CamelMboxSummaryClass), - (CamelObjectClassInitFunc) camel_mbox_summary_class_init, - NULL, - (CamelObjectInitFunc) camel_mbox_summary_init, - (CamelObjectFinalizeFunc) camel_mbox_summary_finalise); + type = camel_type_register(camel_folder_summary_get_type(), "CamelMboxSummary", + sizeof (CamelMboxSummary), + sizeof (CamelMboxSummaryClass), + (CamelObjectClassInitFunc) camel_mbox_summary_class_init, + NULL, + (CamelObjectInitFunc) camel_mbox_summary_init, + (CamelObjectFinalizeFunc) camel_mbox_summary_finalise); } return type; } static void -camel_mbox_summary_class_init (CamelMboxSummaryClass *klass) +camel_mbox_summary_class_init(CamelMboxSummaryClass *klass) { CamelFolderSummaryClass *sklass = (CamelFolderSummaryClass *) klass; - camel_mbox_summary_parent = CAMEL_FOLDER_SUMMARY_CLASS(camel_type_get_global_classfuncs (camel_folder_summary_get_type ())); + camel_mbox_summary_parent = CAMEL_FOLDER_SUMMARY_CLASS(camel_type_get_global_classfuncs(camel_folder_summary_get_type())); sklass->summary_header_load = summary_header_load; sklass->summary_header_save = summary_header_save; @@ -91,7 +91,7 @@ camel_mbox_summary_class_init (CamelMboxSummaryClass *klass) } static void -camel_mbox_summary_init (CamelMboxSummary *obj) +camel_mbox_summary_init(CamelMboxSummary *obj) { struct _CamelMboxSummaryPrivate *p; struct _CamelFolderSummary *s = (CamelFolderSummary *)obj; @@ -107,11 +107,11 @@ camel_mbox_summary_init (CamelMboxSummary *obj) } static void -camel_mbox_summary_finalise (CamelObject *obj) +camel_mbox_summary_finalise(CamelObject *obj) { - CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (obj); + CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(obj); - g_free (mbs->folder_path); + g_free(mbs->folder_path); } /** @@ -122,85 +122,92 @@ camel_mbox_summary_finalise (CamelObject *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 (camel_object_new (camel_mbox_summary_get_type ())); + CamelMboxSummary *new = CAMEL_MBOX_SUMMARY(camel_object_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); + g_free(header); return *uid; } - g_free (header); + 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; - 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); + if (camel_folder_summary_uid(s, mi->uid)) { + g_free(mi->uid); + mi->uid = camel_folder_summary_next_uid_string(s); + } else { + /* so we dont get clashes later on */ + camel_folder_summary_set_uid(s, uid+1); + } 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; } @@ -209,25 +216,25 @@ message_info_new (CamelFolderSummary *s, struct _header_raw *h) } 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; - 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 || !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); } } @@ -235,18 +242,18 @@ message_info_new_from_parser (CamelFolderSummary *s, CamelMimeParser *mp) } 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) { guint32 position; CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; - camel_folder_summary_decode_uint32 (in, &position); + camel_folder_summary_decode_uint32(in, &position); mbi->frompos = position; } @@ -254,74 +261,74 @@ message_info_load (CamelFolderSummary *s, FILE *in) } static int -message_info_save (CamelFolderSummary *s, FILE *out, CamelMessageInfo *mi) +message_info_save(CamelFolderSummary *s, FILE *out, CamelMessageInfo *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) { + 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); + 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 { - camel_object_unref (CAMEL_OBJECT (mp)); + camel_object_unref(CAMEL_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"); 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); } - camel_object_unref (CAMEL_OBJECT (mp)); + camel_object_unref(CAMEL_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; } @@ -615,16 +622,16 @@ camel_mbox_summary_sync(CamelMboxSummary *mbs, gboolean expunge, CamelException /* make sure we're in sync */ 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); + 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; @@ -632,37 +639,36 @@ camel_mbox_summary_sync(CamelMboxSummary *mbs, gboolean expunge, CamelException 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)); + 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); + fdout = open(tmpname, O_WRONLY|O_CREAT|O_EXCL, 0600); if (fdout == -1) { if (errno == EEXIST) if (unlink(tmpname) != -1) goto retry_out; tmpname = NULL; - g_warning ("Something failed (yo!)"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot open temporary mailbox: %s", strerror (errno)); + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + "Cannot open temporary mailbox: %s", strerror(errno)); goto error; } } @@ -676,191 +682,189 @@ camel_mbox_summary_sync(CamelMboxSummary *mbs, gboolean expunge, CamelException 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"); + 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)"); + 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); + 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"); goto error; } } else { - 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)); + 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) { + 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); - camel_object_unref (CAMEL_OBJECT (mp)); + camel_object_unref(CAMEL_OBJECT(mp)); return 0; error: if (fd != -1) - close (fd); + close(fd); if (fdout != -1) - close (fdout); + close(fdout); - g_free (xevnew); + g_free(xevnew); if (tmpname) - unlink (tmpname); + unlink(tmpname); if (mp) - camel_object_unref (CAMEL_OBJECT (mp)); + camel_object_unref(CAMEL_OBJECT(mp)); return -1; } diff --git a/camel/providers/mh/camel-mh-summary.c b/camel/providers/mh/camel-mh-summary.c index dff025b258..5d304b4a42 100644 --- a/camel/providers/mh/camel-mh-summary.c +++ b/camel/providers/mh/camel-mh-summary.c @@ -235,6 +235,13 @@ int camel_mh_summary_check(CamelMhSummary * mhs, int forceindex) g_hash_table_foreach(left, (GHFunc)remove_summary, mhs); g_hash_table_destroy(left); + /* force a save of the index, just to make sure */ + /* note this could be expensive so possibly shouldn't be here + as such */ + if (mhs->index) { + ibex_save(mhs->index); + } + return 0; } @@ -248,6 +255,9 @@ int camel_mh_summary_sync(CamelMhSummary * mhs, int expunge, CamelException *ex printf("summary_sync(expunge=%s)\n", expunge?"true":"false"); + if (mhs->index) { + ibex_save(mhs->index); + } if (!expunge) return 0; |