Skip to content

Commit 3e999df

Browse files
docs(gmail): add comments explaining QP decoding heuristics
1 parent 2e5a43d commit 3e999df

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

internal/cmd/gmail_thread.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,18 @@ func isQuotedPrintableEncoding(value string) bool {
510510
if value == "" {
511511
return false
512512
}
513+
// Handle potential parameters defensively, though RFC 2045 doesn't define them.
513514
if idx := strings.Index(value, ";"); idx != -1 {
514515
value = value[:idx]
515516
}
516517
return strings.EqualFold(strings.TrimSpace(value), "quoted-printable")
517518
}
518519

520+
// shouldSkipQuotedPrintable returns true when QP decoding should be skipped.
521+
// This handles emails where Content-Transfer-Encoding is declared as quoted-printable
522+
// but the body is already decoded. Applying QP decoding to such content corrupts
523+
// '=' characters (e.g., in URLs). We detect this by checking if raw is valid UTF-8
524+
// but decoded becomes invalid (indicating the decoder treated literal '=' as escapes).
519525
func shouldSkipQuotedPrintable(raw, decoded []byte, charsetLabel string) bool {
520526
if !isUTF8Charset(charsetLabel) {
521527
return false

0 commit comments

Comments
 (0)