1.1 --- a/actions/SendMessage.py Thu Jun 13 19:44:56 2013 +0200
1.2 +++ b/actions/SendMessage.py Fri Jun 14 01:26:44 2013 +0200
1.3 @@ -16,6 +16,7 @@
1.4 from MoinMoin.wikiutil import escape, MimeType, parseQueryString, \
1.5 taintfilename, getInterwikiHomePage
1.6
1.7 +from email.mime.base import MIMEBase
1.8 from email.mime.image import MIMEImage
1.9 from email.mime.multipart import MIMEMultipart
1.10 from email.mime.text import MIMEText
1.11 @@ -62,6 +63,7 @@
1.12
1.13 message = form.get("message", [""])[0]
1.14 recipient = form.get("recipient", [""])[0]
1.15 + format = form.get("format", ["wiki"])[0]
1.16 preview = form.get("preview")
1.17 queue = form.get("queue")
1.18
1.19 @@ -80,13 +82,16 @@
1.20
1.21 # Prepare any preview.
1.22
1.23 + parser_cls = getParserClass(request, format)
1.24 request.formatter.setPage(self.page)
1.25 - preview_output = preview and formatText(message, request, request.formatter, inhibit_p=False) or ""
1.26 + preview_output = preview and formatText(message, request, request.formatter, inhibit_p=False, parser_cls=parser_cls) or ""
1.27
1.28 # Fill in the fields and labels.
1.29
1.30 d = {
1.31 "buttons_html" : buttons_html,
1.32 + "format_label" : escape(_("Message format")),
1.33 + "format" : escattr(format),
1.34 "recipient_label" : escape(_("Recipient")),
1.35 "recipients_list" : "\n".join(recipients_list),
1.36 "message_label" : escape(_("Message text")),
1.37 @@ -110,6 +115,12 @@
1.38 </td>
1.39 </tr>
1.40 <tr>
1.41 + <td class="label"><label>%(format_label)s</label></td>
1.42 + <td>
1.43 + <input name="format" type="text" value="%(format)s" size="20" />
1.44 + </td>
1.45 + </tr>
1.46 + <tr>
1.47 <td class="label"><label>%(message_label)s</label></td>
1.48 <td>
1.49 <textarea name="message" cols="60" rows="10">%(message_default)s</textarea>
1.50 @@ -152,6 +163,7 @@
1.51
1.52 text = form.get("message", [None])[0]
1.53 recipient = form.get("recipient", [None])[0]
1.54 + format = form.get("format", ["wiki"])[0]
1.55 queue = form.get("queue")
1.56
1.57 if not text:
1.58 @@ -176,11 +188,42 @@
1.59
1.60 # Add the message body and any attachments.
1.61
1.62 - fmt = OutgoingHTMLFormatter(request)
1.63 - fmt.setPage(request.page)
1.64 - body = formatText(text, request, fmt, inhibit_p=False)
1.65 + parser_cls = getParserClass(request, format)
1.66 +
1.67 + # Determine whether alternative output types are produced and, if so,
1.68 + # bundle them in a multipart/alternative part.
1.69 +
1.70 + output_types = getParserOutputTypes(parser_cls)
1.71 +
1.72 + if len(output_types) > 1:
1.73 + alternatives = MIMEMultipart("alternative")
1.74 + container.attach(alternatives)
1.75 + else:
1.76 + alternatives = container
1.77 +
1.78 + # Produce each of the representations.
1.79 +
1.80 + for output_type in output_types:
1.81
1.82 - container.attach(MIMEText(body, "html"))
1.83 + # HTML must be processed to identify attachments.
1.84 +
1.85 + if output_type == "text/html":
1.86 + fmt = OutgoingHTMLFormatter(request)
1.87 + fmt.setPage(request.page)
1.88 + body = formatText(text, request, fmt, inhibit_p=False, parser_cls=parser_cls)
1.89 + else:
1.90 + body = formatTextForOutputType(text, request, parser_cls, output_type)
1.91 +
1.92 + maintype, subtype = output_type.split("/", 1)
1.93 + if maintype == "text":
1.94 + part = MIMEText(body.encode("utf-8"), subtype, "utf-8")
1.95 + else:
1.96 + part = MIMEBase(maintype, subtype)
1.97 + part.set_payload(body)
1.98 +
1.99 + alternatives.attach(part)
1.100 +
1.101 + # Produce any identified attachments.
1.102
1.103 for pos, (path, filename) in enumerate(fmt.attachments):
1.104