unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#35507: Gnus mojibakifies UTF-8 text/x-patch attachments from Thunderbird
@ 2019-04-30 19:20 Paul Eggert
  2019-05-01  0:35 ` Andy Moreton
                   ` (2 more replies)
  0 siblings, 3 replies; 36+ messages in thread
From: Paul Eggert @ 2019-04-30 19:20 UTC (permalink / raw)
  To: 35507

[-- Attachment #1: Type: text/plain, Size: 2401 bytes --]

Package: emacs,gnus
Version: 27

When I send email from Thunderbird with a patch attachment, Thunderbird
puts something like the following into the email:

  --------------AA6C74B60F40E0D600CCD03A
  Content-Type: text/x-patch;
   name="0001-Fix-decode-time-encode-time-roundtrip-on-macOS.patch"
  Content-Transfer-Encoding: 8bit
  Content-Disposition: attachment;
   filename*0="0001-Fix-decode-time-encode-time-roundtrip-on-macOS.patch"

  From 325f51c84d9ad4d9776784bd324b347ffe4fe51b Mon Sep 17 00:00:00 2001
  From: Paul Eggert <eggert@cs.ucla.edu>
  Date: Tue, 30 Apr 2019 10:45:48 -0700
  Subject: [PATCH] Fix decode-time/encode-time roundtrip on macOS
  MIME-Version: 1.0
  Content-Type: text/plain; charset=UTF-8
  Content-Transfer-Encoding: 8bit

  * src/timefns.c (Fencode_time): Ignore DST flag when the zone is
  ...

The attachment has a text/* media type but it has no charset parameter.
The patch itself (output by git format-patch) says its charset is UTF-8.
Unfortunately, Gnus doesn't recognize the patch as UTF-8 and so
mishandles the non-ASCII characters in the attachment. To reproduce the
problem, read this email with Gnus; the full attachment is attached to
this email in the Thunderbird way.

Although Internet RFC 2046 section 4.1.2 says the default charset for
text/* media types is US-ASCII, Internet RFC 6557 section 3 amends this
to say that registered text/* media types should require a charset
specification (or should say it's not needed because the payload has
that info, which obviously doesn't apply here). It later says that if
there is a strong reason to have a charset default, the default should
be UTF-8.

Unfortunately Gnus apparently doesn't default to UTF-8 for such
attachments, which means that sending a text/x-patch attachment from
Thunderbird to Gnus messes up if the attachment contains non-ASCII
characters. This has been causing problems on the Emacs mailing list for
years and it bit a correspondent of mine again today; see
<https://debbugs.gnu.org/cgi/bugreport.cgi?bug=35502#35>.

I have filed a Thunderbird bug report for this, as Thunderbird should
specify a charset; see
<https://bugzilla.mozilla.org/show_bug.cgi?id=1167982>. However, Gnus
should be a polite citizen and handle these attachments nicely rather
than converting the non-ASCII UTF-8 characters to mojibake.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-decode-time-encode-time-roundtrip-on-macOS.patch --]
[-- Type: text/x-patch; name="0001-Fix-decode-time-encode-time-roundtrip-on-macOS.patch", Size: 2058 bytes --]

From 325f51c84d9ad4d9776784bd324b347ffe4fe51b Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 30 Apr 2019 10:45:48 -0700
Subject: [PATCH] Fix decode-time/encode-time roundtrip on macOS
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/timefns.c (Fencode_time): Ignore DST flag when the zone is
numeric or is a cons, as the doc string says it’s ignored in that
case, and not ignoring it causes encode-time to not invert
decode-time on some platforms (Bug#35502).
* test/src/timefns-tests.el (encode-time-dst-numeric-zone):
New test.
---
 src/timefns.c             | 5 +++--
 test/src/timefns-tests.el | 6 ++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/timefns.c b/src/timefns.c
index 5005c73b7f..7b5af6a5d2 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -1488,10 +1488,11 @@ usage: (encode-time &optional TIME FORM &rest OBSOLESCENT-ARGUMENTS)  */)
       tm.tm_mon  = check_tm_member (XCAR (a), 1); a = XCDR (a);
       tm.tm_year = check_tm_member (XCAR (a), TM_YEAR_BASE); a = XCDR (a);
       a = XCDR (a);
-      if (SYMBOLP (XCAR (a)))
-	tm.tm_isdst = !NILP (XCAR (a));
+      Lisp_Object dstflag = XCAR (a);
       a = XCDR (a);
       zone = XCAR (a);
+      if (SYMBOLP (dstflag) && !FIXNUMP (zone) && !CONSP (zone))
+	tm.tm_isdst = !NILP (dstflag);
     }
   else if (nargs < 6)
     xsignal2 (Qwrong_number_of_arguments, Qencode_time, make_fixnum (nargs));
diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el
index 5c858ef3bd..2c90af757f 100644
--- a/test/src/timefns-tests.el
+++ b/test/src/timefns-tests.el
@@ -142,3 +142,9 @@ timefns-tests--have-leap-seconds
 		      (< 0.99 (/ x y) 1.01)
 		      (< 0.99 (/ (- (float-time a)) (float-time b))
 			 1.01))))))))
+
+(ert-deftest encode-time-dst-numeric-zone ()
+    "Check for Bug#35502."
+    (should (time-equal-p
+             (encode-time '(29 31 17 30 4 2019 2 t 7200))
+             '(23752 27217))))
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2019-05-03 15:20 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-30 19:20 bug#35507: Gnus mojibakifies UTF-8 text/x-patch attachments from Thunderbird Paul Eggert
2019-05-01  0:35 ` Andy Moreton
2019-05-01 15:22   ` Robert Pluim
2019-05-01 15:45     ` Andy Moreton
2019-05-01 16:42       ` Andy Moreton
2019-05-01 17:36         ` Eli Zaretskii
2019-05-01 23:54           ` Andy Moreton
2019-05-02  3:07           ` Noam Postavsky
2019-05-02  7:17             ` Andy Moreton
2019-05-02 11:04               ` Eli Zaretskii
2019-05-02 15:43                 ` Andy Moreton
2019-05-02 15:57                   ` Eli Zaretskii
2019-05-02 16:08                     ` Andy Moreton
2019-05-02 16:50                       ` Eli Zaretskii
2019-05-02 17:13                       ` Eric Abrahamsen
2019-05-02 17:45                         ` Andy Moreton
2019-05-02 16:10                     ` Basil L. Contovounesios
2019-05-02 16:50                       ` Eli Zaretskii
2019-05-02 17:20                         ` Eli Zaretskii
2019-05-03 13:55                           ` Basil L. Contovounesios
2019-05-02 16:29                     ` Robert Pluim
2019-05-02 16:53                       ` Eli Zaretskii
2019-05-02 12:01               ` Noam Postavsky
2019-05-02 15:40                 ` Eli Zaretskii
2019-05-03 14:02                   ` Basil L. Contovounesios
2019-05-03 15:14                     ` Eli Zaretskii
2019-05-03 15:20                       ` Basil L. Contovounesios
2019-05-01 17:34     ` Eli Zaretskii
2019-05-02  6:35       ` Robert Pluim
2019-05-01 17:33   ` Eli Zaretskii
2019-05-01 17:32 ` Eli Zaretskii
2019-05-01 18:26   ` Paul Eggert
2019-05-01 19:05     ` Eli Zaretskii
2019-05-01 19:47       ` Andreas Schwab
2019-05-01 19:57         ` Eli Zaretskii
2019-05-02 23:24 ` Paul Eggert

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).