From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel,gmane.emacs.gnus.general Subject: Re: master ef14acf: Make nnml handle invalid non-ASCII headers more consistently Date: Sat, 17 Dec 2022 09:45:40 +0200 Message-ID: <83k02qiicb.fsf@gnu.org> References: <20210122180801.14756.84264@vcs0.savannah.gnu.org> <20210122180802.F0A1E20A10@vcs0.savannah.gnu.org> <874jtvq8c2.fsf@oldenburg.str.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="384"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , Eric Abrahamsen , emacs-devel@gnu.org, ding@gnus.org To: Florian Weimer Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Dec 17 08:46:31 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p6Rtu-000ARH-8k for ged-emacs-devel@m.gmane-mx.org; Sat, 17 Dec 2022 08:46:30 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p6RtD-0000Pk-Ky; Sat, 17 Dec 2022 02:45:49 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6Rt4-0000NV-Dc for emacs-devel@gnu.org; Sat, 17 Dec 2022 02:45:38 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6Rt3-0001uE-2L; Sat, 17 Dec 2022 02:45:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=3UXTzLfMtlVE9SAHTnBeIKGSI/BTsxsth6ZMBIJQdwQ=; b=iS1nogm57xiNnKxTM5v8 oqSx15FLrISophvV5BpeMUofm8++W2lVDeCssbKygNtA8G8mJAn0U7fPImhLx0bp90qcUyg8eCsg4 vX2EVAWs3Cp0egV7NWRkPomFn2pQGykxrswEEhGU9DNA0oyvzYP0faR0NbGuyBg0LC5sxZ/eLDVtd ok2gOMAVoGoIBLZLsOBClbddEu0aEMd4y9yhsyc2tLybevVxyLjIhxRW4I1qDISKVOSa/pfMFL2/L sSLUwNHvHRnPoL2mkO1qCVscS7sM0+GeVbZKnLergc1P4FuSzJcXahc+NxOjZpb6wCPY0fWmBs8WK a8HiKG731Is2uA==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6Rt2-0004qI-Hr; Sat, 17 Dec 2022 02:45:36 -0500 In-Reply-To: <874jtvq8c2.fsf@oldenburg.str.redhat.com> (message from Florian Weimer on Fri, 16 Dec 2022 23:42:21 +0100) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:301547 gmane.emacs.gnus.general:91026 Archived-At: > From: Florian Weimer > Cc: Lars Ingebrigtsen , ding@gnus.org > Date: Fri, 16 Dec 2022 23:42:21 +0100 > > * Lars Ingebrigtsen: > > > branch: master > > commit ef14acfb68bb5b0ce42221e9681b93562f8085eb > > Author: Lars Ingebrigtsen > > Commit: Lars Ingebrigtsen > > > > Make nnml handle invalid non-ASCII headers more consistently > > > > * lisp/gnus/nnml.el (nnml--encode-headers): New function to > > RFC2047-encode invalid Subject/From headers (bug#45925). This > > will make them be displayed more consistently in the Summary > > buffer (but still "wrong" sometimes, since there's not that much > > we can guess at at this stage, charset wise). > > (nnml-parse-head): Use it. > > --- > > lisp/gnus/nnml.el | 16 ++++++++++++++++ > > 1 file changed, 16 insertions(+) > > > > diff --git a/lisp/gnus/nnml.el b/lisp/gnus/nnml.el > > index ebececa..3cdfc74 100644 > > --- a/lisp/gnus/nnml.el > > +++ b/lisp/gnus/nnml.el > > @@ -769,8 +769,24 @@ article number. This function is called narrowed to an article." > > (let ((headers (nnheader-parse-head t))) > > (setf (mail-header-chars headers) chars) > > (setf (mail-header-number headers) number) > > + ;; If there's non-ASCII raw characters in the data, > > + ;; RFC2047-encode them to avoid having arbitrary data in the > > + ;; .overview file. > > + (nnml--encode-headers headers) > > headers)))) > > Unfortunately, this change in particular causes Gnus to stops storing > messages into nnmail after receiving a message with this header: > > From: =?utf-8?b?572X5YuH5YiaKFlvbmdnYW5nIEx1bykgdmlhIEVsZnV0aWxzLWRldmVs?= > > > The logged error message is: > > Mail source (maildir :path …) failed: (error Invalid data for rfc2047 encoding: 罗勇刚(Yonggang Luo) via Elfutils-devel ) > > On an older Emacs without this change, it seems that the original header > is written to the .overview file, which sidestep the problem that not > all strings are encodable by the rfc2047 functions. Thanks. I guess this From header is invalid because there's no space between the "罗勇刚" and the "(Yonggang Luo)" parts? Does the naïve patch below solve the problem? diff --git a/lisp/gnus/nnml.el b/lisp/gnus/nnml.el index 40e4b9e..7aa445e 100644 --- a/lisp/gnus/nnml.el +++ b/lisp/gnus/nnml.el @@ -776,17 +776,22 @@ nnml-parse-head (nnml--encode-headers headers) headers)))) +;; RFC2047-encode Subject and From, but leave invalid headers unencoded. (defun nnml--encode-headers (headers) (let ((subject (mail-header-subject headers)) (rfc2047-encoding-type 'mime)) (unless (string-match "\\`[[:ascii:]]*\\'" subject) - (setf (mail-header-subject headers) - (mail-encode-encoded-word-string subject t)))) + (let ((encoded-subject + (ignore-errors (mail-encode-encoded-word-string subject t)))) + (if encoded-subject + (setf (mail-header-subject headers) encoded-subject))))) (let ((from (mail-header-from headers)) (rfc2047-encoding-type 'address-mime)) (unless (string-match "\\`[[:ascii:]]*\\'" from) - (setf (mail-header-from headers) - (rfc2047-encode-string from t))))) + (let ((encoded-from + (ignore-errors (rfc2047-encode-string from t)))) + (if encoded-from + (setf (mail-header-from headers) encoded-from)))))) (defun nnml-get-nov-buffer (group &optional incrementalp) (let ((buffer (gnus-get-buffer-create