Quantcast

question about the best way to check if an email is valid (RFC compliant)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

question about the best way to check if an email is valid (RFC compliant)

xavier delannoy
Hi,

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:

   # Parse the received email
   try:
     received_email = email.message_from_string(args)
   except email.errors.MessageError, msg:
     self.ok((False, msg), msg)

I test with an invalid email (for example, with a missing closed
boundary), and no exception is raised. The email lib fixes the issue.

Is there a way to tell the email lib to not modify the email, and raise
an exception ?

Regards,

-- Xavier

QA Engineer at Cloudmark Labs.
_______________________________________________
Email-SIG mailing list
[hidden email]
Your options: http://mail.python.org/mailman/options/email-sig/lists%40nabble.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: question about the best way to check if an email is valid (RFC compliant)

R. David Murray
On Wed, 06 Jul 2011 11:53:43 +0200, xavier delannoy <[hidden email]> 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.

--David
_______________________________________________
Email-SIG mailing list
[hidden email]
Your options: http://mail.python.org/mailman/options/email-sig/lists%40nabble.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: question about the best way to check if an email is valid (RFC compliant)

xavier delannoy
On 07/06/2011 02:08 PM, R. David Murray wrote:

> On Wed, 06 Jul 2011 11:53:43 +0200, xavier delannoy<[hidden email]>  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


_______________________________________________
Email-SIG mailing list
[hidden email]
Your options: http://mail.python.org/mailman/options/email-sig/lists%40nabble.com

sample.tgz (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: question about the best way to check if an email is valid (RFC compliant)

R. David Murray
In reply to this post by R. David Murray
On Wed, 06 Jul 2011 14:35:31 +0200, xavier delannoy <[hidden email]> wrote:
> 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.

Please file a bug report about this at bugs.python.org and add me (tracker
id r.david.murray) to the nosy list.  It may not be fixable as a bug since
the current email package makes no promises about detecting all errors.
However, since as you point out the resulting message structure is
changed, it probably is classifiable as a bug.  I'll take a look at
the issue when I get a chance, or you could propose a patch if you are
motivated to do so.

--
R. David Murray           http://www.bitdance.com
_______________________________________________
Email-SIG mailing list
[hidden email]
Your options: http://mail.python.org/mailman/options/email-sig/lists%40nabble.com
Loading...