diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2013-11-30 22:37:08 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2013-11-30 22:45:57 +0800 |
commit | f02bb4526c6b80f728241de157d9c19a8b19187a (patch) | |
tree | b184c04f0cfc58ae32e761b148d3b8973742da7c | |
parent | f911f1754abaf97b9d08f751b97cfb2905d47616 (diff) | |
download | gsoc2013-evolution-f02bb4526c6b80f728241de157d9c19a8b19187a.tar gsoc2013-evolution-f02bb4526c6b80f728241de157d9c19a8b19187a.tar.gz gsoc2013-evolution-f02bb4526c6b80f728241de157d9c19a8b19187a.tar.bz2 gsoc2013-evolution-f02bb4526c6b80f728241de157d9c19a8b19187a.tar.lz gsoc2013-evolution-f02bb4526c6b80f728241de157d9c19a8b19187a.tar.xz gsoc2013-evolution-f02bb4526c6b80f728241de157d9c19a8b19187a.tar.zst gsoc2013-evolution-f02bb4526c6b80f728241de157d9c19a8b19187a.zip |
em_utils_is_local_delivery_mbox_file(): Take a CamelService.
More convenient than constructing a CamelURL just for this function.
Also, document it.
-rw-r--r-- | libemail-engine/e-mail-utils.c | 52 | ||||
-rw-r--r-- | libemail-engine/e-mail-utils.h | 2 | ||||
-rw-r--r-- | libemail-engine/mail-ops.c | 13 | ||||
-rw-r--r-- | mail/em-folder-tree-model.c | 7 | ||||
-rw-r--r-- | mail/mail-send-recv.c | 8 |
5 files changed, 56 insertions, 26 deletions
diff --git a/libemail-engine/e-mail-utils.c b/libemail-engine/e-mail-utils.c index 9610da7419..0e76b2b329 100644 --- a/libemail-engine/e-mail-utils.c +++ b/libemail-engine/e-mail-utils.c @@ -670,16 +670,54 @@ em_utils_ref_mail_identity_for_store (ESourceRegistry *registry, return source; } -/* Returns TRUE if CamelURL points to a local mbox file. */ +/** + * em_utils_is_local_delivery_mbox_file: + * @service: a #CamelService + * + * Returns whether @service refers to a local mbox file where new mail + * is delivered by some external software. + * + * Specifically that means @service's #CamelProvider protocol is "mbox" + * and its #CamelLocalSettings:path setting points to an existing file, + * not a directory. + * + * Returns: whether @service is for local mbox delivery + **/ gboolean -em_utils_is_local_delivery_mbox_file (CamelURL *url) +em_utils_is_local_delivery_mbox_file (CamelService *service) { - g_return_val_if_fail (url != NULL, FALSE); + CamelProvider *provider; + CamelSettings *settings; + gchar *mbox_path = NULL; + gboolean is_local_delivery_mbox_file; + + g_return_val_if_fail (CAMEL_IS_SERVICE (service), FALSE); + + provider = camel_service_get_provider (service); + g_return_val_if_fail (provider != NULL, FALSE); + g_return_val_if_fail (provider->protocol != NULL, FALSE); + + if (!g_str_equal (provider->protocol, "mbox")) + return FALSE; + + settings = camel_service_ref_settings (service); + + if (CAMEL_IS_LOCAL_SETTINGS (settings)) { + CamelLocalSettings *local_settings; + + local_settings = CAMEL_LOCAL_SETTINGS (settings); + mbox_path = camel_local_settings_dup_path (local_settings); + } + + is_local_delivery_mbox_file = + (mbox_path != NULL) && + g_file_test (mbox_path, G_FILE_TEST_EXISTS) && + !g_file_test (mbox_path, G_FILE_TEST_IS_DIR); + + g_free (mbox_path); + g_clear_object (&settings); - return g_str_equal (url->protocol, "mbox") && - (url->path != NULL) && - g_file_test (url->path, G_FILE_TEST_EXISTS) && - !g_file_test (url->path, G_FILE_TEST_IS_DIR); + return is_local_delivery_mbox_file; } /* Expands groups to individual addresses, or removes empty groups completely. diff --git a/libemail-engine/e-mail-utils.h b/libemail-engine/e-mail-utils.h index f055f3d6aa..1643a3f66f 100644 --- a/libemail-engine/e-mail-utils.h +++ b/libemail-engine/e-mail-utils.h @@ -76,7 +76,7 @@ ESource * em_utils_ref_mail_identity_for_store (ESourceRegistry *registry, CamelStore *store); gboolean em_utils_is_local_delivery_mbox_file - (CamelURL *url); + (CamelService *service); void em_utils_expand_groups (CamelInternetAddress *addresses); diff --git a/libemail-engine/mail-ops.c b/libemail-engine/mail-ops.c index df90596e53..406d3d6462 100644 --- a/libemail-engine/mail-ops.c +++ b/libemail-engine/mail-ops.c @@ -245,7 +245,6 @@ fetch_mail_exec (struct _fetch_mail_msg *m, CamelSettings *settings; CamelStore *parent_store; CamelUIDCache *cache = NULL; - CamelURL *url; gboolean keep = TRUE; gboolean delete_fetched; gboolean is_local_delivery = FALSE; @@ -281,15 +280,16 @@ fetch_mail_exec (struct _fetch_mail_msg *m, /* Just for readability. */ delete_fetched = !keep; - url = camel_service_new_camel_url (service); - is_local_delivery = em_utils_is_local_delivery_mbox_file (url); - - if (is_local_delivery) { + if (em_utils_is_local_delivery_mbox_file (service)) { + CamelURL *url; gchar *path; gchar *url_string; path = mail_tool_do_movemail (m->store, error); + + url = camel_service_new_camel_url (service); url_string = camel_url_to_string (url, CAMEL_URL_HIDE_ALL); + camel_url_free (url); if (path && (!error || !*error)) { camel_folder_freeze (fm->destination); @@ -306,6 +306,7 @@ fetch_mail_exec (struct _fetch_mail_msg *m, g_free (path); g_free (url_string); + } else { uid = camel_service_get_uid (service); if (m->provider_lock) @@ -316,8 +317,6 @@ fetch_mail_exec (struct _fetch_mail_msg *m, fm->session, uid, cancellable, error); } - camel_url_free (url); - if (folder == NULL) goto exit; diff --git a/mail/em-folder-tree-model.c b/mail/em-folder-tree-model.c index d25d9d7a1f..0853b640d1 100644 --- a/mail/em-folder-tree-model.c +++ b/mail/em-folder-tree-model.c @@ -1563,11 +1563,10 @@ em_folder_tree_model_add_store (EMFolderTreeModel *model, if ((provider->flags & CAMEL_PROVIDER_IS_STORAGE) == 0) return; - service_url = camel_service_new_camel_url (service); - if (em_utils_is_local_delivery_mbox_file (service_url)) { - camel_url_free (service_url); + if (em_utils_is_local_delivery_mbox_file (service)) return; - } + + service_url = camel_service_new_camel_url (service); uri = camel_url_to_string (service_url, CAMEL_URL_HIDE_ALL); camel_url_free (service_url); diff --git a/mail/mail-send-recv.c b/mail/mail-send-recv.c index dbdf629110..1a89a3b4b4 100644 --- a/mail/mail-send-recv.c +++ b/mail/mail-send-recv.c @@ -432,22 +432,16 @@ format_service_name (CamelService *service) static send_info_t get_receive_type (CamelService *service) { - CamelURL *url; CamelProvider *provider; const gchar *uid; - gboolean is_local_delivery; /* Disregard CamelNullStores. */ if (CAMEL_IS_NULL_STORE (service)) return SEND_INVALID; - url = camel_service_new_camel_url (service); - is_local_delivery = em_utils_is_local_delivery_mbox_file (url); - camel_url_free (url); - /* mbox pointing to a file is a 'Local delivery' * source which requires special processing. */ - if (is_local_delivery) + if (em_utils_is_local_delivery_mbox_file (service)) return SEND_RECEIVE; provider = camel_service_get_provider (service); |