You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.6 KiB
Plaintext

#!/usr/bin/python
import os, argparse, hashlib, sqlite3, time
parser = argparse.ArgumentParser(description='Renders static HTML pages and indexes from an SQLite database of emails and an attachment folder.')
12 years ago
parser.add_argument('-o', dest='output_dir', action='store', default='render',
help='path of the directory where rendered files should be stored')
parser.add_argument('-t', dest='template_dir', action='store', default='templates',
help='path where the template files are')
parser.add_argument('-d', dest='database', action='store', default='emails.db',
help='path of the database that should be used to render the e-mail files')
parser.add_argument('-a', dest='attachment_dir', action='store', default='attachments',
help='path where attachments are stored')
args = parser.parse_args()
options = vars(args)
12 years ago
if os.path.isfile(options['database']) == False:
print "Database file not found. Use the -d switch to specify a custom database path."
exit(1)
# Connect to database
database = sqlite3.connect(options['database'])
cursor = database.cursor()
12 years ago
# Load templates
template_message = open('%s/message.html' % options['template_dir']).read()
12 years ago
for message in cursor.execute("SELECT * FROM emails"):
message_id, sender, recipient, subject, timestamp, textbody, htmlbody, sha1_hash = message
12 years ago
generated = template_message % {'subject': subject, 'date': timestamp, 'from': sender, 'to': recipient, 'body': textbody, 'title': "admin@cryto.net", 'version': "Plaintext version"}
print generated
exit(1)