~sircmpwn/aerc

add mimeType to OriginalMail struct for both forward and reply v1 PROPOSED

Add the mimeType to the OriginalMail struct, when writing the patch I also
found a bug in a related function and fixed that

Reto Brunner (2):
  FindFirstNonMultipart: return the proper path
  add mimeType to OriginalMail struct for both forward and reply

 commands/msg/forward.go  |  4 ++++
 commands/msg/reply.go    | 29 ++++++++++++++++++-----------
 lib/structure_helpers.go |  2 +-
 3 files changed, 23 insertions(+), 12 deletions(-)

-- 
2.30.1
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/20628/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH 1/2] FindFirstNonMultipart: return the proper path Export this patch

There was a bug that lead to the wrong path being returned by the function.
---
 lib/structure_helpers.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/structure_helpers.go b/lib/structure_helpers.go
index 21159a2..4abf304 100644
--- a/lib/structure_helpers.go
+++ b/lib/structure_helpers.go
@@ -27,7 +27,7 @@ func FindFirstNonMultipart(bs *models.BodyStructure, path []int) []int {
		cur := append(path, i+1)
		mimetype := strings.ToLower(part.MIMEType)
		if mimetype != "multipart" {
			return path
			return cur
		} else if mimetype == "multipart" {
			if path := FindFirstNonMultipart(part, cur); path != nil {
				return path
-- 
2.30.1

[PATCH 2/2] add mimeType to OriginalMail struct for both forward and reply Export this patch

---
 commands/msg/forward.go |  4 ++++
 commands/msg/reply.go   | 29 ++++++++++++++++++-----------
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index edade6d..ec89bfa 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -147,6 +147,10 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
			part = lib.FindFirstNonMultipart(msg.BodyStructure, nil)
			// 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) {
			buf := new(bytes.Buffer)
			buf.ReadFrom(reader)
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 778c0ef..2e4a21a 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -207,21 +207,16 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
			// broken (containers only)
			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) {
			buf := new(bytes.Buffer)
			buf.ReadFrom(reader)
			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()
		})
		return nil
@@ -275,3 +270,15 @@ func setReferencesHeader(target, parent *mail.Header) error {
	target.SetMsgIDList("references", refs)
	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
}
-- 
2.30.1