1.1 --- a/README.txt Thu Jun 13 18:51:07 2013 +0200
1.2 +++ b/README.txt Thu Jun 13 19:44:56 2013 +0200
1.3 @@ -80,6 +80,12 @@
1.4 This causes messages sent to a Wiki using the PostMessage action to be
1.5 rejected if date information is missing.
1.6
1.7 + moinmessage_static_files (optional, may refer to the built-in htdocs directory)
1.8 + This explicitly defines the path to static resources used by Moin, enabling
1.9 + such resources to be attached to messages. When set, the path must refer to
1.10 + the htdocs directory (possibly renamed) containing the different theme
1.11 + resource directories, together with the robots.txt and favicon.ico files.)
1.12 +
1.13 For signature verification to function, the following needs to be added:
1.14
1.15 from MoinMoin.auth.pgp import PGPAuth
2.1 --- a/actions/SendMessage.py Thu Jun 13 18:51:07 2013 +0200
2.2 +++ b/actions/SendMessage.py Thu Jun 13 19:44:56 2013 +0200
2.3 @@ -19,10 +19,35 @@
2.4 from email.mime.image import MIMEImage
2.5 from email.mime.multipart import MIMEMultipart
2.6 from email.mime.text import MIMEText
2.7 +from os.path import abspath, exists, join
2.8 import urllib
2.9
2.10 +try:
2.11 + from MoinMoin.web import static
2.12 + htdocs = abspath(join(static.__file__, "htdocs"))
2.13 +except ImportError:
2.14 + htdocs = None
2.15 +
2.16 Dependencies = []
2.17
2.18 +def get_htdocs(request):
2.19 +
2.20 + "Use the 'request' to find the htdocs directory."
2.21 +
2.22 + global htdocs
2.23 +
2.24 + if not htdocs:
2.25 + htdocs_in_cfg = getattr(request.cfg, "moinmessage_static_files", None)
2.26 + if htdocs_in_cfg and exists(htdocs_in_cfg):
2.27 + htdocs = htdocs_in_cfg
2.28 + return htdocs
2.29 + htdocs_in_data = abspath(join(request.cfg.data_dir, "../htdocs"))
2.30 + if exists(htdocs_in_data):
2.31 + htdocs = htdocs_in_data
2.32 + return htdocs
2.33 +
2.34 + return htdocs
2.35 +
2.36 class SendMessage(ActionBase, ActionSupport):
2.37
2.38 "An action that can send a message to another site."
2.39 @@ -157,12 +182,7 @@
2.40
2.41 container.attach(MIMEText(body, "html"))
2.42
2.43 - for pos, (pagename, filename) in enumerate(fmt.attachments):
2.44 -
2.45 - # Obtain the attachment path.
2.46 -
2.47 - filename = taintfilename(filename)
2.48 - path = AttachFile.getFilename(request, pagename, filename)
2.49 + for pos, (path, filename) in enumerate(fmt.attachments):
2.50
2.51 # Obtain the attachment content.
2.52
2.53 @@ -299,13 +319,37 @@
2.54 def getAttachmentFromURL(url, request):
2.55
2.56 """
2.57 - Return a (page name, attachment filename) tuple for the attachment
2.58 + Return a (full path, attachment filename) tuple for the attachment
2.59 referenced by the given 'url', using the 'request' to interpret the
2.60 structure of 'url'.
2.61
2.62 If 'url' does not refer to an attachment on this wiki, None is returned.
2.63 """
2.64
2.65 + # Detect static resources.
2.66 +
2.67 + htdocs_dir = get_htdocs(request)
2.68 +
2.69 + if htdocs_dir:
2.70 + prefix = request.cfg.url_prefix_static
2.71 +
2.72 + # Normalise the
2.73 +
2.74 + if not prefix.endswith("/"):
2.75 + prefix += "/"
2.76 +
2.77 + if url.startswith(prefix):
2.78 + filename = url[len(prefix):]
2.79 +
2.80 + # Obtain the resource path.
2.81 +
2.82 + path = abspath(join(htdocs_dir, filename))
2.83 +
2.84 + if exists(path):
2.85 + return path, taintfilename(filename)
2.86 +
2.87 + # Detect attachments and other resources.
2.88 +
2.89 script = request.getScriptname()
2.90
2.91 # Normalise the URL.
2.92 @@ -327,7 +371,14 @@
2.93
2.94 pagename = unquoteWikinameURL(qpagename)
2.95 qs = qs and parseQueryString(qs) or {}
2.96 - return pagename, qs.get("target") or qs.get("drawing")
2.97 +
2.98 + filename = qs.get("target") or qs.get("drawing")
2.99 + filename = taintfilename(filename)
2.100 +
2.101 + # Obtain the attachment path.
2.102 +
2.103 + path = AttachFile.getFilename(request, pagename, filename)
2.104 + return path, filename
2.105
2.106 class OutgoingHTMLFormatter(text_html.Formatter):
2.107