Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C# Python
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 21-Mar-12 6:46am
soby210
Edited 21-Mar-12 9:17am
v5
Comments
SAKryukov at 21-Mar-12 12:09pm
   
Who told you that rule?
--SA
pietvredeveld at 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 at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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]
  Permalink  
v2
Comments
soby at 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 at 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.
Randor at 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. :)
SAKryukov at 22-Mar-12 16:37pm
   
Sure, a 5. I recognized my mistake and am thankful for pointing it out.
--SA
Jochen Arndt at 23-Mar-12 4:00am
   
Thank you.
soby at 23-Mar-12 14:46pm
   
Thanks everyone for your inputs...it turned out to be a problem with the mail server. The server was letting in mails with attachments(with unknown problem at this time) which were causing the problem...to have a temporary fix we redirected the mails with attachment to another server to be dealt with...

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 195
3 DamithSL 195
4 Richard MacCutchan 178
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 22 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100