[evolution] I#919 - Better figure out intended recipient with Reply to Sender



commit a34178ff746660a6690b33f0bc91550ff5dc0ce7
Author: Milan Crha <mcrha redhat com>
Date:   Mon Aug 31 18:32:50 2020 +0200

    I#919 - Better figure out intended recipient with Reply to Sender
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/919

 src/calendar/gui/CMakeLists.txt    |  1 +
 src/calendar/gui/itip-utils.c      | 37 +++------------------
 src/libemail-engine/e-mail-utils.c | 67 ++++++++++++++++++++++++++++++++++++++
 src/libemail-engine/e-mail-utils.h |  6 ++++
 src/mail/e-mail-enums.h            | 13 +++++---
 src/mail/em-composer-utils.c       |  8 ++++-
 6 files changed, 93 insertions(+), 39 deletions(-)
---
diff --git a/src/calendar/gui/CMakeLists.txt b/src/calendar/gui/CMakeLists.txt
index 405773499f..7514dc3de3 100644
--- a/src/calendar/gui/CMakeLists.txt
+++ b/src/calendar/gui/CMakeLists.txt
@@ -16,6 +16,7 @@ set(DEPENDENCIES
        eabutil
        econtacteditor
        econtactlisteditor
+       email-engine
        evolution-calendar-importers
        evolution-mail-composer
        evolution-shell
diff --git a/src/calendar/gui/itip-utils.c b/src/calendar/gui/itip-utils.c
index feb300d9ab..daa88807a4 100644
--- a/src/calendar/gui/itip-utils.c
+++ b/src/calendar/gui/itip-utils.c
@@ -30,9 +30,11 @@
 
 #include <libsoup/soup.h>
 
-#include <composer/e-msg-composer.h>
 #include <libedataserver/libedataserver.h>
 
+#include "composer/e-msg-composer.h"
+#include "libemail-engine/libemail-engine.h"
+
 #include "calendar-config.h"
 #include "comp-util.h"
 
@@ -287,41 +289,10 @@ gboolean
 itip_address_is_user (ESourceRegistry *registry,
                       const gchar *address)
 {
-       GList *list, *iter;
-       const gchar *extension_name;
-       gboolean match = FALSE;
-
        g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
        g_return_val_if_fail (address != NULL, FALSE);
 
-       extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
-
-       list = e_source_registry_list_sources (registry, extension_name);
-
-       for (iter = list; iter && !match; iter = g_list_next (iter)) {
-               ESource *source = E_SOURCE (iter->data);
-               ESourceMailIdentity *extension;
-               GHashTable *aliases;
-               const gchar *id_address;
-
-               extension = e_source_get_extension (source, extension_name);
-               id_address = e_source_mail_identity_get_address (extension);
-
-               if (id_address && g_ascii_strcasecmp (address, id_address) == 0) {
-                       match = TRUE;
-                       break;
-               }
-
-               aliases = e_source_mail_identity_get_aliases_as_hash_table (extension);
-               if (aliases) {
-                       match = g_hash_table_contains (aliases, address);
-                       g_hash_table_destroy (aliases);
-               }
-       }
-
-       g_list_free_full (list, (GDestroyNotify) g_object_unref);
-
-       return match;
+       return em_utils_address_is_user (registry, address, FALSE);
 }
 
 gboolean
diff --git a/src/libemail-engine/e-mail-utils.c b/src/libemail-engine/e-mail-utils.c
index b608ca50d0..c3cc31c456 100644
--- a/src/libemail-engine/e-mail-utils.c
+++ b/src/libemail-engine/e-mail-utils.c
@@ -940,3 +940,70 @@ em_utils_get_real_folder_and_message_uid (CamelFolder *folder,
        if (message_uid)
                *message_uid = g_strdup (uid);
 }
+
+gboolean
+em_utils_address_is_user (ESourceRegistry *registry,
+                         const gchar *address,
+                         gboolean only_enabled_accounts)
+{
+       GList *list, *iter;
+       const gchar *extension_name;
+       gboolean match = FALSE;
+
+       g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
+       g_return_val_if_fail (address != NULL, FALSE);
+
+       extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
+
+       if (only_enabled_accounts)
+               list = e_source_registry_list_enabled (registry, extension_name);
+       else
+               list = e_source_registry_list_sources (registry, extension_name);
+
+       for (iter = list; iter && !match; iter = g_list_next (iter)) {
+               ESource *source = E_SOURCE (iter->data);
+               ESourceMailIdentity *extension;
+               GHashTable *aliases;
+               const gchar *id_address;
+
+               extension = e_source_get_extension (source, extension_name);
+               id_address = e_source_mail_identity_get_address (extension);
+
+               if (id_address && g_ascii_strcasecmp (address, id_address) == 0) {
+                       match = TRUE;
+                       break;
+               }
+
+               aliases = e_source_mail_identity_get_aliases_as_hash_table (extension);
+               if (aliases) {
+                       match = g_hash_table_contains (aliases, address);
+                       g_hash_table_destroy (aliases);
+               }
+       }
+
+       g_list_free_full (list, (GDestroyNotify) g_object_unref);
+
+       return match;
+}
+
+gboolean
+em_utils_sender_is_user (ESourceRegistry *registry,
+                        CamelMimeMessage *message,
+                        gboolean only_enabled_accounts)
+{
+       CamelInternetAddress *from;
+       const gchar *addr = NULL;
+
+       g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
+       g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE);
+
+       from = camel_mime_message_get_from (message);
+
+       if (!from)
+               return FALSE;
+
+       if (!camel_internet_address_get (from, 0, NULL, &addr) || !addr || !*addr)
+               return FALSE;
+
+       return em_utils_address_is_user (registry, addr, only_enabled_accounts);
+}
diff --git a/src/libemail-engine/e-mail-utils.h b/src/libemail-engine/e-mail-utils.h
index 48f9de7a53..b3126450b1 100644
--- a/src/libemail-engine/e-mail-utils.h
+++ b/src/libemail-engine/e-mail-utils.h
@@ -91,5 +91,11 @@ void         em_utils_get_real_folder_and_message_uid
                                                 CamelFolder **out_real_folder,
                                                 gchar **folder_uri,
                                                 gchar **message_uid);
+gboolean       em_utils_address_is_user        (ESourceRegistry *registry,
+                                                const gchar *address,
+                                                gboolean only_enabled_accounts);
+gboolean       em_utils_sender_is_user         (ESourceRegistry *registry,
+                                                CamelMimeMessage *message,
+                                                gboolean only_enabled_accounts);
 
 #endif /* E_MAIL_UTILS_H */
diff --git a/src/mail/e-mail-enums.h b/src/mail/e-mail-enums.h
index 4ec1605709..9ae17d76bf 100644
--- a/src/mail/e-mail-enums.h
+++ b/src/mail/e-mail-enums.h
@@ -56,13 +56,15 @@ typedef enum {
  *    with @E_MAIL_REPLY_FLAG_FORMAT_PLAIN. If none of these is set, then uses
  *    global setting.
  * @E_MAIL_REPLY_FLAG_TOP_POSTING: Force top posting; cannot be used together
- *    with @E_MAIL_REPLY_FLAG_BOTTOM_POSTING. If none it set, then uses global settings.
+ *    with @E_MAIL_REPLY_FLAG_BOTTOM_POSTING. If none is set, then uses global settings.
  * @E_MAIL_REPLY_FLAG_BOTTOM_POSTING: Force bottom posting; cannot be used together
- *    with @E_MAIL_REPLY_FLAG_TOP_POSTING. If none it set, then uses global settings.
+ *    with @E_MAIL_REPLY_FLAG_TOP_POSTING. If none is set, then uses global settings.
  * @E_MAIL_REPLY_FLAG_TOP_SIGNATURE: Force placing signature to the top; cannot be used together
- *    with @E_MAIL_REPLY_FLAG_BOTTOM_SIGNATURE. If none it set, then uses global settings.
+ *    with @E_MAIL_REPLY_FLAG_BOTTOM_SIGNATURE. If none is set, then uses global settings.
  * @E_MAIL_REPLY_FLAG_BOTTOM_SIGNATURE: Force placing signature to the bottom; cannot be used together
- *    with @E_MAIL_REPLY_FLAG_TOP_SIGNATURE. If none it set, then uses global settings.
+ *    with @E_MAIL_REPLY_FLAG_TOP_SIGNATURE. If none is set, then uses global settings.
+ * @E_MAIL_REPLY_FLAG_FORCE_SENDER_REPLY: Force sender reply, to not switch it to reply-all, when
+ *    the From address of the message is the user.
  *
  * Flags influencing behavior of em_utils_reply_to_message().
  *
@@ -76,7 +78,8 @@ typedef enum { /*< flags >*/
        E_MAIL_REPLY_FLAG_TOP_POSTING           = 1 << 3,
        E_MAIL_REPLY_FLAG_BOTTOM_POSTING        = 1 << 4,
        E_MAIL_REPLY_FLAG_TOP_SIGNATURE         = 1 << 5,
-       E_MAIL_REPLY_FLAG_BOTTOM_SIGNATURE      = 1 << 6
+       E_MAIL_REPLY_FLAG_BOTTOM_SIGNATURE      = 1 << 6,
+       E_MAIL_REPLY_FLAG_FORCE_SENDER_REPLY    = 1 << 7
 } EMailReplyFlags;
 
 G_END_DECLS
diff --git a/src/mail/em-composer-utils.c b/src/mail/em-composer-utils.c
index 00f55403ae..8dc5757718 100644
--- a/src/mail/em-composer-utils.c
+++ b/src/mail/em-composer-utils.c
@@ -3836,7 +3836,7 @@ alt_reply_composer_created_cb (GObject *source_object,
                } else {
                        em_utils_reply_to_message (composer, context->source_message,
                                context->folder, context->message_uid, context->type, context->style,
-                               context->source, NULL, context->flags);
+                               context->source, NULL, context->flags | E_MAIL_REPLY_FLAG_FORCE_SENDER_REPLY);
                }
        } else {
                e_alert_submit (context->alert_sink, "mail-composer:failed-create-composer",
@@ -4522,6 +4522,12 @@ em_utils_reply_to_message (EMsgComposer *composer,
        shell = e_msg_composer_get_shell (composer);
        registry = e_shell_get_registry (shell);
 
+       if (type == E_MAIL_REPLY_TO_SENDER &&
+           !(reply_flags & E_MAIL_REPLY_FLAG_FORCE_SENDER_REPLY) &&
+           em_utils_sender_is_user (registry, message, TRUE)) {
+               type = E_MAIL_REPLY_TO_ALL;
+       }
+
        source = em_composer_utils_guess_identity_source (shell, message, folder, message_uid, 
&identity_name, &identity_address);
 
        if (source != NULL) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]