Dusan Kasan | c2129de | 2017-04-13 10:42:21 +0200 | [diff] [blame] | 1 | package parsemail |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 2 | |
| 3 | import ( |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 4 | "encoding/base64" |
Obi Symons | 333687f | 2020-04-05 14:31:35 +1000 | [diff] [blame] | 5 | "fmt" |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 6 | "io/ioutil" |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 7 | "net/mail" |
| 8 | "strings" |
| 9 | "testing" |
| 10 | "time" |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | func TestParseEmail(t *testing.T) { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 14 | var testData = map[int]struct { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 15 | mailData string |
| 16 | |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 17 | contentType string |
| 18 | content string |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 19 | subject string |
| 20 | date time.Time |
| 21 | from []mail.Address |
| 22 | sender mail.Address |
| 23 | to []mail.Address |
| 24 | replyTo []mail.Address |
| 25 | cc []mail.Address |
| 26 | bcc []mail.Address |
| 27 | messageID string |
| 28 | resentDate time.Time |
| 29 | resentFrom []mail.Address |
| 30 | resentSender mail.Address |
| 31 | resentTo []mail.Address |
| 32 | resentReplyTo []mail.Address |
| 33 | resentCc []mail.Address |
| 34 | resentBcc []mail.Address |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 35 | resentMessageID string |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 36 | inReplyTo []string |
| 37 | references []string |
| 38 | htmlBody string |
| 39 | textBody string |
| 40 | attachments []attachmentData |
| 41 | embeddedFiles []embeddedFileData |
| 42 | headerCheck func(mail.Header, *testing.T) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 43 | }{ |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 44 | 1: { |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 45 | mailData: rfc5322exampleA11, |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 46 | subject: "Saying Hello", |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 47 | from: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 48 | { |
| 49 | Name: "John Doe", |
| 50 | Address: "jdoe@machine.example", |
| 51 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 52 | }, |
| 53 | to: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 54 | { |
| 55 | Name: "Mary Smith", |
| 56 | Address: "mary@example.net", |
| 57 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 58 | }, |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 59 | sender: mail.Address{ |
| 60 | Name: "Michael Jones", |
| 61 | Address: "mjones@machine.example", |
| 62 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 63 | messageID: "1234@local.machine.example", |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 64 | date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"), |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 65 | textBody: `This is a message just to say hello. |
| 66 | So, "Hello".`, |
| 67 | }, |
| 68 | 2: { |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 69 | mailData: rfc5322exampleA12, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 70 | from: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 71 | { |
| 72 | Name: "Joe Q. Public", |
| 73 | Address: "john.q.public@example.com", |
| 74 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 75 | }, |
| 76 | to: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 77 | { |
| 78 | Name: "Mary Smith", |
| 79 | Address: "mary@x.test", |
| 80 | }, |
| 81 | { |
| 82 | Name: "", |
| 83 | Address: "jdoe@example.org", |
| 84 | }, |
| 85 | { |
| 86 | Name: "Who?", |
| 87 | Address: "one@y.test", |
| 88 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 89 | }, |
| 90 | cc: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 91 | { |
| 92 | Name: "", |
| 93 | Address: "boss@nil.test", |
| 94 | }, |
| 95 | { |
| 96 | Name: "Giant; \"Big\" Box", |
| 97 | Address: "sysservices@example.net", |
| 98 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 99 | }, |
| 100 | messageID: "5678.21-Nov-1997@example.com", |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 101 | date: parseDate("Tue, 01 Jul 2003 10:52:37 +0200"), |
| 102 | textBody: `Hi everyone.`, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 103 | }, |
| 104 | 3: { |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 105 | mailData: rfc5322exampleA2a, |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 106 | subject: "Re: Saying Hello", |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 107 | from: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 108 | { |
| 109 | Name: "Mary Smith", |
| 110 | Address: "mary@example.net", |
| 111 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 112 | }, |
| 113 | replyTo: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 114 | { |
| 115 | Name: "Mary Smith: Personal Account", |
| 116 | Address: "smith@home.example", |
| 117 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 118 | }, |
| 119 | to: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 120 | { |
| 121 | Name: "John Doe", |
| 122 | Address: "jdoe@machine.example", |
| 123 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 124 | }, |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 125 | messageID: "3456@example.net", |
| 126 | inReplyTo: []string{"1234@local.machine.example"}, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 127 | references: []string{"1234@local.machine.example"}, |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 128 | date: parseDate("Fri, 21 Nov 1997 10:01:10 -0600"), |
| 129 | textBody: `This is a reply to your hello.`, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 130 | }, |
| 131 | 4: { |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 132 | mailData: rfc5322exampleA2b, |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 133 | subject: "Re: Saying Hello", |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 134 | from: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 135 | { |
| 136 | Name: "John Doe", |
| 137 | Address: "jdoe@machine.example", |
| 138 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 139 | }, |
| 140 | to: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 141 | { |
| 142 | Name: "Mary Smith: Personal Account", |
| 143 | Address: "smith@home.example", |
| 144 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 145 | }, |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 146 | messageID: "abcd.1234@local.machine.test", |
| 147 | inReplyTo: []string{"3456@example.net"}, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 148 | references: []string{"1234@local.machine.example", "3456@example.net"}, |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 149 | date: parseDate("Fri, 21 Nov 1997 11:00:00 -0600"), |
| 150 | textBody: `This is a reply to your reply.`, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 151 | }, |
| 152 | 5: { |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 153 | mailData: rfc5322exampleA3, |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 154 | subject: "Saying Hello", |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 155 | from: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 156 | { |
| 157 | Name: "John Doe", |
| 158 | Address: "jdoe@machine.example", |
| 159 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 160 | }, |
| 161 | to: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 162 | { |
| 163 | Name: "Mary Smith", |
| 164 | Address: "mary@example.net", |
| 165 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 166 | }, |
| 167 | messageID: "1234@local.machine.example", |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 168 | date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"), |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 169 | resentFrom: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 170 | { |
| 171 | Name: "Mary Smith", |
| 172 | Address: "mary@example.net", |
| 173 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 174 | }, |
| 175 | resentTo: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 176 | { |
| 177 | Name: "Jane Brown", |
| 178 | Address: "j-brown@other.example", |
| 179 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 180 | }, |
| 181 | resentMessageID: "78910@example.net", |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 182 | resentDate: parseDate("Mon, 24 Nov 1997 14:22:01 -0800"), |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 183 | textBody: `This is a message just to say hello. |
| 184 | So, "Hello".`, |
| 185 | }, |
| 186 | 6: { |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 187 | mailData: data1, |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 188 | contentType: `multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf`, |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 189 | content: "", |
| 190 | subject: "Peter Paholík", |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 191 | from: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 192 | { |
| 193 | Name: "Peter Paholík", |
| 194 | Address: "peter.paholik@gmail.com", |
| 195 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 196 | }, |
| 197 | to: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 198 | { |
| 199 | Name: "", |
| 200 | Address: "dusan@kasan.sk", |
| 201 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 202 | }, |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 203 | messageID: "CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com", |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 204 | date: parseDate("Fri, 07 Apr 2017 09:17:26 +0200"), |
| 205 | htmlBody: "<div dir=\"ltr\"><br></div>", |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 206 | attachments: []attachmentData{ |
| 207 | { |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 208 | filename: "Peter Paholík 1 4 2017 2017-04-07.json", |
| 209 | contentType: "application/json", |
| 210 | data: "[1, 2, 3]", |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 211 | }, |
| 212 | }, |
| 213 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 214 | 7: { |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 215 | mailData: data2, |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 216 | contentType: `multipart/alternative; boundary="------------C70C0458A558E585ACB75FB4"`, |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 217 | content: "", |
| 218 | subject: "Re: Test Subject 2", |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 219 | from: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 220 | { |
| 221 | Name: "Sender Man", |
| 222 | Address: "sender@domain.com", |
| 223 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 224 | }, |
| 225 | to: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 226 | { |
| 227 | Name: "", |
| 228 | Address: "info@receiver.com", |
| 229 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 230 | }, |
| 231 | cc: []mail.Address{ |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 232 | { |
| 233 | Name: "Cc Man", |
| 234 | Address: "ccman@gmail.com", |
| 235 | }, |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 236 | }, |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 237 | messageID: "0e9a21b4-01dc-e5c1-dcd6-58ce5aa61f4f@receiver.com", |
| 238 | inReplyTo: []string{"9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@receiver.eu"}, |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 239 | references: []string{"2f6b7595-c01e-46e5-42bc-f263e1c4282d@receiver.com", "9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@domain.com"}, |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 240 | date: parseDate("Fri, 07 Apr 2017 12:59:55 +0200"), |
| 241 | htmlBody: `<html>data<img src="part2.9599C449.04E5EC81@develhell.com"/></html>`, |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 242 | textBody: `First level |
| 243 | > Second level |
| 244 | >> Third level |
| 245 | > |
| 246 | `, |
| 247 | embeddedFiles: []embeddedFileData{ |
| 248 | { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 249 | cid: "part2.9599C449.04E5EC81@develhell.com", |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 250 | contentType: "image/png", |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 251 | base64data: "iVBORw0KGgoAAAANSUhEUgAAAQEAAAAYCAIAAAB1IN9NAAAACXBIWXMAAAsTAAALEwEAmpwYYKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg==", |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 252 | }, |
| 253 | }, |
| 254 | }, |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 255 | 8: { |
| 256 | mailData: imageContentExample, |
| 257 | subject: "Saying Hello", |
| 258 | from: []mail.Address{ |
| 259 | { |
| 260 | Name: "John Doe", |
| 261 | Address: "jdoe@machine.example", |
| 262 | }, |
| 263 | }, |
| 264 | to: []mail.Address{ |
| 265 | { |
| 266 | Name: "Mary Smith", |
| 267 | Address: "mary@example.net", |
| 268 | }, |
| 269 | }, |
| 270 | sender: mail.Address{ |
| 271 | Name: "Michael Jones", |
| 272 | Address: "mjones@machine.example", |
| 273 | }, |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 274 | messageID: "1234@local.machine.example", |
| 275 | date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"), |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 276 | contentType: `image/jpeg; x-unix-mode=0644; name="image.gif"`, |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 277 | content: `GIF89a;`, |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 278 | }, |
Dusan Kasan | e97c2f2 | 2020-04-04 10:50:00 +0200 | [diff] [blame] | 279 | 9: { |
| 280 | contentType: `multipart/mixed; boundary="0000000000007e2bb40587e36196"`, |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 281 | mailData: textPlainInMultipart, |
| 282 | subject: "Re: kern/54143 (virtualbox)", |
Maya Rashish | bae116e | 2019-06-10 12:15:25 +0300 | [diff] [blame] | 283 | from: []mail.Address{ |
| 284 | { |
| 285 | Name: "Rares", |
| 286 | Address: "rares@example.com", |
| 287 | }, |
| 288 | }, |
| 289 | to: []mail.Address{ |
| 290 | { |
| 291 | Name: "", |
| 292 | Address: "bugs@example.com", |
| 293 | }, |
| 294 | }, |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 295 | date: parseDate("Fri, 02 May 2019 11:25:35 +0300"), |
Maya Rashish | bae116e | 2019-06-10 12:15:25 +0300 | [diff] [blame] | 296 | textBody: `plain text part`, |
| 297 | }, |
Dusan Kasan | 88226cf | 2020-04-04 11:13:06 +0200 | [diff] [blame] | 298 | 10: { |
k-yomo | 2e670d9 | 2020-04-30 22:42:48 +0900 | [diff] [blame] | 299 | contentType: `multipart/mixed; boundary="0000000000007e2bb40587e36196"`, |
| 300 | mailData: textHTMLInMultipart, |
| 301 | subject: "Re: kern/54143 (virtualbox)", |
| 302 | from: []mail.Address{ |
| 303 | { |
| 304 | Name: "Rares", |
| 305 | Address: "rares@example.com", |
| 306 | }, |
| 307 | }, |
| 308 | to: []mail.Address{ |
| 309 | { |
| 310 | Name: "", |
| 311 | Address: "bugs@example.com", |
| 312 | }, |
| 313 | }, |
| 314 | date: parseDate("Fri, 02 May 2019 11:25:35 +0300"), |
| 315 | textBody: ``, |
| 316 | htmlBody: "<div dir=\"ltr\"><div>html text part</div><div><br></div><div><br><br></div></div>", |
| 317 | }, |
| 318 | 11: { |
Dusan Kasan | 88226cf | 2020-04-04 11:13:06 +0200 | [diff] [blame] | 319 | mailData: rfc5322exampleA12WithTimezone, |
| 320 | from: []mail.Address{ |
| 321 | { |
| 322 | Name: "Joe Q. Public", |
| 323 | Address: "john.q.public@example.com", |
| 324 | }, |
| 325 | }, |
| 326 | to: []mail.Address{ |
| 327 | { |
| 328 | Name: "Mary Smith", |
| 329 | Address: "mary@x.test", |
| 330 | }, |
| 331 | { |
| 332 | Name: "", |
| 333 | Address: "jdoe@example.org", |
| 334 | }, |
| 335 | { |
| 336 | Name: "Who?", |
| 337 | Address: "one@y.test", |
| 338 | }, |
| 339 | }, |
| 340 | cc: []mail.Address{ |
| 341 | { |
| 342 | Name: "", |
| 343 | Address: "boss@nil.test", |
| 344 | }, |
| 345 | { |
| 346 | Name: "Giant; \"Big\" Box", |
| 347 | Address: "sysservices@example.net", |
| 348 | }, |
| 349 | }, |
| 350 | messageID: "5678.21-Nov-1997@example.com", |
| 351 | date: parseDate("Tue, 01 Jul 2003 10:52:37 +0200"), |
| 352 | textBody: `Hi everyone.`, |
| 353 | }, |
k-yomo | 2e670d9 | 2020-04-30 22:42:48 +0900 | [diff] [blame] | 354 | 12: { |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 355 | contentType: "multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf", |
| 356 | mailData: attachment7bit, |
| 357 | subject: "Peter Foobar", |
Edwin Love | f8d8da2 | 2019-04-02 14:07:32 +0100 | [diff] [blame] | 358 | from: []mail.Address{ |
| 359 | { |
| 360 | Name: "Peter Foobar", |
| 361 | Address: "peter.foobar@gmail.com", |
| 362 | }, |
| 363 | }, |
| 364 | to: []mail.Address{ |
| 365 | { |
| 366 | Name: "", |
| 367 | Address: "dusan@kasan.sk", |
| 368 | }, |
| 369 | }, |
| 370 | messageID: "CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com", |
| 371 | date: parseDate("Tue, 02 Apr 2019 11:12:26 +0000"), |
| 372 | htmlBody: "<div dir=\"ltr\"><br></div>", |
| 373 | attachments: []attachmentData{ |
| 374 | { |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 375 | filename: "unencoded.csv", |
| 376 | contentType: "application/csv", |
| 377 | data: fmt.Sprintf("\n"+`"%s", "%s", "%s", "%s", "%s"`+"\n"+`"%s", "%s", "%s", "%s", "%s"`+"\n", "Some", "Data", "In", "Csv", "Format", "Foo", "Bar", "Baz", "Bum", "Poo"), |
Edwin Love | f8d8da2 | 2019-04-02 14:07:32 +0100 | [diff] [blame] | 378 | }, |
| 379 | }, |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 380 | }, |
k-yomo | 2e670d9 | 2020-04-30 22:42:48 +0900 | [diff] [blame] | 381 | 13: { |
Dusan Kasan | 1ce83dc | 2020-04-07 00:53:14 +0200 | [diff] [blame] | 382 | contentType: "multipart/related; boundary=\"000000000000ab2e2205a26de587\"", |
| 383 | mailData: multipartRelatedExample, |
| 384 | subject: "Saying Hello", |
| 385 | from: []mail.Address{ |
| 386 | { |
| 387 | Name: "John Doe", |
| 388 | Address: "jdoe@machine.example", |
| 389 | }, |
| 390 | }, |
| 391 | sender: mail.Address{ |
| 392 | Name: "Michael Jones", |
| 393 | Address: "mjones@machine.example", |
| 394 | }, |
| 395 | to: []mail.Address{ |
| 396 | { |
| 397 | Name: "Mary Smith", |
| 398 | Address: "mary@example.net", |
| 399 | }, |
| 400 | }, |
| 401 | messageID: "1234@local.machine.example", |
| 402 | date: parseDate("Fri, 21 Nov 1997 09:55:06 -0600"), |
| 403 | htmlBody: "<div dir=\"ltr\"><div>Time for the egg.</div><div><br></div><div><br><br></div></div>", |
| 404 | textBody: "Time for the egg.", |
| 405 | }, |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 406 | } |
| 407 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 408 | for index, td := range testData { |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 409 | e, err := Parse(strings.NewReader(td.mailData)) |
Antonio | 331b118 | 2019-01-15 09:58:52 +0100 | [diff] [blame] | 410 | if err != nil { |
| 411 | t.Error(err) |
| 412 | } |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 413 | |
| 414 | if td.contentType != e.ContentType { |
| 415 | t.Errorf("[Test Case %v] Wrong content type. Expected: %s, Got: %s", index, td.contentType, e.ContentType) |
| 416 | } |
| 417 | |
| 418 | if td.content != "" { |
| 419 | b, err := ioutil.ReadAll(e.Content) |
| 420 | if err != nil { |
| 421 | t.Error(err) |
| 422 | } else if td.content != string(b) { |
| 423 | t.Errorf("[Test Case %v] Wrong content. Expected: %s, Got: %s", index, td.content, string(b)) |
| 424 | } |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 425 | } |
| 426 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 427 | if td.subject != e.Subject { |
| 428 | t.Errorf("[Test Case %v] Wrong subject. Expected: %s, Got: %s", index, td.subject, e.Subject) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 429 | } |
| 430 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 431 | if td.messageID != e.MessageID { |
| 432 | t.Errorf("[Test Case %v] Wrong messageID. Expected: '%s', Got: '%s'", index, td.messageID, e.MessageID) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 433 | } |
| 434 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 435 | if !td.date.Equal(e.Date) { |
| 436 | t.Errorf("[Test Case %v] Wrong date. Expected: %v, Got: %v", index, td.date, e.Date) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 437 | } |
| 438 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 439 | d := dereferenceAddressList(e.From) |
| 440 | if !assertAddressListEq(td.from, d) { |
| 441 | t.Errorf("[Test Case %v] Wrong from. Expected: %s, Got: %s", index, td.from, d) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 442 | } |
| 443 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 444 | var sender mail.Address |
| 445 | if e.Sender != nil { |
| 446 | sender = *e.Sender |
| 447 | } |
| 448 | if td.sender != sender { |
| 449 | t.Errorf("[Test Case %v] Wrong sender. Expected: %s, Got: %s", index, td.sender, sender) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 450 | } |
| 451 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 452 | d = dereferenceAddressList(e.To) |
| 453 | if !assertAddressListEq(td.to, d) { |
| 454 | t.Errorf("[Test Case %v] Wrong to. Expected: %s, Got: %s", index, td.to, d) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 455 | } |
| 456 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 457 | d = dereferenceAddressList(e.Cc) |
| 458 | if !assertAddressListEq(td.cc, d) { |
| 459 | t.Errorf("[Test Case %v] Wrong cc. Expected: %s, Got: %s", index, td.cc, d) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 460 | } |
| 461 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 462 | d = dereferenceAddressList(e.Bcc) |
| 463 | if !assertAddressListEq(td.bcc, d) { |
| 464 | t.Errorf("[Test Case %v] Wrong bcc. Expected: %s, Got: %s", index, td.bcc, d) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 465 | } |
| 466 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 467 | if td.resentMessageID != e.ResentMessageID { |
| 468 | t.Errorf("[Test Case %v] Wrong resent messageID. Expected: '%s', Got: '%s'", index, td.resentMessageID, e.ResentMessageID) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 469 | } |
| 470 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 471 | if !td.resentDate.Equal(e.ResentDate) && !td.resentDate.IsZero() && !e.ResentDate.IsZero() { |
| 472 | t.Errorf("[Test Case %v] Wrong resent date. Expected: %v, Got: %v", index, td.resentDate, e.ResentDate) |
| 473 | } |
| 474 | |
| 475 | d = dereferenceAddressList(e.ResentFrom) |
| 476 | if !assertAddressListEq(td.resentFrom, d) { |
| 477 | t.Errorf("[Test Case %v] Wrong resent from. Expected: %s, Got: %s", index, td.resentFrom, d) |
| 478 | } |
| 479 | |
| 480 | var resentSender mail.Address |
| 481 | if e.ResentSender != nil { |
| 482 | resentSender = *e.ResentSender |
| 483 | } |
| 484 | if td.resentSender != resentSender { |
| 485 | t.Errorf("[Test Case %v] Wrong resent sender. Expected: %s, Got: %s", index, td.resentSender, resentSender) |
| 486 | } |
| 487 | |
| 488 | d = dereferenceAddressList(e.ResentTo) |
| 489 | if !assertAddressListEq(td.resentTo, d) { |
| 490 | t.Errorf("[Test Case %v] Wrong resent to. Expected: %s, Got: %s", index, td.resentTo, d) |
| 491 | } |
| 492 | |
| 493 | d = dereferenceAddressList(e.ResentCc) |
| 494 | if !assertAddressListEq(td.resentCc, d) { |
| 495 | t.Errorf("[Test Case %v] Wrong resent cc. Expected: %s, Got: %s", index, td.resentCc, d) |
| 496 | } |
| 497 | |
| 498 | d = dereferenceAddressList(e.ResentBcc) |
| 499 | if !assertAddressListEq(td.resentBcc, d) { |
| 500 | t.Errorf("[Test Case %v] Wrong resent bcc. Expected: %s, Got: %s", index, td.resentBcc, d) |
| 501 | } |
| 502 | |
| 503 | if !assertSliceEq(td.inReplyTo, e.InReplyTo) { |
| 504 | t.Errorf("[Test Case %v] Wrong in reply to. Expected: %s, Got: %s", index, td.inReplyTo, e.InReplyTo) |
| 505 | } |
| 506 | |
| 507 | if !assertSliceEq(td.references, e.References) { |
| 508 | t.Errorf("[Test Case %v] Wrong references. Expected: %s, Got: %s", index, td.references, e.References) |
| 509 | } |
| 510 | |
| 511 | d = dereferenceAddressList(e.ReplyTo) |
| 512 | if !assertAddressListEq(td.replyTo, d) { |
| 513 | t.Errorf("[Test Case %v] Wrong reply to. Expected: %s, Got: %s", index, td.replyTo, d) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | if td.htmlBody != e.HTMLBody { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 517 | t.Errorf("[Test Case %v] Wrong html body. Expected: '%s', Got: '%s'", index, td.htmlBody, e.HTMLBody) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | if td.textBody != e.TextBody { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 521 | t.Errorf("[Test Case %v] Wrong text body. Expected: '%s', Got: '%s'", index, td.textBody, e.TextBody) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 524 | if len(td.attachments) != len(e.Attachments) { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 525 | t.Errorf("[Test Case %v] Incorrect number of attachments! Expected: %v, Got: %v.", index, len(td.attachments), len(e.Attachments)) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 526 | } else { |
| 527 | attachs := e.Attachments[:] |
| 528 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 529 | for _, ad := range td.attachments { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 530 | found := false |
| 531 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 532 | for i, ra := range attachs { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 533 | b, err := ioutil.ReadAll(ra.Data) |
| 534 | if err != nil { |
| 535 | t.Error(err) |
| 536 | } |
| 537 | |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 538 | if ra.Filename == ad.filename && string(b) == ad.data && ra.ContentType == ad.contentType { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 539 | found = true |
| 540 | attachs = append(attachs[:i], attachs[i+1:]...) |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | if !found { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 545 | t.Errorf("[Test Case %v] Attachment not found: %s", index, ad.filename) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | |
| 549 | if len(attachs) != 0 { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 550 | t.Errorf("[Test Case %v] Email contains %v unexpected attachments: %v", index, len(attachs), attachs) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
| 554 | if len(td.embeddedFiles) != len(e.EmbeddedFiles) { |
Dusan Kasan | 1a96648 | 2017-04-18 10:45:25 +0200 | [diff] [blame] | 555 | t.Errorf("[Test Case %v] Incorrect number of embedded files! Expected: %v, Got: %v.", index, len(td.embeddedFiles), len(e.EmbeddedFiles)) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 556 | } else { |
| 557 | embeds := e.EmbeddedFiles[:] |
| 558 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 559 | for _, ad := range td.embeddedFiles { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 560 | found := false |
| 561 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 562 | for i, ra := range embeds { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 563 | b, err := ioutil.ReadAll(ra.Data) |
| 564 | if err != nil { |
| 565 | t.Error(err) |
| 566 | } |
| 567 | |
| 568 | encoded := base64.StdEncoding.EncodeToString(b) |
| 569 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 570 | if ra.CID == ad.cid && encoded == ad.base64data && ra.ContentType == ad.contentType { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 571 | found = true |
| 572 | embeds = append(embeds[:i], embeds[i+1:]...) |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | if !found { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 577 | t.Errorf("[Test Case %v] Embedded file not found: %s", index, ad.cid) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
| 581 | if len(embeds) != 0 { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 582 | t.Errorf("[Test Case %v] Email contains %v unexpected embedded files: %v", index, len(embeds), embeds) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | func parseDate(in string) time.Time { |
| 589 | out, err := time.Parse(time.RFC1123Z, in) |
| 590 | if err != nil { |
| 591 | panic(err) |
| 592 | } |
| 593 | |
| 594 | return out |
| 595 | } |
| 596 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 597 | type attachmentData struct { |
Edwin Love | f8d8da2 | 2019-04-02 14:07:32 +0100 | [diff] [blame] | 598 | filename string |
| 599 | contentType string |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 600 | data string |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 601 | } |
| 602 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 603 | type embeddedFileData struct { |
| 604 | cid string |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 605 | contentType string |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 606 | base64data string |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | func assertSliceEq(a, b []string) bool { |
| 610 | if len(a) == len(b) && len(a) == 0 { |
| 611 | return true |
| 612 | } |
| 613 | |
| 614 | if a == nil && b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 615 | return true |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | if a == nil || b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 619 | return false |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | if len(a) != len(b) { |
| 623 | return false |
| 624 | } |
| 625 | |
| 626 | for i := range a { |
| 627 | if a[i] != b[i] { |
| 628 | return false |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | return true |
| 633 | } |
| 634 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 635 | func assertAddressListEq(a, b []mail.Address) bool { |
| 636 | if len(a) == len(b) && len(a) == 0 { |
| 637 | return true |
| 638 | } |
| 639 | |
| 640 | if a == nil && b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 641 | return true |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | if a == nil || b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 645 | return false |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | if len(a) != len(b) { |
| 649 | return false |
| 650 | } |
| 651 | |
| 652 | for i := range a { |
| 653 | if a[i] != b[i] { |
| 654 | return false |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | return true |
| 659 | } |
| 660 | |
| 661 | func dereferenceAddressList(al []*mail.Address) (result []mail.Address) { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 662 | for _, a := range al { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 663 | result = append(result, *a) |
| 664 | } |
| 665 | |
| 666 | return |
| 667 | } |
| 668 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 669 | var data1 = `From: =?UTF-8?Q?Peter_Pahol=C3=ADk?= <peter.paholik@gmail.com> |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 670 | Date: Fri, 7 Apr 2017 09:17:26 +0200 |
| 671 | Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com> |
Dusan Kasan | f4376a6 | 2017-05-23 21:03:55 +0200 | [diff] [blame] | 672 | Subject: =?UTF-8?Q?Peter_Pahol=C3=ADk?= |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 673 | To: dusan@kasan.sk |
| 674 | Content-Type: multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf |
| 675 | |
| 676 | --f403045f1dcc043a44054c8e6bbf |
| 677 | Content-Type: multipart/alternative; boundary=f403045f1dcc043a3f054c8e6bbd |
| 678 | |
| 679 | --f403045f1dcc043a3f054c8e6bbd |
| 680 | Content-Type: text/plain; charset=UTF-8 |
| 681 | |
| 682 | |
| 683 | |
| 684 | --f403045f1dcc043a3f054c8e6bbd |
| 685 | Content-Type: text/html; charset=UTF-8 |
| 686 | |
| 687 | <div dir="ltr"><br></div> |
| 688 | |
| 689 | --f403045f1dcc043a3f054c8e6bbd-- |
| 690 | --f403045f1dcc043a44054c8e6bbf |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 691 | Content-Type: application/json; |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 692 | name="=?UTF-8?Q?Peter_Paholi=CC=81k_1?= |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 693 | =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Ejson?=" |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 694 | Content-Disposition: attachment; |
| 695 | filename="=?UTF-8?Q?Peter_Paholi=CC=81k_1?= |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 696 | =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Ejson?=" |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 697 | Content-Transfer-Encoding: base64 |
| 698 | X-Attachment-Id: f_j17i0f0d0 |
| 699 | |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 700 | WzEsIDIsIDNd |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 701 | --f403045f1dcc043a44054c8e6bbf-- |
| 702 | ` |
| 703 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 704 | var data2 = `Subject: Re: Test Subject 2 |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 705 | To: info@receiver.com |
| 706 | References: <2f6b7595-c01e-46e5-42bc-f263e1c4282d@receiver.com> |
| 707 | <9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@domain.com> |
| 708 | Cc: Cc Man <ccman@gmail.com> |
| 709 | From: Sender Man <sender@domain.com> |
| 710 | Message-ID: <0e9a21b4-01dc-e5c1-dcd6-58ce5aa61f4f@receiver.com> |
| 711 | Date: Fri, 7 Apr 2017 12:59:55 +0200 |
| 712 | User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) |
| 713 | Gecko/20100101 Thunderbird/45.8.0 |
| 714 | MIME-Version: 1.0 |
| 715 | In-Reply-To: <9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@receiver.eu> |
| 716 | Content-Type: multipart/alternative; |
| 717 | boundary="------------C70C0458A558E585ACB75FB4" |
| 718 | |
| 719 | This is a multi-part message in MIME format. |
| 720 | --------------C70C0458A558E585ACB75FB4 |
| 721 | Content-Type: text/plain; charset=utf-8; format=flowed |
| 722 | Content-Transfer-Encoding: 8bit |
| 723 | |
| 724 | First level |
| 725 | > Second level |
| 726 | >> Third level |
| 727 | > |
| 728 | |
| 729 | |
| 730 | --------------C70C0458A558E585ACB75FB4 |
| 731 | Content-Type: multipart/related; |
| 732 | boundary="------------5DB4A1356834BB602A5F88B2" |
| 733 | |
| 734 | |
| 735 | --------------5DB4A1356834BB602A5F88B2 |
| 736 | Content-Type: text/html; charset=utf-8 |
| 737 | Content-Transfer-Encoding: 8bit |
| 738 | |
| 739 | <html>data<img src="part2.9599C449.04E5EC81@develhell.com"/></html> |
| 740 | |
| 741 | --------------5DB4A1356834BB602A5F88B2 |
| 742 | Content-Type: image/png |
| 743 | Content-Transfer-Encoding: base64 |
| 744 | Content-ID: <part2.9599C449.04E5EC81@develhell.com> |
| 745 | |
| 746 | iVBORw0KGgoAAAANSUhEUgAAAQEAAAAYCAIAAAB1IN9NAAAACXBIWXMAAAsTAAALEwEAmpwY |
| 747 | YKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg== |
| 748 | --------------5DB4A1356834BB602A5F88B2 |
| 749 | |
| 750 | --------------C70C0458A558E585ACB75FB4-- |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 751 | ` |
| 752 | |
Dusan Kasan | e97c2f2 | 2020-04-04 10:50:00 +0200 | [diff] [blame] | 753 | var textPlainInMultipart = `From: Rares <rares@example.com> |
Maya Rashish | bae116e | 2019-06-10 12:15:25 +0300 | [diff] [blame] | 754 | Date: Thu, 2 May 2019 11:25:35 +0300 |
| 755 | Subject: Re: kern/54143 (virtualbox) |
| 756 | To: bugs@example.com |
| 757 | Content-Type: multipart/mixed; boundary="0000000000007e2bb40587e36196" |
| 758 | |
| 759 | --0000000000007e2bb40587e36196 |
| 760 | Content-Type: text/plain; charset="UTF-8" |
| 761 | |
| 762 | plain text part |
| 763 | --0000000000007e2bb40587e36196-- |
| 764 | ` |
| 765 | |
k-yomo | 2e670d9 | 2020-04-30 22:42:48 +0900 | [diff] [blame] | 766 | var textHTMLInMultipart = `From: Rares <rares@example.com> |
| 767 | Date: Thu, 2 May 2019 11:25:35 +0300 |
| 768 | Subject: Re: kern/54143 (virtualbox) |
| 769 | To: bugs@example.com |
| 770 | Content-Type: multipart/mixed; boundary="0000000000007e2bb40587e36196" |
| 771 | |
| 772 | --0000000000007e2bb40587e36196 |
| 773 | Content-Type: text/html; charset="UTF-8" |
| 774 | |
| 775 | <div dir="ltr"><div>html text part</div><div><br></div><div><br><br></div></div> |
| 776 | |
| 777 | --0000000000007e2bb40587e36196-- |
| 778 | ` |
| 779 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 780 | var rfc5322exampleA11 = `From: John Doe <jdoe@machine.example> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 781 | Sender: Michael Jones <mjones@machine.example> |
| 782 | To: Mary Smith <mary@example.net> |
| 783 | Subject: Saying Hello |
| 784 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 785 | Message-ID: <1234@local.machine.example> |
| 786 | |
| 787 | This is a message just to say hello. |
| 788 | So, "Hello". |
| 789 | ` |
| 790 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 791 | var rfc5322exampleA12 = `From: "Joe Q. Public" <john.q.public@example.com> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 792 | To: Mary Smith <mary@x.test>, jdoe@example.org, Who? <one@y.test> |
| 793 | Cc: <boss@nil.test>, "Giant; \"Big\" Box" <sysservices@example.net> |
| 794 | Date: Tue, 1 Jul 2003 10:52:37 +0200 |
| 795 | Message-ID: <5678.21-Nov-1997@example.com> |
| 796 | |
| 797 | Hi everyone. |
| 798 | ` |
| 799 | |
Dusan Kasan | 88226cf | 2020-04-04 11:13:06 +0200 | [diff] [blame] | 800 | var rfc5322exampleA12WithTimezone = `From: "Joe Q. Public" <john.q.public@example.com> |
| 801 | To: Mary Smith <mary@x.test>, jdoe@example.org, Who? <one@y.test> |
| 802 | Cc: <boss@nil.test>, "Giant; \"Big\" Box" <sysservices@example.net> |
Edwin Love | 33953e5 | 2019-04-02 15:29:22 +0100 | [diff] [blame] | 803 | Date: Tue, 1 Jul 2003 10:52:37 +0200 (GMT) |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 804 | Message-ID: <5678.21-Nov-1997@example.com> |
| 805 | |
| 806 | Hi everyone. |
| 807 | ` |
| 808 | |
| 809 | //todo: not yet implemented in net/mail |
| 810 | //once there is support for this, add it |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 811 | var rfc5322exampleA13 = `From: Pete <pete@silly.example> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 812 | To: A Group:Ed Jones <c@a.test>,joe@where.test,John <jdoe@one.test>; |
| 813 | Cc: Undisclosed recipients:; |
| 814 | Date: Thu, 13 Feb 1969 23:32:54 -0330 |
| 815 | Message-ID: <testabcd.1234@silly.example> |
| 816 | |
| 817 | Testing. |
| 818 | ` |
| 819 | |
| 820 | //we skipped the first message bcause it's the same as A 1.1 |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 821 | var rfc5322exampleA2a = `From: Mary Smith <mary@example.net> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 822 | To: John Doe <jdoe@machine.example> |
| 823 | Reply-To: "Mary Smith: Personal Account" <smith@home.example> |
| 824 | Subject: Re: Saying Hello |
| 825 | Date: Fri, 21 Nov 1997 10:01:10 -0600 |
| 826 | Message-ID: <3456@example.net> |
| 827 | In-Reply-To: <1234@local.machine.example> |
| 828 | References: <1234@local.machine.example> |
| 829 | |
| 830 | This is a reply to your hello. |
| 831 | ` |
| 832 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 833 | var rfc5322exampleA2b = `To: "Mary Smith: Personal Account" <smith@home.example> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 834 | From: John Doe <jdoe@machine.example> |
| 835 | Subject: Re: Saying Hello |
| 836 | Date: Fri, 21 Nov 1997 11:00:00 -0600 |
| 837 | Message-ID: <abcd.1234@local.machine.test> |
| 838 | In-Reply-To: <3456@example.net> |
| 839 | References: <1234@local.machine.example> <3456@example.net> |
| 840 | |
| 841 | This is a reply to your reply. |
| 842 | ` |
| 843 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 844 | var rfc5322exampleA3 = `Resent-From: Mary Smith <mary@example.net> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 845 | Resent-To: Jane Brown <j-brown@other.example> |
| 846 | Resent-Date: Mon, 24 Nov 1997 14:22:01 -0800 |
| 847 | Resent-Message-ID: <78910@example.net> |
| 848 | From: John Doe <jdoe@machine.example> |
| 849 | To: Mary Smith <mary@example.net> |
| 850 | Subject: Saying Hello |
| 851 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 852 | Message-ID: <1234@local.machine.example> |
| 853 | |
| 854 | This is a message just to say hello. |
| 855 | So, "Hello".` |
| 856 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 857 | var rfc5322exampleA4 = `Received: from x.y.test |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 858 | by example.net |
| 859 | via TCP |
| 860 | with ESMTP |
| 861 | id ABC12345 |
| 862 | for <mary@example.net>; 21 Nov 1997 10:05:43 -0600 |
| 863 | Received: from node.example by x.y.test; 21 Nov 1997 10:01:22 -0600 |
| 864 | From: John Doe <jdoe@node.example> |
| 865 | To: Mary Smith <mary@example.net> |
| 866 | Subject: Saying Hello |
| 867 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 868 | Message-ID: <1234@local.node.example> |
| 869 | |
| 870 | This is a message just to say hello. |
| 871 | So, "Hello".` |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 872 | |
| 873 | var imageContentExample = `From: John Doe <jdoe@machine.example> |
| 874 | Sender: Michael Jones <mjones@machine.example> |
| 875 | To: Mary Smith <mary@example.net> |
| 876 | Subject: Saying Hello |
| 877 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 878 | Message-ID: <1234@local.machine.example> |
| 879 | Content-Type: image/jpeg; |
| 880 | x-unix-mode=0644; |
| 881 | name="image.gif" |
| 882 | Content-Transfer-Encoding: base64 |
| 883 | |
| 884 | R0lGODlhAQE7` |
Obi Symons | 333687f | 2020-04-05 14:31:35 +1000 | [diff] [blame] | 885 | |
| 886 | var multipartRelatedExample = `MIME-Version: 1.0 |
| 887 | From: John Doe <jdoe@machine.example> |
| 888 | Sender: Michael Jones <mjones@machine.example> |
| 889 | To: Mary Smith <mary@example.net> |
| 890 | Subject: Saying Hello |
| 891 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 892 | Message-ID: <1234@local.machine.example> |
| 893 | Subject: ooops |
| 894 | To: test@example.rocks |
| 895 | Content-Type: multipart/related; boundary="000000000000ab2e2205a26de587" |
| 896 | |
| 897 | --000000000000ab2e2205a26de587 |
| 898 | Content-Type: multipart/alternative; boundary="000000000000ab2e1f05a26de586" |
| 899 | |
| 900 | --000000000000ab2e1f05a26de586 |
| 901 | Content-Type: text/plain; charset="UTF-8" |
| 902 | |
| 903 | Time for the egg. |
| 904 | |
| 905 | --000000000000ab2e1f05a26de586 |
| 906 | Content-Type: text/html; charset="UTF-8" |
| 907 | |
| 908 | <div dir="ltr"><div>Time for the egg.</div><div><br></div><div><br><br></div></div> |
| 909 | |
| 910 | --000000000000ab2e1f05a26de586-- |
| 911 | |
| 912 | |
| 913 | --000000000000ab2e2205a26de587-- |
Obi Symons | 5bf5e01 | 2020-04-05 14:36:29 +1000 | [diff] [blame] | 914 | ` |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 915 | var attachment7bit = `From: =?UTF-8?Q?Peter_Foobar?= <peter.foobar@gmail.com> |
| 916 | Date: Tue, 2 Apr 2019 11:12:26 +0000 |
| 917 | Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com> |
| 918 | Subject: =?UTF-8?Q?Peter_Foobar?= |
| 919 | To: dusan@kasan.sk |
| 920 | Content-Type: multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf |
| 921 | |
| 922 | --f403045f1dcc043a44054c8e6bbf |
| 923 | Content-Type: multipart/alternative; boundary=f403045f1dcc043a3f054c8e6bbd |
| 924 | |
| 925 | --f403045f1dcc043a3f054c8e6bbd |
| 926 | Content-Type: text/plain; charset=UTF-8 |
| 927 | |
| 928 | |
| 929 | |
| 930 | --f403045f1dcc043a3f054c8e6bbd |
| 931 | Content-Type: text/html; charset=UTF-8 |
| 932 | |
| 933 | <div dir="ltr"><br></div> |
| 934 | |
| 935 | --f403045f1dcc043a3f054c8e6bbd-- |
| 936 | --f403045f1dcc043a44054c8e6bbf |
| 937 | Content-Type: application/csv; |
| 938 | name="unencoded.csv" |
| 939 | Content-Transfer-Encoding: 7bit |
| 940 | Content-Disposition: attachment; |
| 941 | filename="unencoded.csv" |
| 942 | |
| 943 | |
| 944 | "Some", "Data", "In", "Csv", "Format" |
| 945 | "Foo", "Bar", "Baz", "Bum", "Poo" |
| 946 | |
| 947 | --f403045f1dcc043a44054c8e6bbf-- |
| 948 | ` |