Skip to content

Commit

Permalink
Add support for Content-Transfer-Encoding=quoted-printable
Browse files Browse the repository at this point in the history
  • Loading branch information
mjarkk committed Jul 28, 2024
1 parent bc73cfa commit 5c0bb73
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dist/assets/Code-DbhFbLet.js → dist/assets/Code-1S_lVFgV.js

Large diffs are not rendered by default.

File renamed without changes.
2 changes: 0 additions & 2 deletions dist/assets/Show-DNYecVsq.js

This file was deleted.

7 changes: 7 additions & 0 deletions dist/assets/Show-pm1-B8_e.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dist/assets/index-DM5YycMT.js

This file was deleted.

File renamed without changes.
7 changes: 7 additions & 0 deletions dist/assets/index-brl1C-fK.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
color: white;
}
</style>
<script type="module" crossorigin src="/assets/index-DM5YycMT.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CygxqtQR.css">
<script type="module" crossorigin src="/assets/index-brl1C-fK.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-WeMh_2BT.css">
</head>
<body>
<div id="root"></div>
Expand Down
4 changes: 4 additions & 0 deletions go/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func ConvertEmail(ulid ulid.ULID, emlRawData []byte, em parsemail.Email, realDat
bodyHint = bodyHint[:100] + "..."
}

if em.Header.Get("Content-Transfer-Encoding") == "quoted-printable" {
em.HTMLBody = sanitize.ConvertQoutedPrintable(em.HTMLBody)
}

htmlBody, err := sanitize.Parse(em.HTMLBody)
if err != nil {
return Email{}, err
Expand Down
63 changes: 63 additions & 0 deletions go/sanitize/quoted_printable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package sanitize

import (
"encoding/hex"
"fmt"
)

func isHexUpper(c byte) bool {
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')
}

func ConvertQoutedPrintable(s string) string {
idx := 0
resp := []byte{}
var err error
hexInput := []byte{0, 0}

for {
if idx >= len(s) {
break
}

c := s[idx]
if c != '=' {
resp = append(resp, c)
idx++
continue
}

if idx+2 >= len(s) {
resp = append(resp, c)
idx++
continue
}

hexInput[0] = s[idx+1]
hexInput[1] = s[idx+2]

if hexInput[0] == '\r' && hexInput[1] == '\n' {
idx += 3
continue
}

if !isHexUpper(hexInput[0]) || !isHexUpper(hexInput[1]) {
resp = append(resp, c)
idx++
continue
}

resp, err = hex.AppendDecode(resp, hexInput)
if err != nil {
fmt.Printf("DECODEING ERROR, Failed to decode %s to a byte: %s", string(hexInput), err)
resp = append(resp, c)
idx++
continue
}

idx += 3
continue
}

return string(resp)
}

0 comments on commit 5c0bb73

Please sign in to comment.