~ubuntu-branches/ubuntu/saucy/evolution-data-server/saucy

« back to all changes in this revision

Viewing changes to camel/providers/local/camel-mbox-summary.c

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-10-08 12:58:16 UTC
  • mfrom: (181.1.7 quantal)
  • Revision ID: package-import@ubuntu.com-20121008125816-i3n76e8c0m64e7xp
Tags: 3.6.0-0ubuntu2
* Fix LP: #1038047 part 1 - Don't abort in e_source_registry_new* when a
  problem occurs connecting to the Dbus service
  - add debian/patches/dont-abort-in-e_source_registry_new.patch
  - update debian/patches/series
* Fix LP: #1038047 part 2 - libedataserver depends on
  evolution-data-server-common to ensure that the GSettings schemas are
  present
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
186
186
                parent_store = camel_folder_get_parent_store (folder);
187
187
 
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";
192
192
 
212
212
        while (*p && isdigit (*p))
213
213
                p++;
214
214
 
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);
217
217
        } else {
218
 
                return g_strdup_printf("%s-%04x", uidstr, mi->info.flags & 0xffff);
 
218
                return g_strdup_printf ("%s-%04x", uidstr, mi->info.flags & 0xffff);
219
219
        }
220
220
}
221
221
 
277
277
 
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);
281
281
                        if (status)
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);
284
284
                        if (xstatus)
285
285
                                flags |= decode_status (xstatus);
286
286
                }
287
287
#endif
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);
290
290
                if (xev != 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);
296
296
                        if (info) {
300
300
                                        mi = info;
301
301
                                } else {
302
302
                                        add = 7;
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);
305
305
                                }
306
306
                        } else {
307
307
                                add = 2;
308
 
                                d(printf("but isn't present in summary\n"));
 
308
                                d (printf ("but isn't present in summary\n"));
309
309
                        }
310
310
                } else {
311
 
                        d(printf("didn't find x-evolution\n"));
 
311
                        d (printf ("didn't find x-evolution\n"));
312
312
                        add = 7;
313
313
                }
314
314
 
384
384
        struct _CamelMIRecord *mir;
385
385
 
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);
388
388
 
389
389
        return mir;
390
390
}
411
411
        GList *del = NULL;
412
412
        GPtrArray *known_uids;
413
413
 
414
 
        d(printf("Calling summary update, from pos %d\n", (gint)offset));
 
414
        d (printf ("Calling summary update, from pos %d\n", (gint) offset));
415
415
 
416
416
        cls->index_force = FALSE;
417
417
 
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);
422
422
        if (fd == -1) {
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);
425
425
                g_set_error (
426
426
                        error, G_IO_ERROR,
444
444
                    && camel_mime_parser_tell_start_from (mp) == offset) {
445
445
                        camel_mime_parser_unstep (mp);
446
446
                } else {
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);
449
449
                        offset = 0;
450
450
                        camel_mime_parser_seek (mp, offset, SEEK_SET);
488
488
                        g_set_error (
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);
493
493
                        ok = -1;
494
494
                        break;
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));
514
514
                        if (changeinfo)
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);
 
517
                        if (mi)
 
518
                                camel_folder_summary_remove (s, (CamelMessageInfo *) mi);
518
519
                }
519
520
 
520
521
                if (mi)
560
561
        gint ret = 0;
561
562
        gint i;
562
563
 
563
 
        d(printf("Checking summary\n"));
 
564
        d (printf ("Checking summary\n"));
564
565
 
565
566
        camel_folder_summary_lock (s, CAMEL_FOLDER_SUMMARY_SUMMARY_LOCK);
566
567
 
584
585
                GPtrArray *known_uids;
585
586
 
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);
608
609
                        } else {
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);
611
612
                        }
612
613
                } else {
613
 
                        d(printf("Folder unchanged, do nothing\n"));
 
614
                        d (printf ("Folder unchanged, do nothing\n"));
614
615
                }
615
616
        }
616
617
 
644
645
        guint32 flags = (expunge ? 1 : 0), filemode = 0600;
645
646
        struct stat st;
646
647
 
647
 
        d(printf("performing full summary/sync\n"));
 
648
        d (printf ("performing full summary/sync\n"));
648
649
 
649
650
        camel_operation_push_message (cancellable, _("Storing folder"));
650
651
        camel_folder_summary_lock (s, CAMEL_FOLDER_SUMMARY_SUMMARY_LOCK);
667
668
 
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) {
673
674
                g_set_error (
683
684
                fd, fdout, cancellable, error) == -1)
684
685
                goto error;
685
686
 
686
 
        d(printf("Closing folders\n"));
 
687
        d (printf ("Closing folders\n"));
687
688
 
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));
690
691
                g_set_error (
691
692
                        error, G_IO_ERROR,
692
693
                        g_io_error_from_errno (errno),
697
698
        }
698
699
 
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));
701
702
                g_set_error (
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));
715
716
#endif
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));
718
719
                g_set_error (
719
720
                        error, G_IO_ERROR,
720
721
                        g_io_error_from_errno (errno),
788
789
        goffset lastpos;
789
790
        GPtrArray *summary = NULL;
790
791
 
791
 
        d(printf("Performing quick summary sync\n"));
 
792
        d (printf ("Performing quick summary sync\n"));
792
793
 
793
794
        camel_operation_push_message (cancellable, _("Storing folder"));
794
795
        camel_folder_summary_lock (s, CAMEL_FOLDER_SUMMARY_SUMMARY_LOCK);
837
838
 
838
839
                info = (CamelMboxMessageInfo *) camel_folder_summary_get (s, summary->pdata[i]);
839
840
 
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));
841
842
 
842
843
                if ((info->info.info.flags & CAMEL_MESSAGE_FOLDER_FLAGGED) == 0) {
843
844
                        camel_message_info_free ((CamelMessageInfo *) info);
845
846
                        continue;
846
847
                }
847
848
 
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));
849
850
 
850
851
                camel_mime_parser_seek (mp, info->frompos, SEEK_SET);
851
852
 
857
858
                }
858
859
 
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));
 
861
                        g_warning (
 
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));
862
864
                        g_set_error (
863
865
                                error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
864
866
                                _("Summary and folder mismatch, even after a sync"));
866
868
                }
867
869
 
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)");
870
872
                        goto error;
871
873
                }
872
874
 
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");
876
878
                        goto error;
877
879
                }
878
880
                xevnew = camel_local_summary_encode_x_evolution (cls, &info->info);
884
886
                if (strlen (xev) - 1 != strlen (xevtmp)) {
885
887
                        g_free (xevnew);
886
888
                        g_free (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");
888
890
                        goto error;
889
891
                }
890
892
                g_free (xevtmp);
892
894
                /* we write out the xevnew string, assuming its been folded identically to the original too! */
893
895
 
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);
896
898
                do {
897
899
                        len = write (fd, xevnew, strlen (xevnew));
898
900
                } while (len == -1 && errno == EINTR);
908
910
                info = NULL;
909
911
        }
910
912
 
911
 
        d(printf("Closing folders\n"));
 
913
        d (printf ("Closing folders\n"));
912
914
 
913
915
        if (close (fd) == -1) {
914
916
                g_warning ("Cannot close source folder: %s", g_strerror (errno));
1008
1010
                        ret = CAMEL_MBOX_SUMMARY_GET_CLASS (cls)->sync_quick (
1009
1011
                                mbs, expunge, changeinfo, cancellable, NULL);
1010
1012
                        if (ret == -1)
1011
 
                                g_warning("failed a quick-sync, trying a full sync");
 
1013
                                g_warning ("failed a quick-sync, trying a full sync");
1012
1014
                } else {
1013
1015
                        ret = 0;
1014
1016
                }
1070
1072
        gchar statnew[8], xstatnew[8];
1071
1073
#endif
1072
1074
 
1073
 
        d(printf("performing full summary/sync\n"));
 
1075
        d (printf ("performing full summary/sync\n"));
1074
1076
 
1075
1077
        camel_folder_summary_lock (s, CAMEL_FOLDER_SUMMARY_SUMMARY_LOCK);
1076
1078
 
1103
1105
                if (!info)
1104
1106
                        continue;
1105
1107
 
1106
 
                d(printf("Looking at message %s\n", camel_message_info_uid(info)));
1107
 
 
1108
 
                d(printf("seeking (%s) to %d\n", ((CamelMessageInfo *) info)->uid, (gint)info->frompos));
 
1108
                d (printf (
 
1109
                        "Looking at message %s\n",
 
1110
                        camel_message_info_uid (info)));
 
1111
 
 
1112
                d (printf (
 
1113
                        "seeking (%s) to %d\n",
 
1114
                        ((CamelMessageInfo *) info)->uid,
 
1115
                        (gint) info->frompos));
 
1116
 
1109
1117
                if (lastdel)
1110
1118
                        camel_mime_parser_seek (mp, info->frompos, SEEK_SET);
1111
1119
 
1112
1120
                if (camel_mime_parser_step (mp, &buffer, &len) != CAMEL_MIME_PARSER_STATE_FROM) {
1113
1121
                        g_set_error (
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.)"));
1116
1125
                        goto error;
1117
1126
                }
1118
1127
 
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));
 
1129
                        g_warning (
 
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));
1122
1134
                        g_set_error (
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));
1132
1144
 
1133
1145
                        if (((CamelLocalSummary *) cls)->index)
1134
1146
                                camel_index_delete_name (((CamelLocalSummary *) cls)->index, uid);
1135
1147
 
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);
1141
1153
                        info = NULL;
1145
1157
                        /* otherwise, the message is staying, copy its From_ line across */
1146
1158
#if 0
1147
1159
                        if (i > 0)
1148
 
                                write(fdout, "\n", 1);
 
1160
                                write (fdout, "\n", 1);
1149
1161
#endif
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);
1155
1167
                }
1156
1168
 
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));
1159
1171
 
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)");
1162
1174
                                goto error;
1163
1175
                        }
1164
1176
 
1175
1187
                        }
1176
1188
#endif
1177
1189
                        if (len == -1) {
1178
 
                                d(printf("Error writing to temporary mailbox\n"));
 
1190
                                d (printf ("Error writing to temporary mailbox\n"));
1179
1191
                                g_set_error (
1180
1192
                                        error, G_IO_ERROR,
1181
1193
                                        g_io_error_from_errno (errno),
1191
1203
 
1192
1204
                camel_mime_parser_drop_step (mp);
1193
1205
                if (info) {
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) {
1205
1217
                                }
1206
1218
                        }
1207
1219
 
1208
 
                        if (write(fdout, "\n", 1) != 1) {
 
1220
                        if (write (fdout, "\n", 1) != 1) {
1209
1221
                                g_set_error (
1210
1222
                                        error, G_IO_ERROR,
1211
1223
                                        g_io_error_from_errno (errno),
1214
1226
                                goto error;
1215
1227
                        }
1216
1228
 
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)));
 
1229
                        d (printf (
 
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);
1221
1235
                        info = NULL;
1231
1245
#if 0
1232
1246
        /* if last was deleted, append the \n we removed */
1233
1247
        if (lastdel && count > 0)
1234
 
                write(fdout, "\n", 1);
 
1248
                write (fdout, "\n", 1);
1235
1249
#endif
1236
1250
 
1237
1251
        g_object_unref (mp);
1293
1307
 
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);
1299
1313
        }
1300
1314
 
1301
1315
        return (CamelMessageInfo *) mi;