Re: question about the best way to check if an email is valid (RFC compliant)
xavier delannoy <[email protected]> Wed, 6 Jul 2011 15:58:22 +0200
| Newsgroups | gmane.comp.python.mime.devel |
|---|---|
| Message-ID | <[email protected]> |
--------------000403090309000904000302 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit On 07/06/2011 02:08 PM, R. David Murray wrote: > On Wed, 06 Jul 2011 11:53:43 +0200, xavier delannoy<[email protected]> 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 --------------000403090309000904000302 Content-Type: application/x-compressed-tar; name="sample.tgz" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="sample.tgz" H4sIALxpFE4AA+1a+3PbNhL2r+aM/weUGdV2r3yApF60qNSRldRtnKS10vTu5kYDiZDEK18l IT/y13dB0g5tSRYtPzpt8cljEiS12F0sdpffKEq8qUoDf+sJoQMalsWPuFnXy0eOZtPStzBu 6HW9bhhGc0vHhoXNLaQ/pVJXmKeMJAhtXZAzjybuyufW3f+L4mc6pt4ZdW00SaIAYaOp6vDB aO+/uG2ouNFSjbql4v/t70jbo0t0fPIBnXtshkbe5zRgMVz1XGT9x/wBz2BZdYOcv4Ej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ICAgICAgICAgIC AgICAgKPhD8A8l4jhgBQAAA= --------------000403090309000904000302 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline