# zwiki mailin - post an email message to a wiki page # # This method expects at least one argument, msg, an RFC822 email # message. This will be formatted as a wiki comment and appended to # the appropriate zwiki page. The page is selected as follows: # # - if called in a page context, use that page # - if called in a folder context, look for # 1. a zwiki page name appearing before @ in a recipient hdr (To,Cc,etc) # 2. or, the first page name appearing in the subject # 3. or, the defaultpage argument # 4. or, defaultpage hardcoded below (FrontPage) # # 1 & 2 may be turned off if you don't want them # # This is intended to receive email messages from a procmail recipe # like the following: # # # forward messages to a zwiki web # # assumes an entry for site in ~/.netrc # # processing only messages whose recipient contains 'wiki': # * ^TO.*wiki # * !^FROM_MAILER # :0 i # | curl -n -F 'msg=<-' http://site/wiki_folder/mailin # # todo: # in procmail, forward message+error to a human if post fails # support checking of sender against a member list # support size limits from types import * import re from DocumentTemplate.DT_Util import html_quote try: from Products.ZWiki.ZWikiRegexes import wikiname1,wikiname2,bracketedexpr except ImportError: # pre-0.9.4 ZWiki : from Products.ZWiki.ZWikiPage import wikiname1,wikiname2,bracketedexpr #wikinameexp = r'(%s|%s|%s)' % (wikiname1,wikiname2,bracketedexpr) wikinameexp = r'(%s|%s)' % (wikiname1,wikiname2) defaultpage = 'FrontPage' def mailin(self, msg, pagenameexp=wikinameexp, defaultpage=defaultpage, separator='\n\n', checkrecipient=1, checksubject=1): # extract essential fields # could use rfc822 ? # mo=rfc822.Message(mfile) # # hd={} # hd['to']=[] # for header in (mo.getaddrlist('to'), # mo.getaddrlist('cc'), # mo.getaddrlist('bcc')): # if not header: continue # for name, addr in header: # hd['to'].append(addr) # # hd['from']=mo.getaddr('from')[1] # hd['subject']=mo.getheader('subject') or '' author = re.search(r'(?m)^From: (.*)',msg) if author: author = author.group(1) else: author = '' date = re.search(r'(?m)^Date: (.*)',msg) if date: date = date.group(1) else: date = '' text = re.search(r'(?s)\n\n(.*)',msg) if text: text = text.group(1) else: text = '' # & do just a little html-prettification for web display. # If this comment gets sent out again to subscribers, zwiki # will try to strip this again. #comment = "