Skip to content

Commit

Permalink
fix(GOMSRV-128): Remover server personality
Browse files Browse the repository at this point in the history
The emoticon personality was interfering with the IMAP tests from the
dovecot suit. These have now been removed.

Since the responses require a bit of text after, we have added the
originating command's name where no other message exited before. This
requirement was previously masked by the emoticon response.
  • Loading branch information
LBeernaertProton committed Jul 11, 2022
1 parent 3134478 commit dd05009
Show file tree
Hide file tree
Showing 55 changed files with 289 additions and 307 deletions.
4 changes: 0 additions & 4 deletions internal/response/bad.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ func (r *bad) String() string {
parts = append(parts, r.err.Error())
}

if r.tag != "*" {
parts = append(parts, faceBad)
}

return join(parts)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/response/bad_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ func TestBadUntagged(t *testing.T) {
}

func TestBadTagged(t *testing.T) {
assert.Equal(t, "tag BAD (>_<)", Bad("tag").String())
assert.Equal(t, "tag BAD", Bad("tag").String())
}

func TestBadError(t *testing.T) {
assert.Equal(t, "tag BAD erroooooor (>_<)", Bad("tag").WithError(errors.New("erroooooor")).String())
assert.Equal(t, "tag BAD erroooooor", Bad("tag").WithError(errors.New("erroooooor")).String())
}
2 changes: 1 addition & 1 deletion internal/response/bye.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (r *bye) Send(s Session) error {
}

func (r *bye) String() string {
parts := []string{"*", "BYE", faceBye}
parts := []string{"*", "BYE"}

if r.msg != "" {
parts = append(parts, r.msg)
Expand Down
4 changes: 2 additions & 2 deletions internal/response/bye_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
)

func TestBye(t *testing.T) {
assert.Equal(t, "* BYE (^_^)/~", Bye().String())
assert.Equal(t, "* BYE", Bye().String())
}

func TestByeMessage(t *testing.T) {
assert.Equal(t, "* BYE (^_^)/~ message", Bye().WithMessage("message").String())
assert.Equal(t, "* BYE message", Bye().WithMessage("message").String())
}
4 changes: 3 additions & 1 deletion internal/response/continuation.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package response

import "strings"

type continuation struct {
tag string
}
Expand All @@ -15,5 +17,5 @@ func (r *continuation) Send(s Session) error {
}

func (r *continuation) String() string {
return join([]string{r.tag, faceCon})
return strings.Join([]string{r.tag, "Ready"}, " ")
}
2 changes: 1 addition & 1 deletion internal/response/continuation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

func TestContinuation(t *testing.T) {
assert.Equal(t, "+ (*_*)", Continuation().String())
assert.Equal(t, "+ Ready", Continuation().String())
}
8 changes: 0 additions & 8 deletions internal/response/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ package response

import "strings"

const (
faceOk = "(^_^)"
faceNo = "(~_~)"
faceBad = "(>_<)"
faceBye = "(^_^)/~"
faceCon = "(*_*)"
)

func join(items []string, withDel ...string) string {
var del string

Expand Down
4 changes: 0 additions & 4 deletions internal/response/no.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ func (r *no) String() (res string) {
parts = append(parts, r.err.Error())
}

if r.tag != "*" {
parts = append(parts, faceNo)
}

return join(parts)
}

Expand Down
6 changes: 3 additions & 3 deletions internal/response/no_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ func TestNoUntagged(t *testing.T) {
}

func TestNoTagged(t *testing.T) {
assert.Equal(t, "tag NO (~_~)", No("tag").String())
assert.Equal(t, "tag NO", No("tag").String())
}

func TestNoError(t *testing.T) {
assert.Equal(t, "tag NO erroooooor (~_~)", No("tag").WithError(errors.New("erroooooor")).String())
assert.Equal(t, "tag NO erroooooor", No("tag").WithError(errors.New("erroooooor")).String())
}

func TestNoTryCreate(t *testing.T) {
assert.Equal(t, "tag NO [TRYCREATE] erroooooor (~_~)", No("tag").WithItems(ItemTryCreate()).WithError(errors.New("erroooooor")).String())
assert.Equal(t, "tag NO [TRYCREATE] erroooooor", No("tag").WithItems(ItemTryCreate()).WithError(errors.New("erroooooor")).String())
}
4 changes: 0 additions & 4 deletions internal/response/ok.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ func (r *ok) String() string {
parts = append(parts, fmt.Sprintf("[%v]", join(items)))
}

if r.tag != "*" {
parts = append(parts, faceOk)
}

if r.msg != "" {
parts = append(parts, r.msg)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/response/ok_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestOkUntagged(t *testing.T) {
}

func TestOkTagged(t *testing.T) {
assert.Equal(t, `tag OK (^_^)`, Ok("tag").String())
assert.Equal(t, `tag OK`, Ok("tag").String())
}

func TestOkUnseen(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/session/handle_capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (s *Session) handleCapability(ctx context.Context, tag string, cmd *proto.C

ch <- response.Capability().WithCapabilities(s.caps...)

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("CAPABILITY")

return nil
}
2 changes: 1 addition & 1 deletion internal/session/handle_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (s *Session) handleCheck(ctx context.Context, tag string, cmd *proto.Check,
return err
}

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("CHECK")

return nil
}
2 changes: 1 addition & 1 deletion internal/session/handle_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *Session) handleClose(ctx context.Context, tag string, cmd *proto.Close,

s.name = ""

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("CLOSE")

return nil
}
2 changes: 1 addition & 1 deletion internal/session/handle_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s *Session) handleCreate(ctx context.Context, tag string, cmd *proto.Creat
return err
}

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("CREATE")

return nil
}
2 changes: 1 addition & 1 deletion internal/session/handle_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s *Session) handleDelete(ctx context.Context, tag string, cmd *proto.Del,
return err
}

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("DELETE")

return nil
}
2 changes: 1 addition & 1 deletion internal/session/handle_examine.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (s *Session) handleExamine(ctx context.Context, tag string, cmd *proto.Exam
return err
}

ch <- response.Ok(tag).WithItems(response.ItemReadOnly())
ch <- response.Ok(tag).WithItems(response.ItemReadOnly()).WithMessage("EXAMINE")

return nil
}
4 changes: 2 additions & 2 deletions internal/session/handle_expunge.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (s *Session) handleExpunge(ctx context.Context, tag string, cmd *proto.Expu
return err
}

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("EXPUNGE")

return nil
}
Expand All @@ -41,7 +41,7 @@ func (s *Session) handleUIDExpunge(ctx context.Context, tag string, cmd *proto.U
return err
}

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("EXPUNGE")

return nil
}
4 changes: 2 additions & 2 deletions internal/session/handle_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func prepareServerResponse(info *internal.VersionInfo) response.Response {

func (s *Session) handleIDGet(ctx context.Context, tag string, ch chan response.Response) error {
ch <- prepareServerResponse(s.version)
ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("ID")

return nil
}
Expand All @@ -34,7 +34,7 @@ func (s *Session) handleIDSet(ctx context.Context, tag string, cmd *proto.IDSet,
}

ch <- prepareServerResponse(s.version)
ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("ID")

return nil
}
2 changes: 1 addition & 1 deletion internal/session/handle_idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *Session) handleIdle(ctx context.Context, tag string, cmd *proto.Idle, c

switch {
case cmd.GetDone() != nil:
return response.Ok(tag).Send(s)
return response.Ok(tag).WithMessage("IDLE").Send(s)

default:
return response.Bad(tag).Send(s)
Expand Down
2 changes: 1 addition & 1 deletion internal/session/handle_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *Session) handleList(ctx context.Context, tag string, cmd *proto.List, c
WithAttributes(match.Atts)
}

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("LIST")

return nil
})
Expand Down
2 changes: 1 addition & 1 deletion internal/session/handle_logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (s *Session) handleLogout(ctx context.Context, tag string, cmd *proto.Logou
return err
}

if err := response.Ok(tag).Send(s); err != nil {
if err := response.Ok(tag).WithMessage("LOGOUT").Send(s); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion internal/session/handle_lsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *Session) handleLsub(ctx context.Context, tag string, cmd *proto.Lsub, c
WithAttributes(match.Atts)
}

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("LSUB")

return nil
})
Expand Down
2 changes: 1 addition & 1 deletion internal/session/handle_rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *Session) handleRename(ctx context.Context, tag string, cmd *proto.Renam
return err
}

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("RENAME")

return nil
}
2 changes: 1 addition & 1 deletion internal/session/handle_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *Session) handleSelect(ctx context.Context, tag string, cmd *proto.Selec
return err
}

ch <- response.Ok(tag).WithItems(response.ItemReadWrite())
ch <- response.Ok(tag).WithItems(response.ItemReadWrite()).WithMessage("SELECT")

s.eventCh <- events.EventSelect{
SessionID: s.sessionID,
Expand Down
2 changes: 1 addition & 1 deletion internal/session/handle_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *Session) handleStatus(ctx context.Context, tag string, cmd *proto.Statu
return err
}

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("STATUS")

return nil
}
2 changes: 1 addition & 1 deletion internal/session/handle_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s *Session) handleSub(ctx context.Context, tag string, cmd *proto.Sub, ch
return err
}

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("SUB")

return nil
}
2 changes: 1 addition & 1 deletion internal/session/handle_unselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (s *Session) handleUnselect(ctx context.Context, tag string, cmd *proto.Uns

s.name = ""

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("UNSELECT")

return nil
}
2 changes: 1 addition & 1 deletion internal/session/handle_unsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s *Session) handleUnsub(ctx context.Context, tag string, cmd *proto.Unsub,
return err
}

ch <- response.Ok(tag)
ch <- response.Ok(tag).WithMessage("UNSUBSCRIBE")

return nil
}
8 changes: 4 additions & 4 deletions tests/close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestClose(t *testing.T) {
// There is currently no way to check for this with the go imap client.
runOneToOneTestWithAuth(t, defaultServerOptions(t), func(c *testConnection, _ *testSession) {
c.C("b001 CREATE saved-messages")
c.S("b001 OK (^_^)")
c.S("b001 OK CREATE")

c.doAppend(`saved-messages`, `To: [email protected]`, `\Seen`).expect("OK")
c.doAppend(`saved-messages`, `To: [email protected]`).expect("OK")
Expand All @@ -25,7 +25,7 @@ func TestClose(t *testing.T) {
c.doAppend(`saved-messages`, `To: [email protected]`, `\Seen`).expect("OK")

c.C(`A002 SELECT saved-messages`)
c.Se(`A002 OK [READ-WRITE] (^_^)`)
c.Se(`A002 OK [READ-WRITE] SELECT`)

// TODO: Match flags in any order.
c.C(`A003 STORE 1 +FLAGS (\Deleted)`)
Expand All @@ -42,12 +42,12 @@ func TestClose(t *testing.T) {

// TODO: GOMSRV-106 - Ensure this also works for cases where multiple clients have the same mailbox open
c.C(`A202 CLOSE`)
c.S("A202 OK (^_^)")
c.S("A202 OK CLOSE")

// There are 2 messages in saved-messages.
c.C(`A006 STATUS saved-messages (MESSAGES)`)
c.S(`* STATUS "saved-messages" (MESSAGES 2)`)
c.S(`A006 OK (^_^)`)
c.S(`A006 OK STATUS`)
})
}

Expand Down
Loading

0 comments on commit dd05009

Please sign in to comment.