[Email-SIG] question about the best way to check if an email is valid (RFC compliant)

xavier delannoy xavier.delannoy at cloudmark.com
Wed Jul 6 15:58:22 CEST 2011


On 07/06/2011 02:08 PM, R. David Murray wrote:
> On Wed, 06 Jul 2011 11:53:43 +0200, xavier delannoy<xavier.delannoy at cloudmark.com>  wrote:
>> I use the python email library for an Automation Test Framework. The
>> framework test a Mail Transfert Agent. I notice that the "email" library
>> silently fix a lot of MIME errors. I can understand this behaviour, but
>> I need to validate that the email sent by the MTA are correct.
>> I wonder if there's a way to use the python MIME Parser more
>> "aggressively" (without modifying the email) and raise and exception as
>> soon as an error is detected.
>>
>> Here's my needs and an extract of my python:
>
> Not at the moment.  You can check the defects attribute afterward to
> see if there were any detected errors, though.
>
> In email6 (planned for python 3.3) we will be providing a facility for
> doing the raise immediately.  I don't know what you mean by leave
> the message unmodified, though, since the input string is already
> unmodified, and you won't get a message object when an error is raised.
>

If an error is raised, and if I won't get a message object, then I'm
fine. But with Python 2.7.1, I get a message object and the attribute
defects is empty.

In the attachment you will find:
   - orig.eml : an email with an error. The boundary
"000101020201080900040301" isn't closed
   - after_parsing.eml: same email after calling email.message_from_file()
The boundary is now closed. And the defects attribute is empty
   - test.py: python script to reproduce.

-- Xavier


> --David

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sample.tgz
Type: application/x-compressed-tar
Size: 1853 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/email-sig/attachments/20110706/42f8810c/attachment.bin>


More information about the Email-SIG mailing list