aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Rogers2022-02-06 04:07:51 +0100
committerLars Ingebrigtsen2022-02-06 04:08:18 +0100
commita3ee390cf7787abde7e6b625f2cd32bad3d29e90 (patch)
tree40ba2e3e041fe87565e067a0156892eede0cef95
parent50e51beabb2420ba3f844742352a98c7987c4932 (diff)
downloademacs-a3ee390cf7787abde7e6b625f2cd32bad3d29e90.tar.gz
emacs-a3ee390cf7787abde7e6b625f2cd32bad3d29e90.zip
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 (bug#53811).
-rw-r--r--lisp/mail/ietf-drums.el2
-rw-r--r--test/lisp/mail/ietf-drums-tests.el162
2 files changed, 164 insertions, 0 deletions
diff --git a/lisp/mail/ietf-drums.el b/lisp/mail/ietf-drums.el
index 952707226f5..9bdc0533e34 100644
--- a/lisp/mail/ietf-drums.el
+++ b/lisp/mail/ietf-drums.el
@@ -191,6 +191,8 @@ the Content-Transfer-Encoding header of a mail."
191 "Parse STRING and return a MAILBOX / DISPLAY-NAME pair. 191 "Parse STRING and return a MAILBOX / DISPLAY-NAME pair.
192If DECODE, the DISPLAY-NAME will have RFC2047 decoding performed 192If DECODE, the DISPLAY-NAME will have RFC2047 decoding performed
193(that's the \"=?utf...q...=?\") stuff." 193(that's the \"=?utf...q...=?\") stuff."
194 (when decode
195 (require 'rfc2047))
194 (with-temp-buffer 196 (with-temp-buffer
195 (let (display-name mailbox c display-string) 197 (let (display-name mailbox c display-string)
196 (ietf-drums-init string) 198 (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 00000000000..4cc38b8763a
--- /dev/null
+++ b/test/lisp/mail/ietf-drums-tests.el
@@ -0,0 +1,162 @@
1;;; ietf-drums-tests.el --- Test suite for ietf-drums.el -*- lexical-binding:t -*-
2
3;; Copyright (C) 2022 Free Software Foundation, Inc.
4
5;; Author: Bob Rogers <rogers@rgrjr.com>
6
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software: you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
21
22;;; Commentary:
23
24;;; Code:
25
26(require 'ert)
27(require 'ietf-drums)
28
29(ert-deftest ietf-drums-tests ()
30 "Test ietf-drums functionality."
31
32 ;; ietf-drums-remove-comments
33 (should (equal (ietf-drums-remove-comments "random string") "random string"))
34 (should (equal (ietf-drums-remove-comments "random \"non comment\" string")
35 "random \"non comment\" string"))
36 (should (equal (ietf-drums-remove-comments "random (comment) string")
37 "random string"))
38 (should (equal (ietf-drums-remove-comments "random (comment) (string)")
39 "random "))
40 (should (equal (ietf-drums-remove-comments
41 "random (first) (second (and)) (third) not fourth")
42 "random not fourth"))
43
44 ;; ietf-drums-remove-whitespace
45 (should (equal (ietf-drums-remove-whitespace "random string")
46 "randomstring"))
47 (should (equal (ietf-drums-remove-whitespace "random (comment) string")
48 "random(comment)string"))
49 (should (equal (ietf-drums-remove-whitespace "random \"non comment\" string")
50 "random\"non comment\"string"))
51 (should (equal (ietf-drums-remove-whitespace "random (comment)\r\n(string)")
52 "random(comment)(string)"))
53 (should (equal (ietf-drums-remove-whitespace
54 "random (first) (second (and)) (third) not fourth")
55 "random(first)(second (and))(third)notfourth"))
56
57 ;; ietf-drums-strip
58 (should (equal (ietf-drums-strip "random string") "randomstring"))
59 (should (equal (ietf-drums-strip "random \"non comment\" string")
60 "random\"non comment\"string"))
61 (should (equal (ietf-drums-strip "random (comment) string")
62 "randomstring"))
63 (should (equal (ietf-drums-strip "random (comment) (string)")
64 "random"))
65 (should (equal (ietf-drums-strip
66 "random (first) (second (and)) (third) not fourth")
67 "randomnotfourth"))
68
69 ;; ietf-drums-strip-cte
70 (should (equal (ietf-drums-strip-cte "random \"non comment\" string")
71 ;; [the " " is still in there because it was quoted
72 ;; through the "strip". -- rgr, 5-Feb-22.]
73 "randomnon commentstring"))
74 (should (equal (ietf-drums-strip-cte "ran(d)do<m@>[s;t:r],,in=g")
75 "randomstring"))
76
77 ;; ietf-drums-quote-string
78 (should (equal (ietf-drums-quote-string "Bob") "Bob"))
79 (should (equal (ietf-drums-quote-string "Foo Bar") "\"Foo Bar\""))
80
81 ;; ietf-drums-get-comment
82 (should (equal (ietf-drums-get-comment "random string") nil))
83 (should (equal (ietf-drums-get-comment "random (comment) string") "comment"))
84 (should (equal (ietf-drums-get-comment "random \"non comment\" string") nil))
85 (should (equal (ietf-drums-get-comment "\"still (non) comment\" string")
86 nil))
87 (should (equal (ietf-drums-get-comment "random (comment)\r\nstring")
88 "comment"))
89 (should (equal (ietf-drums-get-comment "random (comment) (string)") "string"))
90 (should (equal (ietf-drums-get-comment
91 "random (first) (second (and)) (third) not fourth")
92 "third"))
93
94 ;; ietf-drums-make-address
95 (should (equal (ietf-drums-make-address "Bob Rogers" "rogers@rgrjr.com")
96 "\"Bob Rogers\" <rogers@rgrjr.com>"))
97 (should (equal (ietf-drums-make-address nil "rogers@rgrjr.com")
98 "rogers@rgrjr.com"))
99
100 ;; ietf-drums-parse-address
101 (should (equal (ietf-drums-parse-address "foo@example.com")
102 '("foo@example.com")))
103 (should (equal (ietf-drums-parse-address "<foo@example.com>")
104 '("foo@example.com")))
105 (should (equal (ietf-drums-parse-address "'foo' <foo@example.com>")
106 '("foo@example.com" . "'foo'")))
107 (should (equal (ietf-drums-parse-address "foo <foo@example.com>")
108 '("foo@example.com" . "foo")))
109 (should (equal (ietf-drums-parse-address "foo <foo@example.com> bar")
110 ;; [contrary to RFC2822, which wants the display-name
111 ;; before the address. -- rgr, 5-Feb-22.]
112 '("foo@example.com" . "foo bar")))
113 (should (equal (ietf-drums-parse-address " <foo@example.com> foo ")
114 ;; [ditto. -- rgr, 5-Feb-22.]
115 '("foo@example.com" . "foo")))
116 (should (equal (ietf-drums-parse-address "foo@example.com (foo)")
117 '("foo@example.com" . "foo")))
118 (should (equal (ietf-drums-parse-address "Bar Baz <barbaz@example.com>")
119 '("barbaz@example.com" . "Bar Baz")))
120 (should (equal (ietf-drums-parse-address "barbaz@example.com (Bar Baz)")
121 '("barbaz@example.com" . "Bar Baz")))
122 (should (equal (ietf-drums-parse-address
123 "Bar Baz (ignored) <barbaz@example.com>")
124 '("barbaz@example.com" . "Bar Baz")))
125 (should (equal (ietf-drums-parse-address "<barbaz@example.com> Bar Baz")
126 '("barbaz@example.com" . "Bar Baz")))
127 (should (equal (ietf-drums-parse-address
128 "(Bar Baz not ignored) barbaz@example.com")
129 ;; [not strictly RFC2822, which expects the name
130 ;; comment after the address. -- rgr, 5-Feb-22.]
131 '("barbaz@example.com" . "Bar Baz not ignored")))
132 (should (equal (ietf-drums-parse-address
133 "(ignored) <barbaz@example.com> (Bar Baz not ignored)")
134 '("barbaz@example.com" . "Bar Baz not ignored")))
135 (should (equal (ietf-drums-parse-address
136 "(ignored) barbaz@example.com (Bar Baz not ignored)")
137 '("barbaz@example.com" . "Bar Baz not ignored")))
138 ;; Test for RFC2047 token decoding.
139 (should (equal (ietf-drums-parse-address
140 "=?utf-8?B?0JfQtNGA0LDMgdCy0YHRgtCy0YPQudGC0LUh?= <foo@goo.ru>"
141 t)
142 '("foo@goo.ru" . "Здра́вствуйте!")))
143
144 ;; ietf-drums-parse-addresses
145 ;; Note that it's not worth getting too elaborate here, as the heavy
146 ;; lifting is all done by ietf-drums-parse-address.
147 (should (equal (ietf-drums-parse-addresses "foo@example.com")
148 '(("foo@example.com"))))
149 (should (equal (ietf-drums-parse-addresses
150 "foo@example.com, bar@example.com")
151 '(("foo@example.com") ("bar@example.com"))))
152 (should (equal (ietf-drums-parse-addresses
153 "foo@example.com, quux, bar@example.com")
154 '(("foo@example.com") ("bar@example.com"))))
155 (should (equal (ietf-drums-parse-addresses
156 "foo@example.com, Quux Dude <quux@noop.org>, bar@example.com")
157 '(("foo@example.com") ("quux@noop.org" . "Quux Dude")
158 ("bar@example.com")))))
159
160(provide 'ietf-drums-tests)
161
162;;; ietf-drums-tests.el ends here