186
186
parent_store = camel_folder_get_parent_store (folder);
188
188
/* Set the functions for db sorting */
189
camel_db_set_collate (parent_store->cdb_r, "bdata", "mbox_frompos_sort", (CamelDBCollate)camel_local_frompos_sort);
189
camel_db_set_collate (parent_store->cdb_r, "bdata", "mbox_frompos_sort", (CamelDBCollate) camel_local_frompos_sort);
190
190
summary->sort_by = "bdata";
191
191
summary->collate = "mbox_frompos_sort";
212
212
while (*p && isdigit (*p))
215
if (*p == 0 && sscanf(uidstr, "%u", &uid) == 1) {
216
return g_strdup_printf("%08x-%04x", uid, mi->info.flags & 0xffff);
215
if (*p == 0 && sscanf (uidstr, "%u", &uid) == 1) {
216
return g_strdup_printf ("%08x-%04x", uid, mi->info.flags & 0xffff);
218
return g_strdup_printf("%s-%04x", uidstr, mi->info.flags & 0xffff);
218
return g_strdup_printf ("%s-%04x", uidstr, mi->info.flags & 0xffff);
278
278
if (mbs->xstatus) {
279
279
/* check for existance of status & x-status headers */
280
status = camel_header_raw_find(&h, "Status", NULL);
280
status = camel_header_raw_find (&h, "Status", NULL);
282
282
flags = decode_status (status);
283
xstatus = camel_header_raw_find(&h, "X-Status", NULL);
283
xstatus = camel_header_raw_find (&h, "X-Status", NULL);
285
285
flags |= decode_status (xstatus);
288
288
/* if we have an xev header, use it, else assign a new one */
289
xev = camel_header_raw_find(&h, "X-Evolution", NULL);
289
xev = camel_header_raw_find (&h, "X-Evolution", NULL);
291
291
&& camel_local_summary_decode_x_evolution ((CamelLocalSummary *) s, xev, &mi->info) == 0) {
292
292
uid = camel_message_info_uid (mi);
293
d(printf("found valid x-evolution: %s\n", uid));
293
d (printf ("found valid x-evolution: %s\n", uid));
294
294
/* If one is there, it should be there already */
295
295
info = (CamelMboxMessageInfo *) camel_folder_summary_peek_loaded (s, uid);
303
d(printf("seen '%s' before, adding anew\n", uid));
303
d (printf ("seen '%s' before, adding anew\n", uid));
304
304
camel_message_info_free (info);
308
d(printf("but isn't present in summary\n"));
308
d (printf ("but isn't present in summary\n"));
311
d(printf("didn't find x-evolution\n"));
311
d (printf ("didn't find x-evolution\n"));
384
384
struct _CamelMIRecord *mir;
386
386
mir = CAMEL_FOLDER_SUMMARY_CLASS (camel_mbox_summary_parent_class)->message_info_to_db (s, info);
387
mir->bdata = g_strdup_printf("%" G_GOFFSET_FORMAT, mbi->frompos);
387
mir->bdata = g_strdup_printf ("%" G_GOFFSET_FORMAT, mbi->frompos);
411
411
GList *del = NULL;
412
412
GPtrArray *known_uids;
414
d(printf("Calling summary update, from pos %d\n", (gint)offset));
414
d (printf ("Calling summary update, from pos %d\n", (gint) offset));
416
416
cls->index_force = FALSE;
420
420
camel_folder_summary_lock (s, CAMEL_FOLDER_SUMMARY_SUMMARY_LOCK);
421
421
fd = g_open (cls->folder_path, O_LARGEFILE | O_RDONLY | O_BINARY, 0);
423
d(printf("%s failed to open: %s\n", cls->folder_path, g_strerror (errno)));
423
d (printf ("%s failed to open: %s\n", cls->folder_path, g_strerror (errno)));
424
424
camel_folder_summary_unlock (s, CAMEL_FOLDER_SUMMARY_SUMMARY_LOCK);
426
426
error, G_IO_ERROR,
444
444
&& camel_mime_parser_tell_start_from (mp) == offset) {
445
445
camel_mime_parser_unstep (mp);
447
g_warning("The next message didn't start where I expected, building summary from start");
447
g_warning ("The next message didn't start where I expected, building summary from start");
448
448
camel_mime_parser_drop_step (mp);
450
450
camel_mime_parser_seek (mp, offset, SEEK_SET);
489
489
error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
490
490
_("Fatal mail parser error near position %s "
491
"in folder %s"), pos_str, cls->folder_path);
491
"in folder %s"), pos_str, cls->folder_path);
492
492
g_free (pos_str);
510
510
mi = (CamelMboxMessageInfo *) camel_folder_summary_get (s, uid);
511
511
/* must've dissapeared from the file? */
512
512
if (!mi || mi->info.info.flags & CAMEL_MESSAGE_FOLDER_NOTSEEN) {
513
d(printf("uid '%s' vanished, removing", uid));
513
d (printf ("uid '%s' vanished, removing", uid));
515
515
camel_folder_change_info_remove_uid (changeinfo, uid);
516
516
del = g_list_prepend (del, (gpointer) camel_pstring_strdup (uid));
517
camel_folder_summary_remove_uid (s, uid);
518
camel_folder_summary_remove (s, (CamelMessageInfo *) mi);
584
585
GPtrArray *known_uids;
586
587
/* empty? No need to scan at all */
587
d(printf("Empty mbox, clearing summary\n"));
588
d (printf ("Empty mbox, clearing summary\n"));
588
589
camel_folder_summary_prepare_fetch_all (s, NULL);
589
590
known_uids = camel_folder_summary_get_array (s);
590
591
for (i = 0; known_uids && i < known_uids->len; i++) {
603
604
if (st.st_size != mbs->folder_size || st.st_mtime != s->time) {
604
605
if (mbs->folder_size < st.st_size) {
605
606
/* this will automatically rescan from 0 if there is a problem */
606
d(printf("folder grew, attempting to rebuild from %d\n", mbs->folder_size));
607
d (printf ("folder grew, attempting to rebuild from %d\n", mbs->folder_size));
607
608
ret = summary_update (cls, mbs->folder_size, changes, cancellable, error);
609
d(printf("folder shrank! rebuilding from start\n"));
610
d (printf ("folder shrank! rebuilding from start\n"));
610
611
ret = summary_update (cls, 0, changes, cancellable, error);
613
d(printf("Folder unchanged, do nothing\n"));
614
d (printf ("Folder unchanged, do nothing\n"));
644
645
guint32 flags = (expunge ? 1 : 0), filemode = 0600;
647
d(printf("performing full summary/sync\n"));
648
d (printf ("performing full summary/sync\n"));
649
650
camel_operation_push_message (cancellable, _("Storing folder"));
650
651
camel_folder_summary_lock (s, CAMEL_FOLDER_SUMMARY_SUMMARY_LOCK);
668
669
tmpname = g_alloca (strlen (cls->folder_path) + 5);
669
670
sprintf (tmpname, "%s.tmp", cls->folder_path);
670
d(printf("Writing temporary file to %s\n", tmpname));
671
d (printf ("Writing temporary file to %s\n", tmpname));
671
672
fdout = g_open (tmpname, O_LARGEFILE | O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, filemode);
672
673
if (fdout == -1) {
683
684
fd, fdout, cancellable, error) == -1)
686
d(printf("Closing folders\n"));
687
d (printf ("Closing folders\n"));
688
689
if (close (fd) == -1) {
689
g_warning("Cannot close source folder: %s", g_strerror (errno));
690
g_warning ("Cannot close source folder: %s", g_strerror (errno));
691
692
error, G_IO_ERROR,
692
693
g_io_error_from_errno (errno),
699
700
if (close (fdout) == -1) {
700
g_warning("Cannot close temporary folder: %s", g_strerror (errno));
701
g_warning ("Cannot close temporary folder: %s", g_strerror (errno));
702
703
error, G_IO_ERROR,
703
704
g_io_error_from_errno (errno),
714
715
g_warning ("Cannot remove %s: %s", cls->folder_path, g_strerror (errno));
716
717
if (g_rename (tmpname, cls->folder_path) == -1) {
717
g_warning("Cannot rename folder: %s", g_strerror (errno));
718
g_warning ("Cannot rename folder: %s", g_strerror (errno));
719
720
error, G_IO_ERROR,
720
721
g_io_error_from_errno (errno),
789
790
GPtrArray *summary = NULL;
791
d(printf("Performing quick summary sync\n"));
792
d (printf ("Performing quick summary sync\n"));
793
794
camel_operation_push_message (cancellable, _("Storing folder"));
794
795
camel_folder_summary_lock (s, CAMEL_FOLDER_SUMMARY_SUMMARY_LOCK);
838
839
info = (CamelMboxMessageInfo *) camel_folder_summary_get (s, summary->pdata[i]);
840
d(printf("Checking message %s %08x\n", camel_message_info_uid(info), ((CamelMessageInfoBase *)info)->flags));
841
d (printf ("Checking message %s %08x\n", camel_message_info_uid (info), ((CamelMessageInfoBase *) info)->flags));
842
843
if ((info->info.info.flags & CAMEL_MESSAGE_FOLDER_FLAGGED) == 0) {
843
844
camel_message_info_free ((CamelMessageInfo *) info);
848
d(printf("Updating message %s: %d\n", camel_message_info_uid(info), (gint)info->frompos));
849
d (printf ("Updating message %s: %d\n", camel_message_info_uid (info), (gint) info->frompos));
850
851
camel_mime_parser_seek (mp, info->frompos, SEEK_SET);
859
860
if (camel_mime_parser_tell_start_from (mp) != info->frompos) {
860
g_warning("Didn't get the next message where I expected (%d) got %d instead",
861
(gint) info->frompos, (gint) camel_mime_parser_tell_start_from (mp));
862
"Didn't get the next message where I expected (%d) got %d instead",
863
(gint) info->frompos, (gint) camel_mime_parser_tell_start_from (mp));
863
865
error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
864
866
_("Summary and folder mismatch, even after a sync"));
868
870
if (camel_mime_parser_step (mp, NULL, NULL) == CAMEL_MIME_PARSER_STATE_FROM_END) {
869
g_warning("camel_mime_parser_step failed (2)");
871
g_warning ("camel_mime_parser_step failed (2)");
873
xev = camel_mime_parser_header(mp, "X-Evolution", &xevoffset);
875
xev = camel_mime_parser_header (mp, "X-Evolution", &xevoffset);
874
876
if (xev == NULL || camel_local_summary_decode_x_evolution (cls, xev, NULL) == -1) {
875
g_warning("We're supposed to have a valid x-ev header, but we dont");
877
g_warning ("We're supposed to have a valid x-ev header, but we dont");
878
880
xevnew = camel_local_summary_encode_x_evolution (cls, &info->info);
884
886
if (strlen (xev) - 1 != strlen (xevtmp)) {
887
g_warning("Hmm, the xev headers shouldn't have changed size, but they did");
889
g_warning ("Hmm, the xev headers shouldn't have changed size, but they did");
892
894
/* we write out the xevnew string, assuming its been folded identically to the original too! */
894
896
lastpos = lseek (fd, 0, SEEK_CUR);
895
lseek(fd, xevoffset+strlen("X-Evolution: "), SEEK_SET);
897
lseek (fd, xevoffset + strlen ("X-Evolution: "), SEEK_SET);
897
899
len = write (fd, xevnew, strlen (xevnew));
898
900
} while (len == -1 && errno == EINTR);
1008
1010
ret = CAMEL_MBOX_SUMMARY_GET_CLASS (cls)->sync_quick (
1009
1011
mbs, expunge, changeinfo, cancellable, NULL);
1011
g_warning("failed a quick-sync, trying a full sync");
1013
g_warning ("failed a quick-sync, trying a full sync");
1070
1072
gchar statnew[8], xstatnew[8];
1073
d(printf("performing full summary/sync\n"));
1075
d (printf ("performing full summary/sync\n"));
1075
1077
camel_folder_summary_lock (s, CAMEL_FOLDER_SUMMARY_SUMMARY_LOCK);
1106
d(printf("Looking at message %s\n", camel_message_info_uid(info)));
1108
d(printf("seeking (%s) to %d\n", ((CamelMessageInfo *) info)->uid, (gint)info->frompos));
1109
"Looking at message %s\n",
1110
camel_message_info_uid (info)));
1113
"seeking (%s) to %d\n",
1114
((CamelMessageInfo *) info)->uid,
1115
(gint) info->frompos));
1110
1118
camel_mime_parser_seek (mp, info->frompos, SEEK_SET);
1112
1120
if (camel_mime_parser_step (mp, &buffer, &len) != CAMEL_MIME_PARSER_STATE_FROM) {
1114
1122
error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
1115
_("MBOX file is corrupted, please fix it. (Expected a From line, but didn't get it.)"));
1123
_("MBOX file is corrupted, please fix it. "
1124
"(Expected a From line, but didn't get it.)"));
1119
1128
if (camel_mime_parser_tell_start_from (mp) != info->frompos) {
1120
g_warning("Didn't get the next message where I expected (%d) got %d instead",
1121
(gint) info->frompos, (gint) camel_mime_parser_tell_start_from (mp));
1130
"Didn't get the next message where "
1131
"I expected (%d) got %d instead",
1132
(gint) info->frompos,
1133
(gint) camel_mime_parser_tell_start_from (mp));
1123
1135
error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
1124
1136
_("Summary and folder mismatch, even after a sync"));
1128
1140
lastdel = FALSE;
1129
1141
if ((flags&1) && info->info.info.flags & CAMEL_MESSAGE_DELETED) {
1130
1142
const gchar *uid = camel_message_info_uid (info);
1131
d(printf("Deleting %s\n", uid));
1143
d (printf ("Deleting %s\n", uid));
1133
1145
if (((CamelLocalSummary *) cls)->index)
1134
1146
camel_index_delete_name (((CamelLocalSummary *) cls)->index, uid);
1136
1148
/* remove it from the change list */
1137
1149
camel_folder_change_info_remove_uid (changeinfo, uid);
1138
camel_folder_summary_remove_uid (s, uid);
1150
camel_folder_summary_remove (s, (CamelMessageInfo *) info);
1139
1151
del = g_list_prepend (del, (gpointer) camel_pstring_strdup (uid));
1140
1152
camel_message_info_free ((CamelMessageInfo *) info);
1145
1157
/* otherwise, the message is staying, copy its From_ line across */
1148
write(fdout, "\n", 1);
1160
write (fdout, "\n", 1);
1150
1162
info->frompos = lseek (fdout, 0, SEEK_CUR);
1151
1163
((CamelMessageInfo *) info)->dirty = TRUE;
1152
1164
fromline = camel_mime_parser_from_line (mp);
1153
d(printf("Saving %s:%d\n", camel_message_info_uid(info), info->frompos));
1165
d (printf ("Saving %s:%d\n", camel_message_info_uid (info), info->frompos));
1154
1166
g_warn_if_fail (write (fdout, fromline, strlen (fromline)) != -1);
1157
1169
if (info && info->info.info.flags & (CAMEL_MESSAGE_FOLDER_NOXEV | CAMEL_MESSAGE_FOLDER_FLAGGED)) {
1158
d(printf("Updating header for %s flags = %08x\n", camel_message_info_uid(info), info->info.flags));
1170
d (printf ("Updating header for %s flags = %08x\n", camel_message_info_uid (info), info->info.flags));
1160
1172
if (camel_mime_parser_step (mp, &buffer, &len) == CAMEL_MIME_PARSER_STATE_FROM_END) {
1161
g_warning("camel_mime_parser_step failed (2)");
1173
g_warning ("camel_mime_parser_step failed (2)");
1192
1204
camel_mime_parser_drop_step (mp);
1194
d(printf("looking for message content to copy across from %d\n", (gint)camel_mime_parser_tell(mp)));
1206
d (printf ("looking for message content to copy across from %d\n", (gint) camel_mime_parser_tell (mp)));
1195
1207
while (camel_mime_parser_step (mp, &buffer, &len) == CAMEL_MIME_PARSER_STATE_PRE_FROM) {
1196
1208
/*d(printf("copying mbox contents to temporary: '%.*s'\n", len, buffer));*/
1197
1209
if (write (fdout, buffer, len) != len) {
1208
if (write(fdout, "\n", 1) != 1) {
1220
if (write (fdout, "\n", 1) != 1) {
1210
1222
error, G_IO_ERROR,
1211
1223
g_io_error_from_errno (errno),
1217
d(printf("we are now at %d, from = %d\n", (gint)camel_mime_parser_tell(mp),
1218
(gint) camel_mime_parser_tell_start_from (mp)));
1230
"we are now at %d, from = %d\n",
1231
(gint) camel_mime_parser_tell (mp),
1232
(gint) camel_mime_parser_tell_start_from (mp)));
1219
1233
camel_mime_parser_unstep (mp);
1220
1234
camel_message_info_free ((CamelMessageInfo *) info);
1294
1308
/* we snoop and add status/x-status headers to suit */
1295
1309
encode_status (mi->info.info.flags & STATUS_STATUS, status);
1296
camel_medium_set_header((CamelMedium *)msg, "Status", status);
1310
camel_medium_set_header ((CamelMedium *) msg, "Status", status);
1297
1311
encode_status (mi->info.info.flags & STATUS_XSTATUS, status);
1298
camel_medium_set_header((CamelMedium *)msg, "X-Status", status);
1312
camel_medium_set_header ((CamelMedium *) msg, "X-Status", status);
1301
1315
return (CamelMessageInfo *) mi;