Skip to content

Commit

Permalink
feat(GODT-2201): IMAP Empty Value Commands
Browse files Browse the repository at this point in the history
Implements the following IMAP commands which have no attached values:

* Capability
* Check
* Close
* Done
* Expunge
* Idle
* Logout
* Noop
* StartTLS
* Unselect
  • Loading branch information
LBeernaertProton committed Feb 14, 2023
1 parent 9d577e8 commit 0e8821a
Show file tree
Hide file tree
Showing 21 changed files with 466 additions and 4 deletions.
22 changes: 22 additions & 0 deletions imap/command/capability.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"fmt"
"github.com/ProtonMail/gluon/imap/parser"
)

type CapabilityCommand struct{}

func (l CapabilityCommand) String() string {
return fmt.Sprintf("CAPABILITY")
}

func (l CapabilityCommand) SanitizedString() string {
return l.String()
}

type CapabilityCommandParser struct{}

func (CapabilityCommandParser) FromParser(p *parser.Parser) (Payload, error) {
return &CapabilityCommand{}, nil
}
22 changes: 22 additions & 0 deletions imap/command/capability_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"bytes"
"github.com/ProtonMail/gluon/imap/parser"
"github.com/stretchr/testify/require"
"testing"
)

func TestParser_CapabilityCommand(t *testing.T) {
input := toIMAPLine(`tag CAPABILITY`)
s := parser.NewScanner(bytes.NewReader(input))
p := NewParser(s)

expected := Command{Tag: "tag", Payload: &CapabilityCommand{}}

cmd, err := p.Parse()
require.NoError(t, err)
require.Equal(t, expected, cmd)
require.Equal(t, "capability", p.LastParsedCommand())
require.Equal(t, "tag", p.LastParsedTag())
}
22 changes: 22 additions & 0 deletions imap/command/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"fmt"
"github.com/ProtonMail/gluon/imap/parser"
)

type CheckCommand struct{}

func (l CheckCommand) String() string {
return fmt.Sprintf("CHECK")
}

func (l CheckCommand) SanitizedString() string {
return l.String()
}

type CheckCommandParser struct{}

func (CheckCommandParser) FromParser(p *parser.Parser) (Payload, error) {
return &CheckCommand{}, nil
}
22 changes: 22 additions & 0 deletions imap/command/check_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"bytes"
"github.com/ProtonMail/gluon/imap/parser"
"github.com/stretchr/testify/require"
"testing"
)

func TestParser_CheckCommand(t *testing.T) {
input := toIMAPLine(`tag CHECK`)
s := parser.NewScanner(bytes.NewReader(input))
p := NewParser(s)

expected := Command{Tag: "tag", Payload: &CheckCommand{}}

cmd, err := p.Parse()
require.NoError(t, err)
require.Equal(t, expected, cmd)
require.Equal(t, "check", p.LastParsedCommand())
require.Equal(t, "tag", p.LastParsedTag())
}
22 changes: 22 additions & 0 deletions imap/command/close.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"fmt"
"github.com/ProtonMail/gluon/imap/parser"
)

type CloseCommand struct{}

func (l CloseCommand) String() string {
return fmt.Sprintf("CLOSE")
}

func (l CloseCommand) SanitizedString() string {
return l.String()
}

type CloseCommandParser struct{}

func (CloseCommandParser) FromParser(p *parser.Parser) (Payload, error) {
return &CloseCommand{}, nil
}
22 changes: 22 additions & 0 deletions imap/command/close_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"bytes"
"github.com/ProtonMail/gluon/imap/parser"
"github.com/stretchr/testify/require"
"testing"
)

func TestParser_CloseCommand(t *testing.T) {
input := toIMAPLine(`tag CLOSE`)
s := parser.NewScanner(bytes.NewReader(input))
p := NewParser(s)

expected := Command{Tag: "tag", Payload: &CloseCommand{}}

cmd, err := p.Parse()
require.NoError(t, err)
require.Equal(t, expected, cmd)
require.Equal(t, "close", p.LastParsedCommand())
require.Equal(t, "tag", p.LastParsedTag())
}
15 changes: 15 additions & 0 deletions imap/command/done.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package command

import (
"fmt"
)

type DoneCommand struct{}

func (l DoneCommand) String() string {
return fmt.Sprintf("DONE")
}

func (l DoneCommand) SanitizedString() string {
return l.String()
}
31 changes: 31 additions & 0 deletions imap/command/done_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package command

import (
"bytes"
"github.com/ProtonMail/gluon/imap/parser"
"github.com/stretchr/testify/require"
"testing"
)

func TestParser_DoneCommand(t *testing.T) {
input := toIMAPLine(`DONE`)
s := parser.NewScanner(bytes.NewReader(input))
p := NewParser(s)

expected := Command{Tag: "", Payload: &DoneCommand{}}

cmd, err := p.Parse()
require.NoError(t, err)
require.Equal(t, expected, cmd)
require.Equal(t, "done", p.LastParsedCommand())
require.Empty(t, p.LastParsedTag())
}

func TestParser_DoneCommandAfterTagIsError(t *testing.T) {
input := toIMAPLine(`tag DONE`)
s := parser.NewScanner(bytes.NewReader(input))
p := NewParser(s)
_, err := p.Parse()
require.Error(t, err)
require.Equal(t, "tag", p.LastParsedTag())
}
22 changes: 22 additions & 0 deletions imap/command/expunge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"fmt"
"github.com/ProtonMail/gluon/imap/parser"
)

type ExpungeCommand struct{}

func (l ExpungeCommand) String() string {
return fmt.Sprintf("EXPUNGE")
}

func (l ExpungeCommand) SanitizedString() string {
return l.String()
}

type ExpungeCommandParser struct{}

func (ExpungeCommandParser) FromParser(p *parser.Parser) (Payload, error) {
return &ExpungeCommand{}, nil
}
22 changes: 22 additions & 0 deletions imap/command/expunge_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"bytes"
"github.com/ProtonMail/gluon/imap/parser"
"github.com/stretchr/testify/require"
"testing"
)

func TestParser_ExpungeCommand(t *testing.T) {
input := toIMAPLine(`tag EXPUNGE`)
s := parser.NewScanner(bytes.NewReader(input))
p := NewParser(s)

expected := Command{Tag: "tag", Payload: &ExpungeCommand{}}

cmd, err := p.Parse()
require.NoError(t, err)
require.Equal(t, expected, cmd)
require.Equal(t, "expunge", p.LastParsedCommand())
require.Equal(t, "tag", p.LastParsedTag())
}
22 changes: 22 additions & 0 deletions imap/command/idle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"fmt"
"github.com/ProtonMail/gluon/imap/parser"
)

type IdleCommand struct{}

func (l IdleCommand) String() string {
return fmt.Sprintf("IDLE")
}

func (l IdleCommand) SanitizedString() string {
return l.String()
}

type IdleCommandParser struct{}

func (IdleCommandParser) FromParser(p *parser.Parser) (Payload, error) {
return &IdleCommand{}, nil
}
22 changes: 22 additions & 0 deletions imap/command/idle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"bytes"
"github.com/ProtonMail/gluon/imap/parser"
"github.com/stretchr/testify/require"
"testing"
)

func TestParser_IdleCommand(t *testing.T) {
input := toIMAPLine(`tag IDLE`)
s := parser.NewScanner(bytes.NewReader(input))
p := NewParser(s)

expected := Command{Tag: "tag", Payload: &IdleCommand{}}

cmd, err := p.Parse()
require.NoError(t, err)
require.Equal(t, expected, cmd)
require.Equal(t, "idle", p.LastParsedCommand())
require.Equal(t, "tag", p.LastParsedTag())
}
22 changes: 22 additions & 0 deletions imap/command/logout.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"fmt"
"github.com/ProtonMail/gluon/imap/parser"
)

type LogoutCommand struct{}

func (l LogoutCommand) String() string {
return fmt.Sprintf("LOGOUT")
}

func (l LogoutCommand) SanitizedString() string {
return l.String()
}

type LogoutCommandParser struct{}

func (LogoutCommandParser) FromParser(p *parser.Parser) (Payload, error) {
return &LogoutCommand{}, nil
}
22 changes: 22 additions & 0 deletions imap/command/logout_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"bytes"
"github.com/ProtonMail/gluon/imap/parser"
"github.com/stretchr/testify/require"
"testing"
)

func TestParser_LogoutCommand(t *testing.T) {
input := toIMAPLine(`tag LOGOUT`)
s := parser.NewScanner(bytes.NewReader(input))
p := NewParser(s)

expected := Command{Tag: "tag", Payload: &LogoutCommand{}}

cmd, err := p.Parse()
require.NoError(t, err)
require.Equal(t, expected, cmd)
require.Equal(t, "logout", p.LastParsedCommand())
require.Equal(t, "tag", p.LastParsedTag())
}
22 changes: 22 additions & 0 deletions imap/command/noop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"fmt"
"github.com/ProtonMail/gluon/imap/parser"
)

type NoopCommand struct{}

func (l NoopCommand) String() string {
return fmt.Sprintf("NOOP")
}

func (l NoopCommand) SanitizedString() string {
return l.String()
}

type NoopCommandParser struct{}

func (NoopCommandParser) FromParser(p *parser.Parser) (Payload, error) {
return &NoopCommand{}, nil
}
22 changes: 22 additions & 0 deletions imap/command/noop_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command

import (
"bytes"
"github.com/ProtonMail/gluon/imap/parser"
"github.com/stretchr/testify/require"
"testing"
)

func TestParser_NoopCommand(t *testing.T) {
input := toIMAPLine(`tag NOOP`)
s := parser.NewScanner(bytes.NewReader(input))
p := NewParser(s)

expected := Command{Tag: "tag", Payload: &NoopCommand{}}

cmd, err := p.Parse()
require.NoError(t, err)
require.Equal(t, expected, cmd)
require.Equal(t, "noop", p.LastParsedCommand())
require.Equal(t, "tag", p.LastParsedTag())
}
Loading

0 comments on commit 0e8821a

Please sign in to comment.