fix cc handling
This commit is contained in:
31
bot/email.go
31
bot/email.go
@@ -188,7 +188,7 @@ func (b *Bot) SendEmailReply(ctx context.Context) {
|
|||||||
|
|
||||||
var queued bool
|
var queued bool
|
||||||
var hasErr bool
|
var hasErr bool
|
||||||
recipients := meta.Recipients()
|
recipients := meta.Recipients
|
||||||
for _, to := range recipients {
|
for _, to := range recipients {
|
||||||
queued, err = b.Sendmail(evt.ID, meta.From, to, data)
|
queued, err = b.Sendmail(evt.ID, meta.From, to, data)
|
||||||
if queued {
|
if queued {
|
||||||
@@ -221,6 +221,7 @@ type parentEmail struct {
|
|||||||
InReplyTo string
|
InReplyTo string
|
||||||
References string
|
References string
|
||||||
Subject string
|
Subject string
|
||||||
|
Recipients []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// fixtofrom attempts to "fix" or rather reverse the To, From and CC headers
|
// fixtofrom attempts to "fix" or rather reverse the To, From and CC headers
|
||||||
@@ -228,7 +229,7 @@ type parentEmail struct {
|
|||||||
// that will be sent from postmoogle.
|
// that will be sent from postmoogle.
|
||||||
// To do so, we need to reverse From and To headers, but Cc should be adjusted as well,
|
// To do so, we need to reverse From and To headers, but Cc should be adjusted as well,
|
||||||
// thus that hacky workaround below:
|
// thus that hacky workaround below:
|
||||||
func (e *parentEmail) fixtofrom(newSenderMailbox string, domains []string) {
|
func (e *parentEmail) fixtofrom(newSenderMailbox string, domains []string) string {
|
||||||
newSenders := make(map[string]string, len(domains))
|
newSenders := make(map[string]string, len(domains))
|
||||||
for _, domain := range domains {
|
for _, domain := range domains {
|
||||||
sender := newSenderMailbox + "@" + domain
|
sender := newSenderMailbox + "@" + domain
|
||||||
@@ -270,11 +271,28 @@ func (e *parentEmail) fixtofrom(newSenderMailbox string, domains []string) {
|
|||||||
e.CC = strings.ReplaceAll(e.CC, newSender, originalFrom)
|
e.CC = strings.ReplaceAll(e.CC, newSender, originalFrom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return previousSender
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recipients returns list of recipients (to, cc)
|
func (e *parentEmail) calculateRecipients(from string) {
|
||||||
func (e parentEmail) Recipients() []string {
|
recipients := map[string]struct{}{}
|
||||||
return append(email.AddressList(e.CC), strings.Split(email.Address(e.To), ",")...)
|
recipients[e.From] = struct{}{}
|
||||||
|
|
||||||
|
for _, addr := range strings.Split(email.Address(e.To), ",") {
|
||||||
|
recipients[addr] = struct{}{}
|
||||||
|
}
|
||||||
|
for _, addr := range email.AddressList(e.CC) {
|
||||||
|
recipients[addr] = struct{}{}
|
||||||
|
}
|
||||||
|
delete(recipients, from)
|
||||||
|
|
||||||
|
rcpts := make([]string, 0, len(recipients))
|
||||||
|
for rcpt := range recipients {
|
||||||
|
rcpts = append(rcpts, rcpt)
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Recipients = rcpts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) getParentEvent(evt *event.Event) (id.EventID, *event.Event) {
|
func (b *Bot) getParentEvent(evt *event.Event) (id.EventID, *event.Event) {
|
||||||
@@ -330,7 +348,8 @@ func (b *Bot) getParentEmail(evt *event.Event, newFromMailbox string) *parentEma
|
|||||||
parent.RcptTo = utils.EventField[string](&parentEvt.Content, eventRcptToKey)
|
parent.RcptTo = utils.EventField[string](&parentEvt.Content, eventRcptToKey)
|
||||||
parent.InReplyTo = utils.EventField[string](&parentEvt.Content, eventMessageIDkey)
|
parent.InReplyTo = utils.EventField[string](&parentEvt.Content, eventMessageIDkey)
|
||||||
parent.References = utils.EventField[string](&parentEvt.Content, eventReferencesKey)
|
parent.References = utils.EventField[string](&parentEvt.Content, eventReferencesKey)
|
||||||
parent.fixtofrom(newFromMailbox, b.domains)
|
senderEmail := parent.fixtofrom(newFromMailbox, b.domains)
|
||||||
|
parent.calculateRecipients(senderEmail)
|
||||||
parent.MessageID = email.MessageID(parentEvt.ID, parent.FromDomain)
|
parent.MessageID = email.MessageID(parentEvt.ID, parent.FromDomain)
|
||||||
if parent.InReplyTo == "" {
|
if parent.InReplyTo == "" {
|
||||||
parent.InReplyTo = parent.MessageID
|
parent.InReplyTo = parent.MessageID
|
||||||
|
|||||||
Reference in New Issue
Block a user