comparison MoinMoin/mail/mailimport.py @ 1286:2c27897f5c98

mailimport: process all To: addresses, link mail page from subject
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 15 Aug 2006 13:15:59 +0200
parents bb4758056a46
children 210f96eeda09
comparison
equal deleted inserted replaced
1285:1ed1a0ac1715 1286:2c27897f5c98
75 """ Processes the read message and decodes attachments. """ 75 """ Processes the read message and decodes attachments. """
76 attachments = [] 76 attachments = []
77 html_data = [] 77 html_data = []
78 text_data = [] 78 text_data = []
79 79
80 to_addr = get_addrs(message, 'To')[0]
81 from_addr = get_addrs(message, 'From')[0] 80 from_addr = get_addrs(message, 'From')[0]
81 to_addrs = get_addrs(message, 'To')
82 cc_addrs = get_addrs(message, 'Cc') 82 cc_addrs = get_addrs(message, 'Cc')
83 bcc_addrs = get_addrs(message, 'Bcc') 83 bcc_addrs = get_addrs(message, 'Bcc')
84 target_addrs = [to_addr] + cc_addrs + bcc_addrs 84 target_addrs = to_addrs + cc_addrs + bcc_addrs
85 85
86 subject = decode_2044(message['Subject']) 86 subject = decode_2044(message['Subject'])
87 date = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(mktime_tz(parsedate_tz(message['Date'])))) 87 date = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(mktime_tz(parsedate_tz(message['Date']))))
88 88
89 log("Processing mail:\n To: %r\n From: %r\n Subject: %r" % (to_addr, from_addr, subject)) 89 log("Processing mail:\n To: %r\n From: %r\n Subject: %r" % (to_addrs[0], from_addr, subject))
90 90
91 for part in message.walk(): 91 for part in message.walk():
92 log(" Part " + repr((part.get_charsets(), part.get_content_charset(), part.get_content_type(), part.is_multipart(), ))) 92 log(" Part " + repr((part.get_charsets(), part.get_content_charset(), part.get_content_type(), part.is_multipart(), )))
93 ct = part.get_content_type() 93 ct = part.get_content_type()
94 cs = part.get_content_charset() or "latin1" 94 cs = part.get_content_charset() or "latin1"
115 elif not part.is_multipart(): 115 elif not part.is_multipart():
116 log("Unknown mail part " + repr((part.get_charsets(), part.get_content_charset(), part.get_content_type(), part.is_multipart(), ))) 116 log("Unknown mail part " + repr((part.get_charsets(), part.get_content_charset(), part.get_content_type(), part.is_multipart(), )))
117 117
118 return {'text': u"".join(text_data), 'html': u"".join(html_data), 118 return {'text': u"".join(text_data), 'html': u"".join(html_data),
119 'attachments': attachments, 119 'attachments': attachments,
120 'target_addrs': target_addrs, 'to_addr': to_addr, 'cc_addrs': cc_addrs, 'bcc_addrs': bcc_addrs, 120 'target_addrs': target_addrs, 'to_addrs': to_addrs, 'cc_addrs': cc_addrs, 'bcc_addrs': bcc_addrs,
121 'from_addr': from_addr, 121 'from_addr': from_addr,
122 'subject': subject, 'date': date} 122 'subject': subject, 'date': date}
123 123
124 def get_pagename_content(msg, email_subpage_template, wiki_address): 124 def get_pagename_content(msg, email_subpage_template, wiki_address):
125 """ Generates pagename and content according to the specification 125 """ Generates pagename and content according to the specification
258 table_ends = lineno + 1 258 table_ends = lineno + 1
259 elif table_ends is not None and not line.startswith("||"): 259 elif table_ends is not None and not line.startswith("||"):
260 break 260 break
261 261
262 table_header = (u"\n\n## mail_overview (don't delete this line)\n" + 262 table_header = (u"\n\n## mail_overview (don't delete this line)\n" +
263 u"|| '''[[GetText(From)]] ''' || '''[[GetText(To)]] ''' || '''[[GetText(Subject)]] ''' || '''[[GetText(Date)]] ''' || '''[[GetText(Link)]] ''' || '''[[GetText(Attachments)]] ''' ||\n" 263 u"|| '''[[GetText(From)]] ''' || '''[[GetText(To)]] ''' || '''[[GetText(Content)]] ''' || '''[[GetText(Date)]] ''' || '''[[GetText(Attachments)]] ''' ||\n"
264 ) 264 )
265 265
266 from_col = email_to_markup(request, msg['from_addr']) 266 from_col = email_to_markup(request, msg['from_addr'])
267 to_col = ' '.join([email_to_markup(request, (realname, mailaddr)) for realname, mailaddr in msg['target_addrs'] if mailaddr != wiki_address]) 267 to_col = ' '.join([email_to_markup(request, (realname, mailaddr))
268 subj_col = msg['subject'] 268 for realname, mailaddr in msg['target_addrs'] if mailaddr != wiki_address])
269 subj_col = '["%s" %s]' % (pagename, msg['subject'])
269 date_col = msg['date'] 270 date_col = msg['date']
270 page_col = pagename
271 attach_col = " ".join(attachment_links) 271 attach_col = " ".join(attachment_links)
272 new_line = u'|| %s || %s || %s || [[DateTime(%s)]] || ["%s"] || %s ||' % ( 272 new_line = u'|| %s || %s || %s || [[DateTime(%s)]] || %s ||' % (from_col, to_col, subj_col, date_col, attach_col)
273 from_col, to_col, subj_col, date_col, page_col, attach_col)
274 if found_table is not None: 273 if found_table is not None:
275 content = "\n".join(old_content[:table_ends] + [new_line] + old_content[table_ends:]) 274 content = "\n".join(old_content[:table_ends] + [new_line] + old_content[table_ends:])
276 else: 275 else:
277 content = "\n".join(old_content) + table_header + new_line 276 content = "\n".join(old_content) + table_header + new_line
278 277