From 51b8c501be7d952e0023a72b24c91254b98fc48c Mon Sep 17 00:00:00 2001
From: Michael Gratton <mike@vee.net>
Date: Sat, 10 Oct 2020 23:55:02 +1100
Subject: [PATCH 063/124] Util.Email: Use a single unambiguous date format for
 reply quote dates

Rather than using the UI pref for 12/24h clocks, use a single format
string that should be reasonably unambiguous and that includes the
time zone.

Fixes #888
---
 src/client/composer/composer-widget.vala |  9 +--
 src/client/util/util-email.vala          | 78 ++++++++++++++----------
 2 files changed, 49 insertions(+), 38 deletions(-)

diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 37e93fb4..503727a9 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -740,7 +740,7 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
             );
             add_recipients_and_ids(type, full_context);
             complete_quote = Util.Email.quote_email_for_reply(
-                full_context, quote, this.config.clock_format, HTML
+                full_context, quote, HTML
             );
             if (!Geary.String.is_empty(quote)) {
                 this.top_posting = false;
@@ -1291,12 +1291,7 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
         // Always use reply styling, since forward styling doesn't
         // work for inline quotes
         this.editor.body.insert_html(
-            Util.Email.quote_email_for_reply(
-                referred,
-                to_quote,
-                this.config.clock_format,
-                Geary.RFC822.TextFormat.HTML
-            )
+            Util.Email.quote_email_for_reply(referred, to_quote, HTML)
         );
     }
 
diff --git a/src/client/util/util-email.vala b/src/client/util/util-email.vala
index a18a45cf..4a1754a7 100644
--- a/src/client/util/util-email.vala
+++ b/src/client/util/util-email.vala
@@ -177,41 +177,57 @@ namespace Util.Email {
      */
     public string quote_email_for_reply(Geary.Email email,
                                         string? quote,
-                                        Util.Date.ClockFormat clock_format,
                                         Geary.RFC822.TextFormat format) {
-        if (email.body == null && quote == null)
-            return "";
-
         string quoted = "";
+        if (email.body != null || quote != null) {
+            /// GLib g_date_time_format format string for the date and
+            /// time that a message being replied to was
+            /// received. This should be roughly similar to an RFC
+            /// 822-style date header value with optional additional
+            /// punctuation for readability. Note that this date may
+            /// be sent to someone in a different locale than the
+            /// sender, so should be unambiguous (for example, do not
+            /// use mm/dd/yyyy since it could be confused with
+            /// dd/mm/yyyy) and must include the time zone.
+            string date_format = _("%a, %b %-e %Y at %X %Z");
 
-        string DATE_FORMAT = Util.Date.get_full_date(clock_format);
-
-        if (email.date != null && email.from != null) {
-            /// The quoted header for a message being replied to.
-            /// %1$s will be substituted for the date, and %2$s will be substituted for
-            /// the original sender.
-            string QUOTED_LABEL = _("On %1$s, %2$s wrote:");
-            quoted += QUOTED_LABEL.printf(email.date.value.format(DATE_FORMAT),
-                                          Geary.RFC822.Utils.email_addresses_for_reply(email.from, format));
-
-        } else if (email.from != null) {
-            /// The quoted header for a message being replied to (in case the date is not known).
-            /// %s will be replaced by the original sender.
-            string QUOTED_LABEL = _("%s wrote:");
-            quoted += QUOTED_LABEL.printf(Geary.RFC822.Utils.email_addresses_for_reply(email.from, format));
-
-        } else if (email.date != null) {
-            /// The quoted header for a message being replied to (in case the sender is not known).
-            /// %s will be replaced by the original date
-            string QUOTED_LABEL = _("On %s:");
-            quoted += QUOTED_LABEL.printf(email.date.value.format(DATE_FORMAT));
-        }
+            if (email.date != null && email.from != null) {
+                /// The quoted header for a message being replied to.
+                /// %1$s will be substituted for the date, and %2$s
+                /// will be substituted for the original sender.
+                string QUOTED_LABEL = _("On %1$s, %2$s wrote:");
+                quoted += QUOTED_LABEL.printf(
+                    email.date.value.format(date_format),
+                    Geary.RFC822.Utils.email_addresses_for_reply(
+                        email.from, format
+                    )
+                );
+            } else if (email.from != null) {
+                /// The quoted header for a message being replied to
+                /// (in case the date is not known).  %s will be
+                /// replaced by the original sender.
+                string QUOTED_LABEL = _("%s wrote:");
+                quoted += QUOTED_LABEL.printf(
+                    Geary.RFC822.Utils.email_addresses_for_reply(
+                        email.from, format
+                    )
+                );
+            } else if (email.date != null) {
+                /// The quoted header for a message being replied to
+                /// (in case the sender is not known).  %s will be
+                /// replaced by the original date
+                string QUOTED_LABEL = _("On %s:");
+                quoted += QUOTED_LABEL.printf(
+                    email.date.value.format(date_format)
+                );
+            }
 
-        quoted += "<br />";
-        try {
-            quoted += quote_body(email, quote, true, format);
-        } catch (Error err) {
-            debug("Failed to quote body for replying: %s".printf(err.message));
+            quoted += "<br />";
+            try {
+                quoted += quote_body(email, quote, true, format);
+            } catch (Error err) {
+                debug("Failed to quote body for replying: %s".printf(err.message));
+            }
         }
 
         return quoted;
-- 
2.29.2

