diff options
author | Runxi Yu <me@runxiyu.org> | 2025-01-16 08:56:18 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-01-16 08:56:18 +0800 |
commit | 5079850140ad53d2cdb2395c90cb65061249579c (patch) | |
tree | 2e59b51eb2f2c503d5252e77ede6b5eba288ebd8 /common_imap.go | |
parent | Minor fixes (diff) | |
download | maild-5079850140ad53d2cdb2395c90cb65061249579c.tar.gz maild-5079850140ad53d2cdb2395c90cb65061249579c.tar.zst maild-5079850140ad53d2cdb2395c90cb65061249579c.zip |
parse_{smtp,imap}_line
Diffstat (limited to 'common_imap.go')
-rw-r--r-- | common_imap.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/common_imap.go b/common_imap.go new file mode 100644 index 0000000..3d79124 --- /dev/null +++ b/common_imap.go @@ -0,0 +1,31 @@ +package main + +import ( + "errors" + "strings" +) + +var err_imap_generic = errors.New("Error in IMAP command received by server.") + +func parse_imap_line(line string) (tag, cmd, param string, err error) { + line = strings.TrimSuffix(line, "\n") + line = strings.TrimSuffix(line, "\r") + tag_end := strings.IndexByte(line, ' ') + if tag_end == -1 { + err = err_imap_generic + return + } + tag = line[:tag_end] + rest := line[tag_end+1:] + cmd_end := strings.IndexByte(rest, ' ') + var param_start int + if cmd_end == -1 { + cmd_end = len(rest) + param_start = len(rest) + } else { + param_start = cmd_end + 1 + } + cmd = strings.ToUpper(rest[:cmd_end]) + param = rest[param_start:] + return +} |