Skip to content

Commit

Permalink
jmap: handle copy-to and :send -t
Browse files Browse the repository at this point in the history
The jmap:// outgoing backend always copies (actually, just tags) the
sent emails with the mailbox that has the "sent" role. Regardless of the
copy-to or :send -t <folder> argument. Only the copy-to-replied setting
is effective.

Change the CopyTo parameter of the StartSendingMessage backend operation
to hold a list of folder names.

In the JMAP worker, label the sent message with the list of folders,
eliminating duplicates (e.g. do not label with "sent" role twice).

Reported-by: Matěj Cepl <[email protected]>
Signed-off-by: Robin Jarry <[email protected]>
Tested-by: Matěj Cepl <[email protected]>
  • Loading branch information
rjarry committed Dec 21, 2024
1 parent b77bd33 commit 553fabb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
9 changes: 6 additions & 3 deletions commands/compose/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,15 @@ func sendHelper(composer *app.Composer, header *mail.Header, uri *url.URL, domai
go func() {
defer log.PanicHandler()

var parentDir string
var folders []string
if copyTo != "" {
folders = append(folders, copyTo)
}
if copyToReplied && composer.Parent() != nil {
parentDir = composer.Parent().Folder
folders = append(folders, composer.Parent().Folder)
}
sender, err := send.NewSender(
composer.Worker(), uri, domain, from, rcpts, parentDir)
composer.Worker(), uri, domain, from, rcpts, folders)
if err != nil {
failCh <- errors.Wrap(err, "send:")
return
Expand Down
2 changes: 1 addition & 1 deletion commands/msg/bounce.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (b Bounce) Execute(args []string) error {
msg.Envelope.MessageId, addresses)

if sender, err = send.NewSender(acct.Worker(), uri,
domain, config.From, rcpts, ""); err != nil {
domain, config.From, rcpts, nil); err != nil {
return
}
defer func() {
Expand Down
2 changes: 1 addition & 1 deletion lib/send/jmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func newJmapSender(
worker *types.Worker, from *mail.Address, rcpts []*mail.Address,
copyTo string,
copyTo []string,
) (io.WriteCloser, error) {
var writer io.WriteCloser
done := make(chan error)
Expand Down
2 changes: 1 addition & 1 deletion lib/send/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func NewSender(
worker *types.Worker, uri *url.URL, domain string,
from *mail.Address, rcpts []*mail.Address,
copyTo string,
copyTo []string,
) (io.WriteCloser, error) {
protocol, auth, err := parseScheme(uri)
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions worker/jmap/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ func (w *JMAPWorker) handleStartSend(msg *types.StartSendingMessage) error {
w.rolePatch(mailbox.RoleSent): true,
w.rolePatch(mailbox.RoleDrafts): nil,
}
if copyTo := w.dir2mbox[msg.CopyTo]; copyTo != "" {
onSuccess[w.mboxPatch(copyTo)] = true
for _, dir := range msg.CopyTo {
mbox, ok := w.dir2mbox[dir]
if ok && mbox != w.roles[mailbox.RoleSent] {
onSuccess[w.mboxPatch(mbox)] = true
}
}
// Create the submission
req.Invoke(&emailsubmission.Set{
Expand Down
2 changes: 1 addition & 1 deletion worker/types/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ type StartSendingMessage struct {
Message
From *mail.Address
Rcpts []*mail.Address
CopyTo string
CopyTo []string
}

// Messages
Expand Down

0 comments on commit 553fabb

Please sign in to comment.