aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorKarel Balej <balejk@matfyz.cz>2024-01-30 20:11:26 +0100
committerRobin Jarry <robin@jarry.cc>2024-02-12 22:56:16 +0100
commit324e620c5a62fee07970c436f792c7383a3fb1e5 (patch)
tree7bf519252f9fc74c4490dd5e95a1310ebbf909b5 /worker
parent1bc295580e0b2caf9349226f46f4ea29c7b12a7a (diff)
downloadaerc-324e620c5a62fee07970c436f792c7383a3fb1e5.tar.gz
jmap: set explicit sender and recipients
JMAP is able to automatically determine sender and recipients based on the message headers after it is submitted for sending. However this means that it is not possible to send a message with the From header not matching the account with this approach (or to send the message to recipients not listed in the headers). Luckily, JMAP allows setting the envelope containing the envelope sender and recipients manually. Modify the code to do so. Also bump go-jmap to include a fix needed for this to work. Signed-off-by: Karel Balej <balejk@matfyz.cz> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r--worker/jmap/send.go22
-rw-r--r--worker/types/messages.go3
2 files changed, 14 insertions, 11 deletions
diff --git a/worker/jmap/send.go b/worker/jmap/send.go
index 4b033d2e..0d8bb23f 100644
--- a/worker/jmap/send.go
+++ b/worker/jmap/send.go
@@ -27,7 +27,7 @@ func (w *JMAPWorker) handleStartSend(msg *types.StartSendingMessage) error {
defer log.PanicHandler()
defer close(send.done)
- identity, err := w.getSenderIdentity(msg.Header)
+ identity, err := w.getSenderIdentity(msg.From)
if err != nil {
send.done <- err
return
@@ -58,6 +58,14 @@ func (w *JMAPWorker) handleStartSend(msg *types.StartSendingMessage) error {
},
})
+ from := &emailsubmission.Address{Email: msg.From.Address}
+ var rcpts []*emailsubmission.Address
+ for _, address := range msg.Rcpts {
+ rcpts = append(rcpts, &emailsubmission.Address{
+ Email: address.Address,
+ })
+ }
+ envelope := &emailsubmission.Envelope{MailFrom: from, RcptTo: rcpts}
// Create the submission
req.Invoke(&emailsubmission.Set{
Account: w.accountId,
@@ -65,6 +73,7 @@ func (w *JMAPWorker) handleStartSend(msg *types.StartSendingMessage) error {
"sub": {
IdentityID: identity,
EmailID: "#aerc",
+ Envelope: envelope,
},
},
OnSuccessUpdateEmail: map[jmap.ID]jmap.Patch{
@@ -122,15 +131,8 @@ func (w *jmapSendWriter) Close() error {
return sendErr
}
-func (w *JMAPWorker) getSenderIdentity(header *mail.Header) (jmap.ID, error) {
- from, err := header.AddressList("from")
- if err != nil {
- return "", fmt.Errorf("msg.Header.AddressList: %w", err)
- }
- if len(from) != 1 {
- return "", fmt.Errorf("no from header in message")
- }
- name, domain, _ := strings.Cut(from[0].Address, "@")
+func (w *JMAPWorker) getSenderIdentity(from *mail.Address) (jmap.ID, error) {
+ name, domain, _ := strings.Cut(from.Address, "@")
for _, ident := range w.identities {
n, d, _ := strings.Cut(ident.Email, "@")
switch {
diff --git a/worker/types/messages.go b/worker/types/messages.go
index 35310b98..7ebb3aae 100644
--- a/worker/types/messages.go
+++ b/worker/types/messages.go
@@ -213,7 +213,8 @@ type CheckMail struct {
type StartSendingMessage struct {
Message
- Header *mail.Header
+ From *mail.Address
+ Rcpts []*mail.Address
}
// Messages