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