1.1 --- a/actions/SendMessage.py Thu Jun 13 18:51:07 2013 +0200
1.2 +++ b/actions/SendMessage.py Thu Jun 13 19:44:56 2013 +0200
1.3 @@ -19,10 +19,35 @@
1.4 from email.mime.image import MIMEImage
1.5 from email.mime.multipart import MIMEMultipart
1.6 from email.mime.text import MIMEText
1.7 +from os.path import abspath, exists, join
1.8 import urllib
1.9
1.10 +try:
1.11 + from MoinMoin.web import static
1.12 + htdocs = abspath(join(static.__file__, "htdocs"))
1.13 +except ImportError:
1.14 + htdocs = None
1.15 +
1.16 Dependencies = []
1.17
1.18 +def get_htdocs(request):
1.19 +
1.20 + "Use the 'request' to find the htdocs directory."
1.21 +
1.22 + global htdocs
1.23 +
1.24 + if not htdocs:
1.25 + htdocs_in_cfg = getattr(request.cfg, "moinmessage_static_files", None)
1.26 + if htdocs_in_cfg and exists(htdocs_in_cfg):
1.27 + htdocs = htdocs_in_cfg
1.28 + return htdocs
1.29 + htdocs_in_data = abspath(join(request.cfg.data_dir, "../htdocs"))
1.30 + if exists(htdocs_in_data):
1.31 + htdocs = htdocs_in_data
1.32 + return htdocs
1.33 +
1.34 + return htdocs
1.35 +
1.36 class SendMessage(ActionBase, ActionSupport):
1.37
1.38 "An action that can send a message to another site."
1.39 @@ -157,12 +182,7 @@
1.40
1.41 container.attach(MIMEText(body, "html"))
1.42
1.43 - for pos, (pagename, filename) in enumerate(fmt.attachments):
1.44 -
1.45 - # Obtain the attachment path.
1.46 -
1.47 - filename = taintfilename(filename)
1.48 - path = AttachFile.getFilename(request, pagename, filename)
1.49 + for pos, (path, filename) in enumerate(fmt.attachments):
1.50
1.51 # Obtain the attachment content.
1.52
1.53 @@ -299,13 +319,37 @@
1.54 def getAttachmentFromURL(url, request):
1.55
1.56 """
1.57 - Return a (page name, attachment filename) tuple for the attachment
1.58 + Return a (full path, attachment filename) tuple for the attachment
1.59 referenced by the given 'url', using the 'request' to interpret the
1.60 structure of 'url'.
1.61
1.62 If 'url' does not refer to an attachment on this wiki, None is returned.
1.63 """
1.64
1.65 + # Detect static resources.
1.66 +
1.67 + htdocs_dir = get_htdocs(request)
1.68 +
1.69 + if htdocs_dir:
1.70 + prefix = request.cfg.url_prefix_static
1.71 +
1.72 + # Normalise the
1.73 +
1.74 + if not prefix.endswith("/"):
1.75 + prefix += "/"
1.76 +
1.77 + if url.startswith(prefix):
1.78 + filename = url[len(prefix):]
1.79 +
1.80 + # Obtain the resource path.
1.81 +
1.82 + path = abspath(join(htdocs_dir, filename))
1.83 +
1.84 + if exists(path):
1.85 + return path, taintfilename(filename)
1.86 +
1.87 + # Detect attachments and other resources.
1.88 +
1.89 script = request.getScriptname()
1.90
1.91 # Normalise the URL.
1.92 @@ -327,7 +371,14 @@
1.93
1.94 pagename = unquoteWikinameURL(qpagename)
1.95 qs = qs and parseQueryString(qs) or {}
1.96 - return pagename, qs.get("target") or qs.get("drawing")
1.97 +
1.98 + filename = qs.get("target") or qs.get("drawing")
1.99 + filename = taintfilename(filename)
1.100 +
1.101 + # Obtain the attachment path.
1.102 +
1.103 + path = AttachFile.getFilename(request, pagename, filename)
1.104 + return path, filename
1.105
1.106 class OutgoingHTMLFormatter(text_html.Formatter):
1.107