Ran update-copyright.py.
[pygrader.git] / pygrader / extract_mime.py
index 97d6483c76525b8a2827868174421ab069a44e50..e1f897de5c4693767a17811edd4f34eb4db52dfb 100644 (file)
@@ -1,4 +1,18 @@
-# Copyright
+# Copyright (C) 2012 W. Trevor King <wking@tremily.us>
+#
+# This file is part of pygrader.
+#
+# pygrader is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# pygrader is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# pygrader.  If not, see <http://www.gnu.org/licenses/>.
 
 """Extract message parts with a given MIME type from a mailbox.
 """
@@ -13,17 +27,28 @@ import os.path as _os_path
 import time as _time
 
 from . import LOG as _LOG
-from .color import color_string as _color_string
-from .color import standard_colors as _standard_colors
 
 
-def message_time(message, use_color=None):
-    highlight,lowlight,good,bad = _standard_colors(use_color=use_color)
+def message_time(message):
+    """Get the Unix time when ``message`` was received.
+
+    >>> from email.utils import formatdate
+    >>> from pgp_mime.email import encodedMIMEText
+    >>> msg = encodedMIMEText('Ping!')
+    >>> msg['Received'] = (
+    ...     'from smtp.home.net (smtp.home.net [123.456.123.456]) '
+    ...     'by smtp.mail.uu.edu (Postfix) with ESMTP id 5BA225C83EF '
+    ...     'for <wking@tremily.us>; Sun, 09 Oct 2011 11:50:46 -0400 (EDT)')
+    >>> time = message_time(msg)
+    >>> time
+    1318175446.0
+    >>> formatdate(time)
+    'Sun, 09 Oct 2011 15:50:46 -0000'
+    """
     received = message['Received']  # RFC 822
     if received is None:
         mid = message['Message-ID']
-        _LOG.debug(_color_string(
-                string='no Received in {}'.format(mid), color=lowlight))
+        _LOG.debug('no Received in {}'.format(mid))
         return None
     date = received.split(';', 1)[1]
     return _time.mktime(_email_utils.parsedate(date))