SF.net SVN: tmda: [2050] trunk/tmda/TMDA

[email protected] Mon, 02 Oct 2006 14:41:33 -0700
Newsgroups gmane.mail.spam.tmda.cvs
Message-ID <[email protected]>
Revision: 2050
          http://svn.sourceforge.net/tmda/?rev=2050&view=rev
Author:   lack
Date:     2006-10-02 14:41:29 -0700 (Mon, 02 Oct 2006)

Log Message:
-----------
Added "fullParse" optional parameter to Pending.Message,
TMDA.Queue.Queue.fetch_message and friends.  This allows client programs to
request that the entire message be parsed instead of the default "header-only"
parsing.

Modified Paths:
--------------
    trunk/tmda/TMDA/Pending.py
    trunk/tmda/TMDA/Queue/OriginalQueue.py
    trunk/tmda/TMDA/Queue/Queue.py
    trunk/tmda/TMDA/Util.py

Modified: trunk/tmda/TMDA/Pending.py
===================================================================
--- trunk/tmda/TMDA/Pending.py	2006-10-02 20:30:11 UTC (rev 2049)
+++ trunk/tmda/TMDA/Pending.py	2006-10-02 21:41:29 UTC (rev 2050)
@@ -352,11 +352,11 @@
     msg_size = 0
     bytes = 'bytes'
     confirm_accept_address = None
-    def __init__(self, msgid, recipient = None):
+    def __init__(self, msgid, recipient = None, fullParse = False):
         self.msgid = msgid
         if not Q.find_message(self.msgid):
 	    raise Errors.MessageError, '%s not found!' % self.msgid
-        self.msgobj = Q.fetch_message(self.msgid)
+        self.msgobj = Q.fetch_message(self.msgid, fullParse=fullParse)
 	self.recipient = recipient
         if self.recipient is None:
             self.recipient = self.msgobj.get('x-tmda-recipient')

Modified: trunk/tmda/TMDA/Queue/OriginalQueue.py
===================================================================
--- trunk/tmda/TMDA/Queue/OriginalQueue.py	2006-10-02 20:30:11 UTC (rev 2049)
+++ trunk/tmda/TMDA/Queue/OriginalQueue.py	2006-10-02 21:41:29 UTC (rev 2050)
@@ -124,9 +124,9 @@
 	del msg['X-TMDA-Recipient']
 
 
-    def fetch_message(self, mailid):
+    def fetch_message(self, mailid, fullParse=False):
 	fpath = os.path.join(Defaults.PENDING_DIR, mailid + '.msg')
-	msg = Util.msg_from_file(file(fpath, 'r'))
+	msg = Util.msg_from_file(file(fpath, 'r'),fullParse=fullParse)
 	return msg
 
 

Modified: trunk/tmda/TMDA/Queue/Queue.py
===================================================================
--- trunk/tmda/TMDA/Queue/Queue.py	2006-10-02 20:30:11 UTC (rev 2049)
+++ trunk/tmda/TMDA/Queue/Queue.py	2006-10-02 21:41:29 UTC (rev 2050)
@@ -89,10 +89,12 @@
 	pass
 
 
-    def fetch_message(self, mailid):
+    def fetch_message(self, mailid, fullParse=False):
 	"""
 	Fetch the contents of a message in the queue.  Should
 	return an email.Message like object.
+	Normally uses 'email.HeaderParser' for a quick parse unless 'fullParse'
+	is set to True, in which case it uses the full 'email.Parser'.
 	"""
 	pass
 

Modified: trunk/tmda/TMDA/Util.py
===================================================================
--- trunk/tmda/TMDA/Util.py	2006-10-02 20:30:11 UTC (rev 2049)
+++ trunk/tmda/TMDA/Util.py	2006-10-02 21:41:29 UTC (rev 2050)
@@ -517,7 +517,7 @@
     return rp
 
 
-def msg_from_file(fp, strict=False):
+def msg_from_file(fp, strict=False, fullParse=False):
     """Read a file and parse its contents into a Message object model.
     Replacement for email.message_from_file().
     
@@ -526,8 +526,12 @@
     body as a string.  This is faster, and also helps us avoid
     problems trying to parse spam with broken MIME bodies."""
     from email.Message import Message
-    from email.Parser import HeaderParser
-    msg = HeaderParser(Message, strict=strict).parse(fp)
+    if fullParse:
+	from email.Parser import Parser
+	msg = Parser(Message, strict=strict).parse(fp)
+    else:
+	from email.Parser import HeaderParser
+	msg = HeaderParser(Message, strict=strict).parse(fp)
     msg.header_parsed = 1
     return msg
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.