diff --git a/render b/render index 8ac7a8e..b887199 100755 --- a/render +++ b/render @@ -23,6 +23,13 @@ parser.add_argument('-a', dest='attachment_dir', action='store', default='attach args = parser.parse_args() options = vars(args) +def format_size(num): + for unit in [' bytes','KB','MB','GB']: + if num < 1024.0: + return "%3.1f%s" % (num, unit) + num /= 1024.0 + return "%3.1f%s" % (num, 'TB') + if os.path.isfile(options['database']) == False: print "Database file not found. Use the -d switch to specify a custom database path." exit(1) @@ -48,6 +55,19 @@ for message_id, sender, recipient, subject, timestamp, textbody, htmlbody, sha1_ message_id = cgi.escape(message_id, True) timestamp = datetime.fromtimestamp(timestamp).strftime("%A %B %e, %Y %H:%M:%S") + attachment_list = [] + attachment_cursor = database.cursor() + for attachment_hash, attachment_filename, attachment_type, message_hash, attachment_size in attachment_cursor.execute("SELECT * FROM attachments WHERE `message_hash` = ?", (sha1_hash,)): + attachment_extension = os.path.splitext(attachment_filename)[1][1:] + attachment_file = "%s.%s" % (attachment_hash, attachment_extension) + attachment_list.append('%s (%s, %s)' % (attachment_file, attachment_filename, attachment_type, format_size(attachment_size))) + + if len(attachment_list) > 0: + attachments = "".join(attachment_list) + print "ATTACHMENTS %s" % sha1_hash + else: + attachments = '
No attachments.
' + versions = {} if textbody != "": @@ -75,7 +95,8 @@ for message_id, sender, recipient, subject, timestamp, textbody, htmlbody, sha1_ 'title': options['title'], 'version': "Plaintext version", 'index': "../index.html", - 'versions': version_list + 'versions': version_list, + 'attachments': attachments } generated = template_message % variables @@ -93,7 +114,8 @@ for message_id, sender, recipient, subject, timestamp, textbody, htmlbody, sha1_ 'title': options['title'], 'version': "HTML version", 'index': "../index.html", - 'versions': version_list + 'versions': version_list, + 'attachments': attachments } generated = template_message % variables diff --git a/templates/message.html b/templates/message.html index 463ca3e..fbb26b4 100644 --- a/templates/message.html +++ b/templates/message.html @@ -17,6 +17,12 @@
+
+
Attachments:
+ %(attachments)s +
+
+ diff --git a/templates/style.css b/templates/style.css index 323b571..788e1ed 100644 --- a/templates/style.css +++ b/templates/style.css @@ -82,7 +82,7 @@ table td.body padding: 16px 13px; } -.version +.version, .attachment { display: block; margin: 2px 6px 8px 0px; @@ -91,7 +91,7 @@ table td.body font-weight: bold; } -a.version +a.version, a.attachment { padding: 4px 6px; background-color: #464646 !important; @@ -99,7 +99,12 @@ a.version text-decoration: none; } -a.version:hover +a.version:hover, a.attachment:hover { background-color: #333333 !important; } + +.light +{ + font-weight: normal; +}