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

« back to all changes in this revision

Viewing changes to camel/providers/pop3/camel-pop3-folder.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:
36
36
#include "camel-pop3-store.h"
37
37
#include "camel-pop3-settings.h"
38
38
 
39
 
#define d(x) if (camel_debug("pop")) x;
 
39
#define d(x) if (camel_debug("pop3")) x;
40
40
 
41
41
G_DEFINE_TYPE (CamelPOP3Folder, camel_pop3_folder, CAMEL_TYPE_FOLDER)
42
42
 
78
78
                if (ret >= 0) {
79
79
                        if (strlen ((gchar *) line) > 1024)
80
80
                                line[1024] = 0;
81
 
                        if (sscanf((gchar *) line, "%u %s", &id, uid) == 2) {
 
81
                        if (sscanf ((gchar *) line, "%u %s", &id, uid) == 2) {
82
82
                                fi = g_hash_table_lookup (folder->uids_id, GINT_TO_POINTER (id));
83
83
                                if (fi) {
84
84
                                        camel_operation_progress (NULL, (fi->index + 1) * 100 / folder->uids->len);
85
85
                                        fi->uid = g_strdup (uid);
86
86
                                        g_hash_table_insert (folder->uids_fi, fi->uid, fi);
87
87
                                } else {
88
 
                                        g_warning("ID %u (uid: %s) not in previous LIST output", id, uid);
 
88
                                        g_warning ("ID %u (uid: %s) not in previous LIST output", id, uid);
89
89
                                }
90
90
                        }
91
91
                }
122
122
        case CAMEL_MIME_PARSER_STATE_MULTIPART:
123
123
                h = camel_mime_parser_headers_raw (mp);
124
124
                while (h) {
125
 
                        if (g_ascii_strcasecmp(h->name, "status") != 0
126
 
                            && g_ascii_strcasecmp(h->name, "x-status") != 0) {
 
125
                        if (g_ascii_strcasecmp (h->name, "status") != 0
 
126
                            && g_ascii_strcasecmp (h->name, "x-status") != 0) {
127
127
                                g_checksum_update (checksum, (guchar *) h->name, -1);
128
128
                                g_checksum_update (checksum, (guchar *) h->value, -1);
129
129
                        }
138
138
 
139
139
        fi->uid = g_base64_encode ((guchar *) digest, length);
140
140
 
141
 
        d(printf("building uid for id '%d' = '%s'\n", fi->id, fi->uid));
 
141
        d (printf ("building uid for id '%d' = '%s'\n", fi->id, fi->uid));
142
142
}
143
143
 
144
144
static void
164
164
        pop3_store = CAMEL_POP3_STORE (parent_store);
165
165
        pop3_folder = (CamelPOP3Folder *) folder;
166
166
        service = (CamelService *) parent_store;
167
 
        settings = camel_service_get_settings (service);
168
 
 
169
 
        batch_fetch_count = camel_pop3_settings_get_batch_fetch_count (CAMEL_POP3_SETTINGS (settings));
 
167
 
 
168
        settings = camel_service_ref_settings (service);
 
169
 
 
170
        batch_fetch_count = camel_pop3_settings_get_batch_fetch_count (
 
171
                CAMEL_POP3_SETTINGS (settings));
 
172
 
 
173
        g_object_unref (settings);
170
174
 
171
175
        do {
172
176
                ret = camel_pop3_stream_line (stream, &line, &len, cancellable, NULL);
173
177
                if (ret >= 0) {
174
 
                        if (sscanf((gchar *) line, "%u %u", &id, &size) == 2) {
 
178
                        if (sscanf ((gchar *) line, "%u %u", &id, &size) == 2) {
175
179
                                fi = g_malloc0 (sizeof (*fi));
176
180
                                fi->size = size;
177
181
                                fi->id = id;
178
182
                                fi->index = ((CamelPOP3Folder *) folder)->uids->len;
179
183
                                if ((pop3_store->engine->capa & CAMEL_POP3_CAP_UIDL) == 0)
180
 
                                        fi->cmd = camel_pop3_engine_command_new(pe, CAMEL_POP3_COMMAND_MULTI, cmd_builduid, fi, cancellable, NULL, "TOP %u 0\r\n", id);
 
184
                                        fi->cmd = camel_pop3_engine_command_new (
 
185
                                                pe,
 
186
                                                CAMEL_POP3_COMMAND_MULTI,
 
187
                                                cmd_builduid, fi,
 
188
                                                cancellable, NULL,
 
189
                                                "TOP %u 0\r\n", id);
181
190
                                g_ptr_array_add (pop3_folder->uids, fi);
182
 
                                g_hash_table_insert (pop3_folder->uids_id, GINT_TO_POINTER (id), fi);
 
191
                                g_hash_table_insert (
 
192
                                        pop3_folder->uids_id,
 
193
                                        GINT_TO_POINTER (id), fi);
183
194
                        }
184
195
                }
185
196
        } while (ret > 0);
188
199
        if (pop3_folder->mobile_mode && pop3_folder->uids->len) {
189
200
                gint y = 0;
190
201
                gboolean save_uid = FALSE;
191
 
                CamelNetworkSettings *network_settings;
192
 
                const gchar *host;
193
 
 
194
 
                network_settings = CAMEL_NETWORK_SETTINGS (settings);
195
 
                host = camel_network_settings_get_host (network_settings);
196
 
 
197
 
                d(printf("*********** Mobile mode *************\n"));
198
 
                d(printf("Total Count: %s: %d\n", host, pop3_folder->uids->len));
199
202
 
200
203
                /* Preserve the first message's ID */
201
204
                fi = pop3_folder->uids->pdata[0];
208
211
                                /* First time downloading the POP folder, lets just download only a batch. */
209
212
                                last_uid = -1;
210
213
                        }
211
 
                        d(printf("Last stored' first uid: %d\n", last_uid));
 
214
                        d (printf ("Last stored' first uid: %d\n", last_uid));
212
215
                }
213
216
 
214
217
                if (last_uid == -1)
229
232
                        /* Lets pull another window of old messages */
230
233
                        save_uid = TRUE;
231
234
                        /* Decrement 'i' by another batch count or till we reach the first message */
232
 
                        d(printf("Fetch more (%d): from %d", pop3_folder->fetch_more, i));
 
235
                        d (printf ("Fetch more (%d): from %d", pop3_folder->fetch_more, i));
233
236
                        for (k = 0; k< pop3_folder->fetch_more && i>= 0; k++, i--);
234
 
                        d(printf(" to %d\n", i));
 
237
                        d (printf (" to %d\n", i));
235
238
 
236
239
                        /* Don't load messages newer than the latest we already had. We had to just get old messages and not 
237
240
                         * new messages. */
273
276
                                free_fi (pop3_folder, fi);
274
277
                        }
275
278
                        g_ptr_array_remove_range (pop3_folder->uids, 0, i);
276
 
                        d(printf("Removing %d uids that are old\n", i));
 
279
                        d (printf ("Removing %d uids that are old\n", i));
277
280
 
278
281
                }
279
282
 
304
307
                        g_key_file_load_from_file (pop3_folder->key_file, path, G_KEY_FILE_NONE, NULL);
305
308
                        g_free (contents);
306
309
                        g_free (path);
307
 
                        d(printf("Saving last uid %d\n", fi->id));
 
310
                        d (printf ("Saving last uid %d\n", fi->id));
308
311
 
309
312
                }
310
313
 
502
505
        pop3_store = CAMEL_POP3_STORE (parent_store);
503
506
 
504
507
        service = CAMEL_SERVICE (parent_store);
505
 
        settings = camel_service_get_settings (service);
 
508
 
 
509
        settings = camel_service_ref_settings (service);
506
510
 
507
511
        g_object_get (
508
512
                settings,
509
513
                "auto-fetch", &auto_fetch,
510
514
                NULL);
511
515
 
 
516
        g_object_unref (settings);
 
517
 
512
518
        fi = g_hash_table_lookup (pop3_folder->uids_fi, uid);
513
519
        if (fi == NULL) {
514
520
                g_set_error (
553
559
 
554
560
        /* check to see if we have safely written flag set */
555
561
        if (pop3_store->cache == NULL
556
 
            || (stream = camel_data_cache_get(pop3_store->cache, "cache", fi->uid, NULL)) == NULL
 
562
            || (stream = camel_data_cache_get (pop3_store->cache, "cache", fi->uid, NULL)) == NULL
557
563
            || camel_stream_read (stream, buffer, 1, cancellable, NULL) != 1
558
564
            || buffer[0] != '#') {
559
565
 
560
566
                /* Initiate retrieval, if disk backing fails, use a memory backing */
561
567
                if (pop3_store->cache == NULL
562
 
                    || (stream = camel_data_cache_add(pop3_store->cache, "cache", fi->uid, NULL)) == NULL)
 
568
                    || (stream = camel_data_cache_add (pop3_store->cache, "cache", fi->uid, NULL)) == NULL)
563
569
                        stream = camel_stream_mem_new ();
564
570
 
565
571
                /* ref it, the cache storage routine unref's when done */
566
572
                fi->stream = g_object_ref (stream);
567
 
                pcr = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_tocache, fi, cancellable, NULL, "RETR %u\r\n", fi->id);
 
573
                pcr = camel_pop3_engine_command_new (
 
574
                        pop3_store->engine,
 
575
                        CAMEL_POP3_COMMAND_MULTI,
 
576
                        cmd_tocache, fi,
 
577
                        cancellable, NULL,
 
578
                        "RETR %u\r\n", fi->id);
568
579
 
569
 
                /* Also initiate retrieval of some of the following messages, assume we'll be receiving them */
 
580
                /* Also initiate retrieval of some of the following
 
581
                 * messages, assume we'll be receiving them. */
570
582
                if (auto_fetch && pop3_store->cache != NULL) {
571
 
                        /* This should keep track of the last one retrieved, also how many are still
572
 
                         * oustanding incase of random access on large folders */
 
583
                        /* This should keep track of the last one retrieved,
 
584
                         * also how many are still oustanding incase of random
 
585
                         * access on large folders. */
573
586
                        i = fi->index + 1;
574
587
                        last = MIN (i + 10, pop3_folder->uids->len);
575
588
                        for (; i < last; i++) {
576
589
                                CamelPOP3FolderInfo *pfi = pop3_folder->uids->pdata[i];
577
590
 
578
591
                                if (pfi->uid && pfi->cmd == NULL) {
579
 
                                        pfi->stream = camel_data_cache_add(pop3_store->cache, "cache", pfi->uid, NULL);
 
592
                                        pfi->stream = camel_data_cache_add (
 
593
                                                pop3_store->cache,
 
594
                                                "cache", pfi->uid, NULL);
580
595
                                        if (pfi->stream) {
581
 
                                                pfi->cmd = camel_pop3_engine_command_new (pop3_store->engine, CAMEL_POP3_COMMAND_MULTI,
582
 
                                                                                         cmd_tocache, pfi, cancellable, NULL, "RETR %u\r\n", pfi->id);
 
596
                                                pfi->cmd = camel_pop3_engine_command_new (
 
597
                                                        pop3_store->engine,
 
598
                                                        CAMEL_POP3_COMMAND_MULTI,
 
599
                                                        cmd_tocache, pfi,
 
600
                                                        cancellable, NULL,
 
601
                                                        "RETR %u\r\n", pfi->id);
583
602
                                        }
584
603
                                }
585
604
                        }
698
717
        /* only used during setup */
699
718
        pop3_folder->uids_id = g_hash_table_new (NULL, NULL);
700
719
 
701
 
        pcl = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_list, folder, cancellable, &local_error, "LIST\r\n");
 
720
        pcl = camel_pop3_engine_command_new (
 
721
                pop3_store->engine,
 
722
                CAMEL_POP3_COMMAND_MULTI,
 
723
                cmd_list, folder,
 
724
                cancellable, &local_error,
 
725
                "LIST\r\n");
702
726
        if (!local_error && (pop3_store->engine->capa & CAMEL_POP3_CAP_UIDL) != 0)
703
 
                pcu = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_uidl, folder, cancellable, &local_error, "UIDL\r\n");
 
727
                pcu = camel_pop3_engine_command_new (
 
728
                        pop3_store->engine,
 
729
                        CAMEL_POP3_COMMAND_MULTI,
 
730
                        cmd_uidl, folder,
 
731
                        cancellable, &local_error,
 
732
                        "UIDL\r\n");
704
733
        while ((i = camel_pop3_engine_iterate (pop3_store->engine, NULL, cancellable, error)) > 0)
705
734
                ;
706
735
 
758
787
 
759
788
        parent_store = camel_folder_get_parent_store (folder);
760
789
        service = (CamelService *) parent_store;
761
 
        settings = camel_service_get_settings (service);
762
 
 
763
 
        batch_fetch_count = camel_pop3_settings_get_batch_fetch_count (CAMEL_POP3_SETTINGS (settings));
 
790
 
 
791
        settings = camel_service_ref_settings (service);
 
792
 
 
793
        batch_fetch_count = camel_pop3_settings_get_batch_fetch_count (
 
794
                CAMEL_POP3_SETTINGS (settings));
 
795
 
 
796
        g_object_unref (settings);
764
797
 
765
798
        old_len = pop3_folder->uids->len;
766
799
 
808
841
        pop3_store = CAMEL_POP3_STORE (parent_store);
809
842
 
810
843
        service = CAMEL_SERVICE (parent_store);
811
 
        settings = camel_service_get_settings (service);
812
844
        is_online = camel_service_get_connection_status (service) == CAMEL_SERVICE_CONNECTED;
813
845
 
 
846
        settings = camel_service_ref_settings (service);
 
847
 
814
848
        g_object_get (
815
849
                settings,
816
850
                "delete-after-days", &delete_after_days,
818
852
                "keep-on-server", &keep_on_server,
819
853
                NULL);
820
854
 
 
855
        g_object_unref (settings);
 
856
 
821
857
        if (is_online && delete_after_days > 0 && !expunge) {
822
858
                camel_operation_push_message (
823
859
                        cancellable, _("Expunging old messages"));
853
889
                }
854
890
 
855
891
                if (fi->flags & CAMEL_MESSAGE_DELETED) {
856
 
                        fi->cmd = camel_pop3_engine_command_new (pop3_store->engine,
857
 
                                                                0,
858
 
                                                                NULL,
859
 
                                                                NULL,
860
 
                                                                cancellable, NULL,
861
 
                                                                "DELE %u\r\n",
862
 
                                                                fi->id);
 
892
                        fi->cmd = camel_pop3_engine_command_new (
 
893
                                pop3_store->engine,
 
894
                                0, NULL, NULL,
 
895
                                cancellable, NULL,
 
896
                                "DELE %u\r\n", fi->id);
863
897
 
864
898
                        /* also remove from cache */
865
899
                        if (pop3_store->cache && fi->uid)
866
 
                                camel_data_cache_remove(pop3_store->cache, "cache", fi->uid, NULL);
 
900
                                camel_data_cache_remove (pop3_store->cache, "cache", fi->uid, NULL);
867
901
                }
868
902
        }
869
903
 
924
958
        CamelPOP3Folder *pop3_folder;
925
959
 
926
960
        service = CAMEL_SERVICE (parent);
927
 
        settings = camel_service_get_settings (service);
928
961
 
929
 
        d(printf("opening pop3 INBOX folder\n"));
 
962
        d (printf ("opening pop3 INBOX folder\n"));
930
963
 
931
964
        folder = g_object_new (
932
965
                CAMEL_TYPE_POP3_FOLDER,
933
966
                "full-name", "inbox", "display-name", "inbox",
934
967
                "parent-store", parent, NULL);
935
968
 
 
969
        settings = camel_service_ref_settings (service);
 
970
 
936
971
        pop3_folder = (CamelPOP3Folder *) folder;
937
 
        pop3_folder->mobile_mode = camel_pop3_settings_get_mobile_mode (CAMEL_POP3_SETTINGS (settings));
 
972
        pop3_folder->mobile_mode = camel_pop3_settings_get_mobile_mode (
 
973
                CAMEL_POP3_SETTINGS (settings));
 
974
 
 
975
        g_object_unref (settings);
938
976
 
939
977
        pop3_folder->fetch_more = 0;
940
978
        if (pop3_folder->mobile_mode) {
1041
1079
        pop3_store = CAMEL_POP3_STORE (parent_store);
1042
1080
        temp = time (&temp);
1043
1081
 
1044
 
        d(printf("%s(%d): pop3_folder->uids->len=[%d]\n", __FILE__, __LINE__, pop3_folder->uids->len));
 
1082
        d (printf ("%s(%d): pop3_folder->uids->len=[%d]\n", __FILE__, __LINE__, pop3_folder->uids->len));
1045
1083
        for (i = 0; i < pop3_folder->uids->len; i++) {
1046
1084
                message_time = 0;
1047
1085
                fi = pop3_folder->uids->pdata[i];
1059
1097
                if (!fi->uid)
1060
1098
                        continue;
1061
1099
 
1062
 
                d(printf("%s(%d): fi->uid=[%s]\n", __FILE__, __LINE__, fi->uid));
 
1100
                d (printf ("%s(%d): fi->uid=[%s]\n", __FILE__, __LINE__, fi->uid));
1063
1101
                if (!pop3_get_message_time_from_cache (folder, fi->uid, &message_time)) {
1064
 
                        d(printf("could not get message time from cache, trying from pop3\n"));
 
1102
                        d (printf ("could not get message time from cache, trying from pop3\n"));
1065
1103
                        message = pop3_folder_get_message_sync (
1066
1104
                                folder, fi->uid, cancellable, error);
1067
1105
                        if (message) {
1074
1112
                        gdouble time_diff = difftime (temp,message_time);
1075
1113
                        gint day_lag = time_diff / (60 * 60 * 24);
1076
1114
 
1077
 
                        d(printf("%s(%d): message_time= [%ld]\n", __FILE__, __LINE__, message_time));
1078
 
                        d(printf("%s(%d): day_lag=[%d] \t days_to_delete=[%d]\n",
 
1115
                        d (printf (
 
1116
                                "%s(%d): message_time= [%ld]\n",
 
1117
                                __FILE__, __LINE__, message_time));
 
1118
                        d (printf (
 
1119
                                "%s(%d): day_lag=[%d] \t days_to_delete=[%d]\n",
1079
1120
                                __FILE__, __LINE__, day_lag, days_to_delete));
1080
1121
 
1081
1122
                        if (day_lag > days_to_delete) {
1087
1128
                                        camel_pop3_engine_command_free (pop3_store->engine, fi->cmd);
1088
1129
                                        fi->cmd = NULL;
1089
1130
                                }
1090
 
                                d(printf("%s(%d): Deleting old messages\n", __FILE__, __LINE__));
1091
 
                                fi->cmd = camel_pop3_engine_command_new (pop3_store->engine,
1092
 
                                                                        0,
1093
 
                                                                        NULL,
1094
 
                                                                        NULL,
1095
 
                                                                        cancellable, NULL,
1096
 
                                                                        "DELE %u\r\n",
1097
 
                                                                        fi->id);
 
1131
                                d (printf (
 
1132
                                        "%s(%d): Deleting old messages\n",
 
1133
                                        __FILE__, __LINE__));
 
1134
                                fi->cmd = camel_pop3_engine_command_new (
 
1135
                                        pop3_store->engine,
 
1136
                                        0, NULL, NULL,
 
1137
                                        cancellable, NULL,
 
1138
                                        "DELE %u\r\n", fi->id);
1098
1139
                                /* also remove from cache */
1099
1140
                                if (pop3_store->cache && fi->uid) {
1100
 
                                        camel_data_cache_remove(pop3_store->cache, "cache", fi->uid, NULL);
 
1141
                                        camel_data_cache_remove (pop3_store->cache, "cache", fi->uid, NULL);
1101
1142
                                }
1102
1143
                        }
1103
1144
                }