Set deterministic message boundary

This avoids multiple message fetches from returning a different
boundary.

Closes: https://github.com/emersion/hydroxide/issues/131
This commit is contained in:
Simon Ser 2021-01-06 11:33:17 +01:00
parent f06444c165
commit edc8a078b9
1 changed files with 11 additions and 2 deletions

View File

@ -2,6 +2,8 @@ package imap
import ( import (
"bytes" "bytes"
"crypto/sha1"
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -80,6 +82,11 @@ func fetchEnvelope(msg *protonmail.Message) *imap.Envelope {
} }
} }
func msgBoundary(msg *protonmail.Message) string {
h := sha1.Sum([]byte(msg.ID))
return hex.EncodeToString(h[:])
}
func hasLabel(msg *protonmail.Message, labelID string) bool { func hasLabel(msg *protonmail.Message, labelID string) bool {
for _, id := range msg.LabelIDs { for _, id := range msg.LabelIDs {
if labelID == id { if labelID == id {
@ -139,7 +146,7 @@ func (mbox *mailbox) fetchBodyStructure(msg *protonmail.Message, extended bool)
return &imap.BodyStructure{ return &imap.BodyStructure{
MIMEType: "multipart", MIMEType: "multipart",
MIMESubType: "mixed", MIMESubType: "mixed",
// TODO: Params: map[string]string{"boundary": ...}, Params: map[string]string{"boundary": msgBoundary(msg)},
// TODO: Size // TODO: Size
Parts: parts, Parts: parts,
Extended: extended, Extended: extended,
@ -209,8 +216,10 @@ func mailAddressList(addresses []*protonmail.MessageAddress) []*mail.Address {
} }
func messageHeader(msg *protonmail.Message) message.Header { func messageHeader(msg *protonmail.Message) message.Header {
typeParams := map[string]string{"boundary": msgBoundary(msg)}
var h mail.Header var h mail.Header
h.SetContentType("multipart/mixed", nil) h.SetContentType("multipart/mixed", typeParams)
h.SetDate(msg.Time.Time()) h.SetDate(msg.Time.Time())
h.SetSubject(msg.Subject) h.SetSubject(msg.Subject)
h.SetAddressList("From", []*mail.Address{mailAddress(msg.Sender)}) h.SetAddressList("From", []*mail.Address{mailAddress(msg.Sender)})