annotate 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
rev   line source
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
1 """
750
f158c4e8fea2 moved mail related functions to MoinMoin.mail
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 718
diff changeset
2 MoinMoin - E-Mail Import into wiki
694
0c32fb700c3c Added URL support, added comment.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 693
diff changeset
3
0c32fb700c3c Added URL support, added comment.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 693
diff changeset
4 Just call this script with the URL of the wiki as a single argument
0c32fb700c3c Added URL support, added comment.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 693
diff changeset
5 and feed the mail into stdin.
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
6
1154
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
7 @copyright: 2006 by MoinMoin:AlexanderSchremmer,
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
8 2006 by MoinMoin:ThomasWaldmann
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
9 @license: GNU GPL, see COPYING for details.
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
10 """
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
11
702
433a0ee1635d some cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 701
diff changeset
12 import os, sys, re, time
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
13 import email
1155
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
14 from email.Utils import getaddresses, parseaddr, parsedate_tz, mktime_tz
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
15
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
16 from MoinMoin import user, wikiutil, config
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
17 from MoinMoin.action.AttachFile import add_attachment, AttachmentAlreadyExists
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
18 from MoinMoin.Page import Page
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
19 from MoinMoin.PageEditor import PageEditor
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
20 from MoinMoin.request.CLI import Request as RequestCLI
693
dd62645b4219 Commented out debug lines.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 692
diff changeset
21 # python, at least up to 2.4, ships a broken parser for headers
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
22 from MoinMoin.support.HeaderFixed import decode_header
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
23
1152
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
24 infile = sys.stdin
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
25
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
26 debug = False
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
27
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
28 re_subject = re.compile(r"\[([^\]]*)\]")
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
29 re_sigstrip = re.compile("\r?\n-- \r?\n.*$", re.S)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
30
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
31 class attachment(object):
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
32 """ Represents an attachment of a mail. """
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
33 def __init__(self, filename, mimetype, data):
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
34 self.filename = filename
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
35 self.mimetype = mimetype
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
36 self.data = data
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
37
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
38 def __repr__(self):
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
39 return "<attachment filename=%r mimetype=%r size=%i bytes>" % (
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
40 self.filename, self.mimetype, len(self.data))
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
41
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
42 class ProcessingError(Exception):
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
43 pass
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
44
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
45 def log(text):
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
46 if debug:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
47 print >>sys.stderr, text
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
48
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
49 def decode_2044(header):
702
433a0ee1635d some cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 701
diff changeset
50 """ Decodes header field. See RFC 2044. """
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
51 chunks = decode_header(header)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
52 chunks_decoded = []
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
53 for i in chunks:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
54 chunks_decoded.append(i[0].decode(i[1] or 'ascii'))
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
55 return u''.join(chunks_decoded).strip()
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
56
1154
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
57 def email_to_markup(request, email):
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
58 """ transform the (realname, mailaddr) tuple we get in email argument to
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
59 some string usable as wiki markup, that represents that person (either
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
60 HomePage link for a wiki user, or just the realname of the person). """
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
61 realname, mailaddr = email
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
62 u = user.get_by_email_address(request, mailaddr)
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
63 if u:
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
64 markup = u.wikiHomeLink()
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
65 else:
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
66 markup = realname or mailaddr
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
67 return markup
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
68
1155
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
69 def get_addrs(message, header):
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
70 """ get a list of tuples (realname, mailaddr) from the specified header """
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
71 dec_hdr = [decode_2044(hdr) for hdr in message.get_all(header, [])]
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
72 return getaddresses(dec_hdr)
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
73
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
74 def process_message(message):
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
75 """ Processes the read message and decodes attachments. """
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
76 attachments = []
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
77 html_data = []
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
78 text_data = []
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
79
1155
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
80 from_addr = get_addrs(message, 'From')[0]
1286
2c27897f5c98 mailimport: process all To: addresses, link mail page from subject
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1155
diff changeset
81 to_addrs = get_addrs(message, 'To')
1155
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
82 cc_addrs = get_addrs(message, 'Cc')
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
83 bcc_addrs = get_addrs(message, 'Bcc')
1286
2c27897f5c98 mailimport: process all To: addresses, link mail page from subject
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1155
diff changeset
84 target_addrs = to_addrs + cc_addrs + bcc_addrs
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
85
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
86 subject = decode_2044(message['Subject'])
718
7df204e270ff Mail import - Added support for 8 bit mails, renamed config fields from email_ to mail_import_, added support for DateTime macro, fixed table recognition.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 715
diff changeset
87 date = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(mktime_tz(parsedate_tz(message['Date']))))
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
88
1286
2c27897f5c98 mailimport: process all To: addresses, link mail page from subject
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1155
diff changeset
89 log("Processing mail:\n To: %r\n From: %r\n Subject: %r" % (to_addrs[0], from_addr, subject))
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
90
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
91 for part in message.walk():
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
92 log(" Part " + repr((part.get_charsets(), part.get_content_charset(), part.get_content_type(), part.is_multipart(), )))
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
93 ct = part.get_content_type()
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
94 cs = part.get_content_charset() or "latin1"
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
95 payload = part.get_payload(None, True)
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
96
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
97 fn = part.get_filename()
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
98 if fn is not None and fn.startswith("=?"): # heuristics ...
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
99 fn = decode_2044(fn)
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
100
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
101 if fn is None and part["Content-Disposition"] is not None and "attachment" in part["Content-Disposition"]:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
102 # this doesn't catch the case where there is no content-disposition but there is a file to offer to the user
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
103 # i hope that this can be only found in mails that are older than 10 years,
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
104 # so I won't care about it here
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
105 fn = part["Content-Description"] or "NoName"
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
106 if fn:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
107 a = attachment(fn, ct, payload)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
108 attachments.append(a)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
109 else:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
110 if ct == 'text/plain':
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
111 text_data.append(payload.decode(cs))
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
112 log(repr(payload.decode(cs)))
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
113 elif ct == 'text/html':
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
114 html_data.append(payload.decode(cs))
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
115 elif not part.is_multipart():
700
45cf56e067c5 Added support for looking in cc and bcc.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 699
diff changeset
116 log("Unknown mail part " + repr((part.get_charsets(), part.get_content_charset(), part.get_content_type(), part.is_multipart(), )))
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
117
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
118 return {'text': u"".join(text_data), 'html': u"".join(html_data),
700
45cf56e067c5 Added support for looking in cc and bcc.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 699
diff changeset
119 'attachments': attachments,
1286
2c27897f5c98 mailimport: process all To: addresses, link mail page from subject
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1155
diff changeset
120 'target_addrs': target_addrs, 'to_addrs': to_addrs, 'cc_addrs': cc_addrs, 'bcc_addrs': bcc_addrs,
1155
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
121 'from_addr': from_addr,
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
122 'subject': subject, 'date': date}
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
123
700
45cf56e067c5 Added support for looking in cc and bcc.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 699
diff changeset
124 def get_pagename_content(msg, email_subpage_template, wiki_address):
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
125 """ Generates pagename and content according to the specification
701
276079601342 Fixed table search.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 700
diff changeset
126 that can be found on MoinMoin:FeatureRequests/WikiEmailintegration """
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
127
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
128 generate_summary = False
695
82e482f6eb13 Enabled HTML mails, forgot to remove a code line.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 694
diff changeset
129 choose_html = True
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
130
700
45cf56e067c5 Added support for looking in cc and bcc.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 699
diff changeset
131 pagename_tpl = ""
1155
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
132 for addr in msg['target_addrs']:
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
133 if addr[1].strip().lower() == wiki_address:
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
134 pagename_tpl = addr[0]
bb4758056a46 mailimport: list multiple to/cc recipients in To: column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1154
diff changeset
135 break
700
45cf56e067c5 Added support for looking in cc and bcc.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 699
diff changeset
136
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
137 if not pagename_tpl:
1152
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
138 subj = msg['subject'].strip()
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
139 m = re_subject.search(subj)
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
140 if m:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
141 pagename_tpl = m.group(1)
1152
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
142 # remove the pagename template from the subject:
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
143 subj = re_subject.sub('', subj, 1).strip()
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
144 msg['subject'] = subj
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
145 else:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
146 # special fix for outlook users :-)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
147 if pagename_tpl[-1] == pagename_tpl[0] == "'":
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
148 pagename_tpl = pagename_tpl[1:-1]
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
149
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
150 if pagename_tpl.endswith("/"):
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
151 pagename_tpl += email_subpage_template
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
152
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
153 # last resort
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
154 if not pagename_tpl:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
155 pagename_tpl = email_subpage_template
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
156
702
433a0ee1635d some cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 701
diff changeset
157 # rewrite using string.formatter when python 2.4 is mandatory
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
158 pagename = (pagename_tpl.replace("$from", msg['from_addr'][0]).
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
159 replace("$date", msg['date']).
715
eaf76d312ea5 mailimport: use , not
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 707
diff changeset
160 replace("$subject", msg['subject']))
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
161
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
162 if pagename.startswith("+ ") and "/" in pagename:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
163 generate_summary = True
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
164 pagename = pagename[1:].lstrip()
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
165
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
166 if choose_html and msg['html']:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
167 content = "{{{#!html\n%s\n}}}" % msg['html'].replace("}}}", "} } }")
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
168 else:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
169 # strip signatures ...
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
170 content = re_sigstrip.sub("", msg['text'])
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
171
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
172 return {'pagename': pagename, 'content': content, 'generate_summary': generate_summary}
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
173
704
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
174 def import_mail_from_string(request, string):
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
175 """ Reads an RFC 822 compliant message from a string and imports it
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
176 to the wiki. """
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
177 return import_mail_from_message(request, email.message_from_string(string))
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
178
1152
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
179 def import_mail_from_file(request, infile):
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
180 """ Reads an RFC 822 compliant message from the file `infile` and imports it to
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
181 the wiki. """
1152
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
182 return import_mail_from_message(request, email.message_from_file(infile))
704
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
183
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
184 def import_mail_from_message(request, message):
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
185 """ Reads a message generated by the email package and imports it
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
186 to the wiki. """
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
187 msg = process_message(message)
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
188
718
7df204e270ff Mail import - Added support for 8 bit mails, renamed config fields from email_ to mail_import_, added support for DateTime macro, fixed table recognition.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 715
diff changeset
189 email_subpage_template = request.cfg.mail_import_subpage_template
7df204e270ff Mail import - Added support for 8 bit mails, renamed config fields from email_ to mail_import_, added support for DateTime macro, fixed table recognition.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 715
diff changeset
190 wiki_address = request.cfg.mail_import_wiki_address or request.cfg.mail_from
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
191
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
192 request.user = user.get_by_email_address(request, msg['from_addr'][1])
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
193
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
194 if not request.user:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
195 raise ProcessingError("No suitable user found for mail address %r" % (msg['from_addr'][1], ))
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
196
700
45cf56e067c5 Added support for looking in cc and bcc.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 699
diff changeset
197 d = get_pagename_content(msg, email_subpage_template, wiki_address)
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
198 pagename = d['pagename']
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
199 generate_summary = d['generate_summary']
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
200
718
7df204e270ff Mail import - Added support for 8 bit mails, renamed config fields from email_ to mail_import_, added support for DateTime macro, fixed table recognition.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 715
diff changeset
201 comment = u"Mail: '%s'" % (msg['subject'], )
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
202
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
203 page = PageEditor(request, pagename, do_editor_backup=0)
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
204
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
205 if not request.user.may.save(page, "", 0):
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
206 raise ProcessingError("Access denied for page %r" % pagename)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
207
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
208 attachments = []
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
209
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
210 for att in msg['attachments']:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
211 i = 0
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
212 while 1:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
213 if i == 0:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
214 fname = att.filename
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
215 else:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
216 components = att.filename.split(".")
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
217 new_suffix = "-" + str(i)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
218 # add the counter before the file extension
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
219 if len(components) > 1:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
220 fname = u"%s%s.%s" % (u".".join(components[:-1]), new_suffix, components[-1])
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
221 else:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
222 fname = att.filename + new_suffix
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
223 try:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
224 # get the fname again, it might have changed
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
225 fname = add_attachment(request, pagename, fname, att.data)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
226 attachments.append(fname)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
227 except AttachmentAlreadyExists:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
228 i += 1
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
229 else:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
230 break
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
231
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
232 # build an attachment link table for the page with the e-mail
1151
056cd240cff9 mailimport: display only filename (not pagename) in overview table column
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1150
diff changeset
233 attachment_links = [""] + [u'''[attachment:"%s/%s" %s]''' % (pagename, att, att) for att in attachments]
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
234
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
235 # assemble old page content and new mail body together
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
236 old_content = Page(request, pagename).get_raw_body()
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
237 if old_content:
696
0d16d47c6d02 Small clean ups
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 695
diff changeset
238 new_content = u"%s\n-----\n%s" % (old_content, d['content'], )
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
239 else:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
240 new_content = d['content']
699
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
241 new_content += "\n" + u"\n * ".join(attachment_links)
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
242
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
243 try:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
244 page.saveText(new_content, 0, comment=comment)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
245 except page.AccessDenied:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
246 raise ProcessingError("Access denied for page %r" % pagename)
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
247
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
248 if generate_summary and "/" in pagename:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
249 parent_page = u"/".join(pagename.split("/")[:-1])
699
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
250 old_content = Page(request, parent_page).get_raw_body().splitlines()
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
251
699
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
252 found_table = None
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
253 table_ends = None
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
254 for lineno, line in enumerate(old_content):
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
255 if line.startswith("## mail_overview") and old_content[lineno+1].startswith("||"):
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
256 found_table = lineno
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
257 elif found_table is not None and line.startswith("||"):
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
258 table_ends = lineno + 1
701
276079601342 Fixed table search.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 700
diff changeset
259 elif table_ends is not None and not line.startswith("||"):
276079601342 Fixed table search.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 700
diff changeset
260 break
993
1547a168325a mail package whitespace-only cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 750
diff changeset
261
699
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
262 table_header = (u"\n\n## mail_overview (don't delete this line)\n" +
1286
2c27897f5c98 mailimport: process all To: addresses, link mail page from subject
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1155
diff changeset
263 u"|| '''[[GetText(From)]] ''' || '''[[GetText(To)]] ''' || '''[[GetText(Content)]] ''' || '''[[GetText(Date)]] ''' || '''[[GetText(Attachments)]] ''' ||\n"
699
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
264 )
1154
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
265
44632345fbfb mailimport: use link to homepage or realname in from/to column, user.wikiHomeLink() to generate markup for user's homepage link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1152
diff changeset
266 from_col = email_to_markup(request, msg['from_addr'])
1286
2c27897f5c98 mailimport: process all To: addresses, link mail page from subject
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1155
diff changeset
267 to_col = ' '.join([email_to_markup(request, (realname, mailaddr))
2c27897f5c98 mailimport: process all To: addresses, link mail page from subject
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1155
diff changeset
268 for realname, mailaddr in msg['target_addrs'] if mailaddr != wiki_address])
2c27897f5c98 mailimport: process all To: addresses, link mail page from subject
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1155
diff changeset
269 subj_col = '["%s" %s]' % (pagename, msg['subject'])
1152
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
270 date_col = msg['date']
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
271 attach_col = " ".join(attachment_links)
1286
2c27897f5c98 mailimport: process all To: addresses, link mail page from subject
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1155
diff changeset
272 new_line = u'|| %s || %s || %s || [[DateTime(%s)]] || %s ||' % (from_col, to_col, subj_col, date_col, attach_col)
718
7df204e270ff Mail import - Added support for 8 bit mails, renamed config fields from email_ to mail_import_, added support for DateTime macro, fixed table recognition.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 715
diff changeset
273 if found_table is not None:
699
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
274 content = "\n".join(old_content[:table_ends] + [new_line] + old_content[table_ends:])
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
275 else:
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
276 content = "\n".join(old_content) + table_header + new_line
ea6dab2f43f7 Write a table on the parent page in +-mode.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 697
diff changeset
277
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
278 page = PageEditor(request, parent_page, do_editor_backup=0)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
279 page.saveText(content, 0, comment=comment)
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
280
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
281 if __name__ == "__main__":
694
0c32fb700c3c Added URL support, added comment.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 693
diff changeset
282 if len(sys.argv) > 1:
0c32fb700c3c Added URL support, added comment.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 693
diff changeset
283 url = sys.argv[1]
0c32fb700c3c Added URL support, added comment.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 693
diff changeset
284 else:
0c32fb700c3c Added URL support, added comment.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 693
diff changeset
285 url = 'localhost/'
0c32fb700c3c Added URL support, added comment.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 693
diff changeset
286
704
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
287 request = RequestCLI(url=url)
38aa322f35c9 Added two-tier XMLRPC mail import client/server system.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 701
diff changeset
288
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
289 try:
1152
acf14d68b7c8 mailimport: if template is given in subject, use first we find there (can be at beginning or end), src cosmetics
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1151
diff changeset
290 import_mail_from_file(request, infile)
692
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
291 except ProcessingError, e:
7a6e256dd074 Added mail import feature.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
292 print >>sys.stderr, "An error occured while processing the message:", e.args
702
433a0ee1635d some cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 701
diff changeset
293