Attachment 'notes.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - Lotus Notes Parser
   4 
   5     @copyright: 2006 by Bryan Tsai
   6     @license: GNU GPL, see COPYING for details.
   7 """
   8 
   9 import re
  10 from MoinMoin.parser import wiki
  11 
  12 STYLE  = 'margin-top: 2px; color:black; background-color:%s; '\
  13          'border: solid black 1px'
  14 COLOR  = 'white'
  15 
  16 class Parser:
  17     """
  18         Parse notes mail and enclose all headers into boxes.
  19     """
  20     def __init__(self, raw, request, **kw):
  21         self.raw = raw
  22         self.request = request
  23         self.form = request.form
  24         self._ = request.getText
  25         self.out = kw.get('out', request)
  26 
  27     def format(self, formatter):
  28         self.parse(self.raw, formatter)
  29 
  30     def wikify(self, txt, formatter):
  31         wikiizer = wiki.Parser(txt, self.request) 
  32         wikiizer.format(formatter)
  33     
  34     def parse(self, txt, formatter):
  35         if (0 == len(txt)):
  36             return
  37         
  38         html = ""
  39         match = re.search(r"^(from:?\s+?)?(.*)$\s+?^(sent:?\s*)?(.*)$\s+?^to:?\s+?(.*)$\s+?^(cc:?\s+?(.*)$\s+?)?^subject:?\s+?(.*)$", txt, re.IGNORECASE | re.MULTILINE)
  40         if match:
  41             if (-1 == match.start(1)):
  42                 pre_content = match.string[0:match.start(2)]
  43             else:
  44                 pre_content = match.string[0:match.start(1)]
  45             from1 = match.group(2)
  46             date = match.group(4)
  47             to = match.group(5)
  48             if (-1 != match.start(6)) and (-1 != match.start(7)):
  49                 cc = match.group(7)
  50             else:
  51                 cc = ''
  52             subject = match.group(8)
  53             content = match.string[match.end(8):]
  54         else:
  55             return self.wikify(txt, formatter)
  56         
  57         self.wikify(pre_content, formatter)
  58         
  59         html = '<br />'\
  60                '<fieldset style="%s">'\
  61                '<legend style="%s">%s</legend>'\
  62                'From: %s<br />'\
  63                'To: %s<br />' % (STYLE, 
  64                                  STYLE, 
  65                                  date, 
  66                                  from1.replace("<", "&lt;"), 
  67                                  to.replace("<", "&lt;"))
  68         
  69         if (0 < len(cc)):
  70             html += 'Cc: %s<br />' % cc.replace("<", "&lt;")
  71         
  72         html += 'Subject: %s<br />'\
  73                 '</fieldset><br />' % (subject)
  74         
  75         self.out.write(html)
  76         
  77         self.parse(content, formatter)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-03-29 09:29:03, 2.4 KB) [[attachment:notes.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.