Skip to content

Commit 5c0bb73

Browse files
committed
Add support for Content-Transfer-Encoding=quoted-printable
1 parent bc73cfa commit 5c0bb73

10 files changed

+85
-7
lines changed

dist/assets/Code-DbhFbLet.js renamed to dist/assets/Code-1S_lVFgV.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

dist/assets/Show-DNYecVsq.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

dist/assets/Show-pm1-B8_e.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assets/index-DM5YycMT.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

dist/assets/index-brl1C-fK.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
color: white;
1515
}
1616
</style>
17-
<script type="module" crossorigin src="/assets/index-DM5YycMT.js"></script>
18-
<link rel="stylesheet" crossorigin href="/assets/index-CygxqtQR.css">
17+
<script type="module" crossorigin src="/assets/index-brl1C-fK.js"></script>
18+
<link rel="stylesheet" crossorigin href="/assets/index-WeMh_2BT.css">
1919
</head>
2020
<body>
2121
<div id="root"></div>

go/email.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ func ConvertEmail(ulid ulid.ULID, emlRawData []byte, em parsemail.Email, realDat
144144
bodyHint = bodyHint[:100] + "..."
145145
}
146146

147+
if em.Header.Get("Content-Transfer-Encoding") == "quoted-printable" {
148+
em.HTMLBody = sanitize.ConvertQoutedPrintable(em.HTMLBody)
149+
}
150+
147151
htmlBody, err := sanitize.Parse(em.HTMLBody)
148152
if err != nil {
149153
return Email{}, err

go/sanitize/quoted_printable.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package sanitize
2+
3+
import (
4+
"encoding/hex"
5+
"fmt"
6+
)
7+
8+
func isHexUpper(c byte) bool {
9+
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')
10+
}
11+
12+
func ConvertQoutedPrintable(s string) string {
13+
idx := 0
14+
resp := []byte{}
15+
var err error
16+
hexInput := []byte{0, 0}
17+
18+
for {
19+
if idx >= len(s) {
20+
break
21+
}
22+
23+
c := s[idx]
24+
if c != '=' {
25+
resp = append(resp, c)
26+
idx++
27+
continue
28+
}
29+
30+
if idx+2 >= len(s) {
31+
resp = append(resp, c)
32+
idx++
33+
continue
34+
}
35+
36+
hexInput[0] = s[idx+1]
37+
hexInput[1] = s[idx+2]
38+
39+
if hexInput[0] == '\r' && hexInput[1] == '\n' {
40+
idx += 3
41+
continue
42+
}
43+
44+
if !isHexUpper(hexInput[0]) || !isHexUpper(hexInput[1]) {
45+
resp = append(resp, c)
46+
idx++
47+
continue
48+
}
49+
50+
resp, err = hex.AppendDecode(resp, hexInput)
51+
if err != nil {
52+
fmt.Printf("DECODEING ERROR, Failed to decode %s to a byte: %s", string(hexInput), err)
53+
resp = append(resp, c)
54+
idx++
55+
continue
56+
}
57+
58+
idx += 3
59+
continue
60+
}
61+
62+
return string(resp)
63+
}

0 commit comments

Comments
 (0)