While reading joost's PR for the aliases I got fed up with the reply code...
It treated addresses as strings which got messy after a while.
This patch series tries to clean this up.
As an added bonus, the bug mentioned by joost regarding the duplication of the
from address in the CC header was addressed as well.
@joost: Considering that I heavily modified your patch, but still kept your name
as the author, mind giving a review?
If you prefer I can change the author to be me as well.
Opinions of anyone else are of course appreciated as well.
Reto Brunner (3):
base models.Address on the mail.Address type
msg/reply: handle addresses as addresses
msg/reply: don't cc the sending address on reply all
y0ast (1):
Add account alias configuration and correctly set From field
commands/msg/forward.go | 3 +-
commands/msg/reply.go | 73 +++++++++++++++++++++++++++--------------
config/config.go | 3 ++
doc/aerc-config.5.scd | 7 ++++
lib/format/format.go | 50 +++++++++++++++++++++-------
models/models.go | 34 ++++++-------------
widgets/msgviewer.go | 15 +++++----
worker/imap/imap.go | 3 +-
worker/lib/parse.go | 11 +------
worker/lib/sort.go | 3 +-
10 files changed, 119 insertions(+), 83 deletions(-)
--
2.28.0
[PATCH 1/4] base models.Address on the mail.Address type
From: y0ast <joost@joo.st>
We infer the correct From using the To: and Cc: field of the email that
we reply to.
---
commands/msg/reply.go | 25 ++++++++++++++++++++++++-config/config.go | 3 +++doc/aerc-config.5.scd | 7 +++++++
3 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 2ab12a7..c2cd6a7 100644
--- a/commands/msg/reply.go+++ b/commands/msg/reply.go
@@ -69,6 +69,10 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
} else {
from = fa[0]
}
+ alias_of_us, err := format.ParseAddressList(conf.Aliases)+ if err != nil {+ return err+ } store := widget.Store()
if store == nil {
return errors.New("Cannot perform action. Messages still loading")
@@ -77,7 +81,6 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
if err != nil {
return err
}
- acct.Logger().Println("Replying to email " + msg.Envelope.MessageId) var (
to []*models.Address
@@ -89,6 +92,25 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
} else {
to = msg.Envelope.From
}
++ // figure out the sending from address if we have aliases+ if len(alias_of_us) != 0 {+ allRecipients := append(msg.Envelope.To, msg.Envelope.Cc...)+ for _, addr := range allRecipients {+ if addr.Address == from.Address {+ from = addr+ break+ }+ for _, alias := range alias_of_us {+ if addr.Address == alias.Address {+ from = addr+ break+ }+ }+ }++ }+ isMainRecipient := func(a *models.Address) bool {
for _, ta := range to {
if ta.Address == a.Address {
@@ -126,6 +148,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
defaults := map[string]string{
"To": format.FormatAddresses(to),
"Cc": format.FormatAddresses(cc),
+ "From": from.Format(), "Subject": subject,
"In-Reply-To": msg.Envelope.MessageId,
}
diff --git a/config/config.go b/config/config.go
index 12096ba..3ae26c1 100644
--- a/config/config.go+++ b/config/config.go
@@ -75,6 +75,7 @@ type AccountConfig struct {
Default string
Postpone string
From string
+ Aliases string Name string
Source string
SourceCredCmd string
@@ -202,6 +203,8 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
account.OutgoingCredCmd = val
} else if key == "from" {
account.From = val
+ } else if key == "aliases" {+ account.Aliases = val } else if key == "copy-to" {
account.CopyTo = val
} else if key == "archive" {
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index fcd70ec..64a0998 100644
--- a/doc/aerc-config.5.scd+++ b/doc/aerc-config.5.scd
@@ -409,6 +409,13 @@ Note that many of these configuration options are written for you, such as
Default: none
+*aliases*+ All aliases of the current account. These will be used to fill in the From:+ field. Make sure that your email server accepts this value, or for example+ use *aerc-sendmail*(5) in combination with msmtp and --read-envelope-from.++ Default: none+*outgoing*
Specifies the transport for sending outgoing emails on this account. It
should be a connection string, and the specific meaning of each component
--
2.28.0
[PATCH 4/4] msg/reply: don't cc the sending address on reply all
On Thu Aug 20, 2020 at 10:45 AM BST, Reto Brunner wrote:
> This simplifies the code considerably and makes it easier to follow> ---> commands/msg/reply.go | 48 +++++++++++++++++++++----------------------> 1 file changed, 24 insertions(+), 24 deletions(-)>> diff --git a/commands/msg/reply.go b/commands/msg/reply.go> index 6fd6141..2ab12a7 100644> --- a/commands/msg/reply.go> +++ b/commands/msg/reply.go> @@ -5,12 +5,12 @@ import (> "errors"> "fmt"> "io"> - gomail "net/mail"> "strings"> > "git.sr.ht/~sircmpwn/getopt"> > "git.sr.ht/~sircmpwn/aerc/lib"> + "git.sr.ht/~sircmpwn/aerc/lib/format"> "git.sr.ht/~sircmpwn/aerc/models"> "git.sr.ht/~sircmpwn/aerc/widgets"> )> @@ -60,7 +60,15 @@ func (reply) Execute(aerc *widgets.Aerc, args> []string) error {> return errors.New("No account selected")> }> conf := acct.AccountConfig()> - us, _ := gomail.ParseAddress(conf.From)> + var from *models.Address> + fa, err := format.ParseAddressList(conf.From)
Why not use format.parseAddress? Can the from field ever be a list (if
so, you can ignore this comment)? You can skip the third else condition below then too.
Re: [PATCH 3/4] Add account alias configuration and correctly set From field