lawtonca has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
Has anyone else come across and hopefully found an answer to this?

I'm trying to pick up some mail with Mail::POP3Client, but POP3Client sees a . on it's own on a line as the end of the message, which is happening by chance in some of the mails in the mailbox. I am talking to an Exchange POP3 server. Here is some debug info


POP3 <- valid while stocks last. Photos presented are non-contractual.^M
at ./readmail.pl line 28
POP3 <- ^M
at ./readmail.pl line 28
POP3 <- If you do not wish to receive further e-mails from PIXmania.com, please =^M
at ./readmail.pl line 28
POP3 <- click here <http://mailer.pixmania.com/B9kAXK76flsBAX1JswEAGAAAAF8.html> =^M
at ./readmail.pl line 28
POP3 <- .^M
at ./readmail.pl line 28
POP3 -> TOP 65 0^M
at ./readmail.pl line 29
POP3 <- ^M
at ./readmail.pl line 29
POP3 -> DELE 65^M
at ./readmail.pl line 55
POP3 <- Do not hesitate to contact our customer care support via e-mail =^M
at ./readmail.pl line 55
POP3 -> RETR 66^M
at ./readmail.pl line 28
POP3 <- <http://mailer.pixmania.com/B9kAXK76flsBAX1JswEAGQAAAF8.html>=20^M
at ./readmail.pl line 28
POP3 -> TOP 66 0^M



notice the
<http://mailer.pixmania.com/B9kAXK76flsBAX1JswEAGAAAAF8.html> =^M
at ./readmail.pl line 28
POP3 <- .^M
at ./readmail.pl line 28
POP3 -> TOP 65 0^M


so it's got a .^M assumes the message has ended and sends the next command, but then gets the reply of the next line of the message from the server.

POP3 -> TOP 65 0^M
at ./readmail.pl line 29
POP3 <- ^M
at ./readmail.pl line 29
POP3 -> DELE 65^M
at ./readmail.pl line 55
POP3 <- Do not hesitate to contact our customer care support via e-mail =^M
at ./readmail.pl line 55
POP3 -> RETR 66^M
at ./readmail.pl line 28
POP3 <- <http://mailer.pixmania.com/B9kAXK76flsBAX1JswEAGQAAAF8.html>=20^M


Has anyone else had and found a solution to this problem either by changing the settings on the exchange server or POP3Client?

Thanks very much in advance
Chris

Replies are listed 'Best First'.
Re: POP3Client and dots
by kennethk (Abbot) on Mar 26, 2009 at 15:08 UTC

    Please read How (Not) To Ask A Question, particularly as providing your script would be incredibly invaluable in understanding/replicating your issue.

    Seeing as there are carriage returns sitting on the response lines, I would see that as a potential cause. I looked through the source for Mail::POP3Client and noted an undocumented key 'STRIPCR' commented with "# Macs seem to leave CR's or LF's sitting on the socket. This # removes them." Perhaps you could try setting $o->{STRIPCR} = 1 after you call the constructor? If this works, I would suggest submitting a bug report.

      It looks like OP problem is because Mail::POP3Client stops reading message if it sees line consisting only from a dot (that is right thing according to standard, btw), and not because the CRLF line endings which are absolutely normal too. According to RFC 1939:

      When all lines of the response have been sent, a final line is sent, consisting of a termination octet (decimal code 046, ".") and a CRLF pair. If any line of the multi-line response begins with the termination octet, the line is "byte-stuffed" by pre-pending the termination octet to that line of the response. Hence a multi-line response is terminated with the five octets "CRLF.CRLF". When examining a multi-line response, the client checks to see if the line begins with the termination octet. If so and if octets other than CRLF follow, the first octet of the line (the termination octet) is stripped away.

      So if you server returns to you CRLF.CRLF before the message ends, it's a bug in your server and not in the module.