GNU bug report logs - #53811
29.0.50; [PATCH] ietf-drums-parse-address and rfc2047-decode-string

Previous Next

Package: emacs;

Reported by: Bob Rogers <rogers <at> rgrjr.com>

Date: Sun, 6 Feb 2022 02:21:01 UTC

Severity: normal

Tags: patch

Found in version 29.0.50

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 53811 in the body.
You can then email your comments to 53811 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#53811; Package emacs. (Sun, 06 Feb 2022 02:21:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Bob Rogers <rogers <at> rgrjr.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 06 Feb 2022 02:21:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Bob Rogers <rogers <at> rgrjr.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; [PATCH] ietf-drums-parse-address and rfc2047-decode-string
Date: Sat, 05 Feb 2022 21:20:30 -0500
In GNU Emacs 29.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
 of 2022-02-02 built on orion
Repository revision: ed13b0d0f427df333f8e1f9a24015c354da4c62f
Repository branch: rgr-ietf-drums-date
Windowing system distributor 'The X.Org Foundation', version 11.0.12003000
System Description: openSUSE Leap 15.3

   While developing tests for ietf-drums.el, I found that if
ietf-drums-parse-address is asked to do RFC2047 decoding, it does not by
itself load or declare the necessary rfc2047.el code.  So evaluating

        (require 'ietf-drums)
        (ietf-drums-parse-address
          "=?utf-8?B?0JfQtNGA0LDMgdCy0YHRgtCy0YPQudGC0LUh?= <foo <at> goo.ru>"
          t)

gets a "(void-function rfc2047-decode-string)" error.  The patch below
includes a possible fix plus a new test file (with the code above as a
regression test).

					-- Bob Rogers
					   http://www.rgrjr.com/

From 82e26ef8edd40815347b2f1b5311ab07046cd6f7 Mon Sep 17 00:00:00 2001
From: Bob Rogers <rogers <at> rgrjr.com>
Date: Fri, 4 Feb 2022 22:08:07 -0500
Subject: [PATCH] Add ietf-drums tests, fix parse-address decoding

* test/lisp/mail/ietf-drums-tests.el (ietf-drums-tests):  Test most of
     lisp/mail/ietf-drums.el functionality.
* lisp/mail/ietf-drums.el:
   + (ietf-drums-parse-address):  Bug fix:  Require rfc2047 when needed.
---
 lisp/mail/ietf-drums.el            |   2 +
 test/lisp/mail/ietf-drums-tests.el | 162 +++++++++++++++++++++++++++++
 2 files changed, 164 insertions(+)
 create mode 100644 test/lisp/mail/ietf-drums-tests.el

diff --git a/lisp/mail/ietf-drums.el b/lisp/mail/ietf-drums.el
index fd9cb6abb7..473f95ca50 100644
--- a/lisp/mail/ietf-drums.el
+++ b/lisp/mail/ietf-drums.el
@@ -191,6 +191,8 @@ ietf-drums-parse-address
   "Parse STRING and return a MAILBOX / DISPLAY-NAME pair.
 If DECODE, the DISPLAY-NAME will have RFC2047 decoding performed
 (that's the \"=?utf...q...=?\") stuff."
+  (when decode
+    (require 'rfc2047))
   (with-temp-buffer
     (let (display-name mailbox c display-string)
       (ietf-drums-init string)
diff --git a/test/lisp/mail/ietf-drums-tests.el b/test/lisp/mail/ietf-drums-tests.el
new file mode 100644
index 0000000000..4cc38b8763
--- /dev/null
+++ b/test/lisp/mail/ietf-drums-tests.el
@@ -0,0 +1,162 @@
+;;; ietf-drums-tests.el --- Test suite for ietf-drums.el  -*- lexical-binding:t -*-
+
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; Author: Bob Rogers <rogers <at> rgrjr.com>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'ert)
+(require 'ietf-drums)
+
+(ert-deftest ietf-drums-tests ()
+  "Test ietf-drums functionality."
+
+  ;; ietf-drums-remove-comments
+  (should (equal (ietf-drums-remove-comments "random string") "random string"))
+  (should (equal (ietf-drums-remove-comments "random \"non comment\" string")
+                 "random \"non comment\" string"))
+  (should (equal (ietf-drums-remove-comments "random (comment) string")
+                 "random  string"))
+  (should (equal (ietf-drums-remove-comments "random (comment) (string)")
+                 "random  "))
+  (should (equal (ietf-drums-remove-comments
+                  "random (first) (second (and)) (third) not fourth")
+                 "random    not fourth"))
+
+  ;; ietf-drums-remove-whitespace
+  (should (equal (ietf-drums-remove-whitespace "random string")
+                 "randomstring"))
+  (should (equal (ietf-drums-remove-whitespace "random (comment) string")
+                 "random(comment)string"))
+  (should (equal (ietf-drums-remove-whitespace "random \"non comment\" string")
+                 "random\"non comment\"string"))
+  (should (equal (ietf-drums-remove-whitespace "random (comment)\r\n(string)")
+                 "random(comment)(string)"))
+  (should (equal (ietf-drums-remove-whitespace
+                  "random (first) (second (and)) (third) not fourth")
+                 "random(first)(second (and))(third)notfourth"))
+
+  ;; ietf-drums-strip
+  (should (equal (ietf-drums-strip "random string") "randomstring"))
+  (should (equal (ietf-drums-strip "random \"non comment\" string")
+                 "random\"non comment\"string"))
+  (should (equal (ietf-drums-strip "random (comment) string")
+                 "randomstring"))
+  (should (equal (ietf-drums-strip "random (comment) (string)")
+                 "random"))
+  (should (equal (ietf-drums-strip
+                  "random (first) (second (and)) (third) not fourth")
+                 "randomnotfourth"))
+
+  ;; ietf-drums-strip-cte
+  (should (equal (ietf-drums-strip-cte "random \"non comment\" string")
+                 ;; [the " " is still in there because it was quoted
+                 ;; through the "strip".  -- rgr, 5-Feb-22.]
+                 "randomnon commentstring"))
+  (should (equal (ietf-drums-strip-cte "ran(d)do<m@>[s;t:r],,in=g")
+                 "randomstring"))
+
+  ;; ietf-drums-quote-string
+  (should (equal (ietf-drums-quote-string "Bob") "Bob"))
+  (should (equal (ietf-drums-quote-string "Foo Bar") "\"Foo Bar\""))
+
+  ;; ietf-drums-get-comment
+  (should (equal (ietf-drums-get-comment "random string") nil))
+  (should (equal (ietf-drums-get-comment "random (comment) string") "comment"))
+  (should (equal (ietf-drums-get-comment "random \"non comment\" string") nil))
+  (should (equal (ietf-drums-get-comment "\"still (non) comment\" string")
+                 nil))
+  (should (equal (ietf-drums-get-comment "random (comment)\r\nstring")
+                 "comment"))
+  (should (equal (ietf-drums-get-comment "random (comment) (string)") "string"))
+  (should (equal (ietf-drums-get-comment
+                  "random (first) (second (and)) (third) not fourth")
+                 "third"))
+
+  ;; ietf-drums-make-address
+  (should (equal (ietf-drums-make-address "Bob Rogers" "rogers <at> rgrjr.com")
+                 "\"Bob Rogers\" <rogers <at> rgrjr.com>"))
+  (should (equal (ietf-drums-make-address nil "rogers <at> rgrjr.com")
+                 "rogers <at> rgrjr.com"))
+
+  ;; ietf-drums-parse-address
+  (should (equal (ietf-drums-parse-address "foo <at> example.com")
+                 '("foo <at> example.com")))
+  (should (equal (ietf-drums-parse-address "<foo <at> example.com>")
+                 '("foo <at> example.com")))
+  (should (equal (ietf-drums-parse-address "'foo' <foo <at> example.com>")
+                 '("foo <at> example.com" . "'foo'")))
+  (should (equal (ietf-drums-parse-address "foo <foo <at> example.com>")
+                 '("foo <at> example.com" . "foo")))
+  (should (equal (ietf-drums-parse-address "foo <foo <at> example.com> bar")
+                 ;; [contrary to RFC2822, which wants the display-name
+                 ;; before the address.  -- rgr, 5-Feb-22.]
+                 '("foo <at> example.com" . "foo bar")))
+  (should (equal (ietf-drums-parse-address " <foo <at> example.com> foo ")
+                 ;; [ditto.  -- rgr, 5-Feb-22.]
+                 '("foo <at> example.com" . "foo")))
+  (should (equal (ietf-drums-parse-address "foo <at> example.com (foo)")
+                 '("foo <at> example.com" . "foo")))
+  (should (equal (ietf-drums-parse-address "Bar Baz <barbaz <at> example.com>")
+                 '("barbaz <at> example.com" . "Bar Baz")))
+  (should (equal (ietf-drums-parse-address "barbaz <at> example.com (Bar Baz)")
+                 '("barbaz <at> example.com" . "Bar Baz")))
+  (should (equal (ietf-drums-parse-address
+                  "Bar Baz (ignored) <barbaz <at> example.com>")
+                 '("barbaz <at> example.com" . "Bar Baz")))
+  (should (equal (ietf-drums-parse-address "<barbaz <at> example.com> Bar Baz")
+                 '("barbaz <at> example.com" . "Bar Baz")))
+  (should (equal (ietf-drums-parse-address
+                  "(Bar Baz not ignored) barbaz <at> example.com")
+                 ;; [not strictly RFC2822, which expects the name
+                 ;; comment after the address.  -- rgr, 5-Feb-22.]
+                 '("barbaz <at> example.com" . "Bar Baz not ignored")))
+  (should (equal (ietf-drums-parse-address
+                  "(ignored) <barbaz <at> example.com> (Bar Baz not ignored)")
+                 '("barbaz <at> example.com" . "Bar Baz not ignored")))
+  (should (equal (ietf-drums-parse-address
+                  "(ignored) barbaz <at> example.com (Bar Baz not ignored)")
+                 '("barbaz <at> example.com" . "Bar Baz not ignored")))
+  ;; Test for RFC2047 token decoding.
+  (should (equal (ietf-drums-parse-address
+                  "=?utf-8?B?0JfQtNGA0LDMgdCy0YHRgtCy0YPQudGC0LUh?= <foo <at> goo.ru>"
+                  t)
+                 '("foo <at> goo.ru" . "Здра́вствуйте!")))
+
+  ;; ietf-drums-parse-addresses
+  ;; Note that it's not worth getting too elaborate here, as the heavy
+  ;; lifting is all done by ietf-drums-parse-address.
+  (should (equal (ietf-drums-parse-addresses "foo <at> example.com")
+                 '(("foo <at> example.com"))))
+  (should (equal (ietf-drums-parse-addresses
+                  "foo <at> example.com, bar <at> example.com")
+                 '(("foo <at> example.com") ("bar <at> example.com"))))
+  (should (equal (ietf-drums-parse-addresses
+                  "foo <at> example.com, quux, bar <at> example.com")
+                 '(("foo <at> example.com") ("bar <at> example.com"))))
+  (should (equal (ietf-drums-parse-addresses
+                  "foo <at> example.com, Quux Dude <quux <at> noop.org>, bar <at> example.com")
+                 '(("foo <at> example.com") ("quux <at> noop.org" . "Quux Dude")
+                   ("bar <at> example.com")))))
+
+(provide 'ietf-drums-tests)
+
+;;; ietf-drums-tests.el ends here
-- 
2.34.1





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#53811; Package emacs. (Sun, 06 Feb 2022 03:09:01 GMT) Full text and rfc822 format available.

Message #8 received at 53811 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Bob Rogers <rogers <at> rgrjr.com>
Cc: 53811 <at> debbugs.gnu.org
Subject: Re: bug#53811: 29.0.50; [PATCH] ietf-drums-parse-address and
 rfc2047-decode-string
Date: Sun, 06 Feb 2022 04:08:29 +0100
Bob Rogers <rogers <at> rgrjr.com> writes:

> gets a "(void-function rfc2047-decode-string)" error.  The patch below
> includes a possible fix plus a new test file (with the code above as a
> regression test).

Thanks; pushed to Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 29.1, send any further explanations to 53811 <at> debbugs.gnu.org and Bob Rogers <rogers <at> rgrjr.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 06 Feb 2022 03:09:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#53811; Package emacs. (Sun, 06 Feb 2022 04:55:02 GMT) Full text and rfc822 format available.

Message #13 received at 53811 <at> debbugs.gnu.org (full text, mbox):

From: Bob Rogers <rogers-emacs <at> rgrjr.homedns.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 53811 <at> debbugs.gnu.org
Subject: Re: bug#53811: 29.0.50; [PATCH] ietf-drums-parse-address and
 rfc2047-decode-string
Date: Sat, 5 Feb 2022 23:54:50 -0500
   From: Lars Ingebrigtsen <larsi <at> gnus.org>
   Date: Sun, 06 Feb 2022 04:08:29 +0100

   Bob Rogers <rogers <at> rgrjr.com> writes:

   > gets a "(void-function rfc2047-decode-string)" error.  The patch below
   > includes a possible fix plus a new test file (with the code above as a
   > regression test).

   Thanks; pushed to Emacs 29.

Oops; I should also have included an update to ietf-drums.el that
removes the comment implying that said "self test suite" is still
unwritten.

					-- Bob

------------------------------------------------------------------------
From f38700c63f1e3603b59d2a1cca0f4fd10971d28a Mon Sep 17 00:00:00 2001
From: Bob Rogers <rogers <at> rgrjr.com>
Date: Sat, 5 Feb 2022 23:50:46 -0500
Subject: [PATCH] ; * lisp/mail/ietf-drums.el:  This code is now tested.

---
 lisp/mail/ietf-drums.el | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/lisp/mail/ietf-drums.el b/lisp/mail/ietf-drums.el
index 473f95ca50..db77aba172 100644
--- a/lisp/mail/ietf-drums.el
+++ b/lisp/mail/ietf-drums.el
@@ -25,16 +25,6 @@
 ;; library is based on draft-ietf-drums-msg-fmt-05.txt, released on
 ;; 1998-08-05.
 
-;; Pending a real regression self test suite, Simon Josefsson added
-;; various self test expressions snipped from bug reports, and their
-;; expected value, below.  I you believe it could be useful, please
-;; add your own test cases, or write a real self test suite, or just
-;; remove this.
-
-;; <m3oekvfd50.fsf <at> whitebox.m5r.de>
-;; (ietf-drums-parse-address "'foo' <foo <at> example.com>")
-;; => ("foo <at> example.com" . "'foo'")
-
 ;;; Code:
 
 (eval-when-compile (require 'cl-lib))
-- 
2.34.1





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#53811; Package emacs. (Sun, 06 Feb 2022 23:10:02 GMT) Full text and rfc822 format available.

Message #16 received at 53811 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Bob Rogers <rogers-emacs <at> rgrjr.homedns.org>
Cc: 53811 <at> debbugs.gnu.org
Subject: Re: bug#53811: 29.0.50; [PATCH] ietf-drums-parse-address and
 rfc2047-decode-string
Date: Mon, 07 Feb 2022 00:08:48 +0100
Bob Rogers <rogers-emacs <at> rgrjr.homedns.org> writes:

> Oops; I should also have included an update to ietf-drums.el that
> removes the comment implying that said "self test suite" is still
> unwritten.

Thanks; pushed to Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 07 Mar 2022 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 107 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.