go-pop3
go-pop3 copied to clipboard
ReadLines() does not handle dot stuffing correctly
I discovered that reading a mail message using c.ReadLines() is incorrect: while the function interprets a single . as the end of message, it does not un-escape the dot when a line begins with a dot.
Dropping in the code from net/textproto helps:
diff --git i/pop3.go w/pop3.go
index de0727a..cd44007 100644
--- i/pop3.go
+++ w/pop3.go
@@ -72,10 +72,13 @@ func (c *Client) ReadLines() (lines []string, err error) {
return nil, err
}
- // Look for a dot to indicate the end of a message
- // from the server.
- if line == "." {
- break
+ // from go1.20.5/src/net/textproto/reader.go#L298:
+ // Dot by itself marks end; otherwise cut one dot.
+ if len(line) > 0 && line[0] == '.' {
+ if len(line) == 1 {
+ break
+ }
+ line = line[1:]
}
lines = append(lines, line)
}
I suspect that c.Retr() is similarly buggy because it uses mail.ReadMessage, which does use net/textproto, but does not call its DotReader() function, but I haven’t verified.
Filing this issue mostly so that other users are aware of the issue.