Click here to Skip to main content
15,885,876 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey guys,
I am working on a system which receives a corrupted emails blocking the system from pulling emails which get stuck in the mail server. Apparently the bad emails do not end properly. I think according to protocol each email should end with "\r\n.\r\n", however, looks like the malformed emails don't end like I said causing problem with detecting the size which in turn causes reading too much and problem with the next email.

I am not saying exactly that the message itself should be ended with "\r\n.\r\n". I made my question around what I see in the code where it is trying to read (data from bio connection)and detect "\r\n.\r\n". The code, when sees this string, marks the end of buffer with '\0' and returns successfully from the function which is reading the content from socket; otherwise, if it does not find the string prints an error indicating the 'end was not found' and then returns unsuccessful.

I was wondering how can I create and send a malformed email, so I can receive it and debugge our system to see how it is reacting to this problem.

I appreciate any input on how to write a small tool using python, c# or c++ to send such an email.
Thanks,
Posted
Updated 21-Mar-12 8:17am
v5
Comments
Sergey Alexandrovich Kryukov 21-Mar-12 12:09pm    
Who told you that rule?
--SA
pietvredeveld 21-Mar-12 12:14pm    
Don't think you can do that. Besides the rule you mention is part of the smtp protocol and as far a I know not a part of the actual e-mail message.

Piet
soby 21-Mar-12 14:31pm    
I am not saying exactly that the message itself should be ended with "\r\n.\r\n". I made my question around what I see in the code where it is trying to read (data from bio connection)and detect "\r\n.\r\n". The code, when sees this string, marks the end of buffer with '\0' and returns successfully from the function which is reading the content from socket; otherwise, if it does not find the string prints an error indicating the 'end was not found' and then returns unsuccessful.
--soby
Sergey Chepurin 21-Mar-12 14:12pm    
\r\n\r\n (not \r\n.\r\n) is used as a divider between header and the body. If there is no divider, then you can assume all the text is the header. By the way, the combination \r\n.\r\n looks strange at the very least.
Update:
But this combination is used - "a multi-line response is terminated with the five octets "CRLF.CRLF" (From "Post Office Protocol - Version 3")
And -
"Commands in the POP3 consist of a case-insensitive keyword, possibly
followed by one or more arguments. All commands are terminated by a CRLF pair.
...
Responses in the POP3 consist of a status indicator and a keyword
possibly followed by additional information. All responses are
terminated by a CRLF pair. Responses may be up to 512 characters
long, including the terminating CRLF."

1 solution

You may use a telnet program to connect manually to the server. Then you can read the plain text mail and see what is wrong, optional copy the content using the clipboard, and optional delete the malformed mail:
> telnet <server> 110
+OK
user <user name>
+OK
pass <password>
+OK
stat
+OK 2 1980
list
+OK 2 messages (1980 octets)
1 1000
2 980
.
top 1 10
+ OK
<First 10 lines of mail no. 1>
.
retr 2
+OK
<Content of mail no. 2>
.
dele 2
+OK message 2 deleted
quit
+OK
>


[UPDATE]
The ".CRLF" sequence is send by the POP server to indicate the end of data. See RFC 1939 [^], "3. Basic Operation", 4th text block, about this and how text containing the termination sequence is handled. It does not matter if the mail text contains this sequence.

The problem is sourced by the mail providers SMTP server code or setup which accepts an invalid mail (such mails should be rejected), or by his local mail delivery procedure which may damage the message or insert invalid headers.
[/UPDATE]
 
Share this answer
 
v2
Comments
soby 21-Mar-12 13:04pm    
I have used telnet, and when I tried to retrieve the message, I received the error that the email was corrupted.
RETR command returned an error :" -- ERR Message corrupted".

However, I was able to delete the corrupted message, and then the mail flow was fine until another corrupted email was received.
Jochen Arndt 21-Mar-12 13:13pm    
Bad situation. I had a similar problem many years ago. You should contact your mail provider. His SMTP server must not accept such mails or his POP server must be able to deliver them. If he also provides an IMAP server, you may try to access the mail by IMAP which may get the mail.
[no name] 21-Mar-12 17:05pm    
Jochen,
I am very happy to see that there are others out there that rememember that you can check or send your POP3 e-mail via telnet. :)
Sergey Alexandrovich Kryukov 22-Mar-12 16:37pm    
Sure, a 5. I recognized my mistake and am thankful for pointing it out.
--SA
Jochen Arndt 23-Mar-12 4:00am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900