add mimeType to OriginalMail struct for both forward and reply

This commit is contained in:
Reto Brunner 2021-02-26 22:08:49 +01:00
parent f74605793e
commit 413fc431f7
3 changed files with 23 additions and 12 deletions

View file

@ -147,6 +147,10 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
part = lib.FindFirstNonMultipart(msg.BodyStructure, nil) part = lib.FindFirstNonMultipart(msg.BodyStructure, nil)
// if it's still nil here, we don't have a multipart msg, that's fine // if it's still nil here, we don't have a multipart msg, that's fine
} }
err = addMimeType(msg, part, &original)
if err != nil {
return err
}
store.FetchBodyPart(msg.Uid, part, func(reader io.Reader) { store.FetchBodyPart(msg.Uid, part, func(reader io.Reader) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
buf.ReadFrom(reader) buf.ReadFrom(reader)

View file

@ -207,21 +207,16 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
// broken (containers only) // broken (containers only)
part = lib.FindFirstNonMultipart(msg.BodyStructure, nil) part = lib.FindFirstNonMultipart(msg.BodyStructure, nil)
} }
err = addMimeType(msg, part, &original)
if err != nil {
return err
}
store.FetchBodyPart(msg.Uid, part, func(reader io.Reader) { store.FetchBodyPart(msg.Uid, part, func(reader io.Reader) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
buf.ReadFrom(reader) buf.ReadFrom(reader)
original.Text = buf.String() original.Text = buf.String()
if len(msg.BodyStructure.Parts) == 0 {
original.MIMEType = fmt.Sprintf("%s/%s",
msg.BodyStructure.MIMEType, msg.BodyStructure.MIMESubType)
} else {
// TODO: still will be "multipart/mixed" for mixed mails with
// attachments, fix this after aerc could handle responding to
// such mails
original.MIMEType = fmt.Sprintf("%s/%s",
msg.BodyStructure.Parts[0].MIMEType,
msg.BodyStructure.Parts[0].MIMESubType)
}
addTab() addTab()
}) })
return nil return nil
@ -275,3 +270,15 @@ func setReferencesHeader(target, parent *mail.Header) error {
target.SetMsgIDList("references", refs) target.SetMsgIDList("references", refs)
return nil return nil
} }
// addMimeType adds the proper mime type of the part to the originalMail struct
func addMimeType(msg *models.MessageInfo, part []int,
orig *models.OriginalMail) error {
// caution, :forward uses the code as well, keep that in mind when modifying
bs, err := msg.BodyStructure.PartAtIndex(part)
if err != nil {
return err
}
orig.MIMEType = fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType)
return nil
}

View file

@ -71,7 +71,7 @@ available always.
{{.Subject}} {{.Subject}}
*MIME Type* *MIME Type*
MIME Type is available for quoted reply. MIME Type is available for quoted reply and forward.
- OriginalMIMEType: MIME type info of quoted mail part. Usually - OriginalMIMEType: MIME type info of quoted mail part. Usually
"text/plain" or "text/html". "text/plain" or "text/html".