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

« back to all changes in this revision

Viewing changes to camel/providers/imap/camel-imap-store.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:
71
71
static CamelFolder *imap_store_get_junk_folder_sync (CamelStore *store, GCancellable *cancellable, GError **error);
72
72
static CamelFolder *imap_store_get_trash_folder_sync (CamelStore *store, GCancellable *cancellable, GError **error);
73
73
static guint hash_folder_name (gconstpointer key);
74
 
static gint compare_folder_name (gconstpointer a, gconstpointer b);
 
74
static gboolean equal_folder_name (gconstpointer a, gconstpointer b);
75
75
 
76
76
static CamelFolderInfo *imap_store_create_folder_sync (CamelStore *store, const gchar *parent_name, const gchar *folder_name, GCancellable *cancellable, GError **error);
77
77
static gboolean imap_store_delete_folder_sync (CamelStore *store, const gchar *folder_name, GCancellable *cancellable, GError **error);
149
149
         *     to take effect. */
150
150
 
151
151
        service = CAMEL_SERVICE (store);
152
 
        settings = camel_service_get_settings (service);
 
152
        settings = camel_service_ref_settings (service);
153
153
        imap_settings = CAMEL_IMAP_SETTINGS (settings);
154
154
 
155
155
        real_path = camel_imap_settings_dup_real_junk_path (imap_settings);
174
174
                store->flags |= CAMEL_STORE_VTRASH;
175
175
 
176
176
        g_free (real_path);
 
177
 
 
178
        g_object_unref (settings);
177
179
}
178
180
 
179
181
static void
185
187
 
186
188
        for (capa = strtok_r (capa, " ", &lasts); capa; capa = strtok_r (NULL, " ", &lasts)) {
187
189
                if (!strncmp (capa, "AUTH=", 5)) {
188
 
                        g_hash_table_insert (store->authtypes,
189
 
                                             g_strdup (capa + 5),
190
 
                                             GINT_TO_POINTER (1));
 
190
                        g_hash_table_insert (
 
191
                                store->authtypes,
 
192
                                g_strdup (capa + 5),
 
193
                                GINT_TO_POINTER (1));
191
194
                        continue;
192
195
                }
193
196
                for (i = 0; capabilities[i].name; i++) {
300
303
        if (tcp_stream == NULL)
301
304
                return FALSE;
302
305
 
303
 
        settings = camel_service_get_settings (service);
 
306
        settings = camel_service_ref_settings (service);
304
307
 
305
308
        network_settings = CAMEL_NETWORK_SETTINGS (settings);
306
309
        host = camel_network_settings_dup_host (network_settings);
307
310
        method = camel_network_settings_get_security_method (network_settings);
308
311
 
 
312
        g_object_unref (settings);
 
313
 
309
314
        store->ostream = tcp_stream;
310
315
        store->istream = camel_stream_buffer_new (tcp_stream, CAMEL_STREAM_BUFFER_READ);
311
316
 
341
346
                goto exit;
342
347
        }
343
348
 
344
 
        if (!strncmp(buf, "* PREAUTH", 9))
 
349
        if (!strncmp (buf, "* PREAUTH", 9))
345
350
                store->preauthed = TRUE;
346
351
 
347
 
        if (strstr (buf, "Courier-IMAP") || getenv("CAMEL_IMAP_BRAINDAMAGED")) {
 
352
        if (strstr (buf, "Courier-IMAP") || getenv ("CAMEL_IMAP_BRAINDAMAGED")) {
348
353
                /* Courier-IMAP is braindamaged. So far this flag only
349
354
                 * works around the fact that Courier-IMAP is known to
350
355
                 * give invalid BODY responses seemingly because its
470
475
exception:
471
476
 
472
477
        if (clean_quit && store->connected) {
473
 
                /* try to disconnect cleanly */
474
 
                response = camel_imap_command (store, NULL, cancellable, error, "LOGOUT");
 
478
                /* try to disconnect cleanly; error is already set here */
 
479
                response = camel_imap_command (store, NULL, cancellable, NULL, "LOGOUT");
475
480
                if (response)
476
481
                        camel_imap_response_free_without_processing (store, response);
477
482
        }
526
531
 
527
532
        password = camel_service_get_password (service);
528
533
        provider = camel_service_get_provider (service);
529
 
        settings = camel_service_get_settings (service);
 
534
 
 
535
        settings = camel_service_ref_settings (service);
530
536
 
531
537
        network_settings = CAMEL_NETWORK_SETTINGS (settings);
532
538
        host = camel_network_settings_dup_host (network_settings);
533
539
        port = camel_network_settings_get_port (network_settings);
534
540
        user = camel_network_settings_dup_user (network_settings);
535
541
 
 
542
        g_object_unref (settings);
 
543
 
536
544
        camel_url_set_protocol (&url, provider->protocol);
537
545
        camel_url_set_host (&url, host);
538
546
        camel_url_set_port (&url, port);
541
549
        /* Put full details in the environment, in case the connection
542
550
         * program needs them */
543
551
        buf = camel_url_to_string (&url, 0);
544
 
        child_env[i++] = g_strdup_printf("URL=%s", buf);
 
552
        child_env[i++] = g_strdup_printf ("URL=%s", buf);
545
553
        g_free (buf);
546
554
 
547
 
        child_env[i++] = g_strdup_printf("URLHOST=%s", host);
 
555
        child_env[i++] = g_strdup_printf ("URLHOST=%s", host);
548
556
        if (port)
549
 
                child_env[i++] = g_strdup_printf("URLPORT=%d", port);
 
557
                child_env[i++] = g_strdup_printf ("URLPORT=%d", port);
550
558
        if (user)
551
 
                child_env[i++] = g_strdup_printf("URLUSER=%s", user);
 
559
                child_env[i++] = g_strdup_printf ("URLUSER=%s", user);
552
560
        if (password)
553
 
                child_env[i++] = g_strdup_printf("URLPASSWD=%s", password);
 
561
                child_env[i++] = g_strdup_printf ("URLPASSWD=%s", password);
554
562
        child_env[i] = NULL;
555
563
 
556
564
        /* Now do %h, %u, etc. substitution in cmd */
557
565
        buf = cmd_copy = g_strdup (cmd);
558
566
 
559
 
        full_cmd = g_strdup("");
 
567
        full_cmd = g_strdup ("");
560
568
 
561
569
        for (;;) {
562
570
                gchar *pc;
567
575
                pc = strchr (buf, '%');
568
576
        ignore:
569
577
                if (!pc) {
570
 
                        tmp = g_strdup_printf("%s%s", full_cmd, buf);
 
578
                        tmp = g_strdup_printf ("%s%s", full_cmd, buf);
571
579
                        g_free (full_cmd);
572
580
                        full_cmd = tmp;
573
581
                        break;
591
599
                        pc = strchr (pc + 1, '%');
592
600
                        goto ignore;
593
601
                }
594
 
                tmp = g_strdup_printf("%s%.*s%s", full_cmd, len, buf, var);
 
602
                tmp = g_strdup_printf ("%s%.*s%s", full_cmd, len, buf, var);
595
603
                g_free (full_cmd);
596
604
                full_cmd = tmp;
597
605
                buf = pc + 2;
642
650
                return FALSE;
643
651
        }
644
652
 
645
 
        if (!strncmp(buf, "* PREAUTH", 9))
 
653
        if (!strncmp (buf, "* PREAUTH", 9))
646
654
                store->preauthed = TRUE;
647
655
        g_free (buf);
648
656
 
678
686
        gboolean use_shell_command;
679
687
        gboolean success;
680
688
 
681
 
        settings = camel_service_get_settings (service);
 
689
        settings = camel_service_ref_settings (service);
 
690
 
682
691
        shell_command = camel_imap_settings_dup_shell_command (
683
692
                CAMEL_IMAP_SETTINGS (settings));
684
693
        use_shell_command = camel_imap_settings_get_use_shell_command (
685
694
                CAMEL_IMAP_SETTINGS (settings));
686
695
 
 
696
        g_object_unref (settings);
 
697
 
687
698
#ifndef G_OS_WIN32
688
699
        if (use_shell_command && shell_command != NULL)
689
700
                success = connect_to_server_process (
713
724
        gboolean success = TRUE;
714
725
 
715
726
        session = camel_service_get_session (service);
716
 
        settings = camel_service_get_settings (service);
 
727
 
 
728
        settings = camel_service_ref_settings (service);
717
729
 
718
730
        network_settings = CAMEL_NETWORK_SETTINGS (settings);
719
731
        host = camel_network_settings_dup_host (network_settings);
720
732
        mechanism = camel_network_settings_dup_auth_mechanism (network_settings);
721
733
 
 
734
        g_object_unref (settings);
 
735
 
722
736
        if (store->preauthed) {
723
737
                if (camel_verbose_debug)
724
 
                        fprintf(stderr, "Server %s has preauthenticated us.\n",
 
738
                        fprintf (
 
739
                                stderr, "Server %s has preauthenticated us.\n",
725
740
                                host);
726
741
                goto exit;
727
742
        }
732
747
                                error, CAMEL_SERVICE_ERROR,
733
748
                                CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
734
749
                                _("IMAP server %s does not support %s "
735
 
                                  "authentication"), host, mechanism);
 
750
                                "authentication"), host, mechanism);
736
751
                        success = FALSE;
737
752
                        goto exit;
738
753
                }
762
777
{
763
778
        CamelImapStore *imap_store = CAMEL_IMAP_STORE (object);
764
779
 
 
780
        /* This frees current_folder, folders, authtypes, streams, and namespace. */
 
781
        camel_service_disconnect_sync (
 
782
                CAMEL_SERVICE (imap_store), TRUE, NULL, NULL);
 
783
 
765
784
        if (imap_store->summary != NULL) {
766
785
                camel_store_summary_save (
767
786
                        CAMEL_STORE_SUMMARY (imap_store->summary));
778
797
{
779
798
        CamelImapStore *imap_store = CAMEL_IMAP_STORE (object);
780
799
 
781
 
        /* This frees current_folder, folders, authtypes, streams, and namespace. */
782
 
        camel_service_disconnect_sync (
783
 
                CAMEL_SERVICE (imap_store), TRUE, NULL, NULL);
784
 
 
785
800
        g_static_rec_mutex_free (&imap_store->command_and_response_lock);
786
801
        g_hash_table_destroy (imap_store->known_alerts);
787
802
 
799
814
        gchar *user;
800
815
        gchar *name;
801
816
 
802
 
        settings = camel_service_get_settings (service);
 
817
        settings = camel_service_ref_settings (service);
803
818
 
804
819
        network_settings = CAMEL_NETWORK_SETTINGS (settings);
805
820
        host = camel_network_settings_dup_host (network_settings);
806
821
        user = camel_network_settings_dup_user (network_settings);
807
822
 
 
823
        g_object_unref (settings);
 
824
 
808
825
        if (brief)
809
826
                name = g_strdup_printf (
810
827
                        _("IMAP server %s"), host);
832
849
        const gchar *namespace;
833
850
        GError *local_error = NULL;
834
851
 
835
 
        settings = camel_service_get_settings (service);
836
 
        imap_settings = CAMEL_IMAP_SETTINGS (settings);
837
 
 
838
852
        if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store)))
839
853
                return TRUE;
840
854
 
849
863
                return FALSE;
850
864
        }
851
865
 
 
866
        settings = camel_service_ref_settings (service);
 
867
        imap_settings = CAMEL_IMAP_SETTINGS (settings);
 
868
 
852
869
        /* Get namespace and hierarchy separator */
853
870
        if (store->capabilities & IMAP_CAPABILITY_NAMESPACE) {
854
871
                struct _namespaces *namespaces;
997
1014
                        goto done;
998
1015
 
999
1016
                /* Make sure INBOX is present/subscribed */
1000
 
                si = camel_store_summary_path((CamelStoreSummary *)store->summary, "INBOX");
 
1017
                si = camel_store_summary_path ((CamelStoreSummary *) store->summary, "INBOX");
1001
1018
                if (si == NULL || (si->flags & CAMEL_FOLDER_SUBSCRIBED) == 0) {
1002
1019
                        response = camel_imap_command (store, NULL, cancellable, &local_error, "SUBSCRIBE INBOX");
1003
1020
                        if (response != NULL) {
1007
1024
                                camel_store_summary_info_free ((CamelStoreSummary *) store->summary, si);
1008
1025
                        if (local_error != NULL)
1009
1026
                                goto done;
1010
 
                        get_folders_sync(store, "INBOX", cancellable, &local_error);
 
1027
                        get_folders_sync (store, "INBOX", cancellable, &local_error);
1011
1028
                }
1012
1029
 
1013
1030
                store->refresh_stamp = time (NULL);
1014
1031
        }
1015
1032
 
1016
1033
done:
 
1034
        g_object_unref (settings);
 
1035
 
1017
1036
        /* save any changes we had */
1018
1037
        camel_store_summary_save ((CamelStoreSummary *) store->summary);
1019
1038
 
1041
1060
        CamelSettings *settings;
1042
1061
        CamelImapSettings *imap_settings;
1043
1062
 
1044
 
        settings = camel_service_get_settings (service);
1045
 
        imap_settings = CAMEL_IMAP_SETTINGS (settings);
1046
 
 
1047
1063
        if (camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store)) && clean) {
1048
1064
                CamelImapResponse *response;
1049
1065
 
1078
1094
 
1079
1095
        g_hash_table_remove_all (store->known_alerts);
1080
1096
 
 
1097
        settings = camel_service_ref_settings (service);
 
1098
        imap_settings = CAMEL_IMAP_SETTINGS (settings);
 
1099
 
1081
1100
        if (camel_imap_settings_get_use_namespace (imap_settings))
1082
1101
                camel_imap_settings_set_namespace (imap_settings, NULL);
1083
1102
 
 
1103
        g_object_unref (settings);
 
1104
 
1084
1105
        return TRUE;
1085
1106
}
1086
1107
 
1106
1127
                gchar *user;
1107
1128
 
1108
1129
                password = camel_service_get_password (service);
1109
 
                settings = camel_service_get_settings (service);
 
1130
 
 
1131
                settings = camel_service_ref_settings (service);
1110
1132
 
1111
1133
                network_settings = CAMEL_NETWORK_SETTINGS (settings);
1112
1134
                user = camel_network_settings_dup_user (network_settings);
1113
1135
 
 
1136
                g_object_unref (settings);
 
1137
 
1114
1138
                if (user == NULL) {
1115
1139
                        g_set_error_literal (
1116
1140
                                error, CAMEL_SERVICE_ERROR,
1423
1447
        if (!camel_imap_store_connected (imap_store, error))
1424
1448
                return FALSE;
1425
1449
 
1426
 
        response = camel_imap_command (imap_store, NULL, cancellable, error,
1427
 
                                       "SUBSCRIBE %F", folder_name);
 
1450
        response = camel_imap_command (
 
1451
                imap_store, NULL, cancellable, error,
 
1452
                "SUBSCRIBE %F", folder_name);
1428
1453
        if (!response)
1429
1454
                return FALSE;
1430
1455
 
1470
1495
        if (!camel_imap_store_connected (imap_store, error))
1471
1496
                return FALSE;
1472
1497
 
1473
 
        response = camel_imap_command (imap_store, NULL, cancellable, error,
1474
 
                                       "UNSUBSCRIBE %F", folder_name);
 
1498
        response = camel_imap_command (
 
1499
                imap_store, NULL, cancellable, error,
 
1500
                "UNSUBSCRIBE %F", folder_name);
1475
1501
        if (!response)
1476
1502
                return FALSE;
1477
1503
 
1502
1528
 
1503
1529
        store_class = CAMEL_STORE_CLASS (class);
1504
1530
        store_class->hash_folder_name = hash_folder_name;
1505
 
        store_class->compare_folder_name = compare_folder_name;
 
1531
        store_class->equal_folder_name = equal_folder_name;
1506
1532
        store_class->can_refresh_folder = imap_can_refresh_folder;
1507
1533
        store_class->free_folder_info = camel_store_free_folder_info_full;
1508
1534
        store_class->get_folder_sync = imap_store_get_folder_sync;
1651
1677
        camel_db_delete_folder (((CamelStore *) imap_store)->cdb_w, folder_name, NULL);
1652
1678
        camel_imap_message_cache_delete (folder_dir, NULL);
1653
1679
 
1654
 
        state_file = g_strdup_printf("%s/subfolders", folder_dir);
 
1680
        state_file = g_strdup_printf ("%s/subfolders", folder_dir);
1655
1681
        g_rmdir (state_file);
1656
1682
        g_free (state_file);
1657
1683
 
1675
1701
{
1676
1702
        CamelImapResponse *response;
1677
1703
 
1678
 
        response = camel_imap_command (imap_store, NULL, NULL, NULL, "LIST \"\" %F",
1679
 
                                       full_name);
 
1704
        response = camel_imap_command (
 
1705
                imap_store, NULL, NULL, NULL, "LIST \"\" %F", full_name);
1680
1706
 
1681
1707
        if (response) {
1682
1708
                gboolean stillthere = response->untagged->len != 0;
1756
1782
        gchar *trash_path;
1757
1783
 
1758
1784
        service = CAMEL_SERVICE (store);
1759
 
        settings = camel_service_get_settings (service);
1760
1785
        user_cache_dir = camel_service_get_user_cache_dir (service);
1761
1786
 
 
1787
        settings = camel_service_ref_settings (service);
 
1788
 
1762
1789
        trash_path = camel_imap_settings_dup_real_trash_path (
1763
1790
                CAMEL_IMAP_SETTINGS (settings));
1764
1791
        if (trash_path != NULL) {
1770
1797
        }
1771
1798
        g_free (trash_path);
1772
1799
 
 
1800
        g_object_unref (settings);
 
1801
 
1773
1802
        if (folder)
1774
1803
                return folder;
1775
1804
 
1804
1833
        gchar *junk_path;
1805
1834
 
1806
1835
        service = CAMEL_SERVICE (store);
1807
 
        settings = camel_service_get_settings (service);
1808
1836
        user_cache_dir = camel_service_get_user_cache_dir (service);
1809
1837
 
 
1838
        settings = camel_service_ref_settings (service);
 
1839
 
1810
1840
        junk_path = camel_imap_settings_dup_real_junk_path (
1811
1841
                CAMEL_IMAP_SETTINGS (settings));
1812
1842
        if (junk_path != NULL) {
1818
1848
        }
1819
1849
        g_free (junk_path);
1820
1850
 
 
1851
        g_object_unref (settings);
 
1852
 
1821
1853
        if (folder)
1822
1854
                return folder;
1823
1855
 
1849
1881
                return g_str_hash (key);
1850
1882
}
1851
1883
 
1852
 
static gint
1853
 
compare_folder_name (gconstpointer a,
1854
 
                     gconstpointer b)
 
1884
static gboolean
 
1885
equal_folder_name (gconstpointer a,
 
1886
                   gconstpointer b)
1855
1887
{
1856
1888
        gconstpointer aname = a, bname = b;
1857
1889
 
1892
1924
 
1893
1925
        /* FIXME: we assume the server is STATUS-capable */
1894
1926
 
1895
 
        response = camel_imap_command (imap_store, NULL, NULL, NULL,
1896
 
                                       "STATUS %F (%s)",
1897
 
                                       folder_name,
1898
 
                                       type);
 
1927
        response = camel_imap_command (
 
1928
                imap_store, NULL, NULL, NULL,
 
1929
                "STATUS %F (%s)", folder_name, type);
1899
1930
 
1900
1931
        if (!response) {
1901
1932
                if (imap_check_folder_still_extant (imap_store, folder_name, NULL) == FALSE) {
2122
2153
 
2123
2154
                                /* add the dirsep to the end of parent_name */
2124
2155
                                name = g_strdup_printf ("%s%c", parent_real, imap_store->dir_sep);
2125
 
                                response = camel_imap_command (imap_store, NULL, cancellable, error, "CREATE %G",
2126
 
                                                               name);
 
2156
                                response = camel_imap_command (
 
2157
                                        imap_store, NULL,
 
2158
                                        cancellable, error,
 
2159
                                        "CREATE %G", name);
2127
2160
                                g_free (name);
2128
2161
 
2129
2162
                                if (!response) {
2169
2202
        new_folder = camel_imap_folder_new (store, folder_name, folder_dir, error);
2170
2203
        g_free (folder_dir);
2171
2204
        if (new_folder) {
 
2205
                if (imap_store->current_folder)
 
2206
                        g_object_unref (imap_store->current_folder);
2172
2207
                imap_store->current_folder = g_object_ref (new_folder);
2173
2208
                if (!camel_imap_folder_selected (
2174
2209
                        new_folder, response, cancellable, error)) {
2254
2289
        /* no need to actually create a CamelFolder for INBOX */
2255
2290
        imap_store->current_folder = NULL;
2256
2291
 
2257
 
        response = camel_imap_command(imap_store, NULL, cancellable, error, "DELETE %F", folder_name);
 
2292
        response = camel_imap_command (imap_store, NULL, cancellable, error, "DELETE %F", folder_name);
2258
2293
        if (response) {
2259
2294
                camel_imap_response_free (imap_store, response);
2260
2295
                imap_forget_folder (imap_store, folder_name, NULL);
2315
2350
                path = camel_store_info_path (imap_store->summary, si);
2316
2351
                if (strncmp (path, old_name, olen) == 0) {
2317
2352
                        if (strlen (path) > olen)
2318
 
                                npath = g_strdup_printf("%s/%s", new_name, path+olen+1);
 
2353
                                npath = g_strdup_printf ("%s/%s", new_name, path + olen + 1);
2319
2354
                        else
2320
2355
                                npath = g_strdup (new_name);
2321
2356
                        nfull = camel_imap_store_summary_path_to_full (imap_store->summary, npath, imap_store->dir_sep);
2358
2393
        gboolean success = TRUE;
2359
2394
 
2360
2395
        service = CAMEL_SERVICE (store);
2361
 
        settings = camel_service_get_settings (service);
2362
2396
        user_cache_dir = camel_service_get_user_cache_dir (service);
2363
2397
 
 
2398
        settings = camel_service_ref_settings (service);
 
2399
 
2364
2400
        use_subscriptions = camel_imap_settings_get_use_subscriptions (
2365
2401
                CAMEL_IMAP_SETTINGS (settings));
2366
2402
 
 
2403
        g_object_unref (settings);
 
2404
 
2367
2405
        if (!camel_imap_store_connected (imap_store, error)) {
2368
2406
                success = FALSE;
2369
2407
                goto fail;
2413
2451
 
2414
2452
        /* So do we care if this didn't work?  Its just a cache? */
2415
2453
        if (g_rename (oldpath, newpath) == -1) {
2416
 
                g_warning ("Could not rename message cache '%s' to '%s': %s: cache reset",
2417
 
                           oldpath, newpath, g_strerror (errno));
 
2454
                g_warning (
 
2455
                        "Could not rename message cache "
 
2456
                        "'%s' to '%s': %s: cache reset",
 
2457
                        oldpath, newpath, g_strerror (errno));
2418
2458
        }
2419
2459
 
2420
2460
        if (CAMEL_STORE (imap_store)->folders) {
2499
2539
        }
2500
2540
 
2501
2541
        need_convert = FALSE;
2502
 
        response = camel_imap_command (imap_store, NULL, cancellable, error, "LIST \"\" %G",
2503
 
                                       parent_real);
 
2542
        response = camel_imap_command (
 
2543
                imap_store, NULL, cancellable, error,
 
2544
                "LIST \"\" %G", parent_real);
2504
2545
        if (!response) /* whoa, this is bad */ {
2505
2546
                g_free (parent_real);
2506
2547
                return NULL;
2556
2597
 
2557
2598
                /* add the dirsep to the end of parent_name */
2558
2599
                name = g_strdup_printf ("%s%c", parent_real, imap_store->dir_sep);
2559
 
                response = camel_imap_command (imap_store, NULL, cancellable, error, "CREATE %G",
2560
 
                                               name);
 
2600
                response = camel_imap_command (
 
2601
                        imap_store, NULL, cancellable, error,
 
2602
                        "CREATE %G", name);
2561
2603
                g_free (name);
2562
2604
 
2563
2605
                if (!response) {
2573
2615
        real_name = camel_imap_store_summary_path_to_full (imap_store->summary, folder_name, imap_store->dir_sep);
2574
2616
        full_name = imap_concat (imap_store, parent_real, real_name);
2575
2617
        g_free (real_name);
2576
 
        response = camel_imap_command (imap_store, NULL, cancellable, error, "CREATE %G", full_name);
 
2618
        response = camel_imap_command (
 
2619
                imap_store, NULL, cancellable, error,
 
2620
                "CREATE %G", full_name);
2577
2621
 
2578
2622
        if (response) {
2579
2623
                CamelImapStoreInfo *si;
2635
2679
 
2636
2680
        fi = camel_folder_info_new ();
2637
2681
        fi->full_name = g_strdup (camel_store_info_path (imap_store->summary, si));
2638
 
        if (!g_ascii_strcasecmp(fi->full_name, "inbox")) {
 
2682
        if (!g_ascii_strcasecmp (fi->full_name, "inbox")) {
2639
2683
                flags |= CAMEL_FOLDER_SYSTEM | CAMEL_FOLDER_TYPE_INBOX;
2640
2684
                fi->display_name = g_strdup (_("Inbox"));
2641
2685
        } else
2690
2734
{
2691
2735
        const gchar *a = ap;
2692
2736
 
2693
 
        if (g_ascii_strcasecmp(a, "INBOX") == 0)
 
2737
        if (g_ascii_strcasecmp (a, "INBOX") == 0)
2694
2738
                a = "INBOX";
2695
2739
 
2696
2740
        return g_str_hash (a);
2701
2745
        const gchar *a = ap;
2702
2746
        const gchar *b = bp;
2703
2747
 
2704
 
        if (g_ascii_strcasecmp(a, "INBOX") == 0)
 
2748
        if (g_ascii_strcasecmp (a, "INBOX") == 0)
2705
2749
                a = "INBOX";
2706
 
        if (g_ascii_strcasecmp(b, "INBOX") == 0)
 
2750
        if (g_ascii_strcasecmp (b, "INBOX") == 0)
2707
2751
                b = "INBOX";
2708
2752
 
2709
2753
        return g_str_equal (a, b);
2733
2777
        CamelImapStoreNamespace *ns;
2734
2778
        gboolean success = TRUE, first_namespace = TRUE;
2735
2779
 
 
2780
        if (g_cancellable_is_cancelled (cancellable))
 
2781
                return FALSE;
 
2782
 
2736
2783
        /* We do a LIST followed by LSUB, and merge the results.  LSUB may not be a strict
2737
2784
         * subset of LIST for some servers, so we can't use either or separately */
2738
2785
        present = g_hash_table_new (folder_hash, folder_eq);
2740
2787
        if (!pattern)
2741
2788
                pattern = "";
2742
2789
 
2743
 
        for (ns = imap_store->summary->namespace; ns; ns = ns->next, first_namespace = FALSE) {
 
2790
        for (ns = imap_store->summary->namespace;
 
2791
             ns && !g_cancellable_is_cancelled (cancellable);
 
2792
             ns = ns->next, first_namespace = FALSE) {
2744
2793
                for (k = 0; k < 2; k++) {
2745
2794
                        gchar *tmp = NULL;
2746
2795
 
2757
2806
                        }
2758
2807
 
2759
2808
                        for (j = 0; j < 2; j++) {
2760
 
                                response = camel_imap_command (imap_store, NULL, cancellable, first_namespace ? error : NULL,
2761
 
                                                                "%s \"\" %G", j==1 ? "LSUB" : "LIST",
2762
 
                                                                pattern);
 
2809
                                response = camel_imap_command (
 
2810
                                        imap_store, NULL, cancellable,
 
2811
                                        first_namespace ? error : NULL,
 
2812
                                        "%s \"\" %G",
 
2813
                                        j == 1 ? "LSUB" : "LIST",
 
2814
                                        pattern);
2763
2815
                                if (!response) {
 
2816
                                        /* do not worry if checking in some namespace fails */
 
2817
                                        if (!ppattern)
 
2818
                                                continue;
 
2819
 
2764
2820
                                        success = FALSE;
2765
2821
                                        g_free (tmp);
2766
2822
                                        goto fail;
2799
2855
                }
2800
2856
        }
2801
2857
 
 
2858
        if (g_cancellable_is_cancelled (cancellable))
 
2859
                goto fail;
 
2860
 
2802
2861
        /* Sync summary to match */
2803
2862
 
2804
2863
        /* FIXME: we need to emit folder_create/subscribed/etc events for any new folders */
2868
2927
        }
2869
2928
 
2870
2929
        while (fi) {
2871
 
                printf("%-25s %-25s %*s\n", fi->name, fi->full_name, (gint)(depth*2+strlen(fi->uri)), fi->uri);
 
2930
                printf ("%-25s %-25s %*s\n", fi->name, fi->full_name, (gint)(depth * 2 + strlen (fi->uri)), fi->uri);
2872
2931
                if (fi->child)
2873
2932
                        dumpfi (fi->child);
2874
2933
                fi = fi->next;
2912
2971
        gchar *namespace;
2913
2972
 
2914
2973
        service = CAMEL_SERVICE (store);
2915
 
        settings = camel_service_get_settings (service);
 
2974
 
 
2975
        settings = camel_service_ref_settings (service);
2916
2976
 
2917
2977
        namespace = camel_imap_settings_dup_namespace (
2918
2978
                CAMEL_IMAP_SETTINGS (settings));
2919
2979
 
2920
 
        camel_operation_push_message (cancellable,
 
2980
        g_object_unref (settings);
 
2981
 
 
2982
        camel_operation_push_message (
 
2983
                cancellable,
2921
2984
                _("Retrieving list of folders at '%s'"),
2922
2985
                camel_service_get_display_name (service));
2923
2986
 
2928
2991
                if (!get_folders_sync (store, "INBOX", cancellable, error))
2929
2992
                        goto done;
2930
2993
        } else {
2931
 
                if (!get_folders_sync (store, "*", cancellable, error))
 
2994
                /* this can fail on some servers, thus just try it, but do not skip
 
2995
                 * look in all namespaces, unless the operation was cancelled */
 
2996
                if (!get_folders_sync (store, "*", cancellable, NULL) &&
 
2997
                    g_cancellable_is_cancelled (cancellable))
2932
2998
                        goto done;
2933
2999
        }
2934
3000
 
2935
3001
        /* look in all namespaces */
2936
3002
        get_folders_sync (store, NULL, cancellable, error);
2937
3003
 
2938
 
        camel_store_summary_save (CAMEL_STORE_SUMMARY (store->summary));
 
3004
        if (!g_cancellable_is_cancelled (cancellable))
 
3005
                camel_store_summary_save (CAMEL_STORE_SUMMARY (store->summary));
2939
3006
 
2940
3007
done:
2941
3008
        camel_operation_pop_message (cancellable);
2965
3032
        if (top == NULL)
2966
3033
                top = "";
2967
3034
 
2968
 
        if (camel_debug("imap:folder_info"))
2969
 
                printf("get folder info online\n");
 
3035
        if (camel_debug ("imap:folder_info"))
 
3036
                printf ("get folder info online\n");
2970
3037
 
2971
3038
        if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store))) {
2972
3039
                tree = get_folder_info_offline (store, top, flags, error);
3053
3120
        gchar *junk_path;
3054
3121
        gchar *trash_path;
3055
3122
 
3056
 
        if (camel_debug("imap:folder_info"))
3057
 
                printf("get folder info offline\n");
 
3123
        if (camel_debug ("imap:folder_info"))
 
3124
                printf ("get folder info offline\n");
3058
3125
 
3059
3126
        service = CAMEL_SERVICE (store);
3060
 
        settings = camel_service_get_settings (service);
 
3127
 
 
3128
        settings = camel_service_ref_settings (service);
3061
3129
 
3062
3130
        use_subscriptions = camel_imap_settings_get_use_subscriptions (
3063
3131
                CAMEL_IMAP_SETTINGS (settings));
3065
3133
        junk_path = camel_imap_settings_dup_real_junk_path (
3066
3134
                CAMEL_IMAP_SETTINGS (settings));
3067
3135
 
 
3136
        trash_path = camel_imap_settings_dup_real_trash_path (
 
3137
                CAMEL_IMAP_SETTINGS (settings));
 
3138
 
 
3139
        g_object_unref (settings);
 
3140
 
3068
3141
        /* So we can safely compare strings. */
3069
3142
        if (junk_path == NULL)
3070
3143
                junk_path = g_strdup ("");
3071
3144
 
3072
 
        trash_path = camel_imap_settings_dup_real_trash_path (
3073
 
                CAMEL_IMAP_SETTINGS (settings));
3074
 
 
3075
3145
        /* So we can safely compare strings. */
3076
3146
        if (trash_path == NULL)
3077
3147
                trash_path = g_strdup ("");
3087
3157
 
3088
3158
        /* get starting point */
3089
3159
        if (top[0] == 0) {
3090
 
                name = g_strdup("");
 
3160
                name = g_strdup ("");
3091
3161
        } else {
3092
3162
                name = camel_imap_store_summary_full_from_path (imap_store->summary, top);
3093
3163
                if (name == NULL)
3095
3165
        }
3096
3166
 
3097
3167
        main_ns = camel_imap_store_summary_get_main_namespace (imap_store->summary);
3098
 
        pattern = imap_concat(imap_store, name, "*");
 
3168
        pattern = imap_concat (imap_store, name, "*");
3099
3169
 
3100
3170
        /* folder_info_build will insert parent nodes as necessary and mark
3101
3171
         * them as noselect, which is information we actually don't have at
3139
3209
                                fi->flags = (fi->flags & ~CAMEL_FOLDER_NOINFERIORS) | CAMEL_FOLDER_NOCHILDREN;
3140
3210
 
3141
3211
                        /* blah, this gets lost somewhere, i can't be bothered finding out why */
3142
 
                        if (!g_ascii_strcasecmp(fi->full_name, "inbox"))
 
3212
                        if (!g_ascii_strcasecmp (fi->full_name, "inbox"))
3143
3213
                                fi->flags = (fi->flags & ~CAMEL_FOLDER_TYPE_MASK) | CAMEL_FOLDER_TYPE_INBOX;
3144
3214
 
3145
3215
                        folder_is_trash =
3217
3287
                        error, CAMEL_SERVICE_ERROR,
3218
3288
                        CAMEL_SERVICE_ERROR_UNAVAILABLE,
3219
3289
                        _("You must be working online "
3220
 
                          "to complete this operation"));
 
3290
                        "to complete this operation"));
3221
3291
 
3222
3292
        return FALSE;
3223
3293
}
3232
3302
        gchar linebuf[1024] = {0};
3233
3303
        GByteArray *ba;
3234
3304
        gssize nread;
 
3305
        GError *local_error = NULL;
3235
3306
 
3236
3307
        g_return_val_if_fail (CAMEL_IS_IMAP_STORE (store), -1);
3237
3308
        g_return_val_if_fail (dest, -1);
3249
3320
        stream = CAMEL_STREAM_BUFFER (store->istream);
3250
3321
 
3251
3322
        ba = g_byte_array_new ();
3252
 
        while ((nread = camel_stream_buffer_gets (stream, linebuf, sizeof (linebuf), cancellable, error)) > 0) {
 
3323
        while ((nread = camel_stream_buffer_gets (stream, linebuf, sizeof (linebuf), cancellable, &local_error)) > 0) {
3253
3324
                g_byte_array_append (ba, (const guint8 *) linebuf, nread);
3254
3325
                if (linebuf[nread - 1] == '\n')
3255
3326
                        break;
3256
3327
        }
3257
3328
 
3258
 
        if (nread <= 0) {
3259
 
                if (nread == 0)
 
3329
        if (nread <= 0 || local_error) {
 
3330
                if (!local_error)
3260
3331
                        g_set_error (
3261
3332
                                error, CAMEL_SERVICE_ERROR,
3262
3333
                                CAMEL_SERVICE_ERROR_UNAVAILABLE,
3263
3334
                                _("Server unexpectedly disconnected"));
3264
 
                else
 
3335
                else {
 
3336
                        g_propagate_error (error, local_error);
3265
3337
                        g_prefix_error (
3266
3338
                                error, _("Server unexpectedly disconnected: "));
 
3339
                }
3267
3340
 
3268
3341
                /* do not pass cancellable, the connection is gone or
3269
3342
                 * the cancellable cancelled, thus there will be no I/O */
3307
3380
        GError *local_error = NULL;
3308
3381
 
3309
3382
        service = CAMEL_SERVICE (store);
3310
 
        settings = camel_service_get_settings (service);
 
3383
 
 
3384
        settings = camel_service_ref_settings (service);
3311
3385
 
3312
3386
        check_all = camel_imap_settings_get_check_all (
3313
3387
                CAMEL_IMAP_SETTINGS (settings));
3315
3389
        check_subscribed = camel_imap_settings_get_check_subscribed (
3316
3390
                CAMEL_IMAP_SETTINGS (settings));
3317
3391
 
 
3392
        g_object_unref (settings);
 
3393
 
3318
3394
        subscribed = ((info->flags & CAMEL_FOLDER_SUBSCRIBED) != 0);
3319
3395
 
3320
3396
        res = CAMEL_STORE_CLASS (camel_imap_store_parent_class)->