Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadLines() does not handle dot stuffing correctly #5

Open
stapelberg opened this issue Jul 4, 2023 · 0 comments
Open

ReadLines() does not handle dot stuffing correctly #5

stapelberg opened this issue Jul 4, 2023 · 0 comments

Comments

@stapelberg
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant