-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GODT-2201): IMAP Copy & Move Commands
- Loading branch information
1 parent
6aac246
commit ddda34b
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ProtonMail/gluon/imap/parser" | ||
) | ||
|
||
type CopyCommand struct { | ||
SeqSet []SeqRange | ||
Mailbox string | ||
} | ||
|
||
func (l CopyCommand) String() string { | ||
return fmt.Sprintf("COPY %v '%v'", l.SeqSet, l.Mailbox) | ||
} | ||
|
||
func (l CopyCommand) SanitizedString() string { | ||
return fmt.Sprintf("COPY %v '%v'", l.SeqSet, sanitizeString(l.Mailbox)) | ||
} | ||
|
||
type CopyCommandParser struct{} | ||
|
||
func (CopyCommandParser) FromParser(p *parser.Parser) (Payload, error) { | ||
// copy = "COPY" SP sequence-set SP mailbox | ||
if err := p.Consume(parser.TokenTypeSP, "expected space after command"); err != nil { | ||
return nil, err | ||
} | ||
|
||
seqSet, err := ParseSeqSet(p) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := p.Consume(parser.TokenTypeSP, "expected space after seqset"); err != nil { | ||
return nil, err | ||
} | ||
|
||
mailbox, err := p.ParseMailbox() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &CopyCommand{ | ||
SeqSet: seqSet, | ||
Mailbox: mailbox, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package command | ||
|
||
import ( | ||
"bytes" | ||
"github.com/ProtonMail/gluon/imap/parser" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestParser_CopyCommand(t *testing.T) { | ||
input := toIMAPLine(`tag COPY 1:* INBOX`) | ||
s := parser.NewScanner(bytes.NewReader(input)) | ||
p := NewParser(s) | ||
|
||
expected := Command{Tag: "tag", Payload: &CopyCommand{ | ||
Mailbox: "INBOX", | ||
SeqSet: []SeqRange{{Begin: 1, End: SeqNumValueAsterisk}}, | ||
}} | ||
|
||
cmd, err := p.Parse() | ||
require.NoError(t, err) | ||
require.Equal(t, expected, cmd) | ||
require.Equal(t, "copy", p.LastParsedCommand()) | ||
require.Equal(t, "tag", p.LastParsedTag()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ProtonMail/gluon/imap/parser" | ||
) | ||
|
||
type MoveCommand struct { | ||
SeqSet []SeqRange | ||
Mailbox string | ||
} | ||
|
||
func (l MoveCommand) String() string { | ||
return fmt.Sprintf("MOVE %v '%v'", l.SeqSet, l.Mailbox) | ||
} | ||
|
||
func (l MoveCommand) SanitizedString() string { | ||
return fmt.Sprintf("MOVE %v '%v'", l.SeqSet, sanitizeString(l.Mailbox)) | ||
} | ||
|
||
type MoveCommandParser struct{} | ||
|
||
func (MoveCommandParser) FromParser(p *parser.Parser) (Payload, error) { | ||
// move = "MOVE" SP sequence-set SP mailbox | ||
if err := p.Consume(parser.TokenTypeSP, "expected space after command"); err != nil { | ||
return nil, err | ||
} | ||
|
||
seqSet, err := ParseSeqSet(p) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := p.Consume(parser.TokenTypeSP, "expected space after seqset"); err != nil { | ||
return nil, err | ||
} | ||
|
||
mailbox, err := p.ParseMailbox() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &MoveCommand{ | ||
SeqSet: seqSet, | ||
Mailbox: mailbox, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package command | ||
|
||
import ( | ||
"bytes" | ||
"github.com/ProtonMail/gluon/imap/parser" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestParser_MoveCommand(t *testing.T) { | ||
input := toIMAPLine(`tag MOVE 1:* INBOX`) | ||
s := parser.NewScanner(bytes.NewReader(input)) | ||
p := NewParser(s) | ||
|
||
expected := Command{Tag: "tag", Payload: &MoveCommand{ | ||
Mailbox: "INBOX", | ||
SeqSet: []SeqRange{{Begin: 1, End: SeqNumValueAsterisk}}, | ||
}} | ||
|
||
cmd, err := p.Parse() | ||
require.NoError(t, err) | ||
require.Equal(t, expected, cmd) | ||
require.Equal(t, "move", p.LastParsedCommand()) | ||
require.Equal(t, "tag", p.LastParsedTag()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters