aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--serve_imap.go40
1 files changed, 38 insertions, 2 deletions
diff --git a/serve_imap.go b/serve_imap.go
index 742bb0f..64a6ad0 100644
--- a/serve_imap.go
+++ b/serve_imap.go
@@ -2,9 +2,12 @@ package main
import (
"bufio"
+ "fmt"
"context"
"crypto/tls"
+ "io"
"net"
+ "strings"
"github.com/jackc/pgx/v5/pgxpool"
"go.lindenii.runxiyu.org/lindenii-common/clog"
@@ -29,9 +32,42 @@ type imap_recv_session struct {
func (session *imap_recv_session) handle(ctx context.Context) error {
session.buf_conn = bufio.NewReadWriter(bufio.NewReader(session.net_conn), bufio.NewWriter(session.net_conn))
- session.buf_conn.WriteString("Not implemented\r\n")
+ session.buf_conn.WriteString("* OK [CAPABILITY IMAP4rev2 AUTH=PLAIN] " + VERSION + "\r\n")
session.buf_conn.Flush()
- return nil
+
+ 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
+ }
+ cmd = strings.ToUpper(rest[:cmd_end])
+ param = rest[param_start:]
+ }
+ fmt.Printf("received tag=%s, cmd=%s, param=%s\n", tag, cmd, param)
+ }
}
func imap_new_session(ctx context.Context, net_conn net.Conn) error {