1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
/* camel-imap-store.c : class for a imap store */
4
* Authors: Michael Zucchi <notzed@ximian.com>
2
/* camel-imap-store.c : class for a imap store
6
4
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
8
* This library is free software; you can redistribute it and/or modify it
6
* This library is free software: you can redistribute it and/or modify it
9
7
* under the terms of the GNU Lesser General Public License as published by
10
8
* the Free Software Foundation.
12
10
* This library is distributed in the hope that it will be useful, but
13
11
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
13
* for more details.
17
15
* You should have received a copy of the GNU Lesser General Public License
18
* along with this library; if not, see <http://www.gnu.org/licenses/>.
16
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18
* Authors: Michael Zucchi <notzed@ximian.com>
21
21
#ifdef HAVE_CONFIG_H
468
468
fi = imapx_store_build_folder_info (store, folder_path, flags);
470
470
/* Figure out which signals to emit, if any. */
471
if (use_subscriptions) {
471
if (use_subscriptions || camel_imapx_namespace_get_category (camel_imapx_mailbox_get_namespace (mailbox)) != CAMEL_IMAPX_NAMESPACE_PERSONAL) {
472
472
/* If we are honoring folder subscriptions, then
473
473
* subscription changes are equivalent to folder
474
474
* creation / deletion as far as we're concerned. */
775
774
CamelIMAPXServer *imapx_server;
776
775
gboolean success;
777
/* Chain up to parent's method. */
778
if (!CAMEL_SERVICE_CLASS (camel_imapx_store_parent_class)->connect_sync (service, cancellable, error))
778
781
imapx_store = CAMEL_IMAPX_STORE (service);
780
783
imapx_server = camel_imapx_store_ref_server (imapx_store, NULL, FALSE, cancellable, error);
1080
1084
if (!si_is_match)
1087
if (!use_subscriptions && !(si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) &&
1088
!(flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST)) {
1089
CamelIMAPXMailbox *mailbox;
1091
mailbox = camel_imapx_store_ref_mailbox (imapx_store, ((CamelIMAPXStoreInfo *) si)->mailbox_name);
1092
if (!mailbox || camel_imapx_namespace_get_category (camel_imapx_mailbox_get_namespace (mailbox)) != CAMEL_IMAPX_NAMESPACE_PERSONAL) {
1093
/* Skip unsubscribed mailboxes which are not in the Personal namespace */
1094
g_clear_object (&mailbox);
1098
g_clear_object (&mailbox);
1083
1101
fi = imapx_store_build_folder_info (
1084
1102
imapx_store, folder_path, 0);
1085
1103
fi->unread = si->unread;
1420
1438
static gboolean
1439
imapx_store_mailbox_is_unknown (CamelIMAPXStore *imapx_store,
1440
GPtrArray *store_infos,
1441
const CamelIMAPXStoreInfo *to_check)
1443
CamelIMAPXMailbox *mailbox;
1444
gboolean is_unknown;
1446
g_return_val_if_fail (CAMEL_IS_IMAPX_STORE (imapx_store), FALSE);
1447
g_return_val_if_fail (store_infos != NULL, FALSE);
1449
if (!to_check || !to_check->mailbox_name || !*to_check->mailbox_name)
1452
mailbox = camel_imapx_store_ref_mailbox (imapx_store, to_check->mailbox_name);
1454
is_unknown = mailbox && camel_imapx_mailbox_get_state (mailbox) == CAMEL_IMAPX_MAILBOX_STATE_UNKNOWN;
1456
if (!mailbox && to_check->separator) {
1457
CamelSettings *settings;
1458
gboolean use_subscriptions;
1459
gchar *mailbox_with_separator;
1462
settings = camel_service_ref_settings (CAMEL_SERVICE (imapx_store));
1463
use_subscriptions = camel_imapx_settings_get_use_subscriptions (CAMEL_IMAPX_SETTINGS (settings));
1464
g_object_unref (settings);
1466
mailbox_with_separator = g_strdup_printf ("%s%c", to_check->mailbox_name, to_check->separator);
1468
for (ii = 0; ii < store_infos->len; ii++) {
1469
CamelIMAPXStoreInfo *si;
1471
si = g_ptr_array_index (store_infos, ii);
1473
if (si->mailbox_name && g_str_has_prefix (si->mailbox_name, mailbox_with_separator) && (
1474
!use_subscriptions || (((CamelStoreInfo *) si)->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) != 0)) {
1475
/* This can be a 'virtual' parent folder of some subscribed subfolder */
1480
is_unknown = ii == store_infos->len;
1482
g_free (mailbox_with_separator);
1485
g_clear_object (&mailbox);
1421
1491
sync_folders (CamelIMAPXStore *imapx_store,
1422
1492
const gchar *root_folder_path,
1423
1493
CamelStoreGetFolderInfoFlags flags,
1446
1515
* in imapx_store_process_mailbox_attributes(). */
1447
1516
g_atomic_int_inc (&imapx_store->priv->syncing_folders);
1449
if (!initial_setup && (!root_folder_path || !*root_folder_path)) {
1518
update_folder_list = !initial_setup && (!root_folder_path || !*root_folder_path);
1520
if (update_folder_list) {
1450
1521
g_mutex_lock (&imapx_store->priv->mailboxes_lock);
1451
1522
g_hash_table_foreach (imapx_store->priv->mailboxes, imapx_store_mark_mailbox_unknown_cb, imapx_store);
1452
1523
g_mutex_unlock (&imapx_store->priv->mailboxes_lock);
1460
1531
gboolean have_folder_info_for_inbox;
1462
/* XXX We only fetch personal mailboxes at this time. */
1463
1533
success = fetch_folder_info_for_namespace_category (
1464
imapx_store, server, CAMEL_IMAPX_NAMESPACE_PERSONAL, flags,
1534
imapx_store, server, CAMEL_IMAPX_NAMESPACE_PERSONAL, flags |
1535
(update_folder_list ? CAMEL_STORE_FOLDER_INFO_SUBSCRIBED : 0),
1465
1536
folder_info_results, cancellable, error);
1467
1538
have_folder_info_for_inbox =
1485
if (!initial_setup && (!root_folder_path || !*root_folder_path)) {
1556
if (update_folder_list) {
1486
1557
g_mutex_lock (&imapx_store->priv->mailboxes_lock);
1487
1558
g_hash_table_foreach_remove (imapx_store->priv->mailboxes, imapx_store_remove_unknown_mailboxes_cb, imapx_store);
1488
1559
g_mutex_unlock (&imapx_store->priv->mailboxes_lock);
1491
array = camel_store_summary_array (imapx_store->summary);
1493
for (ii = 0; ii < array->len; ii++) {
1495
CamelFolderInfo *fi;
1496
const gchar *mailbox_name;
1497
const gchar *si_path;
1498
gboolean pattern_match;
1500
si = g_ptr_array_index (array, ii);
1501
si_path = camel_store_info_path (imapx_store->summary, si);
1503
mailbox_name = ((CamelIMAPXStoreInfo *) si)->mailbox_name;
1504
if (mailbox_name == NULL || *mailbox_name == '\0')
1508
(root_folder_path == NULL) ||
1509
(*root_folder_path == '\0') ||
1510
(g_str_has_prefix (si_path, root_folder_path));
1514
fi = g_hash_table_lookup (folder_info_results, mailbox_name);
1517
gchar *dup_folder_path = g_strdup (si_path);
1519
if (dup_folder_path != NULL) {
1520
/* Do not unsubscribe from it, it influences UI for non-subscribable folders */
1521
imapx_delete_folder_from_cache (
1522
imapx_store, dup_folder_path, FALSE);
1523
g_free (dup_folder_path);
1525
camel_store_summary_remove (
1526
imapx_store->summary, si);
1562
if (!root_folder_path || !*root_folder_path) {
1566
/* Finally update store's summary */
1567
array = camel_store_summary_array (imapx_store->summary);
1568
for (ii = 0; array && ii < array->len; ii++) {
1570
const gchar *si_path;
1572
si = g_ptr_array_index (array, ii);
1573
si_path = camel_store_info_path (imapx_store->summary, si);
1575
if (imapx_store_mailbox_is_unknown (imapx_store, array, (CamelIMAPXStoreInfo *) si)) {
1576
gchar *dup_folder_path = g_strdup (si_path);
1578
if (dup_folder_path != NULL) {
1579
/* Do not unsubscribe from it, it influences UI for non-subscribable folders */
1580
imapx_delete_folder_from_cache (imapx_store, dup_folder_path, FALSE);
1581
g_free (dup_folder_path);
1583
camel_store_summary_remove (imapx_store->summary, si);
1588
camel_store_summary_array_free (imapx_store->summary, array);
1531
camel_store_summary_array_free (imapx_store->summary, array);
1532
1591
camel_store_summary_save (imapx_store->summary);
1552
1611
display_name = camel_service_get_display_name (service);
1554
1613
camel_operation_push_message (
1555
cancellable, _("Retrieving folder list for %s"),
1614
cancellable, _("Retrieving folder list for '%s'"),
1558
1617
if (!camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store)))
1645
1704
res = store_class->can_refresh_folder (store, info, &local_error) ||
1646
1705
check_all || (check_subscribed && subscribed);
1707
if (!res && !local_error) {
1708
CamelFolder *folder;
1710
folder = camel_store_get_folder_sync (store, info->full_name, 0, NULL, &local_error);
1711
if (folder && CAMEL_IS_IMAPX_FOLDER (folder))
1712
res = camel_imapx_folder_get_check_folder (CAMEL_IMAPX_FOLDER (folder));
1714
g_clear_object (&folder);
1648
1717
if (local_error != NULL)
1649
1718
g_propagate_error (error, local_error);
1783
1852
if (time_since_last_refresh > FINFO_REFRESH_INTERVAL) {
1784
1853
CamelSession *session;
1786
1856
imapx_store->priv->last_refresh_time = time (NULL);
1788
1858
session = camel_service_ref_session (service);
1859
description = g_strdup_printf (_("Retrieving folder list for '%s'"), camel_service_get_display_name (service));
1790
1861
camel_session_submit_job (
1791
session, (CamelSessionCallback)
1862
session, description, (CamelSessionCallback)
1792
1863
imapx_refresh_finfo,
1793
1864
g_object_ref (store),
1794
1865
(GDestroyNotify) g_object_unref);
1796
1867
g_object_unref (session);
1868
g_free (description);
2778
2850
CAMEL_SERVICE_ERROR_UNAVAILABLE,
2779
2851
_("You must be working online to complete this operation"));
2781
local_error->domain = CAMEL_SERVICE_ERROR;
2782
local_error->code = CAMEL_SERVICE_ERROR_UNAVAILABLE;
2854
error, CAMEL_SERVICE_ERROR,
2855
CAMEL_SERVICE_ERROR_UNAVAILABLE,
2856
_("You must be working online to complete this operation (%s)"),
2857
local_error->message);
2859
g_clear_error (&local_error);