summaryrefslogtreecommitdiff
path: root/test/lisp/mail/mail-utils-tests.el
blob: 5b54f2440c7ddd57d0795e34568332c5c8874469 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
;;; mail-utils-tests.el --- tests for mail-utils.el  -*- lexical-binding: t -*-

;; Copyright (C) 2021 Free Software Foundation, Inc.

;; Author: Stefan Kangas <stefankangas@gmail.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 'sasl)
(require 'mail-utils)

(ert-deftest mail-utils-tests-mail-quote-printable ()
  (should (equal (mail-quote-printable "abc") "abc"))
  (should (equal (mail-quote-printable "åäö") "=E5=E4=F6"))
  (should (equal (mail-quote-printable "åäö" t) "=?ISO-8859-1?Q?=E5=E4=F6?=")))

(ert-deftest mail-utils-tests-mail-quote-printable-region ()
  (with-temp-buffer
    (insert "?=\"\"")
    (mail-quote-printable-region (point-min) (point-max))
    (should (equal (buffer-string) "=3F=3D=22=22")))
  (with-temp-buffer
    (insert "x")
    (mail-quote-printable-region (point-min) (point-max) t)
    (should (equal (buffer-string) "=?=?ISO-8859-1?Q?x"))))

(ert-deftest mail-utils-tests-mail-unquote-printable ()
  (should (equal (mail-unquote-printable "=E5=E4=F6") "åäö"))
  (should (equal (mail-unquote-printable "=?ISO-8859-1?Q?=E5=E4=F6?=" t) "åäö")))

(ert-deftest mail-utils-tests-mail-unquote-printable-region ()
  (with-temp-buffer
    (insert "=E5=E4=F6")
    (mail-unquote-printable-region (point-min) (point-max))
    (should (equal (buffer-string) "åäö")))
  (with-temp-buffer
    (insert "=?ISO-8859-1?Q?=E5=E4=F6?=")
    (mail-unquote-printable-region (point-min) (point-max) t)
    (should (equal (buffer-string) "åäö"))))

(ert-deftest mail-utils-tests-mail-strip-quoted-names ()
  (should (equal (mail-strip-quoted-names
                  "\"foo\" <foo@example.org>, bar@example.org")
                 "foo@example.org, bar@example.org")))

(ert-deftest mail-utils-tests-mail-dont-reply-to ()
  (let ((mail-dont-reply-to-names "foo@example.org"))
    (should (equal (mail-dont-reply-to "foo@example.org, bar@example.org")
                   "bar@example.org"))))


(ert-deftest mail-utils-tests-mail-fetch-field ()
  (with-temp-buffer
    (insert "Foo: bar\nBaz: zut")
    (should (equal (mail-fetch-field "Foo") "bar"))))

(ert-deftest mail-utils-tests-mail-parse-comma-list ()
  (with-temp-buffer
    (insert "foo@example.org,bar@example.org,baz@example.org")
    (goto-char (point-min))
    (should (equal (mail-parse-comma-list)
                   '("baz@example.org" "bar@example.org" "foo@example.org")))))

(ert-deftest mail-utils-tests-mail-comma-list-regexp ()
  (should (equal (mail-comma-list-regexp
                  "foo@example.org,bar@example.org,baz@example.org")
                 "foo@example.org\\|bar@example.org\\|baz@example.org")))

(ert-deftest mail-utils-tests-mail-rfc822-time-zone ()
  (should (stringp (mail-rfc822-time-zone (current-time)))))

(ert-deftest mail-utils-test-mail-rfc822-date/contains-year ()
  (should (string-match (rx " 20" digit digit " ")
                        (mail-rfc822-date))))

(ert-deftest mail-utils-test-mail-mbox-from ()
  (with-temp-buffer
    (insert "Subject: Hello
From: jrh@example.org
To: emacs-devel@gnu.org
Date: Sun, 07 Feb 2021 22:46:37 -0500")
    (should (equal (mail-mbox-from)
                   "From jrh@example.org Sun Feb  7 22:46:37 2021\n"))))

(provide 'mail-utils-tests)
;;; mail-utils-tests.el ends here