Skip to content

Commit

Permalink
server: Reintroduce TRYCREATE response for APPEND (and now COPY)
Browse files Browse the repository at this point in the history
Was accidentally removed when moving CreateMessage.
Also it was never present for COPY so it was added there
along the way.

memory backend is also updated to conform with that and
return backend.ErrNoSuchMailbox.
  • Loading branch information
foxcpp committed Aug 2, 2020
1 parent cb86aaa commit cf943ff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions backend/memory/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (u *User) CreateMessage(mboxName string, flags []string, date time.Time, bo

func (u *User) CreateMailbox(name string) error {
if _, ok := u.mailboxes[name]; ok {
return errors.New("Mailbox already exists")
return backend.ErrMailboxAlreadyExists
}

u.mailboxes[name] = &Mailbox{name: name, user: u}
Expand All @@ -133,7 +133,7 @@ func (u *User) DeleteMailbox(name string) error {
return errors.New("Cannot delete INBOX")
}
if _, ok := u.mailboxes[name]; !ok {
return errors.New("No such mailbox")
return backend.ErrNoSuchMailbox
}

delete(u.mailboxes, name)
Expand All @@ -143,7 +143,7 @@ func (u *User) DeleteMailbox(name string) error {
func (u *User) RenameMailbox(existingName, newName string) error {
mbox, ok := u.mailboxes[existingName]
if !ok {
return errors.New("No such mailbox")
return backend.ErrNoSuchMailbox
}

u.mailboxes[newName] = &Mailbox{
Expand Down
8 changes: 8 additions & 0 deletions server/cmd_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"

"github.com/emersion/go-imap"
"github.com/emersion/go-imap/backend"
"github.com/emersion/go-imap/commands"
"github.com/emersion/go-imap/responses"
)
Expand Down Expand Up @@ -216,6 +217,13 @@ func (cmd *Append) Handle(conn Conn) error {
}

if err := ctx.User.CreateMessage(cmd.Mailbox, cmd.Flags, cmd.Date, cmd.Message); err != nil {
if err == backend.ErrNoSuchMailbox {
return ErrStatusResp(&imap.StatusResp{
Type: imap.StatusRespNo,
Code: imap.CodeTryCreate,
Info: "No such mailbox",
})
}
return err
}

Expand Down
14 changes: 13 additions & 1 deletion server/cmd_selected.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"

"github.com/emersion/go-imap"
"github.com/emersion/go-imap/backend"
"github.com/emersion/go-imap/commands"
"github.com/emersion/go-imap/responses"
)
Expand Down Expand Up @@ -214,7 +215,18 @@ func (cmd *Copy) handle(uid bool, conn Conn) error {
return ErrNoMailboxSelected
}

return ctx.Mailbox.CopyMessages(uid, cmd.SeqSet, cmd.Mailbox)
err := ctx.Mailbox.CopyMessages(uid, cmd.SeqSet, cmd.Mailbox)
if err != nil {
if err == backend.ErrNoSuchMailbox {
return ErrStatusResp(&imap.StatusResp{
Type: imap.StatusRespNo,
Code: imap.CodeTryCreate,
Info: "No such mailbox",
})
}
return err
}
return nil
}

func (cmd *Copy) Handle(conn Conn) error {
Expand Down

0 comments on commit cf943ff

Please sign in to comment.