Commit ebe6fc8 1 parent f7e2be8 commit ebe6fc8 Copy full SHA for ebe6fc8
File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package message
3
3
import (
4
4
"mime"
5
5
"net/textproto"
6
+ "regexp"
6
7
"strings"
7
8
8
9
"github.com/emersion/go-message/charset"
@@ -40,6 +41,8 @@ func formatHeaderField(k, v string) string {
40
41
return s + "\r \n "
41
42
}
42
43
44
+ qpReg := regexp .MustCompile ("(=[0-9A-Z]{2,2})+" )
45
+
43
46
first := true
44
47
for len (v ) > 0 {
45
48
maxlen := maxHeaderLen
@@ -60,7 +63,13 @@ func formatHeaderField(k, v string) string {
60
63
}
61
64
} else {
62
65
// Find the closest whitespace before i
63
- foldAt = strings .LastIndexAny (v [:foldBefore ], " \t \n " )
66
+ foldAtQP := qpReg .FindAllStringIndex (v [:foldBefore ], - 1 )
67
+ foldAtEOL := strings .LastIndexAny (v [:foldBefore ], " \t \n " )
68
+ if len (foldAtQP ) > 0 {
69
+ foldAt = foldAtQP [len (foldAtQP )- 1 ][0 ]
70
+ } else {
71
+ foldAt = foldAtEOL
72
+ }
64
73
if foldAt == 0 {
65
74
// The whitespace we found was the previous folding WSP
66
75
foldAt = foldBefore - 1
Original file line number Diff line number Diff line change @@ -59,6 +59,11 @@ var formatHeaderFieldTests = []struct {
59
59
v : "This is yet \t another subject \t with many whitespace characters" ,
60
60
formatted : "Subject: This is yet \t another subject \t \r \n with many whitespace characters\r \n " ,
61
61
},
62
+ {
63
+ k : "Subject" ,
64
+ v : "=?utf-8?q?=E2=80=9CDeveloper_reads_customer_requested_change.=E2=80=9D=0A?= =?utf-8?q?=0ACaravaggio=0A=0AOil_on...?=" ,
65
+ formatted : "Subject: =?utf-8?q?=E2=80=9CDeveloper_reads_customer_requested_change.\r \n =E2=80=9D=0A?= =?utf-8?q?=0ACaravaggio=0A=0AOil_on...?=\r \n " ,
66
+ },
62
67
{
63
68
k : "DKIM-Signature" ,
64
69
v : "v=1;\r \n h=From:To:Reply-To:Subject:Message-ID:References:In-Reply-To:MIME-Version;\r \n d=example.org\r \n " ,
You can’t perform that action at this time.
0 commit comments