Code

e4af8bca033935d96eae22a0eb78762c445b2343
[roundup.git] / detectors / emailauditor.py
2 def eml_to_mht(db, cl, nodeid, newvalues):
3     '''This auditor fires whenever a new file entity is created.
5     If the file is of type message/rfc822, we tack onthe extension .eml.
7     The reason for this is that Microsoft Internet Explorer will not open
8     things with a .eml attachment, as they deem it 'unsafe'. Worse yet,
9     they'll just give you an incomprehensible error message. For more 
10     information, please see: 
12     http://support.microsoft.com/default.aspx?scid=kb;EN-US;825803
14     Their suggested work around is (excerpt):
16      WORKAROUND
18      To work around this behavior, rename the .EML file that the URL
19      links to so that it has a .MHT file name extension, and then update
20      the URL to reflect the change to the file name. To do this:
22      1. In Windows Explorer, locate and then select the .EML file that
23         the URL links.
24      2. Right-click the .EML file, and then click Rename.
25      3. Change the file name so that the .EML file uses a .MHT file name
26         extension, and then press ENTER.
27      4. Updated the URL that links to the file to reflect the new file
28         name extension.
30     So... we do that. :)'''
31     if newvalues.get('type', '').lower() == "message/rfc822":
32         if not newvalues.has_key('name'):
33             newvalues['name'] = 'email.mht'
34             return
35         name = newvalues['name']
36         if name.endswith('.eml'):
37             name = name[:-4]
38         newvalues['name'] = name + '.mht'
40 def init(db):
41     db.file.audit('create', eml_to_mht)