~sircmpwn/aerc

6a1c0f60afcbc56d11ef3a2b58f04f83fc67bf3b — y0ast 2 months ago 2a186cf
Add account alias configuration and correctly set From field

We infer the correct From using the To: and Cc: field of the email that
we reply to.
3 files changed, 34 insertions(+), 1 deletions(-)

M commands/msg/reply.go
M config/config.go
M doc/aerc-config.5.scd
M commands/msg/reply.go => commands/msg/reply.go +24 -1
@@ 64,6 64,10 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
	if err != nil {
		return err
	}
	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")


@@ 72,7 76,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


@@ 84,6 87,26 @@ 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...)
		outer:
			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 outer
					}
				}
			}

		}

		isMainRecipient := func(a *models.Address) bool {
			for _, ta := range to {
				if ta.Address == a.Address {

M config/config.go => config/config.go +3 -0
@@ 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" {

M doc/aerc-config.5.scd => doc/aerc-config.5.scd +7 -0
@@ 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