Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12d2fee2d4 | ||
|
|
ddf2460dbd | ||
|
|
3f1fd00fb6 |
32
bot/email.go
32
bot/email.go
@@ -128,7 +128,6 @@ func (b *Bot) IncomingEmail(ctx context.Context, email *email.Email) error {
|
||||
|
||||
b.setThreadID(roomID, email.MessageID, threadID)
|
||||
b.setLastEventID(roomID, threadID, eventID)
|
||||
threadID = eventID
|
||||
|
||||
if !cfg.NoFiles() {
|
||||
b.sendFiles(ctx, roomID, email.Files, cfg.NoThreads(), threadID)
|
||||
@@ -189,7 +188,7 @@ func (b *Bot) SendEmailReply(ctx context.Context) {
|
||||
|
||||
var queued bool
|
||||
var hasErr bool
|
||||
recipients := meta.Recipients()
|
||||
recipients := meta.Recipients
|
||||
for _, to := range recipients {
|
||||
queued, err = b.Sendmail(evt.ID, meta.From, to, data)
|
||||
if queued {
|
||||
@@ -222,6 +221,7 @@ type parentEmail struct {
|
||||
InReplyTo string
|
||||
References string
|
||||
Subject string
|
||||
Recipients []string
|
||||
}
|
||||
|
||||
// fixtofrom attempts to "fix" or rather reverse the To, From and CC headers
|
||||
@@ -229,7 +229,7 @@ type parentEmail struct {
|
||||
// that will be sent from postmoogle.
|
||||
// To do so, we need to reverse From and To headers, but Cc should be adjusted as well,
|
||||
// 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))
|
||||
for _, domain := range domains {
|
||||
sender := newSenderMailbox + "@" + domain
|
||||
@@ -271,11 +271,28 @@ func (e *parentEmail) fixtofrom(newSenderMailbox string, domains []string) {
|
||||
e.CC = strings.ReplaceAll(e.CC, newSender, originalFrom)
|
||||
}
|
||||
}
|
||||
|
||||
return previousSender
|
||||
}
|
||||
|
||||
// Recipients returns list of recipients (to, cc)
|
||||
func (e parentEmail) Recipients() []string {
|
||||
return append(email.AddressList(e.CC), strings.Split(email.Address(e.To), ",")...)
|
||||
func (e *parentEmail) calculateRecipients(from string) {
|
||||
recipients := map[string]struct{}{}
|
||||
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) {
|
||||
@@ -331,7 +348,8 @@ func (b *Bot) getParentEmail(evt *event.Event, newFromMailbox string) *parentEma
|
||||
parent.RcptTo = utils.EventField[string](&parentEvt.Content, eventRcptToKey)
|
||||
parent.InReplyTo = utils.EventField[string](&parentEvt.Content, eventMessageIDkey)
|
||||
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)
|
||||
if parent.InReplyTo == "" {
|
||||
parent.InReplyTo = parent.MessageID
|
||||
|
||||
@@ -60,7 +60,7 @@ func (q *Queue) Remove(id string) error {
|
||||
|
||||
q.mu.Lock(itemkey)
|
||||
defer q.mu.Unlock(itemkey)
|
||||
return q.lp.SetAccountData(itemkey, nil)
|
||||
return q.lp.SetAccountData(itemkey, map[string]string{})
|
||||
}
|
||||
|
||||
// try to send email
|
||||
|
||||
Reference in New Issue
Block a user