imports: wrap inline part in multipart message

Apparently the ProtonMail API no longer accepts non-multipart messages
when importing. This fixes the error:

    [36027] Imported message is not fully encrypted
This commit is contained in:
Simon Ser 2020-12-17 14:28:19 +01:00
parent 7b6061868f
commit fe98e9c3ac
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
1 changed files with 17 additions and 2 deletions

View File

@ -81,13 +81,25 @@ func ImportMessage(c *protonmail.Client, r io.Reader) error {
return err
}
mwc, err := mail.CreateSingleInlineWriter(w, hdr)
var ihdr mail.InlineHeader
ihdr.Set("Content-Type", hdr.Get("Content-Type"))
ihdr.Set("Content-Transfer-Encoding", "8bit")
hdr.Del("Content-Type")
hdr.Del("Content-Transfer-Encoding")
hdr.Del("Content-Disposition")
mwc, err := mail.CreateWriter(w, hdr)
if err != nil {
return err
}
defer mwc.Close()
awc, err := armor.Encode(mwc, "PGP MESSAGE", nil)
iwc, err := mwc.CreateSingleInline(ihdr)
if err != nil {
return err
}
awc, err := armor.Encode(iwc, "PGP MESSAGE", nil)
if err != nil {
return err
}
@ -107,6 +119,9 @@ func ImportMessage(c *protonmail.Client, r io.Reader) error {
if err := awc.Close(); err != nil {
return err
}
if err := iwc.Close(); err != nil {
return err
}
if err := mwc.Close(); err != nil {
return err
}