[evolution] Bug 781744 - Support not storing sent messages
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug 781744 - Support not storing sent messages
- Date: Mon, 3 Jul 2017 10:37:55 +0000 (UTC)
commit 963ca6fd2e68c2a49d9479df7daec068683c6d74
Author: Milan Crha <mcrha redhat com>
Date: Mon Jul 3 12:37:44 2017 +0200
Bug 781744 - Support not storing sent messages
src/composer/e-msg-composer.c | 5 +-
src/libemail-engine/e-mail-session-utils.c | 65 +++++++++++++++++++++++++---
src/libemail-engine/e-mail-session-utils.h | 2 +
src/libemail-engine/e-mail-utils.c | 9 ++--
src/libemail-engine/mail-ops.c | 11 +++-
src/mail/e-mail-backend.c | 20 +++------
src/mail/e-mail-config-defaults-page.c | 50 ++++++++++++++++++---
src/mail/em-folder-tree-model.c | 3 +-
src/modules/mdn/evolution-mdn.c | 6 +-
9 files changed, 129 insertions(+), 42 deletions(-)
---
diff --git a/src/composer/e-msg-composer.c b/src/composer/e-msg-composer.c
index 3e83199..70179cf 100644
--- a/src/composer/e-msg-composer.c
+++ b/src/composer/e-msg-composer.c
@@ -518,7 +518,7 @@ build_message_headers (EMsgComposer *composer,
const gchar *header_name;
const gchar *name = NULL, *address = NULL;
const gchar *transport_uid;
- const gchar *sent_folder;
+ const gchar *sent_folder = NULL;
composer_header = e_composer_header_table_get_header (table, E_COMPOSER_HEADER_FROM);
if (e_composer_from_header_get_override_visible (E_COMPOSER_FROM_HEADER (composer_header))) {
@@ -551,7 +551,8 @@ build_message_headers (EMsgComposer *composer,
extension_name = E_SOURCE_EXTENSION_MAIL_SUBMISSION;
ms = e_source_get_extension (source, extension_name);
- sent_folder = e_source_mail_submission_get_sent_folder (ms);
+ if (e_source_mail_submission_get_use_sent_folder (ms))
+ sent_folder = e_source_mail_submission_get_sent_folder (ms);
transport_uid = e_source_mail_submission_get_transport_uid (ms);
medium = CAMEL_MEDIUM (message);
diff --git a/src/libemail-engine/e-mail-session-utils.c b/src/libemail-engine/e-mail-session-utils.c
index c58790b..cdcea02 100644
--- a/src/libemail-engine/e-mail-session-utils.c
+++ b/src/libemail-engine/e-mail-session-utils.c
@@ -59,6 +59,8 @@ struct _AsyncContext {
gchar *folder_uri;
gchar *message_uid;
+
+ gboolean use_sent_folder;
};
static void
@@ -669,7 +671,10 @@ skip_send:
session, E_MAIL_LOCAL_FOLDER_SENT);
folder = e_mail_session_get_fcc_for_message_sync (
- session, context->message, cancellable, &error);
+ session, context->message, ©_to_sent, cancellable, &error);
+
+ if (!copy_to_sent)
+ goto cleanup;
/* Sanity check. */
g_return_if_fail (
@@ -1048,6 +1053,7 @@ static CamelFolder *
mail_session_ref_fcc_from_identity (EMailSession *session,
ESource *source,
CamelMimeMessage *message,
+ gboolean *out_use_sent_folder,
GCancellable *cancellable,
GError **error)
{
@@ -1056,6 +1062,7 @@ mail_session_ref_fcc_from_identity (EMailSession *session,
CamelFolder *folder = NULL;
const gchar *extension_name;
gchar *folder_uri;
+ gboolean use_sent_folder;
registry = e_mail_session_get_registry (session);
extension_name = E_SOURCE_EXTENSION_MAIL_SUBMISSION;
@@ -1070,6 +1077,13 @@ mail_session_ref_fcc_from_identity (EMailSession *session,
return NULL;
extension = e_source_get_extension (source, extension_name);
+ use_sent_folder = e_source_mail_submission_get_use_sent_folder (extension);
+
+ if (out_use_sent_folder)
+ *out_use_sent_folder = use_sent_folder;
+
+ if (!use_sent_folder)
+ return NULL;
if (e_source_mail_submission_get_replies_to_origin_folder (extension)) {
GError *local_error = NULL;
@@ -1102,6 +1116,7 @@ mail_session_ref_fcc_from_identity (EMailSession *session,
static CamelFolder *
mail_session_ref_fcc_from_x_identity (EMailSession *session,
CamelMimeMessage *message,
+ gboolean *out_use_sent_folder,
GCancellable *cancellable,
GError **error)
{
@@ -1127,7 +1142,7 @@ mail_session_ref_fcc_from_x_identity (EMailSession *session,
/* This may return NULL without setting a GError. */
folder = mail_session_ref_fcc_from_identity (
- session, source, message, cancellable, error);
+ session, source, message, out_use_sent_folder, cancellable, error);
g_clear_object (&source);
@@ -1163,6 +1178,7 @@ mail_session_ref_fcc_from_x_fcc (EMailSession *session,
static CamelFolder *
mail_session_ref_fcc_from_default_identity (EMailSession *session,
CamelMimeMessage *message,
+ gboolean *out_use_sent_folder,
GCancellable *cancellable,
GError **error)
{
@@ -1175,7 +1191,7 @@ mail_session_ref_fcc_from_default_identity (EMailSession *session,
/* This may return NULL without setting a GError. */
folder = mail_session_ref_fcc_from_identity (
- session, source, message, cancellable, error);
+ session, source, message, out_use_sent_folder, cancellable, error);
g_clear_object (&source);
@@ -1186,6 +1202,8 @@ mail_session_ref_fcc_from_default_identity (EMailSession *session,
* e_mail_session_get_fcc_for_message_sync:
* @session: an #EMailSession
* @message: a #CamelMimeMessage
+ * @out_use_sent_folder: (out) (nullable): optional return location to store
+ * corresponding use-sent-folder for the mail account, or %NULL
* @cancellable: optional #GCancellable object, or %NULL
* @error: return location for a #GError, or %NULL
*
@@ -1202,34 +1220,47 @@ mail_session_ref_fcc_from_default_identity (EMailSession *session,
* unreferenced with g_object_unref() when finished with it.
*
* If a non-recoverable error occurs, the function sets @error and returns
- * %NULL.
+ * %NULL. It returns %NULL without setting @error when the mail account
+ * has set to not use sent folder, in which case it indicates that
+ * in @out_use_sent_folder too.
*
* Returns: a #CamelFolder, or %NULL
**/
CamelFolder *
e_mail_session_get_fcc_for_message_sync (EMailSession *session,
CamelMimeMessage *message,
+ gboolean *out_use_sent_folder,
GCancellable *cancellable,
GError **error)
{
CamelFolder *folder = NULL;
+ gboolean use_sent_folder = TRUE;
g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL);
+ if (out_use_sent_folder)
+ *out_use_sent_folder = TRUE;
+
/* Check for "X-Evolution-Identity" header. */
if (folder == NULL) {
GError *local_error = NULL;
/* This may return NULL without setting a GError. */
folder = mail_session_ref_fcc_from_x_identity (
- session, message, cancellable, &local_error);
+ session, message, &use_sent_folder, cancellable, &local_error);
if (local_error != NULL) {
g_warn_if_fail (folder == NULL);
g_propagate_error (error, local_error);
return NULL;
}
+
+ if (!use_sent_folder) {
+ if (out_use_sent_folder)
+ *out_use_sent_folder = use_sent_folder;
+ return NULL;
+ }
}
/* Check for "X-Evolution-Fcc" header. */
@@ -1253,13 +1284,19 @@ e_mail_session_get_fcc_for_message_sync (EMailSession *session,
/* This may return NULL without setting a GError. */
folder = mail_session_ref_fcc_from_default_identity (
- session, message, cancellable, &local_error);
+ session, message, &use_sent_folder, cancellable, &local_error);
if (local_error != NULL) {
g_warn_if_fail (folder == NULL);
g_propagate_error (error, local_error);
return NULL;
}
+
+ if (!use_sent_folder) {
+ if (out_use_sent_folder)
+ *out_use_sent_folder = use_sent_folder;
+ return NULL;
+ }
}
/* Last resort - local Sent folder. */
@@ -1287,6 +1324,7 @@ mail_session_get_fcc_for_message_thread (GSimpleAsyncResult *simple,
e_mail_session_get_fcc_for_message_sync (
E_MAIL_SESSION (source_object),
async_context->message,
+ &async_context->use_sent_folder,
cancellable, &local_error);
if (local_error != NULL)
@@ -1352,6 +1390,8 @@ e_mail_session_get_fcc_for_message (EMailSession *session,
* e_mail_session_get_fcc_for_message_finish:
* @session: an #EMailSession
* @result: a #GAsyncResult
+ * @out_use_sent_folder: (out) (nullable): optional return location to store
+ * corresponding use-sent-folder for the mail account, or %NULL
* @error: return location for a #GError, or %NULL
*
* Finishes the operation started with e_mail_session_get_fcc_for_message().
@@ -1360,13 +1400,16 @@ e_mail_session_get_fcc_for_message (EMailSession *session,
* unreferenced with g_object_unref() when finished with it.
*
* If a non-recoverable error occurred, the function sets @error and
- * returns %NULL.
+ * returns %NULL. It returns %NULL without setting @error when the mail account
+ * has set to not use sent folder, in which case it indicates that
+ * in @out_use_sent_folder too.
*
* Returns: a #CamelFolder, or %NULL
**/
CamelFolder *
e_mail_session_get_fcc_for_message_finish (EMailSession *session,
GAsyncResult *result,
+ gboolean *out_use_sent_folder,
GError **error)
{
GSimpleAsyncResult *simple;
@@ -1383,6 +1426,14 @@ e_mail_session_get_fcc_for_message_finish (EMailSession *session,
if (g_simple_async_result_propagate_error (simple, error))
return NULL;
+ if (out_use_sent_folder)
+ *out_use_sent_folder = async_context->use_sent_folder;
+
+ if (!async_context->use_sent_folder) {
+ g_return_val_if_fail (async_context->folder == NULL, NULL);
+ return NULL;
+ }
+
g_return_val_if_fail (async_context->folder != NULL, NULL);
return g_object_ref (async_context->folder);
diff --git a/src/libemail-engine/e-mail-session-utils.h b/src/libemail-engine/e-mail-session-utils.h
index 7474a69..3f4a117 100644
--- a/src/libemail-engine/e-mail-session-utils.h
+++ b/src/libemail-engine/e-mail-session-utils.h
@@ -103,6 +103,7 @@ gboolean e_mail_session_send_to_finish (EMailSession *session,
CamelFolder * e_mail_session_get_fcc_for_message_sync
(EMailSession *session,
CamelMimeMessage *message,
+ gboolean *out_use_sent_folder,
GCancellable *cancellable,
GError **error);
void e_mail_session_get_fcc_for_message
@@ -115,6 +116,7 @@ void e_mail_session_get_fcc_for_message
CamelFolder * e_mail_session_get_fcc_for_message_finish
(EMailSession *session,
GAsyncResult *result,
+ gboolean *out_use_sent_folder,
GError **error);
CamelService * e_mail_session_ref_transport (EMailSession *session,
const gchar *transport_uid);
diff --git a/src/libemail-engine/e-mail-utils.c b/src/libemail-engine/e-mail-utils.c
index 9be8b04..84de797 100644
--- a/src/libemail-engine/e-mail-utils.c
+++ b/src/libemail-engine/e-mail-utils.c
@@ -286,14 +286,15 @@ em_utils_folder_is_sent (ESourceRegistry *registry,
for (iter = list; iter != NULL; iter = g_list_next (iter)) {
ESource *source = E_SOURCE (iter->data);
- ESourceExtension *extension;
+ ESourceMailSubmission *extension;
const gchar *sent_folder_uri;
extension = e_source_get_extension (source, extension_name);
- sent_folder_uri =
- e_source_mail_submission_get_sent_folder (
- E_SOURCE_MAIL_SUBMISSION (extension));
+ if (!e_source_mail_submission_get_use_sent_folder (extension))
+ continue;
+
+ sent_folder_uri = e_source_mail_submission_get_sent_folder (extension);
if (sent_folder_uri != NULL)
is_sent = e_mail_folder_uri_equal (
diff --git a/src/libemail-engine/mail-ops.c b/src/libemail-engine/mail-ops.c
index 99689e6..ee4b164 100644
--- a/src/libemail-engine/mail-ops.c
+++ b/src/libemail-engine/mail-ops.c
@@ -750,13 +750,17 @@ mail_send_message (struct _send_queue_msg *m,
if (local_error == NULL && !sent_message_saved && (provider == NULL
|| !(provider->flags & CAMEL_PROVIDER_DISABLE_SENT_FOLDER))) {
CamelFolder *local_sent_folder;
+ gboolean use_sent_folder = TRUE;
+
+ folder = e_mail_session_get_fcc_for_message_sync (
+ m->session, message, &use_sent_folder, cancellable, &local_error);
+
+ if (!use_sent_folder)
+ goto cleanup;
local_sent_folder = e_mail_session_get_local_folder (
m->session, E_MAIL_LOCAL_FOLDER_SENT);
- folder = e_mail_session_get_fcc_for_message_sync (
- m->session, message, cancellable, &local_error);
-
/* Sanity check. */
g_return_if_fail (
((folder == NULL) && (local_error != NULL)) ||
@@ -823,6 +827,7 @@ mail_send_message (struct _send_queue_msg *m,
}
}
+ cleanup:
if (local_error == NULL) {
/* Mark the draft message for deletion, if present. */
e_mail_session_handle_draft_headers_sync (
diff --git a/src/mail/e-mail-backend.c b/src/mail/e-mail-backend.c
index 242576d..26f1af0 100644
--- a/src/mail/e-mail-backend.c
+++ b/src/mail/e-mail-backend.c
@@ -616,14 +616,12 @@ mail_backend_folder_deleted_cb (MailFolderCache *folder_cache,
for (link = list; link != NULL; link = g_list_next (link)) {
ESource *source = E_SOURCE (link->data);
- ESourceExtension *extension;
+ ESourceMailSubmission *extension;
const gchar *sent_folder_uri;
extension = e_source_get_extension (source, extension_name);
- sent_folder_uri =
- e_source_mail_submission_get_sent_folder (
- E_SOURCE_MAIL_SUBMISSION (extension));
+ sent_folder_uri = e_source_mail_submission_get_sent_folder (extension);
if (sent_folder_uri == NULL)
continue;
@@ -631,9 +629,7 @@ mail_backend_folder_deleted_cb (MailFolderCache *folder_cache,
if (class->equal_folder_name (sent_folder_uri, uri)) {
GError *error = NULL;
- e_source_mail_submission_set_sent_folder (
- E_SOURCE_MAIL_SUBMISSION (extension),
- local_sent_folder_uri);
+ e_source_mail_submission_set_sent_folder (extension, local_sent_folder_uri);
/* FIXME This is a blocking D-Bus method call. */
if (!e_source_write_sync (source, NULL, &error)) {
@@ -729,15 +725,13 @@ mail_backend_folder_renamed_cb (MailFolderCache *folder_cache,
for (link = list; link != NULL; link = g_list_next (link)) {
ESource *source = E_SOURCE (link->data);
- ESourceExtension *extension;
+ ESourceMailSubmission *extension;
const gchar *sent_folder_uri;
gboolean need_update;
extension = e_source_get_extension (source, extension_name);
- sent_folder_uri =
- e_source_mail_submission_get_sent_folder (
- E_SOURCE_MAIL_SUBMISSION (extension));
+ sent_folder_uri = e_source_mail_submission_get_sent_folder (extension);
need_update =
(sent_folder_uri != NULL) &&
@@ -746,9 +740,7 @@ mail_backend_folder_renamed_cb (MailFolderCache *folder_cache,
if (need_update) {
GError *error = NULL;
- e_source_mail_submission_set_sent_folder (
- E_SOURCE_MAIL_SUBMISSION (extension),
- new_uri);
+ e_source_mail_submission_set_sent_folder (extension, new_uri);
/* FIXME This is a blocking D-Bus method call. */
if (!e_source_write_sync (source, NULL, &error)) {
diff --git a/src/mail/e-mail-config-defaults-page.c b/src/mail/e-mail-config-defaults-page.c
index 39ebfeb..13285a7 100644
--- a/src/mail/e-mail-config-defaults-page.c
+++ b/src/mail/e-mail-config-defaults-page.c
@@ -786,6 +786,7 @@ mail_config_defaults_page_constructed (GObject *object)
const gchar *extension_name;
const gchar *text;
gchar *markup;
+ gboolean disable_sent_folder;
page = E_MAIL_CONFIG_DEFAULTS_PAGE (object);
@@ -859,27 +860,54 @@ mail_config_defaults_page_constructed (GObject *object)
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
+ disable_sent_folder = provider && (provider->flags & CAMEL_PROVIDER_DISABLE_SENT_FOLDER) != 0;
+
text = _("Sent _Messages Folder:");
- widget = gtk_label_new_with_mnemonic (text);
- gtk_widget_set_margin_left (widget, 12);
- gtk_size_group_add_widget (size_group, widget);
- gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
+ if (disable_sent_folder) {
+ widget = gtk_label_new_with_mnemonic (text);
+ gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
+ gtk_widget_set_margin_left (widget, 12);
+ gtk_size_group_add_widget (size_group, widget);
+ } else {
+ widget = gtk_check_button_new_with_mnemonic (text);
+ g_object_set (G_OBJECT (widget),
+ "hexpand", TRUE,
+ "halign", GTK_ALIGN_END,
+ "vexpand", FALSE,
+ "valign", GTK_ALIGN_CENTER,
+ NULL);
+ }
gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1);
gtk_widget_show (widget);
- label = GTK_LABEL (widget);
+ if (disable_sent_folder) {
+ label = GTK_LABEL (widget);
+ } else {
+ e_binding_bind_property (
+ submission_ext, "use-sent-folder",
+ widget, "active",
+ G_BINDING_BIDIRECTIONAL |
+ G_BINDING_SYNC_CREATE);
+ }
text = _("Choose a folder for saving sent messages.");
widget = em_folder_selection_button_new (session, "", text);
gtk_widget_set_hexpand (widget, TRUE);
- gtk_label_set_mnemonic_widget (label, widget);
+ if (disable_sent_folder)
+ gtk_label_set_mnemonic_widget (label, widget);
gtk_grid_attach (GTK_GRID (container), widget, 1, 2, 1, 1);
page->priv->sent_button = widget; /* not referenced */
gtk_widget_show (widget);
- if (provider && (provider->flags & CAMEL_PROVIDER_DISABLE_SENT_FOLDER) != 0) {
+ if (disable_sent_folder) {
gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
gtk_widget_set_sensitive (widget, FALSE);
+ } else {
+ e_binding_bind_property (
+ submission_ext, "use-sent-folder",
+ widget, "sensitive",
+ G_BINDING_BIDIRECTIONAL |
+ G_BINDING_SYNC_CREATE);
}
e_binding_bind_object_text_property (
@@ -895,8 +923,14 @@ mail_config_defaults_page_constructed (GObject *object)
page->priv->replies_toggle = widget; /* not referenced */
gtk_widget_show (widget);
- if (provider && (provider->flags & CAMEL_PROVIDER_DISABLE_SENT_FOLDER) != 0) {
+ if (disable_sent_folder) {
gtk_widget_set_sensitive (widget, FALSE);
+ } else {
+ e_binding_bind_property (
+ submission_ext, "use-sent-folder",
+ widget, "sensitive",
+ G_BINDING_BIDIRECTIONAL |
+ G_BINDING_SYNC_CREATE);
}
e_binding_bind_property (
diff --git a/src/mail/em-folder-tree-model.c b/src/mail/em-folder-tree-model.c
index a1d4a60..7ab81ec 100644
--- a/src/mail/em-folder-tree-model.c
+++ b/src/mail/em-folder-tree-model.c
@@ -1115,7 +1115,8 @@ folder_tree_model_get_special_folders_uri (ESourceRegistry *registry,
extension = e_source_get_extension (source, extension_name);
- *sent_folder_uri = e_source_mail_submission_dup_sent_folder (extension);
+ if (e_source_mail_submission_get_use_sent_folder (extension))
+ *sent_folder_uri = e_source_mail_submission_dup_sent_folder (extension);
}
g_object_unref (source);
diff --git a/src/modules/mdn/evolution-mdn.c b/src/modules/mdn/evolution-mdn.c
index 9b7605d..e3b57eb 100644
--- a/src/modules/mdn/evolution-mdn.c
+++ b/src/modules/mdn/evolution-mdn.c
@@ -229,7 +229,7 @@ mdn_notify_sender (ESource *identity_source,
const gchar *message_subject;
const gchar *extension_name;
const gchar *transport_uid;
- const gchar *sent_folder_uri;
+ const gchar *sent_folder_uri = NULL;
const gchar *hostname;
gchar *self_address;
gchar *receipt_subject;
@@ -272,8 +272,8 @@ mdn_notify_sender (ESource *identity_source,
extension_name = E_SOURCE_EXTENSION_MAIL_SUBMISSION;
extension = e_source_get_extension (identity_source, extension_name);
- sent_folder_uri = e_source_mail_submission_get_sent_folder (
- E_SOURCE_MAIL_SUBMISSION (extension));
+ if (e_source_mail_submission_get_use_sent_folder (E_SOURCE_MAIL_SUBMISSION (extension)))
+ sent_folder_uri = e_source_mail_submission_get_sent_folder (E_SOURCE_MAIL_SUBMISSION
(extension));
transport_uid = e_source_mail_submission_get_transport_uid (
E_SOURCE_MAIL_SUBMISSION (extension));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]