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 | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 297 | } |
| 298 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 299 | for index, td := range testData { |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 300 | e, err := Parse(strings.NewReader(td.mailData)) |
Antonio | 331b118 | 2019-01-15 09:58:52 +0100 | [diff] [blame] | 301 | if err != nil { |
| 302 | t.Error(err) |
| 303 | } |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 304 | |
| 305 | if td.contentType != e.ContentType { |
| 306 | t.Errorf("[Test Case %v] Wrong content type. Expected: %s, Got: %s", index, td.contentType, e.ContentType) |
| 307 | } |
| 308 | |
| 309 | if td.content != "" { |
| 310 | b, err := ioutil.ReadAll(e.Content) |
| 311 | if err != nil { |
| 312 | t.Error(err) |
| 313 | } else if td.content != string(b) { |
| 314 | t.Errorf("[Test Case %v] Wrong content. Expected: %s, Got: %s", index, td.content, string(b)) |
| 315 | } |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 316 | } |
| 317 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 318 | if td.subject != e.Subject { |
| 319 | 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] | 320 | } |
| 321 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 322 | if td.messageID != e.MessageID { |
| 323 | 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] | 324 | } |
| 325 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 326 | if !td.date.Equal(e.Date) { |
| 327 | 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] | 328 | } |
| 329 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 330 | d := dereferenceAddressList(e.From) |
| 331 | if !assertAddressListEq(td.from, d) { |
| 332 | 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] | 333 | } |
| 334 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 335 | var sender mail.Address |
| 336 | if e.Sender != nil { |
| 337 | sender = *e.Sender |
| 338 | } |
| 339 | if td.sender != sender { |
| 340 | 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] | 341 | } |
| 342 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 343 | d = dereferenceAddressList(e.To) |
| 344 | if !assertAddressListEq(td.to, d) { |
| 345 | 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] | 346 | } |
| 347 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 348 | d = dereferenceAddressList(e.Cc) |
| 349 | if !assertAddressListEq(td.cc, d) { |
| 350 | 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] | 351 | } |
| 352 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 353 | d = dereferenceAddressList(e.Bcc) |
| 354 | if !assertAddressListEq(td.bcc, d) { |
| 355 | 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] | 356 | } |
| 357 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 358 | if td.resentMessageID != e.ResentMessageID { |
| 359 | 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] | 360 | } |
| 361 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 362 | if !td.resentDate.Equal(e.ResentDate) && !td.resentDate.IsZero() && !e.ResentDate.IsZero() { |
| 363 | t.Errorf("[Test Case %v] Wrong resent date. Expected: %v, Got: %v", index, td.resentDate, e.ResentDate) |
| 364 | } |
| 365 | |
| 366 | d = dereferenceAddressList(e.ResentFrom) |
| 367 | if !assertAddressListEq(td.resentFrom, d) { |
| 368 | t.Errorf("[Test Case %v] Wrong resent from. Expected: %s, Got: %s", index, td.resentFrom, d) |
| 369 | } |
| 370 | |
| 371 | var resentSender mail.Address |
| 372 | if e.ResentSender != nil { |
| 373 | resentSender = *e.ResentSender |
| 374 | } |
| 375 | if td.resentSender != resentSender { |
| 376 | t.Errorf("[Test Case %v] Wrong resent sender. Expected: %s, Got: %s", index, td.resentSender, resentSender) |
| 377 | } |
| 378 | |
| 379 | d = dereferenceAddressList(e.ResentTo) |
| 380 | if !assertAddressListEq(td.resentTo, d) { |
| 381 | t.Errorf("[Test Case %v] Wrong resent to. Expected: %s, Got: %s", index, td.resentTo, d) |
| 382 | } |
| 383 | |
| 384 | d = dereferenceAddressList(e.ResentCc) |
| 385 | if !assertAddressListEq(td.resentCc, d) { |
| 386 | t.Errorf("[Test Case %v] Wrong resent cc. Expected: %s, Got: %s", index, td.resentCc, d) |
| 387 | } |
| 388 | |
| 389 | d = dereferenceAddressList(e.ResentBcc) |
| 390 | if !assertAddressListEq(td.resentBcc, d) { |
| 391 | t.Errorf("[Test Case %v] Wrong resent bcc. Expected: %s, Got: %s", index, td.resentBcc, d) |
| 392 | } |
| 393 | |
| 394 | if !assertSliceEq(td.inReplyTo, e.InReplyTo) { |
| 395 | t.Errorf("[Test Case %v] Wrong in reply to. Expected: %s, Got: %s", index, td.inReplyTo, e.InReplyTo) |
| 396 | } |
| 397 | |
| 398 | if !assertSliceEq(td.references, e.References) { |
| 399 | t.Errorf("[Test Case %v] Wrong references. Expected: %s, Got: %s", index, td.references, e.References) |
| 400 | } |
| 401 | |
| 402 | d = dereferenceAddressList(e.ReplyTo) |
| 403 | if !assertAddressListEq(td.replyTo, d) { |
| 404 | 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] | 405 | } |
| 406 | |
| 407 | if td.htmlBody != e.HTMLBody { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 408 | 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] | 409 | } |
| 410 | |
| 411 | if td.textBody != e.TextBody { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 412 | 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] | 413 | } |
| 414 | |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 415 | if len(td.attachments) != len(e.Attachments) { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 416 | 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] | 417 | } else { |
| 418 | attachs := e.Attachments[:] |
| 419 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 420 | for _, ad := range td.attachments { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 421 | found := false |
| 422 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 423 | for i, ra := range attachs { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 424 | b, err := ioutil.ReadAll(ra.Data) |
| 425 | if err != nil { |
| 426 | t.Error(err) |
| 427 | } |
| 428 | |
| 429 | encoded := base64.StdEncoding.EncodeToString(b) |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 430 | if ra.Filename == ad.filename && encoded == ad.base64data && ra.ContentType == ad.contentType { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 431 | found = true |
| 432 | attachs = append(attachs[:i], attachs[i+1:]...) |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if !found { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 437 | t.Errorf("[Test Case %v] Attachment not found: %s", index, ad.filename) |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | |
| 441 | if len(attachs) != 0 { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 442 | 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] | 443 | } |
| 444 | } |
| 445 | |
| 446 | if len(td.embeddedFiles) != len(e.EmbeddedFiles) { |
Dusan Kasan | 1a96648 | 2017-04-18 10:45:25 +0200 | [diff] [blame] | 447 | 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] | 448 | } else { |
| 449 | embeds := e.EmbeddedFiles[:] |
| 450 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 451 | for _, ad := range td.embeddedFiles { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 452 | found := false |
| 453 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 454 | for i, ra := range embeds { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 455 | b, err := ioutil.ReadAll(ra.Data) |
| 456 | if err != nil { |
| 457 | t.Error(err) |
| 458 | } |
| 459 | |
| 460 | encoded := base64.StdEncoding.EncodeToString(b) |
| 461 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 462 | if ra.CID == ad.cid && encoded == ad.base64data && ra.ContentType == ad.contentType { |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 463 | found = true |
| 464 | embeds = append(embeds[:i], embeds[i+1:]...) |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | if !found { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 469 | 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] | 470 | } |
| 471 | } |
| 472 | |
| 473 | if len(embeds) != 0 { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 474 | 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] | 475 | } |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | func parseDate(in string) time.Time { |
| 481 | out, err := time.Parse(time.RFC1123Z, in) |
| 482 | if err != nil { |
| 483 | panic(err) |
| 484 | } |
| 485 | |
| 486 | return out |
| 487 | } |
| 488 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 489 | type attachmentData struct { |
| 490 | filename string |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 491 | contentType string |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 492 | base64data string |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 493 | } |
| 494 | |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 495 | type embeddedFileData struct { |
| 496 | cid string |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 497 | contentType string |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 498 | base64data string |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | func assertSliceEq(a, b []string) bool { |
| 502 | if len(a) == len(b) && len(a) == 0 { |
| 503 | return true |
| 504 | } |
| 505 | |
| 506 | if a == nil && b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 507 | return true |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | if a == nil || b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 511 | return false |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | if len(a) != len(b) { |
| 515 | return false |
| 516 | } |
| 517 | |
| 518 | for i := range a { |
| 519 | if a[i] != b[i] { |
| 520 | return false |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | return true |
| 525 | } |
| 526 | |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 527 | func assertAddressListEq(a, b []mail.Address) bool { |
| 528 | if len(a) == len(b) && len(a) == 0 { |
| 529 | return true |
| 530 | } |
| 531 | |
| 532 | if a == nil && b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 533 | return true |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | if a == nil || b == nil { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 537 | return false |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | if len(a) != len(b) { |
| 541 | return false |
| 542 | } |
| 543 | |
| 544 | for i := range a { |
| 545 | if a[i] != b[i] { |
| 546 | return false |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | return true |
| 551 | } |
| 552 | |
| 553 | func dereferenceAddressList(al []*mail.Address) (result []mail.Address) { |
Dusan Kasan | 4595dfe | 2017-04-13 00:38:24 +0200 | [diff] [blame] | 554 | for _, a := range al { |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 555 | result = append(result, *a) |
| 556 | } |
| 557 | |
| 558 | return |
| 559 | } |
| 560 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 561 | 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] | 562 | Date: Fri, 7 Apr 2017 09:17:26 +0200 |
| 563 | Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com> |
Dusan Kasan | f4376a6 | 2017-05-23 21:03:55 +0200 | [diff] [blame] | 564 | Subject: =?UTF-8?Q?Peter_Pahol=C3=ADk?= |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 565 | To: dusan@kasan.sk |
| 566 | Content-Type: multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf |
| 567 | |
| 568 | --f403045f1dcc043a44054c8e6bbf |
| 569 | Content-Type: multipart/alternative; boundary=f403045f1dcc043a3f054c8e6bbd |
| 570 | |
| 571 | --f403045f1dcc043a3f054c8e6bbd |
| 572 | Content-Type: text/plain; charset=UTF-8 |
| 573 | |
| 574 | |
| 575 | |
| 576 | --f403045f1dcc043a3f054c8e6bbd |
| 577 | Content-Type: text/html; charset=UTF-8 |
| 578 | |
| 579 | <div dir="ltr"><br></div> |
| 580 | |
| 581 | --f403045f1dcc043a3f054c8e6bbd-- |
| 582 | --f403045f1dcc043a44054c8e6bbf |
| 583 | Content-Type: application/pdf; |
| 584 | name="=?UTF-8?Q?Peter_Paholi=CC=81k_1?= |
| 585 | =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Epdf?=" |
| 586 | Content-Disposition: attachment; |
| 587 | filename="=?UTF-8?Q?Peter_Paholi=CC=81k_1?= |
| 588 | =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Epdf?=" |
| 589 | Content-Transfer-Encoding: base64 |
| 590 | X-Attachment-Id: f_j17i0f0d0 |
| 591 | |
| 592 | JVBERi0xLjQNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIvTGFu |
| 593 | Zyhlbi1VUykgL1N0cnVjdFRyZWVSb290IDY3IDAgUi9NYXJrSW5mbzw8L01hcmtlZCB0cnVlPj4v |
| 594 | T3V0cHV0SW50ZW50c1s8PC9UeXBlL091dHB1dEludGVudC9TL0dUU19QREZBMS9PdXRwdXRDb25k |
| 595 | ZXYgMzk1MzYyDQo+Pg0Kc3RhcnR4cmVmDQo0MTk4ODUNCiUlRU9GDQo= |
| 596 | --f403045f1dcc043a44054c8e6bbf-- |
| 597 | ` |
| 598 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 599 | var data2 = `Subject: Re: Test Subject 2 |
Dusan Kasan | 17e497e | 2017-04-10 22:44:22 +0200 | [diff] [blame] | 600 | To: info@receiver.com |
| 601 | References: <2f6b7595-c01e-46e5-42bc-f263e1c4282d@receiver.com> |
| 602 | <9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@domain.com> |
| 603 | Cc: Cc Man <ccman@gmail.com> |
| 604 | From: Sender Man <sender@domain.com> |
| 605 | Message-ID: <0e9a21b4-01dc-e5c1-dcd6-58ce5aa61f4f@receiver.com> |
| 606 | Date: Fri, 7 Apr 2017 12:59:55 +0200 |
| 607 | User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) |
| 608 | Gecko/20100101 Thunderbird/45.8.0 |
| 609 | MIME-Version: 1.0 |
| 610 | In-Reply-To: <9ff38d03-c4ab-89b7-9328-e99d5e24e3ba@receiver.eu> |
| 611 | Content-Type: multipart/alternative; |
| 612 | boundary="------------C70C0458A558E585ACB75FB4" |
| 613 | |
| 614 | This is a multi-part message in MIME format. |
| 615 | --------------C70C0458A558E585ACB75FB4 |
| 616 | Content-Type: text/plain; charset=utf-8; format=flowed |
| 617 | Content-Transfer-Encoding: 8bit |
| 618 | |
| 619 | First level |
| 620 | > Second level |
| 621 | >> Third level |
| 622 | > |
| 623 | |
| 624 | |
| 625 | --------------C70C0458A558E585ACB75FB4 |
| 626 | Content-Type: multipart/related; |
| 627 | boundary="------------5DB4A1356834BB602A5F88B2" |
| 628 | |
| 629 | |
| 630 | --------------5DB4A1356834BB602A5F88B2 |
| 631 | Content-Type: text/html; charset=utf-8 |
| 632 | Content-Transfer-Encoding: 8bit |
| 633 | |
| 634 | <html>data<img src="part2.9599C449.04E5EC81@develhell.com"/></html> |
| 635 | |
| 636 | --------------5DB4A1356834BB602A5F88B2 |
| 637 | Content-Type: image/png |
| 638 | Content-Transfer-Encoding: base64 |
| 639 | Content-ID: <part2.9599C449.04E5EC81@develhell.com> |
| 640 | |
| 641 | iVBORw0KGgoAAAANSUhEUgAAAQEAAAAYCAIAAAB1IN9NAAAACXBIWXMAAAsTAAALEwEAmpwY |
| 642 | YKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg== |
| 643 | --------------5DB4A1356834BB602A5F88B2 |
| 644 | |
| 645 | --------------C70C0458A558E585ACB75FB4-- |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 646 | ` |
| 647 | |
Dusan Kasan | e97c2f2 | 2020-04-04 10:50:00 +0200 | [diff] [blame^] | 648 | var textPlainInMultipart = `From: Rares <rares@example.com> |
Maya Rashish | bae116e | 2019-06-10 12:15:25 +0300 | [diff] [blame] | 649 | Date: Thu, 2 May 2019 11:25:35 +0300 |
| 650 | Subject: Re: kern/54143 (virtualbox) |
| 651 | To: bugs@example.com |
| 652 | Content-Type: multipart/mixed; boundary="0000000000007e2bb40587e36196" |
| 653 | |
| 654 | --0000000000007e2bb40587e36196 |
| 655 | Content-Type: text/plain; charset="UTF-8" |
| 656 | |
| 657 | plain text part |
| 658 | --0000000000007e2bb40587e36196-- |
| 659 | ` |
| 660 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 661 | var rfc5322exampleA11 = `From: John Doe <jdoe@machine.example> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 662 | Sender: Michael Jones <mjones@machine.example> |
| 663 | To: Mary Smith <mary@example.net> |
| 664 | Subject: Saying Hello |
| 665 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 666 | Message-ID: <1234@local.machine.example> |
| 667 | |
| 668 | This is a message just to say hello. |
| 669 | So, "Hello". |
| 670 | ` |
| 671 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 672 | var rfc5322exampleA12 = `From: "Joe Q. Public" <john.q.public@example.com> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 673 | To: Mary Smith <mary@x.test>, jdoe@example.org, Who? <one@y.test> |
| 674 | Cc: <boss@nil.test>, "Giant; \"Big\" Box" <sysservices@example.net> |
| 675 | Date: Tue, 1 Jul 2003 10:52:37 +0200 |
| 676 | Message-ID: <5678.21-Nov-1997@example.com> |
| 677 | |
| 678 | Hi everyone. |
| 679 | ` |
| 680 | |
| 681 | //todo: not yet implemented in net/mail |
| 682 | //once there is support for this, add it |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 683 | var rfc5322exampleA13 = `From: Pete <pete@silly.example> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 684 | To: A Group:Ed Jones <c@a.test>,joe@where.test,John <jdoe@one.test>; |
| 685 | Cc: Undisclosed recipients:; |
| 686 | Date: Thu, 13 Feb 1969 23:32:54 -0330 |
| 687 | Message-ID: <testabcd.1234@silly.example> |
| 688 | |
| 689 | Testing. |
| 690 | ` |
| 691 | |
| 692 | //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] | 693 | var rfc5322exampleA2a = `From: Mary Smith <mary@example.net> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 694 | To: John Doe <jdoe@machine.example> |
| 695 | Reply-To: "Mary Smith: Personal Account" <smith@home.example> |
| 696 | Subject: Re: Saying Hello |
| 697 | Date: Fri, 21 Nov 1997 10:01:10 -0600 |
| 698 | Message-ID: <3456@example.net> |
| 699 | In-Reply-To: <1234@local.machine.example> |
| 700 | References: <1234@local.machine.example> |
| 701 | |
| 702 | This is a reply to your hello. |
| 703 | ` |
| 704 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 705 | var rfc5322exampleA2b = `To: "Mary Smith: Personal Account" <smith@home.example> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 706 | From: John Doe <jdoe@machine.example> |
| 707 | Subject: Re: Saying Hello |
| 708 | Date: Fri, 21 Nov 1997 11:00:00 -0600 |
| 709 | Message-ID: <abcd.1234@local.machine.test> |
| 710 | In-Reply-To: <3456@example.net> |
| 711 | References: <1234@local.machine.example> <3456@example.net> |
| 712 | |
| 713 | This is a reply to your reply. |
| 714 | ` |
| 715 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 716 | var rfc5322exampleA3 = `Resent-From: Mary Smith <mary@example.net> |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 717 | Resent-To: Jane Brown <j-brown@other.example> |
| 718 | Resent-Date: Mon, 24 Nov 1997 14:22:01 -0800 |
| 719 | Resent-Message-ID: <78910@example.net> |
| 720 | From: John Doe <jdoe@machine.example> |
| 721 | To: Mary Smith <mary@example.net> |
| 722 | Subject: Saying Hello |
| 723 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 724 | Message-ID: <1234@local.machine.example> |
| 725 | |
| 726 | This is a message just to say hello. |
| 727 | So, "Hello".` |
| 728 | |
Dusan Kasan | 45ca264 | 2017-04-18 10:39:35 +0200 | [diff] [blame] | 729 | var rfc5322exampleA4 = `Received: from x.y.test |
Dusan Kasan | b49ceb6 | 2017-04-13 00:00:36 +0200 | [diff] [blame] | 730 | by example.net |
| 731 | via TCP |
| 732 | with ESMTP |
| 733 | id ABC12345 |
| 734 | for <mary@example.net>; 21 Nov 1997 10:05:43 -0600 |
| 735 | Received: from node.example by x.y.test; 21 Nov 1997 10:01:22 -0600 |
| 736 | From: John Doe <jdoe@node.example> |
| 737 | To: Mary Smith <mary@example.net> |
| 738 | Subject: Saying Hello |
| 739 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 740 | Message-ID: <1234@local.node.example> |
| 741 | |
| 742 | This is a message just to say hello. |
| 743 | So, "Hello".` |
Dusan Kasan | 428369f | 2020-02-24 00:47:31 +0100 | [diff] [blame] | 744 | |
| 745 | var imageContentExample = `From: John Doe <jdoe@machine.example> |
| 746 | Sender: Michael Jones <mjones@machine.example> |
| 747 | To: Mary Smith <mary@example.net> |
| 748 | Subject: Saying Hello |
| 749 | Date: Fri, 21 Nov 1997 09:55:06 -0600 |
| 750 | Message-ID: <1234@local.machine.example> |
| 751 | Content-Type: image/jpeg; |
| 752 | x-unix-mode=0644; |
| 753 | name="image.gif" |
| 754 | Content-Transfer-Encoding: base64 |
| 755 | |
| 756 | R0lGODlhAQE7` |