about summary refs log tree commit diff
path: root/third_party/lisp/mime4cl/test/address.lisp
blob: a3653985c40eed36d3791b5ae7b57bb009b7f27e (plain) (blame)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
;;;  address.lisp --- tests for the e-mail address parser

;;;  Copyright (C) 2007, 2009 by Walter C. Pelissero
;;;  Copyright (C) 2022 by The TVL Authors

;;;  Author: Walter C. Pelissero <walter@pelissero.de>
;;;  Project: mime4cl

;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public License
;;; as published by the Free Software Foundation; either version 2.1
;;; of the License, or (at your option) any later version.
;;; This library 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
;;; Lesser General Public License for more details.
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with this library; if not, write to the Free
;;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
;;; 02111-1307 USA

(in-package :mime4cl-tests)

(defun test-parsing (string)
  (format nil "~{~A~^, ~}" (parse-addresses string)))

(deftest address-parse-simple.1
    (test-parsing "foo@bar")
  "foo@bar")

(deftest address-parse-simple.2
    (test-parsing "foo@bar.com")
  "foo@bar.com")

(deftest address-parse-simple.3
    (test-parsing "foo@bar.baz.com")
  "foo@bar.baz.com")

(deftest address-parse-simple.4
    (test-parsing "foo.ooo@bar.baz.com")
  "foo.ooo@bar.baz.com")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftest address-parse-simple-commented.1
    (test-parsing "foo@bar (Some Comment)")
  "\"Some Comment\" <foo@bar>")

(deftest address-parse-simple-commented.2
    (test-parsing "foo@bar (Some, Comment)")
  "\"Some, Comment\" <foo@bar>")

(deftest address-parse-simple-commented.3
    (test-parsing "foo@bar (Some Comment (yes, indeed))")
  "\"Some Comment (yes, indeed)\" <foo@bar>")

(deftest address-parse-simple-commented.4
    (test-parsing "foo.bar@host.complicated.domain.net (Some Comment (yes, indeed))")
  "\"Some Comment (yes, indeed)\" <foo.bar@host.complicated.domain.net>")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftest address-parse-angle.1
    (test-parsing "<foo@bar.baz.net>")
  "foo@bar.baz.net")

(deftest address-parse-angle.2
    (test-parsing "My far far friend <foo@bar.baz.net>")
  "\"My far far friend\" <foo@bar.baz.net>")

(deftest address-parse-angle.3
    (test-parsing "\"someone, I don't like\" <foo@bar.baz.net>")
  "\"someone, I don't like\" <foo@bar.baz.net>")

(deftest address-parse-angle.4
    (test-parsing "\"this could (be a comment)\" <foo@bar.net>")
  "\"this could (be a comment)\" <foo@bar.net>")

(deftest address-parse-angle.5
    (test-parsing "don't be fooled <foo@bar.net>")
  "\"don't be fooled\" <foo@bar.net>")

(deftest address-parse-angle.6
    (test-parsing "<foo@bar>")
  "foo@bar")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftest address-parse-domain-literal.1
    (test-parsing "<foo@[bar]>")
  "foo@[bar]")

(deftest address-parse-domain-literal.2
    (test-parsing "<foo@[bar.net]>")
  "foo@[bar.net]")

(deftest address-parse-domain-literal.3
    (test-parsing "<foo@[10.0.0.2]>")
  "foo@[10.0.0.2]")

(deftest address-parse-domain-literal.4
    (test-parsing "<foo.bar@[10.0.0.2]>")
  "foo.bar@[10.0.0.2]")

(deftest address-parse-domain-literal.5
    (test-parsing "somewhere unkown <foo.bar@[10.0.0.2]>")
  "\"somewhere unkown\" <foo.bar@[10.0.0.2]>")

(deftest address-parse-domain-literal.6
    (test-parsing "\"Some--One\" <foo.bar@[10.0.0.23]>")
  "\"Some--One\" <foo.bar@[10.0.0.23]>")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftest address-parse-group.1
    (test-parsing "friends:john@bar.in.soho, jack@pub.round.the.corner, jim@[10.0.1.2];")
  "friends: john@bar.in.soho, jack@pub.round.the.corner, jim@[10.0.1.2];")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftest address-parse-mixed.1
    (test-parsing "Foo BAR <foo@bar.com>, \"John, Smith (that one!)\" <john.smith@host.domain.org>, friends:john@bar,jack@pub;, foo.bar.baz@wow.mail.mine, dont.bark@me (Fierce Dog)")
  "\"Foo BAR\" <foo@bar.com>, \"John, Smith (that one!)\" <john.smith@host.domain.org>, friends: john@bar, jack@pub;, foo.bar.baz@wow.mail.mine, \"Fierce Dog\" <dont.bark@me>")