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: { |
| 299 | mailData: rfc5322exampleA12WithTimezone, |
| 300 | from: []mail.Address{ |
| 301 | { |
| 302 | Name: "Joe Q. Public", |
| 303 | Address: "john.q.public@example.com", |
| 304 | }, |
| 305 | }, |
| 306 | to: []mail.Address{ |
| 307 | { |
| 308 | Name: "Mary Smith", |
| 309 | Address: "mary@x.test", |
| 310 | }, |
| 311 | { |
| 312 | Name: "", |
| 313 | Address: "jdoe@example.org", |
| 314 | }, |
| 315 | { |
| 316 | Name: "Who?", |
| 317 | Address: "one@y.test", |
| 318 | }, |
| 319 | }, |
| 320 | cc: []mail.Address{ |
| 321 | { |
| 322 | Name: "", |
| 323 | Address: "boss@nil.test", |
| 324 | }, |
| 325 | { |
| 326 | Name: "Giant; \"Big\" Box", |
| 327 | Address: "sysservices@example.net", |
| 328 | }, |
| 329 | }, |
| 330 | messageID: "5678.21-Nov-1997@example.com", |
| 331 | date: parseDate("Tue, 01 Jul 2003 10:52:37 +0200"), |
| 332 | textBody: `Hi everyone.`, |
| 333 | }, |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 334 | 11: { |
| 335 | contentType: "multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf", |
| 336 | mailData: attachment7bit, |
| 337 | subject: "Peter Foobar", |
Edwin Love | f8d8da2 | 2019-04-02 14:07:32 +0100 | [diff] [blame] | 338 | from: []mail.Address{ |
| 339 | { |
| 340 | Name: "Peter Foobar", |
| 341 | Address: "peter.foobar@gmail.com", |
| 342 | }, |
| 343 | }, |
| 344 | to: []mail.Address{ |
| 345 | { |
| 346 | Name: "", |
| 347 | Address: "dusan@kasan.sk", |
| 348 | }, |
| 349 | }, |
| 350 | messageID: "CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com", |
| 351 | date: parseDate("Tue, 02 Apr 2019 11:12:26 +0000"), |
| 352 | htmlBody: "<div dir=\"ltr\"><br></div>", |
| 353 | attachments: []attachmentData{ |
| 354 | { |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 355 | filename: "unencoded.csv", |
| 356 | contentType: "application/csv", |
| 357 | 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] | 358 | }, |
| 359 | }, |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 360 | }, |
| 361 | } |
| 362 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 363 | for index, td := range testData { |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 364 | e, err := Parse(strings.NewReader(td.mailData)) |
Antonio | 331b118 | 2019-01-15 09:58:52 +0100 | [diff] [blame] | 365 | if err != nil { |
| 366 | t.Error(err) |
| 367 | } |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 368 | |
| 369 | if td.contentType != e.ContentType { |
| 370 | t.Errorf("[Test Case %v] Wrong content type. Expected: %s, Got: %s", index, td.contentType, e.ContentType) |
| 371 | } |
| 372 | |
| 373 | if td.content != "" { |
| 374 | b, err := ioutil.ReadAll(e.Content) |
| 375 | if err != nil { |
| 376 | t.Error(err) |
| 377 | } else if td.content != string(b) { |
| 378 | t.Errorf("[Test Case %v] Wrong content. Expected: %s, Got: %s", index, td.content, string(b)) |
| 379 | } |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 380 | } |
| 381 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 382 | if td.subject != e.Subject { |
| 383 | 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] | 384 | } |
| 385 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 386 | if td.messageID != e.MessageID { |
| 387 | 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] | 388 | } |
| 389 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 390 | if !td.date.Equal(e.Date) { |
| 391 | 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] | 392 | } |
| 393 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 394 | d := dereferenceAddressList(e.From) |
| 395 | if !assertAddressListEq(td.from, d) { |
| 396 | 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] | 397 | } |
| 398 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 399 | var sender mail.Address |
| 400 | if e.Sender != nil { |
| 401 | sender = *e.Sender |
| 402 | } |
| 403 | if td.sender != sender { |
| 404 | 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] | 405 | } |
| 406 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 407 | d = dereferenceAddressList(e.To) |
| 408 | if !assertAddressListEq(td.to, d) { |
| 409 | 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] | 410 | } |
| 411 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 412 | d = dereferenceAddressList(e.Cc) |
| 413 | if !assertAddressListEq(td.cc, d) { |
| 414 | 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] | 415 | } |
| 416 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 417 | d = dereferenceAddressList(e.Bcc) |
| 418 | if !assertAddressListEq(td.bcc, d) { |
| 419 | 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] | 420 | } |
| 421 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 422 | if td.resentMessageID != e.ResentMessageID { |
| 423 | 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] | 424 | } |
| 425 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 426 | if !td.resentDate.Equal(e.ResentDate) && !td.resentDate.IsZero() && !e.ResentDate.IsZero() { |
| 427 | t.Errorf("[Test Case %v] Wrong resent date. Expected: %v, Got: %v", index, td.resentDate, e.ResentDate) |
| 428 | } |
| 429 | |
| 430 | d = dereferenceAddressList(e.ResentFrom) |
| 431 | if !assertAddressListEq(td.resentFrom, d) { |
| 432 | t.Errorf("[Test Case %v] Wrong resent from. Expected: %s, Got: %s", index, td.resentFrom, d) |
| 433 | } |
| 434 | |
| 435 | var resentSender mail.Address |
| 436 | if e.ResentSender != nil { |
| 437 | resentSender = *e.ResentSender |
| 438 | } |
| 439 | if td.resentSender != resentSender { |
| 440 | t.Errorf("[Test Case %v] Wrong resent sender. Expected: %s, Got: %s", index, td.resentSender, resentSender) |
| 441 | } |
| 442 | |
| 443 | d = dereferenceAddressList(e.ResentTo) |
| 444 | if !assertAddressListEq(td.resentTo, d) { |
| 445 | t.Errorf("[Test Case %v] Wrong resent to. Expected: %s, Got: %s", index, td.resentTo, d) |
| 446 | } |
| 447 | |
| 448 | d = dereferenceAddressList(e.ResentCc) |
| 449 | if !assertAddressListEq(td.resentCc, d) { |
| 450 | t.Errorf("[Test Case %v] Wrong resent cc. Expected: %s, Got: %s", index, td.resentCc, d) |
| 451 | } |
| 452 | |
| 453 | d = dereferenceAddressList(e.ResentBcc) |
| 454 | if !assertAddressListEq(td.resentBcc, d) { |
| 455 | t.Errorf("[Test Case %v] Wrong resent bcc. Expected: %s, Got: %s", index, td.resentBcc, d) |
| 456 | } |
| 457 | |
| 458 | if !assertSliceEq(td.inReplyTo, e.InReplyTo) { |
| 459 | t.Errorf("[Test Case %v] Wrong in reply to. Expected: %s, Got: %s", index, td.inReplyTo, e.InReplyTo) |
| 460 | } |
| 461 | |
| 462 | if !assertSliceEq(td.references, e.References) { |
| 463 | t.Errorf("[Test Case %v] Wrong references. Expected: %s, Got: %s", index, td.references, e.References) |
| 464 | } |
| 465 | |
| 466 | d = dereferenceAddressList(e.ReplyTo) |
| 467 | if !assertAddressListEq(td.replyTo, d) { |
| 468 | 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] | 469 | } |
| 470 | |
| 471 | if td.htmlBody != e.HTMLBody { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 472 | 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] | 473 | } |
| 474 | |
| 475 | if td.textBody != e.TextBody { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 476 | 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] | 477 | } |
| 478 | |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 479 | if len(td.attachments) != len(e.Attachments) { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 480 | 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] | 481 | } else { |
| 482 | attachs := e.Attachments[:] |
| 483 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 484 | for _, ad := range td.attachments { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 485 | found := false |
| 486 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 487 | for i, ra := range attachs { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 488 | b, err := ioutil.ReadAll(ra.Data) |
| 489 | if err != nil { |
| 490 | t.Error(err) |
| 491 | } |
| 492 | |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 493 | 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] | 494 | found = true |
| 495 | attachs = append(attachs[:i], attachs[i+1:]...) |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | if !found { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 500 | t.Errorf("[Test Case %v] Attachment not found: %s", index, ad.filename) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
| 504 | if len(attachs) != 0 { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 505 | 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] | 506 | } |
| 507 | } |
| 508 | |
| 509 | if len(td.embeddedFiles) != len(e.EmbeddedFiles) { |
Dusan Kasan | 1a96648 | 2017-04-18 10:45:25 +0200 | [diff] [blame] | 510 | 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] | 511 | } else { |
| 512 | embeds := e.EmbeddedFiles[:] |
| 513 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 514 | for _, ad := range td.embeddedFiles { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 515 | found := false |
| 516 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 517 | for i, ra := range embeds { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 518 | b, err := ioutil.ReadAll(ra.Data) |
| 519 | if err != nil { |
| 520 | t.Error(err) |
| 521 | } |
| 522 | |
| 523 | encoded := base64.StdEncoding.EncodeToString(b) |
| 524 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 525 | if ra.CID == ad.cid && encoded == ad.base64data && ra.ContentType == ad.contentType { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 526 | found = true |
| 527 | embeds = append(embeds[:i], embeds[i+1:]...) |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | if !found { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 532 | 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] | 533 | } |
| 534 | } |
| 535 | |
| 536 | if len(embeds) != 0 { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 537 | 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] | 538 | } |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | |
Obi Symons | 333687f | 2020-04-05 14:31:35 +1000 | [diff] [blame] | 543 | func TestMultiPartRelatedEmail(t *testing.T) { |
| 544 | email, err := Parse(strings.NewReader(multipartRelatedExample)) |
| 545 | if err != nil { |
| 546 | t.Errorf("[Test Multipart Related] Emailed failed to parse: %v", err) |
| 547 | } |
| 548 | |
| 549 | if len(email.TextBody) == 0 { |
| 550 | t.Errorf("[Test Multipart Related] Failed to parse multipart related at the top level.") |
| 551 | } |
| 552 | body := "Time for the egg." |
| 553 | fmt.Println(email.TextBody) |
| 554 | if email.TextBody != body { |
| 555 | t.Errorf("Test Multipart Related] Body didn't match. \nExpected: %v,\nbut got: %v", body, email.TextBody) |
| 556 | } |
| 557 | |
| 558 | html := "<div dir=\"ltr\"><div>Time for the egg.</div><div><br></div><div><br><br></div></div>" |
| 559 | if email.HTMLBody != html { |
| 560 | t.Errorf("Test Multipart Related] HTML didn't match. \nExpected: %v,\nbut got: %v", html, email.TextBody) |
| 561 | } |
| 562 | } |
| 563 | |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 564 | func parseDate(in string) time.Time { |
| 565 | out, err := time.Parse(time.RFC1123Z, in) |
| 566 | if err != nil { |
| 567 | panic(err) |
| 568 | } |
| 569 | |
| 570 | return out |
| 571 | } |
| 572 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 573 | type attachmentData struct { |
Edwin Love | f8d8da2 | 2019-04-02 14:07:32 +0100 | [diff] [blame] | 574 | filename string |
| 575 | contentType string |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 576 | data string |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 577 | } |
| 578 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 579 | type embeddedFileData struct { |
| 580 | cid string |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 581 | contentType string |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 582 | base64data string |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | func assertSliceEq(a, b []string) bool { |
| 586 | if len(a) == len(b) && len(a) == 0 { |
| 587 | return true |
| 588 | } |
| 589 | |
| 590 | if a == nil && b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 591 | return true |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | if a == nil || b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 595 | return false |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | if len(a) != len(b) { |
| 599 | return false |
| 600 | } |
| 601 | |
| 602 | for i := range a { |
| 603 | if a[i] != b[i] { |
| 604 | return false |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | return true |
| 609 | } |
| 610 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 611 | func assertAddressListEq(a, b []mail.Address) bool { |
| 612 | if len(a) == len(b) && len(a) == 0 { |
| 613 | return true |
| 614 | } |
| 615 | |
| 616 | if a == nil && b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 617 | return true |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | if a == nil || b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 621 | return false |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | if len(a) != len(b) { |
| 625 | return false |
| 626 | } |
| 627 | |
| 628 | for i := range a { |
| 629 | if a[i] != b[i] { |
| 630 | return false |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | return true |
| 635 | } |
| 636 | |
| 637 | func dereferenceAddressList(al []*mail.Address) (result []mail.Address) { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 638 | for _, a := range al { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 639 | result = append(result, *a) |
| 640 | } |
| 641 | |
| 642 | return |
| 643 | } |
| 644 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 645 | 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] | 646 | Date: Fri, 7 Apr 2017 09:17:26 +0200 |
| 647 | Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com> |
Dusan Kasan | f4376a6 | 2017-05-23 21:03:55 +0200 | [diff] [blame] | 648 | Subject: =?UTF-8?Q?Peter_Pahol=C3=ADk?= |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 649 | To: dusan@kasan.sk |
| 650 | Content-Type: multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf |
| 651 | |
| 652 | --f403045f1dcc043a44054c8e6bbf |
| 653 | Content-Type: multipart/alternative; boundary=f403045f1dcc043a3f054c8e6bbd |
| 654 | |
| 655 | --f403045f1dcc043a3f054c8e6bbd |
| 656 | Content-Type: text/plain; charset=UTF-8 |
| 657 | |
| 658 | |
| 659 | |
| 660 | --f403045f1dcc043a3f054c8e6bbd |
| 661 | Content-Type: text/html; charset=UTF-8 |
| 662 | |
| 663 | <div dir="ltr"><br></div> |
| 664 | |
| 665 | --f403045f1dcc043a3f054c8e6bbd-- |
| 666 | --f403045f1dcc043a44054c8e6bbf |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 667 | Content-Type: application/json; |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 668 | name="=?UTF-8?Q?Peter_Paholi=CC=81k_1?= |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 669 | =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Ejson?=" |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 670 | Content-Disposition: attachment; |
| 671 | filename="=?UTF-8?Q?Peter_Paholi=CC=81k_1?= |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 672 | =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Ejson?=" |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 673 | Content-Transfer-Encoding: base64 |
| 674 | X-Attachment-Id: f_j17i0f0d0 |
| 675 | |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 676 | WzEsIDIsIDNd |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 677 | --f403045f1dcc043a44054c8e6bbf-- |
| 678 | ` |
| 679 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 680 | var data2 = `Subject: Re: Test Subject 2 |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 681 | To: info@receiver.com |
| 682 | References: <2f6b7595-c01e-46e5-42bc-f263e1c4282d@receiver.com> |
| 683 | <9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@domain.com> |
| 684 | Cc: Cc Man <ccman@gmail.com> |
| 685 | From: Sender Man <sender@domain.com> |
| 686 | Message-ID: <0e9a21b4-01dc-e5c1-dcd6-58ce5aa61f4f@receiver.com> |
| 687 | Date: Fri, 7 Apr 2017 12:59:55 +0200 |
| 688 | User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) |
| 689 | Gecko/20100101 Thunderbird/45.8.0 |
| 690 | MIME-Version: 1.0 |
| 691 | In-Reply-To: <9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@receiver.eu> |
| 692 | Content-Type: multipart/alternative; |
| 693 | boundary="------------C70C0458A558E585ACB75FB4" |
| 694 | |
| 695 | This is a multi-part message in MIME format. |
| 696 | --------------C70C0458A558E585ACB75FB4 |
| 697 | Content-Type: text/plain; charset=utf-8; format=flowed |
| 698 | Content-Transfer-Encoding: 8bit |
| 699 | |
| 700 | First level |
| 701 | > Second level |
| 702 | >> Third level |
| 703 | > |
| 704 | |
| 705 | |
| 706 | --------------C70C0458A558E585ACB75FB4 |
| 707 | Content-Type: multipart/related; |
| 708 | boundary="------------5DB4A1356834BB602A5F88B2" |
| 709 | |
| 710 | |
| 711 | --------------5DB4A1356834BB602A5F88B2 |
| 712 | Content-Type: text/html; charset=utf-8 |
| 713 | Content-Transfer-Encoding: 8bit |
| 714 | |
| 715 | <html>data<img src="part2.9599C449.04E5EC81@develhell.com"/></html> |
| 716 | |
| 717 | --------------5DB4A1356834BB602A5F88B2 |
| 718 | Content-Type: image/png |
| 719 | Content-Transfer-Encoding: base64 |
| 720 | Content-ID: <part2.9599C449.04E5EC81@develhell.com> |
| 721 | |
| 722 | iVBORw0KGgoAAAANSUhEUgAAAQEAAAAYCAIAAAB1IN9NAAAACXBIWXMAAAsTAAALEwEAmpwY |
| 723 | YKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg== |
| 724 | --------------5DB4A1356834BB602A5F88B2 |
| 725 | |
| 726 | --------------C70C0458A558E585ACB75FB4-- |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 727 | ` |
| 728 | |
Dusan Kasan | e97c2f2 | 2020-04-04 10:50:00 +0200 | [diff] [blame] | 729 | var textPlainInMultipart = `From: Rares <rares@example.com> |
Maya Rashish | bae116e | 2019-06-10 12:15:25 +0300 | [diff] [blame] | 730 | Date: Thu, 2 May 2019 11:25:35 +0300 |
| 731 | Subject: Re: kern/54143 (virtualbox) |
| 732 | To: bugs@example.com |
| 733 | Content-Type: multipart/mixed; boundary="0000000000007e2bb40587e36196" |
| 734 | |
| 735 | --0000000000007e2bb40587e36196 |
| 736 | Content-Type: text/plain; charset="UTF-8" |
| 737 | |
| 738 | plain text part |
| 739 | --0000000000007e2bb40587e36196-- |
| 740 | ` |
| 741 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 742 | var rfc5322exampleA11 = `From: John Doe <jdoe@machine.example> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 743 | Sender: Michael Jones <mjones@machine.example> |
| 744 | To: Mary Smith <mary@example.net> |
| 745 | Subject: Saying Hello |
| 746 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 747 | Message-ID: <1234@local.machine.example> |
| 748 | |
| 749 | This is a message just to say hello. |
| 750 | So, "Hello". |
| 751 | ` |
| 752 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 753 | var rfc5322exampleA12 = `From: "Joe Q. Public" <john.q.public@example.com> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 754 | To: Mary Smith <mary@x.test>, jdoe@example.org, Who? <one@y.test> |
| 755 | Cc: <boss@nil.test>, "Giant; \"Big\" Box" <sysservices@example.net> |
| 756 | Date: Tue, 1 Jul 2003 10:52:37 +0200 |
| 757 | Message-ID: <5678.21-Nov-1997@example.com> |
| 758 | |
| 759 | Hi everyone. |
| 760 | ` |
| 761 | |
Dusan Kasan | 88226cf | 2020-04-04 11:13:06 +0200 | [diff] [blame] | 762 | var rfc5322exampleA12WithTimezone = `From: "Joe Q. Public" <john.q.public@example.com> |
| 763 | To: Mary Smith <mary@x.test>, jdoe@example.org, Who? <one@y.test> |
| 764 | Cc: <boss@nil.test>, "Giant; \"Big\" Box" <sysservices@example.net> |
Edwin Love | 33953e5 | 2019-04-02 15:29:22 +0100 | [diff] [blame] | 765 | Date: Tue, 1 Jul 2003 10:52:37 +0200 (GMT) |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 766 | Message-ID: <5678.21-Nov-1997@example.com> |
| 767 | |
| 768 | Hi everyone. |
| 769 | ` |
| 770 | |
| 771 | //todo: not yet implemented in net/mail |
| 772 | //once there is support for this, add it |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 773 | var rfc5322exampleA13 = `From: Pete <pete@silly.example> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 774 | To: A Group:Ed Jones <c@a.test>,joe@where.test,John <jdoe@one.test>; |
| 775 | Cc: Undisclosed recipients:; |
| 776 | Date: Thu, 13 Feb 1969 23:32:54 -0330 |
| 777 | Message-ID: <testabcd.1234@silly.example> |
| 778 | |
| 779 | Testing. |
| 780 | ` |
| 781 | |
| 782 | //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] | 783 | var rfc5322exampleA2a = `From: Mary Smith <mary@example.net> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 784 | To: John Doe <jdoe@machine.example> |
| 785 | Reply-To: "Mary Smith: Personal Account" <smith@home.example> |
| 786 | Subject: Re: Saying Hello |
| 787 | Date: Fri, 21 Nov 1997 10:01:10 -0600 |
| 788 | Message-ID: <3456@example.net> |
| 789 | In-Reply-To: <1234@local.machine.example> |
| 790 | References: <1234@local.machine.example> |
| 791 | |
| 792 | This is a reply to your hello. |
| 793 | ` |
| 794 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 795 | var rfc5322exampleA2b = `To: "Mary Smith: Personal Account" <smith@home.example> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 796 | From: John Doe <jdoe@machine.example> |
| 797 | Subject: Re: Saying Hello |
| 798 | Date: Fri, 21 Nov 1997 11:00:00 -0600 |
| 799 | Message-ID: <abcd.1234@local.machine.test> |
| 800 | In-Reply-To: <3456@example.net> |
| 801 | References: <1234@local.machine.example> <3456@example.net> |
| 802 | |
| 803 | This is a reply to your reply. |
| 804 | ` |
| 805 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 806 | var rfc5322exampleA3 = `Resent-From: Mary Smith <mary@example.net> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 807 | Resent-To: Jane Brown <j-brown@other.example> |
| 808 | Resent-Date: Mon, 24 Nov 1997 14:22:01 -0800 |
| 809 | Resent-Message-ID: <78910@example.net> |
| 810 | From: John Doe <jdoe@machine.example> |
| 811 | To: Mary Smith <mary@example.net> |
| 812 | Subject: Saying Hello |
| 813 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 814 | Message-ID: <1234@local.machine.example> |
| 815 | |
| 816 | This is a message just to say hello. |
| 817 | So, "Hello".` |
| 818 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 819 | var rfc5322exampleA4 = `Received: from x.y.test |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 820 | by example.net |
| 821 | via TCP |
| 822 | with ESMTP |
| 823 | id ABC12345 |
| 824 | for <mary@example.net>; 21 Nov 1997 10:05:43 -0600 |
| 825 | Received: from node.example by x.y.test; 21 Nov 1997 10:01:22 -0600 |
| 826 | From: John Doe <jdoe@node.example> |
| 827 | To: Mary Smith <mary@example.net> |
| 828 | Subject: Saying Hello |
| 829 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 830 | Message-ID: <1234@local.node.example> |
| 831 | |
| 832 | This is a message just to say hello. |
| 833 | So, "Hello".` |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 834 | |
| 835 | var imageContentExample = `From: John Doe <jdoe@machine.example> |
| 836 | Sender: Michael Jones <mjones@machine.example> |
| 837 | To: Mary Smith <mary@example.net> |
| 838 | Subject: Saying Hello |
| 839 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 840 | Message-ID: <1234@local.machine.example> |
| 841 | Content-Type: image/jpeg; |
| 842 | x-unix-mode=0644; |
| 843 | name="image.gif" |
| 844 | Content-Transfer-Encoding: base64 |
| 845 | |
| 846 | R0lGODlhAQE7` |
Obi Symons | 333687f | 2020-04-05 14:31:35 +1000 | [diff] [blame] | 847 | |
| 848 | var multipartRelatedExample = `MIME-Version: 1.0 |
| 849 | From: John Doe <jdoe@machine.example> |
| 850 | Sender: Michael Jones <mjones@machine.example> |
| 851 | To: Mary Smith <mary@example.net> |
| 852 | Subject: Saying Hello |
| 853 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 854 | Message-ID: <1234@local.machine.example> |
| 855 | Subject: ooops |
| 856 | To: test@example.rocks |
| 857 | Content-Type: multipart/related; boundary="000000000000ab2e2205a26de587" |
| 858 | |
| 859 | --000000000000ab2e2205a26de587 |
| 860 | Content-Type: multipart/alternative; boundary="000000000000ab2e1f05a26de586" |
| 861 | |
| 862 | --000000000000ab2e1f05a26de586 |
| 863 | Content-Type: text/plain; charset="UTF-8" |
| 864 | |
| 865 | Time for the egg. |
| 866 | |
| 867 | --000000000000ab2e1f05a26de586 |
| 868 | Content-Type: text/html; charset="UTF-8" |
| 869 | |
| 870 | <div dir="ltr"><div>Time for the egg.</div><div><br></div><div><br><br></div></div> |
| 871 | |
| 872 | --000000000000ab2e1f05a26de586-- |
| 873 | |
| 874 | |
| 875 | --000000000000ab2e2205a26de587-- |
Obi Symons | 5bf5e01 | 2020-04-05 14:36:29 +1000 | [diff] [blame^] | 876 | ` |
Dusan Kasan | 3325e73 | 2020-04-04 11:46:04 +0200 | [diff] [blame] | 877 | var attachment7bit = `From: =?UTF-8?Q?Peter_Foobar?= <peter.foobar@gmail.com> |
| 878 | Date: Tue, 2 Apr 2019 11:12:26 +0000 |
| 879 | Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com> |
| 880 | Subject: =?UTF-8?Q?Peter_Foobar?= |
| 881 | To: dusan@kasan.sk |
| 882 | Content-Type: multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf |
| 883 | |
| 884 | --f403045f1dcc043a44054c8e6bbf |
| 885 | Content-Type: multipart/alternative; boundary=f403045f1dcc043a3f054c8e6bbd |
| 886 | |
| 887 | --f403045f1dcc043a3f054c8e6bbd |
| 888 | Content-Type: text/plain; charset=UTF-8 |
| 889 | |
| 890 | |
| 891 | |
| 892 | --f403045f1dcc043a3f054c8e6bbd |
| 893 | Content-Type: text/html; charset=UTF-8 |
| 894 | |
| 895 | <div dir="ltr"><br></div> |
| 896 | |
| 897 | --f403045f1dcc043a3f054c8e6bbd-- |
| 898 | --f403045f1dcc043a44054c8e6bbf |
| 899 | Content-Type: application/csv; |
| 900 | name="unencoded.csv" |
| 901 | Content-Transfer-Encoding: 7bit |
| 902 | Content-Disposition: attachment; |
| 903 | filename="unencoded.csv" |
| 904 | |
| 905 | |
| 906 | "Some", "Data", "In", "Csv", "Format" |
| 907 | "Foo", "Bar", "Baz", "Bum", "Poo" |
| 908 | |
| 909 | --f403045f1dcc043a44054c8e6bbf-- |
| 910 | ` |