mirror of
https://github.com/mjl-/mox.git
synced 2025-06-27 22:28:16 +03:00

The imapclient needs more changes, like more strict parsing, before it can be a generally usable IMAP client, these are a few steps towards that. - Fix a bug in the imapserver METADATA responses for TOOMANY and MAXSIZE. - Split low-level IMAP protocol handling (new Proto type) from the higher-level client command handling (existing Conn type). The idea is that some simple uses of IMAP can get by with just using these commands, while more intricate uses of IMAP (like a synchronizing client that needs to talk to all kinds of servers with different behaviours and implemented extensions) can write custom commands and read untagged responses or command completion results explicitly. The lower-level method names have clearer names now, like ReadResponse instead of Response. - Merge the untagged responses and (command completion) "Result" into a new type Response. Makes function signatures simpler. And make Response implement the error interface, and change command methods to return the Response as error if the result is NO or BAD. Simplifies error handling, and still provides the option to continue after a NO or BAD. - Add UIDSearch/MSNSearch commands, with a custom "search program", so mostly to indicate these commands exist. - More complete coverage of types for response codes, for easier handling. - Automatically handle any ENABLED or CAPABILITY untagged response or response code for IMAP command methods on type Conn. - Make difference between MSN vs UID versions of FETCH/STORE/SEARCH/COPY/MOVE/REPLACE commands more clear. The original MSN commands now have MSN prefixed to their name, so they are grouped together in the documentation. - Document which capabilities are needed for a command.
39 lines
780 B
Go
39 lines
780 B
Go
package imapclient
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func FuzzParser(f *testing.F) {
|
|
/*
|
|
Gathering all untagged responses and command completion results from the RFCs:
|
|
|
|
cd ../rfc
|
|
(
|
|
grep ' S: \* [A-Z]' * | sed 's/^.*S: //g'
|
|
grep -E ' S: [^ *]+ (OK|NO|BAD) ' * | sed 's/^.*S: //g'
|
|
) | grep -v '\.\.\/' | sort | uniq >../testdata/imapclient/fuzzseed.txt
|
|
*/
|
|
buf, err := os.ReadFile("../testdata/imapclient/fuzzseed.txt")
|
|
if err != nil {
|
|
f.Fatalf("reading seed: %v", err)
|
|
}
|
|
for _, s := range strings.Split(string(buf), "\n") {
|
|
f.Add(s + "\r\n")
|
|
}
|
|
f.Add("1:3")
|
|
f.Add("3:1")
|
|
f.Add("3,1")
|
|
f.Add("*")
|
|
|
|
f.Fuzz(func(t *testing.T, data string) {
|
|
ParseUntagged(data)
|
|
ParseCode(data)
|
|
ParseResult(data)
|
|
ParseNumSet(data)
|
|
ParseUIDRange(data)
|
|
})
|
|
}
|