From: Andrew V. <av...@us...> - 2005-04-15 13:11:08
|
Update of /cvsroot/mailmanager/mailmanager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15402 Modified Files: Tag: db-backend MailManager.py Log Message: Links now displayed correctly & new lines in messages are now respected. Index: MailManager.py =================================================================== RCS file: /cvsroot/mailmanager/mailmanager/MailManager.py,v retrieving revision 1.147.2.35 retrieving revision 1.147.2.36 diff -u -d -r1.147.2.35 -r1.147.2.36 --- MailManager.py 15 Apr 2005 12:17:26 -0000 1.147.2.35 +++ MailManager.py 15 Apr 2005 13:10:53 -0000 1.147.2.36 @@ -29,7 +29,7 @@ from MMUserFolder import manage_addMMUserFolder # Python library modules. -import re, os, stat +import re, os, stat, cgi import time import email.Utils from calendar import monthrange @@ -39,6 +39,7 @@ # Constants. mversion = 9 +url_pat = re.compile(r'(https?|ftp)://\S*[^,;:.!?)\]\'"\s]') manage_addMailManagerForm = PageTemplateFile('www/manage_addMailManagerForm', @@ -144,10 +145,6 @@ {'id': 'mversion', 'type': 'int', 'mode': ''} ) - def testHook(self): - """ """ - return 'mailmanager_db' - # Initialization def __init__(self, id, title, admin_username, admin_email, admin_password, @@ -357,6 +354,21 @@ # Convenience Functions for Page Templates + security.declareProtected('View MailManager', 'formatBody') + def formatBody(self, body): + """Format a message body ready for display. + + This boils down to quoting HTML characters, makeing URLs links and + converting newlines to <br />. We assume the message is in unicode. + + Once http://www.zope.org/Collectors/CMF/335 is released this could + move into a Pluggable Brain on the listMessages ZSQL method. + """ + body = cgi.escape(body, quote=True) + body = url_pat.sub(r'<a href="\g<0>" target="_blank">\g<0></a>', body) + body = '<br />'.join(body.splitlines()) + return body.encode('utf-8') + security.declareProtected('View MailManager', 'formatTarget') def formatTarget(self, target): """Convert a response target in days to a human readable form. |