Display a list of attachments

master
Sven Slootweg 12 years ago
parent 31cd9e70c1
commit 42bcaae8d7

@ -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('<a href="../attachments/%s" class="attachment">%s (%s, %s)</a>' % (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 = '<div class="attachment light">No attachments.</div>'
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

@ -17,6 +17,12 @@
<div class="clear"></div>
</div>
<div>
<div class="version">Attachments:</div>
%(attachments)s
<div class="clear"></div>
</div>
<table class="message message-detail">
<tbody>
<tr>

@ -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;
}

Loading…
Cancel
Save