modoboa / modoboa-webmail

The webmail of Modoboa
MIT License
73 stars 48 forks source link

Cannot reply to mails with quoted From #199

Closed vtoc closed 3 years ago

vtoc commented 4 years ago

It's not possible to reply to a mail with quoted From or Reply-To header, which is pefectly valid:

"Just, Test" <Test.Just@example.com>

Will become:

Just, Test <Test.Just@example.com>

Which is invalid and therefore leads to an error, when clicking on Send:

modoboa_webmail

The reason is, in email.utils parseaddr, which is used by ImapEmail thru modoboas EmailAddress class and does return the address as:

('Just, Test', 'Test.Just@example.com')

Seems to not really be a bug of modooa, however as the lib is what it is, i think it cannot be used as source for reply, an easy enough workarround is"

--- lib/imapemail.py.orig   2020-07-09 16:49:59.654694020 +0200
+++ lib/imapemail.py    2020-07-09 17:05:40.129073238 +0200

@@ -95,6 +95,10 @@
         We also try to decode the default value.
         """
         hdrvalue = super(ImapEmail, self).get_header(msg, hdrname)
+        if hdrname == "From":
+            self.original_From = hdrvalue
+        if hdrname == "Reply-To":
+            self.original_ReplyTo = hdrvalue
         if not hdrvalue:
             return ""
         try:
@@ -277,9 +281,9 @@
         if hasattr(self, "Message_ID"):
             self.form.fields["origmsgid"].initial = self.Message_ID
         if not hasattr(self, "Reply_To"):
-            self.form.fields["to"].initial = self.From
+            self.form.fields["to"].initial = self.original_From
         else:
-            self.form.fields["to"].initial = self.Reply_To
+            self.form.fields["to"].initial = self.original_ReplyTo
         if self.request.GET.get("all", "0") == "1":  # reply-all
             self.form.fields["cc"].initial = ""
             toparse = self.To.split(",")
harryfoster commented 3 years ago

Cheers for this, I had a user report the same as they've had a few senders using that 'Surname, Firstname' style. However I think the issue still remains in a sense, because a comma in the display name breaks the 'to' form field. I'm guessing because the parsing right after is looking purely for commas, whether they are quoted or not.

It's a shame it doesn't use semi-colons to split addresses in the form field instead of a comma. I might see if I can have a play around.