about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--commands/msg/reply.go11
-rw-r--r--doc/aerc-templates.7.scd6
-rw-r--r--lib/templates/template.go33
-rw-r--r--models/models.go7
4 files changed, 39 insertions, 18 deletions
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 2964a83..3c69e27 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -157,6 +157,17 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
 			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
diff --git a/doc/aerc-templates.7.scd b/doc/aerc-templates.7.scd
index 3c8b123..9382f2e 100644
--- a/doc/aerc-templates.7.scd
+++ b/doc/aerc-templates.7.scd
@@ -60,6 +60,12 @@ available always.
 	Example:
 	{{.Subject}}
 
+*MIME Type*
+	MIME Type is available for quoted reply.
+
+	- OriginalMIMEType: MIME type info of quoted mail part. Usually
+	  "text/plain" or "text/html".
+
 *Original Message*
 	When using quoted reply or forward, the original message is available.
 	It can be used using two functions that are available to templates.
diff --git a/lib/templates/template.go b/lib/templates/template.go
index 8a345d9..6eae5a2 100644
--- a/lib/templates/template.go
+++ b/lib/templates/template.go
@@ -22,9 +22,10 @@ type TemplateData struct {
 	Date    time.Time
 	Subject string
 	// Only available when replying with a quote
-	OriginalText string
-	OriginalFrom []*mail.Address
-	OriginalDate time.Time
+	OriginalText     string
+	OriginalFrom     []*mail.Address
+	OriginalDate     time.Time
+	OriginalMIMEType string
 }
 
 func TestTemplateData() TemplateData {
@@ -36,9 +37,10 @@ func TestTemplateData() TemplateData {
 	}
 
 	original := models.OriginalMail{
-		Date: time.Now().Format("Mon Jan 2, 2006 at 3:04 PM"),
-		From: "John Doe <john@example.com>",
-		Text: "This is only a test text",
+		Date:     time.Now().Format("Mon Jan 2, 2006 at 3:04 PM"),
+		From:     "John Doe <john@example.com>",
+		Text:     "This is only a test text",
+		MIMEType: "text/plain",
 	}
 
 	return ParseTemplateData(defaults, original)
@@ -47,15 +49,16 @@ func TestTemplateData() TemplateData {
 func ParseTemplateData(defaults map[string]string, original models.OriginalMail) TemplateData {
 	originalDate, _ := time.Parse("Mon Jan 2, 2006 at 3:04 PM", original.Date)
 	td := TemplateData{
-		To:           parseAddressList(defaults["To"]),
-		Cc:           parseAddressList(defaults["Cc"]),
-		Bcc:          parseAddressList(defaults["Bcc"]),
-		From:         parseAddressList(defaults["From"]),
-		Date:         time.Now(),
-		Subject:      defaults["Subject"],
-		OriginalText: original.Text,
-		OriginalFrom: parseAddressList(original.From),
-		OriginalDate: originalDate,
+		To:               parseAddressList(defaults["To"]),
+		Cc:               parseAddressList(defaults["Cc"]),
+		Bcc:              parseAddressList(defaults["Bcc"]),
+		From:             parseAddressList(defaults["From"]),
+		Date:             time.Now(),
+		Subject:          defaults["Subject"],
+		OriginalText:     original.Text,
+		OriginalFrom:     parseAddressList(original.From),
+		OriginalDate:     originalDate,
+		OriginalMIMEType: original.MIMEType,
 	}
 	return td
 }
diff --git a/models/models.go b/models/models.go
index 7c3c192..8d254a1 100644
--- a/models/models.go
+++ b/models/models.go
@@ -167,7 +167,8 @@ func FormatAddresses(addrs []*Address) string {
 
 // OriginalMail is helper struct used for reply/forward
 type OriginalMail struct {
-	Date string
-	From string
-	Text string
+	Date     string
+	From     string
+	Text     string
+	MIMEType string
 }