From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bob Rogers Newsgroups: gmane.emacs.bugs Subject: bug#53811: 29.0.50; [PATCH] ietf-drums-parse-address and rfc2047-decode-string Date: Sat, 05 Feb 2022 21:20:30 -0500 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36286"; mail-complaints-to="usenet@ciao.gmane.io" To: 53811@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 06 03:21:32 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1nGXBE-0009EZ-IT for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 06 Feb 2022 03:21:32 +0100 Original-Received: from localhost ([::1]:33368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGXBD-0000z8-Ja for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Feb 2022 21:21:31 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:58810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGXAk-0000xX-DH for bug-gnu-emacs@gnu.org; Sat, 05 Feb 2022 21:21:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42163) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGXAj-0008Dv-VN for bug-gnu-emacs@gnu.org; Sat, 05 Feb 2022 21:21:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nGXAj-0001cB-S9 for bug-gnu-emacs@gnu.org; Sat, 05 Feb 2022 21:21:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Bob Rogers Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 06 Feb 2022 02:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 53811 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16441140426158 (code B ref -1); Sun, 06 Feb 2022 02:21:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Feb 2022 02:20:42 +0000 Original-Received: from localhost ([127.0.0.1]:36060 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nGXAQ-0001bF-4D for submit@debbugs.gnu.org; Sat, 05 Feb 2022 21:20:42 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:35468) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nGXAO-0001b8-Mo for submit@debbugs.gnu.org; Sat, 05 Feb 2022 21:20:41 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:58780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGXAJ-0000x3-P9 for bug-gnu-emacs@gnu.org; Sat, 05 Feb 2022 21:20:38 -0500 Original-Received: from rgrjr.com ([69.164.211.47]:55660) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGXAF-0008Bk-Nx for bug-gnu-emacs@gnu.org; Sat, 05 Feb 2022 21:20:34 -0500 Original-Received: from rgrjr.com (c-73-16-206-7.hsd1.ma.comcast.net [73.16.206.7]) by rgrjr.com (Postfix on openSUSE) with ESMTP id 665461D6BAE for ; Sun, 6 Feb 2022 02:20:41 +0000 (UTC) Original-Received: from orion.rgrjr.com (orion.rgrjr.com [192.168.0.3]) by scorpio.rgrjr.com (Postfix on openSUSE GNU/Linux) with ESMTP id D90585FEC6; Sat, 5 Feb 2022 21:20:30 -0500 (EST) Received-SPF: none client-ip=69.164.211.47; envelope-from=rogers@rgrjr.com; helo=rgrjr.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:226125 Archived-At: In GNU Emacs 29.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, c= airo 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 "=3D?utf-8?B?0JfQtNGA0LDMgdCy0YHRgtCy0YPQudGC0LUh?=3D " 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 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 \"=3D?utf...q...=3D?\") 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-bind= ing:t -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; Author: Bob Rogers + +;; 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 . + +;;; 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 stri= ng")) + (should (equal (ietf-drums-remove-comments "random \"non comment\" strin= g") + "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\" str= ing") + "random\"non comment\"string")) + (should (equal (ietf-drums-remove-whitespace "random (comment)\r\n(strin= g)") + "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[s;t:r],,in=3Dg") + "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") "comme= nt")) + (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)") "str= ing")) + (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@rgrjr.com") + "\"Bob Rogers\" ")) + (should (equal (ietf-drums-make-address nil "rogers@rgrjr.com") + "rogers@rgrjr.com")) + + ;; ietf-drums-parse-address + (should (equal (ietf-drums-parse-address "foo@example.com") + '("foo@example.com"))) + (should (equal (ietf-drums-parse-address "") + '("foo@example.com"))) + (should (equal (ietf-drums-parse-address "'foo' ") + '("foo@example.com" . "'foo'"))) + (should (equal (ietf-drums-parse-address "foo ") + '("foo@example.com" . "foo"))) + (should (equal (ietf-drums-parse-address "foo bar") + ;; [contrary to RFC2822, which wants the display-name + ;; before the address. -- rgr, 5-Feb-22.] + '("foo@example.com" . "foo bar"))) + (should (equal (ietf-drums-parse-address " foo ") + ;; [ditto. -- rgr, 5-Feb-22.] + '("foo@example.com" . "foo"))) + (should (equal (ietf-drums-parse-address "foo@example.com (foo)") + '("foo@example.com" . "foo"))) + (should (equal (ietf-drums-parse-address "Bar Baz ") + '("barbaz@example.com" . "Bar Baz"))) + (should (equal (ietf-drums-parse-address "barbaz@example.com (Bar Baz)") + '("barbaz@example.com" . "Bar Baz"))) + (should (equal (ietf-drums-parse-address + "Bar Baz (ignored) ") + '("barbaz@example.com" . "Bar Baz"))) + (should (equal (ietf-drums-parse-address " Bar Baz") + '("barbaz@example.com" . "Bar Baz"))) + (should (equal (ietf-drums-parse-address + "(Bar Baz not ignored) barbaz@example.com") + ;; [not strictly RFC2822, which expects the name + ;; comment after the address. -- rgr, 5-Feb-22.] + '("barbaz@example.com" . "Bar Baz not ignored"))) + (should (equal (ietf-drums-parse-address + "(ignored) (Bar Baz not ignored)") + '("barbaz@example.com" . "Bar Baz not ignored"))) + (should (equal (ietf-drums-parse-address + "(ignored) barbaz@example.com (Bar Baz not ignored)") + '("barbaz@example.com" . "Bar Baz not ignored"))) + ;; Test for RFC2047 token decoding. + (should (equal (ietf-drums-parse-address + "=3D?utf-8?B?0JfQtNGA0LDMgdCy0YHRgtCy0YPQudGC0LUh?=3D " + t) + '("foo@goo.ru" . "=D0=97=D0=B4=D1=80=D0=B0=CC=81=D0=B2=D1= =81=D1=82=D0=B2=D1=83=D0=B9=D1=82=D0=B5!"))) + + ;; 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@example.com") + '(("foo@example.com")))) + (should (equal (ietf-drums-parse-addresses + "foo@example.com, bar@example.com") + '(("foo@example.com") ("bar@example.com")))) + (should (equal (ietf-drums-parse-addresses + "foo@example.com, quux, bar@example.com") + '(("foo@example.com") ("bar@example.com")))) + (should (equal (ietf-drums-parse-addresses + "foo@example.com, Quux Dude , bar@example= .com") + '(("foo@example.com") ("quux@noop.org" . "Quux Dude") + ("bar@example.com"))))) + +(provide 'ietf-drums-tests) + +;;; ietf-drums-tests.el ends here --=20 2.34.1