mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-24 06:48:35 +02:00
fix: using MEDIA_URL inside templates.
wip: #36, using tinyMCE (django-tinymce) to write messages in HTML. Currently, compose a new message is working pretty well. Answering or forwarding a message is still a mess...
This commit is contained in:
+20
-7
@@ -169,10 +169,6 @@ class Email(object):
|
||||
|
||||
if part.has_key("Content-Location"):
|
||||
fname = part["Content-Location"]
|
||||
if re.match("^http:", fname):
|
||||
path = fname
|
||||
else:
|
||||
path = self.__save_image(fname, part)
|
||||
elif part.has_key("Content-Disposition"):
|
||||
if not part["Content-Disposition"].startswith("inline"):
|
||||
continue
|
||||
@@ -183,12 +179,18 @@ class Email(object):
|
||||
if len(p) and p[0] == "filename":
|
||||
fname = p[1]
|
||||
break
|
||||
path = self.__save_image(fname is None and cid or fname, part)
|
||||
if fname is None:
|
||||
fname = cid
|
||||
elif part.has_key("Content-Type"):
|
||||
m = re.match(".*name=[\"'](.+)[\"']", part["Content-Type"])
|
||||
if m is None:
|
||||
continue
|
||||
fname = m.group(1)
|
||||
else:
|
||||
continue
|
||||
|
||||
self.attached_map[cid] = path
|
||||
continue
|
||||
self.attached_map[cid] = re.match("^http:", fname) and fname \
|
||||
or self.__save_image(fname, part)
|
||||
|
||||
|
||||
if not contents.has_key(mode) or contents[mode] == "":
|
||||
@@ -201,6 +203,16 @@ class Email(object):
|
||||
getattr(self, "viewmail_%s" % mode)(contents[mode], links=links)
|
||||
|
||||
def __save_image(self, fname, part):
|
||||
"""Save an inline image on the filesystem.
|
||||
|
||||
Some HTML messages are using inline images (attached images
|
||||
with links on them inside the body). In order to display them,
|
||||
images are saved on the filesystem and links contained in the
|
||||
message are modified.
|
||||
|
||||
:param fname: the image associated filename
|
||||
:param part: the email part that contains the image payload
|
||||
"""
|
||||
from django.conf import settings
|
||||
|
||||
if re.search("\.\.", fname):
|
||||
@@ -216,6 +228,7 @@ class Email(object):
|
||||
|
||||
m = re.match(".*cid:(.+)", url)
|
||||
if m:
|
||||
print self.attached_map
|
||||
if self.attached_map.has_key(m.group(1)):
|
||||
return self.attached_map[m.group(1)]
|
||||
return url
|
||||
|
||||
@@ -21,6 +21,13 @@ events = ["CreateDomain",
|
||||
callbacks = {}
|
||||
|
||||
def register(event, callback):
|
||||
"""Register a plugin callback for a specific event
|
||||
|
||||
The event must be declared in this module.
|
||||
|
||||
:param event: the event to listen to
|
||||
:param callback: a function to execute when the event is raised
|
||||
"""
|
||||
if not event in events:
|
||||
return 0
|
||||
if not event in callbacks.keys():
|
||||
@@ -30,6 +37,11 @@ def register(event, callback):
|
||||
return 1
|
||||
|
||||
def unregister(event, callback):
|
||||
"""Unregister a callback for a specific event
|
||||
|
||||
:param event: the targeted event
|
||||
:param callback: the callback to remove
|
||||
"""
|
||||
if not event in events:
|
||||
return False
|
||||
if not callbacks.has_key(event):
|
||||
@@ -40,6 +52,13 @@ def unregister(event, callback):
|
||||
pass
|
||||
|
||||
def raiseEvent(event, **kwargs):
|
||||
"""Raise a specific event
|
||||
|
||||
Any additional keyword argument will be passed to registered
|
||||
callbacks.
|
||||
|
||||
:param event: the event to raise
|
||||
"""
|
||||
if not event in events or not event in callbacks.keys():
|
||||
return 0
|
||||
for callback in callbacks[event]:
|
||||
@@ -47,6 +66,13 @@ def raiseEvent(event, **kwargs):
|
||||
return 1
|
||||
|
||||
def raiseQueryEvent(event, **kwargs):
|
||||
"""Raise a specific event and wait for answers from callbacks
|
||||
|
||||
Any additional keyword argument will be passed to registered
|
||||
callbacks. Callback answers are returned as a list.
|
||||
|
||||
:param event: the event to raise
|
||||
"""
|
||||
result = []
|
||||
if not event in events or not event in callbacks.keys():
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user