aboutsummaryrefslogtreecommitdiff
path: root/serve_imap.go
diff options
context:
space:
mode:
Diffstat (limited to 'serve_imap.go')
-rw-r--r--serve_imap.go40
1 files changed, 11 insertions, 29 deletions
diff --git a/serve_imap.go b/serve_imap.go
index 2789ca3..01bb334 100644
--- a/serve_imap.go
+++ b/serve_imap.go
@@ -7,7 +7,6 @@ import (
"fmt"
"io"
"net"
- "strings"
"github.com/jackc/pgx/v5/pgxpool"
"go.lindenii.runxiyu.org/lindenii-common/clog"
@@ -36,35 +35,18 @@ func (session *imap_recv_session) handle(ctx context.Context) error {
_ = session.buf_conn.Flush()
for {
- var tag, cmd, param string
- {
- line, err := session.buf_conn.ReadString('\n')
- if err != nil {
- if err == io.EOF {
- return err_connection_handler_eof
- }
- return err
- }
- line = strings.TrimSuffix(line, "\n")
- line = strings.TrimSuffix(line, "\r")
- tag_end := strings.IndexByte(line, ' ')
- if tag_end == -1 {
- _, _ = session.buf_conn.WriteString(line + " BAD Error in IMAP command received by server.\r\n")
- _ = session.buf_conn.Flush()
- continue
- }
- 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
+ line, err := session.buf_conn.ReadString('\n')
+ if err != nil {
+ if err == io.EOF {
+ return err_connection_handler_eof
}
- cmd = strings.ToUpper(rest[:cmd_end])
- param = rest[param_start:]
+ return err
+ }
+ tag, cmd, param, err := parse_imap_line(line)
+ if err != nil {
+ _, _ = session.buf_conn.WriteString(line + " BAD " + err.Error() + "\r\n")
+ _ = session.buf_conn.Flush()
+ continue
}
fmt.Printf("received tag=%s, cmd=%s, param=%s\n", tag, cmd, param)
}