(t *testing.T)
| 174 | } |
| 175 | |
| 176 | func TestParseEmail_CharsetConversion(t *testing.T) { |
| 177 | t.Run("single part windows-1250", func(t *testing.T) { |
| 178 | // "café" in windows-1250: 0x63 0x61 0x66 0xe9 |
| 179 | body := string([]byte{0x63, 0x61, 0x66, 0xe9}) |
| 180 | raw := []byte("From: sender@example.com\r\nTo: recipient@example.com\r\nSubject: Test\r\nContent-Type: text/plain; charset=windows-1250\r\n\r\n" + body) |
| 181 | |
| 182 | parsed, _, err := parseEmail(raw, []string{"recipient@example.com"}) |
| 183 | if err != nil { |
| 184 | t.Fatal(err) |
| 185 | } |
| 186 | if parsed.Text != "café" { |
| 187 | t.Errorf("Text = %q, want %q", parsed.Text, "café") |
| 188 | } |
| 189 | }) |
| 190 | |
| 191 | t.Run("single part html iso-8859-2", func(t *testing.T) { |
| 192 | // "Vaše zpráva" in iso-8859-2: V=56 a=61 š=B9 e=65 sp=20 z=7A p=70 r=72 á=E1 v=76 a=61 |
| 193 | body := string([]byte{0x56, 0x61, 0xB9, 0x65, 0x20, 0x7A, 0x70, 0x72, 0xE1, 0x76, 0x61}) |
| 194 | raw := []byte("From: sender@example.com\r\nTo: recipient@example.com\r\nSubject: Test\r\nContent-Type: text/html; charset=iso-8859-2\r\n\r\n" + body) |
| 195 | |
| 196 | parsed, _, err := parseEmail(raw, []string{"recipient@example.com"}) |
| 197 | if err != nil { |
| 198 | t.Fatal(err) |
| 199 | } |
| 200 | want := "Vaše zpráva" |
| 201 | if parsed.HTML != want { |
| 202 | t.Errorf("HTML = %q, want %q", parsed.HTML, want) |
| 203 | } |
| 204 | }) |
| 205 | |
| 206 | t.Run("multipart with charset", func(t *testing.T) { |
| 207 | // "café" in iso-8859-1 |
| 208 | body := string([]byte{0x63, 0x61, 0x66, 0xe9}) |
| 209 | raw := []byte("From: sender@example.com\r\nTo: recipient@example.com\r\nSubject: Test\r\nContent-Type: multipart/alternative; boundary=\"bnd\"\r\n\r\n--bnd\r\nContent-Type: text/plain; charset=iso-8859-1\r\n\r\n" + body + "\r\n--bnd\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n<p>" + body + "</p>\r\n--bnd--") |
| 210 | |
| 211 | parsed, _, err := parseEmail(raw, []string{"recipient@example.com"}) |
| 212 | if err != nil { |
| 213 | t.Fatal(err) |
| 214 | } |
| 215 | if !strings.Contains(parsed.Text, "café") { |
| 216 | t.Errorf("Text = %q, want to contain %q", parsed.Text, "café") |
| 217 | } |
| 218 | if !strings.Contains(parsed.HTML, "café") { |
| 219 | t.Errorf("HTML = %q, want to contain %q", parsed.HTML, "café") |
| 220 | } |
| 221 | }) |
| 222 | } |
| 223 | |
| 224 | func TestParseAddresses(t *testing.T) { |
| 225 | t.Run("name and email", func(t *testing.T) { |
nothing calls this directly
no test coverage detected