Skip to content

Commit

Permalink
Fixed reply mode.
Browse files Browse the repository at this point in the history
see #69
  • Loading branch information
tonioo committed Apr 25, 2017
1 parent 37ed4b5 commit 9007c61
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
19 changes: 11 additions & 8 deletions modoboa_webmail/lib/imapemail.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _insert_contact_links(self, addresses):
result.append(address)
return result

def fetch_headers(self):
def fetch_headers(self, raw_addresses=False):
"""Fetch message headers from server."""
msg = self.imapc.fetchmail(
self.mbox, self.mailid, readonly=False,
Expand All @@ -72,18 +72,19 @@ def fetch_headers(self):
headers_with_address = ("From", "To", "Cc")
for hdr in self.headernames:
label = hdr[0]
hdrvalue = self.get_header(msg, label)
hdrvalue = self.get_header(msg, label, raw=raw_addresses)
if not hdrvalue:
continue
if hdr[1]:
if contacts_plugin_installed and label in headers_with_address:
hdrvalue = self._insert_contact_links(hdrvalue)
if not raw_addresses:
hdrvalue = self._insert_contact_links(hdrvalue)
hdrvalue = ", ".join(hdrvalue)
self.headers += [{"name": label, "value": hdrvalue}]
label = re.sub("-", "_", label)
setattr(self, label, hdrvalue)

def get_header(self, msg, hdrname):
def get_header(self, msg, hdrname, **kwargs):
"""Look for a particular header.
We also try to decode the default value.
Expand All @@ -93,7 +94,8 @@ def get_header(self, msg, hdrname):
return ""
try:
key = re.sub("-", "_", hdrname).lower()
hdrvalue = getattr(imapheader, "parse_%s" % key)(hdrvalue)
hdrvalue = getattr(imapheader, "parse_%s" % key)(
hdrvalue, **kwargs)
except AttributeError:
pass
return hdrvalue
Expand Down Expand Up @@ -221,10 +223,11 @@ def fetch_attachment(self, pnum):
class Modifier(ImapEmail):
"""Message modifier."""

def __init__(self, form, *args, **kwargs):
kwargs["dformat"] = "EDITOR"
super(Modifier, self).__init__(*args, **kwargs)
def __init__(self, form, request, *args, **kwargs):
kwargs["dformat"] = request.user.parameters.get_value("editor")
super(Modifier, self).__init__(request, *args, **kwargs)
self.form = form
self.fetch_headers(raw_addresses=True)
getattr(self, "_modify_%s" % self.dformat)()

def _modify_plain(self):
Expand Down
2 changes: 2 additions & 0 deletions modoboa_webmail/lib/imapheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def parse_address(value, **kwargs):
"""Parse an email address."""
addr = EmailAddress(value)
if addr.name:
if kwargs.get("raw"):
return to_unicode(addr.fulladdress)
return u"<span title={}>{}</span>".format(
to_unicode(addr.address), to_unicode(addr.name))
return to_unicode(addr.address)
Expand Down
2 changes: 1 addition & 1 deletion modoboa_webmail/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def new_compose_form(request, action, mbox, mailid):
"""
form = ComposeMailForm()
modclass = globals()["%sModifier" % action.capitalize()]
email = modclass(form, request, True, "%s:%s" % (mbox, mailid), links="1")
email = modclass(form, request, "%s:%s" % (mbox, mailid), links="1")
url = "?action=%s&mbox=%s&mailid=%s" % (action, mbox, mailid)
return render_compose(request, form, url, email)

Expand Down

0 comments on commit 9007c61

Please sign in to comment.