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