[evolution] I#1793 - Mail: Apply custom locale also to localized fwd-re
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] I#1793 - Mail: Apply custom locale also to localized fwd-re
- Date: Wed, 2 Feb 2022 10:17:11 +0000 (UTC)
commit f4f552bb2f92391f6e9d86798f1d86d519de81db
Author: Milan Crha <mcrha redhat com>
Date: Wed Feb 2 11:16:02 2022 +0100
I#1793 - Mail: Apply custom locale also to localized fwd-re
Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1793
src/libemail-engine/e-mail-folder-utils.c | 20 ++---
src/libemail-engine/e-mail-folder-utils.h | 4 +-
src/libemail-engine/e-mail-session.c | 122 +++++++++++++++++++++++++++++-
src/libemail-engine/mail-tools.c | 9 ++-
src/libemail-engine/mail-tools.h | 3 +-
src/mail/em-composer-utils.c | 99 ++++++++++++++++++------
src/mail/em-composer-utils.h | 2 +-
7 files changed, 217 insertions(+), 42 deletions(-)
---
diff --git a/src/libemail-engine/e-mail-folder-utils.c b/src/libemail-engine/e-mail-folder-utils.c
index 99c08284b9..8c2857cf1d 100644
--- a/src/libemail-engine/e-mail-folder-utils.c
+++ b/src/libemail-engine/e-mail-folder-utils.c
@@ -40,7 +40,7 @@ struct _AsyncContext {
GHashTable *hash_table;
GPtrArray *ptr_array;
GFile *destination;
- gchar *fwd_subject;
+ gchar *orig_subject;
gchar *message_uid;
};
@@ -58,7 +58,7 @@ async_context_free (AsyncContext *context)
g_clear_object (&context->part);
g_clear_object (&context->destination);
- g_free (context->fwd_subject);
+ g_free (context->orig_subject);
g_free (context->message_uid);
g_slice_free (AsyncContext, context);
@@ -492,7 +492,7 @@ mail_folder_build_attachment_thread (GSimpleAsyncResult *simple,
context->part = e_mail_folder_build_attachment_sync (
CAMEL_FOLDER (object), context->ptr_array,
- &context->fwd_subject, cancellable, &error);
+ &context->orig_subject, cancellable, &error);
if (error != NULL)
g_simple_async_result_take_error (simple, error);
@@ -501,7 +501,7 @@ mail_folder_build_attachment_thread (GSimpleAsyncResult *simple,
CamelMimePart *
e_mail_folder_build_attachment_sync (CamelFolder *folder,
GPtrArray *message_uids,
- gchar **fwd_subject,
+ gchar **orig_subject,
GCancellable *cancellable,
GError **error)
{
@@ -530,8 +530,8 @@ e_mail_folder_build_attachment_sync (CamelFolder *folder,
message = g_hash_table_lookup (hash_table, uid);
g_return_val_if_fail (message != NULL, NULL);
- if (fwd_subject != NULL)
- *fwd_subject = mail_tool_generate_forward_subject (message);
+ if (orig_subject != NULL)
+ *orig_subject = g_strdup (camel_mime_message_get_subject (message));
if (message_uids->len == 1) {
part = mail_tool_make_message_attachment (message);
@@ -613,7 +613,7 @@ e_mail_folder_build_attachment (CamelFolder *folder,
CamelMimePart *
e_mail_folder_build_attachment_finish (CamelFolder *folder,
GAsyncResult *result,
- gchar **fwd_subject,
+ gchar **orig_subject,
GError **error)
{
GSimpleAsyncResult *simple;
@@ -630,9 +630,9 @@ e_mail_folder_build_attachment_finish (CamelFolder *folder,
if (g_simple_async_result_propagate_error (simple, error))
return NULL;
- if (fwd_subject != NULL) {
- *fwd_subject = context->fwd_subject;
- context->fwd_subject = NULL;
+ if (orig_subject != NULL) {
+ *orig_subject = context->orig_subject;
+ context->orig_subject = NULL;
}
g_return_val_if_fail (CAMEL_IS_MIME_PART (context->part), NULL);
diff --git a/src/libemail-engine/e-mail-folder-utils.h b/src/libemail-engine/e-mail-folder-utils.h
index e2eed4c8c5..0953560653 100644
--- a/src/libemail-engine/e-mail-folder-utils.h
+++ b/src/libemail-engine/e-mail-folder-utils.h
@@ -63,7 +63,7 @@ gboolean e_mail_folder_expunge_finish (CamelFolder *folder,
CamelMimePart * e_mail_folder_build_attachment_sync
(CamelFolder *folder,
GPtrArray *message_uids,
- gchar **fwd_subject,
+ gchar **orig_subject,
GCancellable *cancellable,
GError **error);
void e_mail_folder_build_attachment (CamelFolder *folder,
@@ -75,7 +75,7 @@ void e_mail_folder_build_attachment (CamelFolder *folder,
CamelMimePart * e_mail_folder_build_attachment_finish
(CamelFolder *folder,
GAsyncResult *result,
- gchar **fwd_subject,
+ gchar **orig_subject,
GError **error);
GHashTable * e_mail_folder_find_duplicate_messages_sync
diff --git a/src/libemail-engine/e-mail-session.c b/src/libemail-engine/e-mail-session.c
index e1dbe548ff..2bf8b6c6f9 100644
--- a/src/libemail-engine/e-mail-session.c
+++ b/src/libemail-engine/e-mail-session.c
@@ -27,6 +27,7 @@
#include "evolution-config.h"
#include <errno.h>
+#include <locale.h>
#include <stdlib.h>
#include <string.h>
@@ -1584,6 +1585,116 @@ mail_session_decode_forward_with (ESourceRegistry *registry,
return source;
}
+static void
+ems_change_locale (const gchar *lc_messages,
+ const gchar *lc_time,
+ gchar **out_lc_messages,
+ gchar **out_lc_time)
+{
+ gboolean success;
+ gchar *previous;
+
+ if (lc_messages) {
+ #if defined(LC_MESSAGES)
+ previous = g_strdup (setlocale (LC_MESSAGES, NULL));
+ success = setlocale (LC_MESSAGES, lc_messages) != NULL;
+ #else
+ previous = g_strdup (setlocale (LC_ALL, NULL));
+ success = setlocale (LC_ALL, lc_messages) != NULL;
+ #endif
+
+ if (out_lc_messages)
+ *out_lc_messages = success ? g_strdup (previous) : NULL;
+
+ g_free (previous);
+ }
+
+ if (lc_time) {
+ #if defined(LC_TIME)
+ previous = g_strdup (setlocale (LC_TIME, NULL));
+ success = setlocale (LC_TIME, lc_time) != NULL;
+ #elif defined(LC_MESSAGES)
+ previous = g_strdup (setlocale (LC_ALL, NULL));
+ success = setlocale (LC_ALL, lc_time) != NULL;
+ #else
+ previous = NULL;
+ success = FALSE;
+ #endif
+
+ if (out_lc_time)
+ *out_lc_time = success ? g_strdup (previous) : NULL;
+
+ g_free (previous);
+ }
+}
+
+static void
+ems_prepare_attribution_locale (ESource *identity_source,
+ gchar **out_lc_messages,
+ gchar **out_lc_time)
+{
+ gchar *lang = NULL;
+
+ g_return_if_fail (out_lc_messages != NULL);
+ g_return_if_fail (out_lc_time != NULL);
+
+ if (identity_source && e_source_has_extension (identity_source, E_SOURCE_EXTENSION_MAIL_COMPOSITION))
{
+ ESourceMailComposition *extension;
+
+ extension = e_source_get_extension (identity_source, E_SOURCE_EXTENSION_MAIL_COMPOSITION);
+ lang = e_source_mail_composition_dup_language (extension);
+ }
+
+ if (!lang || !*lang) {
+ GSettings *settings;
+
+ g_free (lang);
+
+ settings = e_util_ref_settings ("org.gnome.evolution.mail");
+ lang = g_settings_get_string (settings, "composer-attribution-language");
+ g_object_unref (settings);
+
+ if (!lang || !*lang)
+ g_clear_pointer (&lang, g_free);
+ }
+
+ if (!lang) {
+ /* Set the locale always, even when using the user interface
+ language, because gettext() can return wrong text (in the previously
+ used language) */
+ #if defined(LC_MESSAGES)
+ lang = g_strdup (setlocale (LC_MESSAGES, NULL));
+ #else
+ lang = g_strdup (setlocale (LC_ALL, NULL));
+ #endif
+ }
+
+ if (lang) {
+ if (!g_str_equal (lang, "C") && !strchr (lang, '.')) {
+ gchar *tmp;
+
+ tmp = g_strconcat (lang, ".UTF-8", NULL);
+ g_free (lang);
+ lang = tmp;
+ }
+
+ ems_change_locale (lang, lang, out_lc_messages, out_lc_time);
+
+ g_free (lang);
+ }
+}
+
+/* Takes ownership (frees) the 'restore_locale' */
+static void
+ems_restore_locale_after_attribution (gchar *restore_lc_messages,
+ gchar *restore_lc_time)
+{
+ ems_change_locale (restore_lc_messages, restore_lc_time, NULL, NULL);
+
+ g_free (restore_lc_messages);
+ g_free (restore_lc_time);
+}
+
static gboolean
mail_session_forward_to_sync (CamelSession *session,
CamelFolder *folder,
@@ -1604,6 +1715,7 @@ mail_session_forward_to_sync (CamelSession *session,
CamelMessageInfo *info;
CamelMedium *medium;
CamelNameValueArray *orig_headers;
+ GSettings *settings;
GString *references = NULL;
const gchar *extension_name;
const gchar *from_address;
@@ -1612,6 +1724,7 @@ mail_session_forward_to_sync (CamelSession *session,
gboolean success;
gchar *subject;
gchar *alias_name = NULL, *alias_address = NULL;
+ gchar *restore_lc_messages = NULL, *restore_lc_time = NULL;
guint ii, len;
g_return_val_if_fail (folder != NULL, FALSE);
@@ -1753,10 +1866,17 @@ mail_session_forward_to_sync (CamelSession *session,
g_object_unref (addr);
/* subject */
- subject = mail_tool_generate_forward_subject (message);
+ settings = e_util_ref_settings ("org.gnome.evolution.mail");
+ if (g_settings_get_boolean (settings, "composer-use-localized-fwd-re"))
+ ems_prepare_attribution_locale (source, &restore_lc_messages, &restore_lc_time);
+ g_object_unref (settings);
+
+ subject = mail_tool_generate_forward_subject (message, NULL);
camel_mime_message_set_subject (forward, subject);
g_free (subject);
+ ems_restore_locale_after_attribution (restore_lc_messages, restore_lc_time);
+
/* store send account information */
mail_submission = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_SUBMISSION);
if (e_source_mail_submission_get_use_sent_folder (mail_submission))
diff --git a/src/libemail-engine/mail-tools.c b/src/libemail-engine/mail-tools.c
index cb6ecfe351..e042d39020 100644
--- a/src/libemail-engine/mail-tools.c
+++ b/src/libemail-engine/mail-tools.c
@@ -150,16 +150,17 @@ mail_tool_do_movemail (CamelStore *store,
}
gchar *
-mail_tool_generate_forward_subject (CamelMimeMessage *msg)
+mail_tool_generate_forward_subject (CamelMimeMessage *msg,
+ const gchar *orig_subject)
{
- const gchar *orig_subject;
gchar *subject = NULL;
gchar *fwd_subj;
const gint max_subject_length = 1024;
const gchar *format;
GSettings *settings;
- orig_subject = camel_mime_message_get_subject (msg);
+ if ((!orig_subject || !*orig_subject) && msg)
+ orig_subject = camel_mime_message_get_subject (msg);
if (orig_subject && *orig_subject) {
gchar *utf8;
@@ -184,7 +185,7 @@ mail_tool_generate_forward_subject (CamelMimeMessage *msg)
g_free (utf8);
}
- if (!subject) {
+ if (!subject && msg) {
const CamelInternetAddress *from;
from = camel_mime_message_get_from (msg);
diff --git a/src/libemail-engine/mail-tools.h b/src/libemail-engine/mail-tools.h
index 172d94cf85..f8b355e890 100644
--- a/src/libemail-engine/mail-tools.h
+++ b/src/libemail-engine/mail-tools.h
@@ -42,7 +42,8 @@ void mail_tool_restore_xevolution_headers
/* Generates the subject for a message forwarding @msg */
gchar * mail_tool_generate_forward_subject
- (CamelMimeMessage *msg);
+ (CamelMimeMessage *msg,
+ const gchar *orig_subject);
/* Make a message into an attachment */
CamelMimePart * mail_tool_make_message_attachment
diff --git a/src/mail/em-composer-utils.c b/src/mail/em-composer-utils.c
index a54d72dee9..33d29d99ef 100644
--- a/src/mail/em-composer-utils.c
+++ b/src/mail/em-composer-utils.c
@@ -2010,6 +2010,36 @@ emcu_restore_locale_after_attribution (gchar *restore_lc_messages,
g_free (restore_lc_time);
}
+static gchar *
+emcu_generate_forward_subject (EMsgComposer *composer,
+ CamelMimeMessage *message,
+ const gchar *orig_subject)
+{
+ GSettings *settings;
+ gchar *restore_lc_messages = NULL, *restore_lc_time = NULL;
+ gchar *subject;
+
+ settings = e_util_ref_settings ("org.gnome.evolution.mail");
+
+ if (g_settings_get_boolean (settings, "composer-use-localized-fwd-re")) {
+ ESource *identity_source;
+
+ identity_source = emcu_ref_identity_source_from_composer (composer);
+
+ emcu_prepare_attribution_locale (identity_source, &restore_lc_messages, &restore_lc_time);
+
+ g_clear_object (&identity_source);
+ }
+
+ g_object_unref (settings);
+
+ subject = mail_tool_generate_forward_subject (message, orig_subject);
+
+ emcu_restore_locale_after_attribution (restore_lc_messages, restore_lc_time);
+
+ return subject;
+}
+
/* Editing messages... */
typedef enum {
@@ -2538,6 +2568,7 @@ forward_non_attached (EMsgComposer *composer,
EMailForwardStyle style)
{
CamelSession *session;
+ EComposerHeaderTable *table;
EMailPartList *part_list = NULL;
gchar *text, *forward, *subject;
guint32 validity_found = 0;
@@ -2554,10 +2585,13 @@ forward_non_attached (EMsgComposer *composer,
if (!e_content_editor_get_html_mode (e_html_editor_get_content_editor (e_msg_composer_get_editor
(composer))))
flags |= E_MAIL_FORMATTER_QUOTE_FLAG_NO_FORMATTING;
- /* Setup composer's From account before calling quoting_text(),
- because quoting_text() relies on that account. */
- subject = mail_tool_generate_forward_subject (message);
- set_up_new_composer (composer, subject, folder, message, uid, FALSE);
+ /* Setup composer's From account before calling quoting_text() and
+ forward subject, because both rely on that account. */
+ set_up_new_composer (composer, NULL, folder, message, uid, FALSE);
+
+ subject = emcu_generate_forward_subject (composer, message, NULL);
+ table = e_msg_composer_get_header_table (composer);
+ e_composer_header_table_set_subject (table, subject);
g_free (subject);
forward = quoting_text (QUOTING_FORWARD, composer);
@@ -2618,7 +2652,6 @@ em_utils_forward_message (EMsgComposer *composer,
{
CamelMimePart *part;
GPtrArray *uids = NULL;
- gchar *subject;
g_return_if_fail (E_IS_MSG_COMPOSER (composer));
g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
@@ -2629,17 +2662,15 @@ em_utils_forward_message (EMsgComposer *composer,
case E_MAIL_FORWARD_STYLE_ATTACHED:
default:
part = mail_tool_make_message_attachment (message);
- subject = mail_tool_generate_forward_subject (message);
if (folder && uid) {
uids = g_ptr_array_new ();
g_ptr_array_add (uids, (gpointer) uid);
}
- em_utils_forward_attachment (composer, part, subject, uids ? folder : NULL, uids);
+ em_utils_forward_attachment (composer, part, camel_mime_message_get_subject
(message), uids ? folder : NULL, uids);
g_object_unref (part);
- g_free (subject);
break;
case E_MAIL_FORWARD_STYLE_INLINE:
@@ -2655,7 +2686,7 @@ em_utils_forward_message (EMsgComposer *composer,
void
em_utils_forward_attachment (EMsgComposer *composer,
CamelMimePart *part,
- const gchar *subject,
+ const gchar *orig_subject,
CamelFolder *folder,
GPtrArray *uids)
{
@@ -2669,7 +2700,15 @@ em_utils_forward_attachment (EMsgComposer *composer,
e_msg_composer_set_is_reply_or_forward (composer, TRUE);
- set_up_new_composer (composer, subject, folder, NULL, NULL, FALSE);
+ set_up_new_composer (composer, NULL, folder, NULL, NULL, FALSE);
+
+ if (orig_subject) {
+ gchar *subject;
+
+ subject = emcu_generate_forward_subject (composer, NULL, orig_subject);
+ e_composer_header_table_set_subject (e_msg_composer_get_header_table (composer), subject);
+ g_free (subject);
+ }
e_msg_composer_attach (composer, part);
@@ -2809,7 +2848,8 @@ em_utils_camel_address_to_destination (CamelInternetAddress *iaddr)
}
static gchar *
-emcu_construct_reply_subject (const gchar *source_subject)
+emcu_construct_reply_subject (EMsgComposer *composer,
+ const gchar *source_subject)
{
gchar *res;
@@ -2822,8 +2862,22 @@ emcu_construct_reply_subject (const gchar *source_subject)
settings = e_util_ref_settings ("org.gnome.evolution.mail");
if (g_settings_get_boolean (settings, "composer-use-localized-fwd-re")) {
+ gchar *restore_lc_messages = NULL, *restore_lc_time = NULL;
+
+ if (composer) {
+ ESource *identity_source;
+
+ identity_source = emcu_ref_identity_source_from_composer (composer);
+
+ emcu_prepare_attribution_locale (identity_source, &restore_lc_messages,
&restore_lc_time);
+
+ g_clear_object (&identity_source);
+ }
+
/* Translators: This is a reply attribution in the message reply subject. The %s is
replaced with the subject of the original message. Both 'Re'-s in the 'reply-attribution' translation context
should translate into the same string, the same as the ':' separator. */
res = g_strdup_printf (C_("reply-attribution", "Re: %s"), source_subject);
+
+ emcu_restore_locale_after_attribution (restore_lc_messages, restore_lc_time);
} else {
/* Do not localize this string */
res = g_strdup_printf ("Re: %s", source_subject);
@@ -2938,13 +2992,12 @@ reply_setup_composer (EMsgComposer *composer,
reply_setup_composer_recipients (composer, to, cc, folder, message_uid, postto);
- /* Set the subject of the new message. */
- subject = emcu_construct_reply_subject (camel_mime_message_get_subject (message));
-
table = e_msg_composer_get_header_table (composer);
- e_composer_header_table_set_subject (table, subject);
e_composer_header_table_set_identity_uid (table, identity_uid, identity_name, identity_address);
+ /* Set the subject of the new message. */
+ subject = emcu_construct_reply_subject (composer, camel_mime_message_get_subject (message));
+ e_composer_header_table_set_subject (table, subject);
g_free (subject);
/* Add In-Reply-To and References. */
@@ -3811,6 +3864,14 @@ alt_reply_composer_created_cb (GObject *source_object,
CamelNNTPAddress *postto = NULL;
gboolean need_reply_all = FALSE;
+ if (context->template_preserve_subject) {
+ gchar *subject;
+
+ subject = emcu_construct_reply_subject (composer,
camel_mime_message_get_subject (context->source_message));
+ camel_mime_message_set_subject (context->new_message, subject);
+ g_free (subject);
+ }
+
if ((context->flags & (E_MAIL_REPLY_FLAG_FORMAT_PLAIN |
E_MAIL_REPLY_FLAG_FORMAT_HTML)) != 0) {
e_content_editor_set_html_mode (cnt_editor, (context->flags &
E_MAIL_REPLY_FLAG_FORMAT_HTML) != 0);
}
@@ -3887,14 +3948,6 @@ alt_reply_template_applied_cb (GObject *source_object,
context->new_message = e_mail_templates_apply_finish (source_object, result, &error);
if (context->new_message) {
- if (context->template_preserve_subject) {
- gchar *subject;
-
- subject = emcu_construct_reply_subject (camel_mime_message_get_subject
(context->source_message));
- camel_mime_message_set_subject (context->new_message, subject);
- g_free (subject);
- }
-
e_msg_composer_new (context->shell, alt_reply_composer_created_cb, context);
} else {
e_alert_submit (context->alert_sink, "mail:no-retrieve-message",
diff --git a/src/mail/em-composer-utils.h b/src/mail/em-composer-utils.h
index 1c30bfc531..c102e30cbf 100644
--- a/src/mail/em-composer-utils.h
+++ b/src/mail/em-composer-utils.h
@@ -61,7 +61,7 @@ void em_utils_forward_message (EMsgComposer *composer,
const gchar *uid);
void em_utils_forward_attachment (EMsgComposer *composer,
CamelMimePart *part,
- const gchar *subject,
+ const gchar *orig_subject,
CamelFolder *folder,
GPtrArray *uids);
void em_utils_redirect_message (EMsgComposer *composer,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]