git » sea » commit 2c77293

Use the email date for path generation

author Alberto Bertogli
2010-05-03 07:11:54 UTC
committer Alberto Bertogli
2010-05-03 07:11:54 UTC
parent 6f87155b8ab9f8121cc37c7ba9550938f73cb918

Use the email date for path generation

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

sea +7 -2

diff --git a/sea b/sea
index ed85d52..248d356 100755
--- a/sea
+++ b/sea
@@ -9,6 +9,7 @@ first parameter.
 
 import sys
 import email
+import email.utils
 import mimetypes
 import os
 import time
@@ -17,16 +18,20 @@ import time
 def main(infd, basepath):
 	m = email.message_from_file(infd)
 
-	f_name, f_email = email.Utils.parseaddr(m['from'])
+	f_name, f_email = email.utils.parseaddr(m['from'])
 	subject = m['subject']
 
 	if not m.is_multipart():
 		# no attachments
 		return 0
 
+	date = time.localtime()
+	if 'date' in m:
+		date = email.utils.parsedate(m['date'])
+
 	# put the attachments in basepath/<from>-<time>
 	outpath = "%s/%s~%s/" % (basepath, f_email.replace('/', ''),
-			time.strftime("%Y-%m-%d-%H:%M:%S"))
+			time.strftime("%Y-%m-%d-%H:%M:%S", date))
 
 	if not os.path.exists(outpath):
 		os.mkdir(outpath)