mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
GODT-1261: Fix building messages with long key
This commit is contained in:
@ -494,7 +494,10 @@ func toMessageHeader(hdr mail.Header) message.Header {
|
||||
|
||||
for key, val := range hdr {
|
||||
for _, val := range val {
|
||||
res.Add(key, val)
|
||||
// Using AddRaw instead of Add to save key-value pair as byte buffer within Header.
|
||||
// This buffer is used latter on in message writer to construct message and avoid crash
|
||||
// when key length is more than 76 characters long.
|
||||
res.AddRaw([]byte(key + ": " + val + "\r\n"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -52,6 +52,27 @@ func TestBuildPlainMessage(t *testing.T) {
|
||||
expectTransferEncoding(is(`quoted-printable`))
|
||||
}
|
||||
|
||||
func TestBuildPlainMessageWithLongKey(t *testing.T) {
|
||||
m := gomock.NewController(t)
|
||||
defer m.Finish()
|
||||
|
||||
b := NewBuilder(1, 1, 1)
|
||||
defer b.Done()
|
||||
|
||||
kr := tests.MakeKeyRing(t)
|
||||
msg := newTestMessage(t, kr, "messageID", "addressID", "text/plain", "body", time.Now())
|
||||
msg.Header["ReallyVeryVeryVeryVeryVeryLongLongLongLongLongLongLongKeyThatWillHaveNotSoLongValue"] = []string{"value"}
|
||||
|
||||
res, err := b.NewJob(context.Background(), newTestFetcher(m, kr, msg), msg.ID).GetResult()
|
||||
require.NoError(t, err)
|
||||
|
||||
section(t, res).
|
||||
expectContentType(is(`text/plain`)).
|
||||
expectBody(is(`body`)).
|
||||
expectTransferEncoding(is(`quoted-printable`)).
|
||||
expectHeader(`ReallyVeryVeryVeryVeryVeryLongLongLongLongLongLongLongKeyThatWillHaveNotSoLongValue`, is(`value`))
|
||||
}
|
||||
|
||||
func TestBuildHTMLMessage(t *testing.T) {
|
||||
m := gomock.NewController(t)
|
||||
defer m.Finish()
|
||||
|
||||
Reference in New Issue
Block a user