-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Content-Transfer-Encoding=quoted-printable
- Loading branch information
Showing
10 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |