feat(GODT-3193): preserve attachment encoding.

This commit is contained in:
Jakub 2024-02-29 12:21:29 +01:00 committed by Jakub Cuth
parent 54859a34b2
commit 63e272e270
3 changed files with 37 additions and 0 deletions

View File

@ -205,6 +205,10 @@ func convertForeignEncodings(p *parser.Parser) error {
return p.ConvertMetaCharset()
}).
RegisterContentTypeHandler("text/.*", func(p *parser.Part) error {
if p.IsAttachment() {
return nil
}
return p.ConvertToUTF8()
}).
Walk()

View File

@ -837,6 +837,17 @@ func TestPatchNewLineWithHtmlBreaks(t *testing.T) {
}
}
func TestParseCp1250Attachment(t *testing.T) {
r := require.New(t)
f := getFileReader("text_plain_xml_attachment_cp1250.eml")
m, err := Parse(f)
r.NoError(err)
r.Len(m.Attachments, 1)
r.Equal("text/xml; charset=windows-1250; name=\"cp1250.xml\"", m.Attachments[0].Header.Get("Content-Type"))
}
func getFileReader(filename string) io.Reader {
f, err := os.Open(filepath.Join("testdata", filename))
if err != nil {

View File

@ -0,0 +1,22 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: multipart/mixed; boundary="------------iOaeSk0jVHjMucH3kQFwS1LB"
This is a multi-part message in MIME format.
--------------iOaeSk0jVHjMucH3kQFwS1LB
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
created by me 😎
--------------iOaeSk0jVHjMucH3kQFwS1LB
Content-Type: text/xml; charset=windows-1250; name="cp1250.xml"
Content-Disposition: attachment; filename="cp1250.xml"
Content-Transfer-Encoding: 8bit
<?xml version="1.0" encoding="WINDOWS-1250" ?>
<pvpoj xmlns="http://schemas.cssz.cz/POJ/PVPOJ2023">
<ulice>Horní námìstí</ulice>
<prijmeni>ŠCheckCharsá</prijmeni>
</pvpoj>
--------------iOaeSk0jVHjMucH3kQFwS1LB--