~sircmpwn/aerc

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
5 2

[PATCH] Parse headers from template

Details
Message ID
<20191125123925.10626-1-r@gnzler.io>
DKIM signature
missing
Download raw message
Patch: +39 -3
Parse the processed template for headers and populates matching header
editors accordingly.
Those are then stripped from the template body before prepending it
and remaining header fields to the composer content.

The motivation for this is keeping receiver, sender and subject
lines in the template file and generating the message subject with the
date functions.
---
 widgets/compose.go | 42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/widgets/compose.go b/widgets/compose.go
index 62aaafe..6e527cb 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -179,8 +179,7 @@ func (c *Composer) AddTemplate(template string, data interface{}) error {
	if err != nil {
		return err
	}
	c.PrependContents(bytes.NewReader(templateText))
	return nil
	return c.addTemplate(bytes.NewReader(templateText))
}

func (c *Composer) AddTemplateFromString(template string, data interface{}) error {
@@ -192,7 +191,44 @@ func (c *Composer) AddTemplateFromString(template string, data interface{}) erro
	if err != nil {
		return err
	}
	c.PrependContents(bytes.NewReader(templateText))
	return c.addTemplate(bytes.NewReader(templateText))
}

func (c *Composer) addTemplate(tmpl io.Reader) error {
	reader, err := mail.CreateReader(tmpl)
	if err != nil {
		return errors.Wrap(err, "mail.CreateReader")
	}
	defer reader.Close()

	// populate header editors
	header := reader.Header
	mhdr := (*message.Header)(&header.Header)
	for _, editor := range c.editors {
		if mhdr.Has(editor.name) {
			editor.input.Set(mhdr.Get(editor.name))
			mhdr.Del(editor.name)
		}
	}

	part, err := reader.NextPart()
	if err != nil {
		return errors.Wrap(err, "reader.NextPart")
	}
	c.PrependContents(part.Body)

	var (
		headers string
		fds     = mhdr.Fields()
	)
	for fds.Next() {
		headers += fmt.Sprintf("%s: %s\n", fds.Key(), fds.Value())
	}
	if headers != "" {
		headers += "\n"
	}

	c.PrependContents(bytes.NewReader([]byte(headers)))
	return nil
}

-- 
2.23.0
Details
Message ID
<BYP4ZPFQ7QQ9.1MC5NRVRLY26S@homura>
In-Reply-To
<20191125123925.10626-1-r@gnzler.io> (view parent)
DKIM signature
missing
Download raw message
On Mon Nov 25, 2019 at 1:39 PM, Robert Günzler wrote:
> The motivation for this is keeping receiver, sender and subject
> lines in the template file and generating the message subject with the
> date functions.

I'm not sure I understand. Can you explain your use-case in more detail?
Robert Guenzler
Details
Message ID
<BYPZCE57HMEI.3GP2P4M5N321E@hibiki>
In-Reply-To
<BYP4ZPFQ7QQ9.1MC5NRVRLY26S@homura> (view parent)
DKIM signature
missing
Download raw message
On Mon Nov 25, 2019 at 12:00 PM, Drew DeVault wrote:
> On Mon Nov 25, 2019 at 1:39 PM, Robert Günzler wrote:
> > The motivation for this is keeping receiver, sender and subject
> > lines in the template file and generating the message subject with the
> > date functions.
>
> 
> I'm not sure I understand. Can you explain your use-case in more detail?
>
> 
I basically have a template for an email I'm sending monthly like this:

```
From: Robert <r+finance@gnzler.io>
Subject: Invoice for {{dateFormat .Date "January 2006"}}
To: client@exmaple.com

Hello,

this message has the invoice for {{dateFormat .Date "January 2006"}} attached.

Best regards,
Robert
```

I am trying to get rid of Thunderbird where templates contain the
message headers... I use them as blueprints for mail that I often send
to specific contacts.
Details
Message ID
<BYPZV0KWDI4Y.J8PEIFG5EQD4@homura>
In-Reply-To
<BYPZCE57HMEI.3GP2P4M5N321E@hibiki> (view parent)
DKIM signature
missing
Download raw message
Aha, that makes sense. Thanks for clarifying, I'll have this patch
reviewed shortly.
Details
Message ID
<BYWPP2PLNBDJ.27EGW2TJ5XJC0@homura>
In-Reply-To
<BYPZCE57HMEI.3GP2P4M5N321E@hibiki> (view parent)
DKIM signature
missing
Download raw message
Thanks!

To git.sr.ht:~sircmpwn/aerc
   c1d5797..31e3e9f  master -> master
Details
Message ID
<BYWPVCB0B0PM.414BYGJ4UOAG@homura>
In-Reply-To
<BYPZCE57HMEI.3GP2P4M5N321E@hibiki> (view parent)
DKIM signature
missing
Download raw message
Whoops, I had to revert this. :reply -q fails with this patch, because
it tries to interpret the message body as headers.
Reply to thread Export thread (mbox)