mirror of
https://github.com/axllent/mailpit.git
synced 2026-04-26 00:35:51 +03:00
[GH-ISSUE #311] POP3 end of file reached error #207
Labels
No labels
awaiting feedback
bug
docker
documentation
enhancement
github_actions
invalid
pull-request
question
stale
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/mailpit#207
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @antonionardella on GitHub (Jun 12, 2024).
Original GitHub issue: https://github.com/axllent/mailpit/issues/311
Hello,
I am trying to set up mailpit to be used as mock email server for a staging installation of https://github.com/zammad/zammad according to their documentation here: https://admin-docs.zammad.org/en/latest/channels/email/index.html
This to see if the email are sent and received correctly and do further testing in a staging environment.
My issue is that once I set up mailpit and the pop3 connection parameters in zammad all I get is:
end of file reachedon Zammad's sideand
ERRO[2024/06/12 13:20:15] [pop3] EOFon mailpits side.I installed
mkcertto create certificates and keys like so:To generate certs for the IP of the test server
Then a pop3 auth file which contains nothing but
user:passThen I start mailpit with
mailpit --pop3-auth-file ./mailpit.auth --pop3-tls-cert ./cert.pem --pop3-tls-key ./key.pemWhat else could I try to make this work or debug it?
Thanks
@antonionardella commented on GitHub (Jun 12, 2024):
I know that mailpit replies, because if I write the wrong password I get
WARN[2024/06/12 14:39:24] [pop3] failed login: user@axllent commented on GitHub (Jun 12, 2024):
Sorry to hear you're having issues @antonionardella. I'm wondering if this was a result of a change we made in v1.18.3 (called dot-stuffing to prevent an email containing a single
.on a line being interprited as the "end of the email"). Could you please try using v.1.18.2 (which does not have this fix) and let me know if it solves your issue? If it does, then it gives me some idea of where to look. If not (you still get the error), then I'm wondering if it has something to do with the TLS (you could then try without the TLS certs).@antonionardella commented on GitHub (Jun 13, 2024):
Hello @axllent!
Thank you very much for your response!


I installed the 1.18.2 version as suggested and the Zammad app is still giving the same error
I tried also without TLS without success


SMTP works fine as expected

But I am having issues with POP3 even with telnet

This is uncharted territory for me, so please bear with my lack of knowledge.
@axllent commented on GitHub (Jun 13, 2024):
That's all good. Port
1025is for SMTP which isn't the problem here, it's POP3, sotelnet localhost 1110(followed by POP3 commands which you can see on sites like this, or this.So at a guess it'll be something like:
(I've added
...because that is where Mailpit should be answering you).There are a lot more commands, but this should log you in as user
userwith the passwordpass, list your messages, retrieve the first message (print it on screen), and finally quit.@antonionardella commented on GitHub (Jun 13, 2024):
Alright, telnet works
At this point I suppose that there might be a different issue with Zammad
Thank you so much for your support. I'll come back if there is something else I can bring to the discussion
@axllent commented on GitHub (Jun 13, 2024):
I suspect that may be the case (an issue with Zammad) - but I can' t be 100% sure as I don't know that software. I have tested with Thunderbird & telnet, but I'm assuming it should work with all POP3 clients. Zammad is open source, so maybe they can help?
@antonionardella commented on GitHub (Jun 13, 2024):
Zammad is open source, yes. I posted to their forum https://community.zammad.org/t/pop3-issues-with-mailpit/14629
Let's see what happens next.
Again, thanks for your time.
@antonionardella commented on GitHub (Jun 13, 2024):
Hello @axllent
I got this feedback from the zammad team:
Not sure if there is time from your side to do anything about it, but at least we know more now.
Each line is expected to contain a message number and a size, separated by whitespace. The regular expression \A(\d+)[ \t]+(\d+) is used to match lines that start with one or more digits (message number), followed by one or more spaces or tabs, followed by one or more digits (message size). If the line does not match this format, an exception POPBadResponse is raised with the message "bad response: #{line}".
Given this LIST response from mailpit when the
LISTis calledI see now where it might be incompatible.
According to the RFC 1939 https://www.rfc-editor.org/rfc/rfc1939#page-6
The list example looks like the following:
@antonionardella commented on GitHub (Jun 13, 2024):
Alright, the size part should be fixed with this PR: https://github.com/axllent/mailpit/pull/312
Now I have to understand why I am getting the
end of file reachederror@antonionardella commented on GitHub (Jun 13, 2024):
Further help from Zammad comes from
@antonionardella commented on GitHub (Jun 13, 2024):
I was able to make it work with this commit
github.com/antonionardella/mailpit@e2f28f1dd8But it is also a huge refactoring of your code, so I am not pushing a PR unless you would like to do so.
This way Zammad was perfectly able to set up the POP3 mailbox without any issues so far
I was not able to compile the front-end on Windows (had no time to set up the node env), so please test it if possible
Have a great day!
@axllent commented on GitHub (Jun 13, 2024):
@antonionardella Firstly thank you so much for looking into this, identifying the bug, and the PR. It's the start of another busy workday for me (plus I have another event this evening I have to attend) so I will look at this as soon as I'm able to (including your latest commit). If not today then tomorrow...
@antonionardella commented on GitHub (Jun 13, 2024):
No hurry at all! Please.
Take your priorities first, I am only hoping that this is helping, more than making further mess (since I am not a professional developer).
Enjoy your day and weekend!
@axllent commented on GitHub (Jun 13, 2024):
It is helping more than you know! The POP3 server implementation was originally a bit of a hack (and not something I personally use), so clearly some bugs have crept in over time, nor was it seemingly fully compliant. Compliance is something I strive for in Mailpit, so POP3 shouldn't be any different.
@antonionardella commented on GitHub (Jun 13, 2024):
Readded also the websocket support
github.com/antonionardella/mailpit@5c33dd132a@axllent commented on GitHub (Jun 14, 2024):
@antonionardella Firstly, I have merged the first PR - thank you, Mailpit was in fact printing garbage sizes, and the RFC 600-second timeout was a good catch too.
Secondly, I have been looking at your refactored branch which looks a lot nicer than my version, but which has some flaws in the logic (probably due to over-simplification). Before I get into that though, I'm curious as to what part exactly solved the issue with zammad? Was it just the fact that the sizes were incorrectly formatted (ie:
LIST), or that you also needed to addsendResponse(conn, "LIST")to theCAPAlist (I don't believeLISTis an expected CAPA response because it's just a standard POP3 command, not a "capability"), or was it something else?Generally speaking with POP3:
CAPA&QUITrequire you to be logged in.USERfollowed by a validPASS(at which point the user and pass is validated).USERandPASS(you can't log in again while already being logged in)In your refactored code however, you have greatly simplified the logic to just two states:
UNAUTHORIZED&TRANSACTION. You setstate = TRANSACTION(which in this context means "logged in") afterUSER, but you haven't checked the password yet. I realise that you don't load any messages until a valid password has been supplied, however you should not be allowed to run any of those other commands until being actually authorised.In your refactor the following works when it shouldn't be allowed (note how there is no
PASS):So to summarise - I like/prefer your refactored structure (it is much tidier), but there is a bit too much oversimplification of the logic which is resulting in non-compliant POP3. I think a few additional checks in your code would fix it though, but they are definitely needed. I'm also very curious to know what exactly fixed zammad.
@antonionardella commented on GitHub (Jun 17, 2024):
Hello @axllent and thank you for your extensive feedback!
To add some context and pointers:
The first and merged PR (thank you!) fixed the size reporting issue described here: https://github.com/axllent/mailpit/issues/311#issuecomment-2165453243
After that, the ruby library, net-pop used by Zammad was only giving an
end of file reachederror as described here https://github.com/axllent/mailpit/issues/311#issuecomment-2164384970. This was blocking Zammad from adding the POP3 mailbox as email channel.Once I applied my hack I was able to successfully add the mailpit POP3 mailbox to Zammad without errors, which also sends and retrieves a test email using the library.
I did not have the time to test it through though.
I will look into it and add the checks to reach compliance and compatibility, thank you for taking the time to go through the code and add your valuable comments.
@antonionardella commented on GitHub (Jun 17, 2024):
I took some time to refactor the code a little bit more:
github.com/antonionardella/mailpit@edf3041383Now the code allows specific commands either in
AUTHENTICATIONorTRANSACTIONstate according to RFC2449I also change the wording to make it easier to read the code according to the RFC (changed
UNAUTHORIZEDtoAUTHENTICATIONstate).Let me know if this works for you and is getting closer to the RFCs as expected.
I was able to compile it and test it with

telnetand Zammad still no webUI tests thoughBest,
Antonio
@axllent commented on GitHub (Jun 17, 2024):
@antonionardella This code is looking much cleaner than my version, so thank you! I haven't tested it yet (I'm not able to today, but will try in about 24h) - sorry. From what I can see thought your implementation should work as expected. I'm still curious as to why Zammad is working with your version and not mine, do you have any idea? I promise to look into your version as soon as I'm able to, I'm just very busy right now and need to get to bed.
@axllent commented on GitHub (Jun 17, 2024):
I should also add that the web UI is not important for this, in fact the two are not linked in any way. POP3 is only for POP3 clients, not the web UI 👍
@antonionardella commented on GitHub (Jun 18, 2024):
Good question, I added a handler specifically for EOF errors, which might be the key to the whole issue
github.com/antonionardella/mailpit@881ede5be4/server/pop3/pop3.go (L127C1-L132C10)@axllent commented on GitHub (Jun 18, 2024):
Actually that's not really a handler, but rather just "hiding" (using the debug log) the logged
EOFerror - it shouldn't make any difference to the client connection. The only thing (I think) it tells me is that the Zammad client potentially doesn't send aQUITwhen it is finished, but rather just breaks the connection instead when it is finished (if so then it's not RFC, and things like deleted messages won't actually get deleted). Please see below for more testing...If Zammad isn't working after the first int64() fix, then I think it must actually be something else. Would you mind please confirming for me if the current
developbranch ofgithub.com/axllent/mailpitreally doesn't work with Zammad? I understand that Mailpit will print an error, but my question is really whether Zammad can or can't add the POP3 server?In addition to that, running Mailpit with the
-vflag will print out exactly what the mail client is sending and receiving, for example:Do you mind providing me with the output displayed (
using-v` in Mailpit) when you try connect Zammad?I've tested your version using Thunderbird and it works fine for me, so I'll be happy for another MR once we can find out exactly what was broken (if it was actually broken) after the previous int64() fix. Thanks!
@antonionardella commented on GitHub (Jun 18, 2024):
What I did on the Zammad staging server:
Mailpit
sudo bash < <(curl -sL https://raw.githubusercontent.com/axllent/mailpit/develop/install.sh)echo -e "user1:password1\nuser2:password2" > mailpit.authmailpit -v --pop3-auth-file ./mailpit.authZammad
Channels-EmailEmailaccountHere the Mailpit Debug log:
Here the error in Zammad

This with the latest version built from my fork:
Mailpit
mailpit -v --pop3-auth-file ./mailpit.authZammad
Add account with same parameters
No error in Zammad and asks for the next step, which is the

SMTP setupAt this point, the difference I see, is that the updated fork sends an
+OK Goodbyemessage after theQUITcommandI hope that helps
@axllent commented on GitHub (Jun 18, 2024):
Yes, I believe you are right! Good catch - Mailpit was just closing the connection without returning a response to the
QUIT. Thanks, I missed that...Would you mind opening another PR (you closed the original one) with your current code and I will get that merged in (and released as soon as possible)? Thanks @antonionardella!
@antonionardella commented on GitHub (Jun 18, 2024):
PR is open
https://github.com/axllent/mailpit/pull/315
Thanks a lot for your questions, feedback, time and awesome project!
@axllent commented on GitHub (Jun 19, 2024):
You're very welcome, and thank you for all your hard work finding & fixing the bug(s), plus refactoring the POP3 code (it is so much better now)!
I also made a few more additional changes:
RSETcommandpop3.gotoserver.go(so it's clear this is a server, not a client)user usernameis the same asUSER username), so I fixed that tooYour changes, my changes, and some dependency updates to the Go & JS libraries have been released in v.1.18.6 🎉
Thanks again! ❤️