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