~sircmpwn/aerc

Fix dates in reply/forward commands. v1 PROPOSED

Reto Brunner: 1
 Fix dates in reply/forward commands.

 4 files changed, 5 insertions(+), 6 deletions(-)
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/11341/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Fix dates in reply/forward commands. Export this patch

The data was passed around as a string for some reason, which led to time
precision loss and wrong dates being displayed.
Simply pass the time as is to fix that.
---
 commands/msg/forward.go   | 2 +-
 commands/msg/reply.go     | 2 +-
 lib/templates/template.go | 5 ++---
 models/models.go          | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index 28abbed..5f4da5c 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -77,7 +77,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
	addTab := func() (*widgets.Composer, error) {
		if template != "" {
			original.From = models.FormatAddresses(msg.Envelope.From)
			original.Date = msg.Envelope.Date.Format("Mon Jan 2, 2006 at 3:04 PM")
			original.Date = msg.Envelope.Date
		}

		composer, err := widgets.NewComposer(aerc, acct, aerc.Config(), acct.AccountConfig(),
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 28ce245..1deab31 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -133,7 +133,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
	addTab := func() error {
		if template != "" {
			original.From = models.FormatAddresses(msg.Envelope.From)
			original.Date = msg.Envelope.Date.Format("Mon Jan 2, 2006 at 3:04 PM")
			original.Date = msg.Envelope.Date
		}

		composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
diff --git a/lib/templates/template.go b/lib/templates/template.go
index d16ac1f..4346111 100644
--- a/lib/templates/template.go
+++ b/lib/templates/template.go
@@ -46,7 +46,7 @@ func TestTemplateData() TemplateData {
	}

	original := models.OriginalMail{
		Date:     time.Now().Format("Mon Jan 2, 2006 at 3:04 PM"),
		Date:     time.Now(),
		From:     "John Doe <john@example.com>",
		Text:     "This is only a test text",
		MIMEType: "text/plain",
@@ -56,7 +56,6 @@ 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"]),
@@ -66,7 +65,7 @@ func ParseTemplateData(defaults map[string]string, original models.OriginalMail)
		Subject:          defaults["Subject"],
		OriginalText:     original.Text,
		OriginalFrom:     parseAddressList(original.From),
		OriginalDate:     originalDate,
		OriginalDate:     original.Date,
		OriginalMIMEType: original.MIMEType,
	}
	return td
diff --git a/models/models.go b/models/models.go
index 7654cf0..d61b774 100644
--- a/models/models.go
+++ b/models/models.go
@@ -170,7 +170,7 @@ func FormatAddresses(addrs []*Address) string {

// OriginalMail is helper struct used for reply/forward
type OriginalMail struct {
	Date     string
	Date     time.Time
	From     string
	Text     string
	MIMEType string
-- 
2.27.0
Confirmed to fix the problem by the issue reporter in #417
Merged to master.