[Remail] [RFC/RFT patch 1/2] remail: Optionally add X-Remail-Originally-From header
Thomas Gleixner
tglx at linutronix.de
Tue Jun 13 01:44:28 CEST 2023
The 'From:' header mangling makes it unnecessarily hard to figure out the
name and email address of the person who posted to a list.
Provide an option for the list administrator which adds an
'X-Remail-Originally-From: <mailname at sender.domain>'
header to the outgoing reencrypted mail.
Defaults to 'false' for backwards compatibility.
The header name might be odd, but List-* headers are a reserved name space
and 'Originally-From:' is already taken and defined for a different
purpose. As especially gmail is very picky about RFC defined headers, use
one in the custom 'X-' namespae which is definitely not used yet and does
not violate any real or established by use standards.
Suggested-by: Linus Torvalds <torvalds at linux-foundation.org>
Signed-off-by: Thomas Gleixner <tglx at linutronix.de>
---
Documentation/man5/remail.config.rst | 8 ++++++++
remail/config.py | 1 +
remail/mail.py | 10 +++++++---
remail/maillist.py | 14 ++++++++++----
4 files changed, 26 insertions(+), 7 deletions(-)
--- a/Documentation/man5/remail.config.rst
+++ b/Documentation/man5/remail.config.rst
@@ -263,6 +263,7 @@ Base configuration items
enabled: True
moderated: True
attach_sender_info: False
+ set_original_from: False
listid: ...
archive:
...
@@ -280,6 +281,7 @@ Base configuration items
enabled: True
moderated: True
attach_sender_info: False
+ set_original_from: False
enabled:
@@ -304,6 +306,12 @@ Base configuration items
lists and especially contact points so that the subscribers are able
to contact the sender.
+ set_original_from:
+
+ Set the 'X-Remail-Original-From:' custom mail header to reflect the
+ original 'From:' mail header, which has to be rewritten due to
+ re-encryption.
+
listid:
Optional item to override the default list-id with a custom value.
--- a/remail/config.py
+++ b/remail/config.py
@@ -270,6 +270,7 @@ list_defaults = {
'enabled' : False,
'moderated' : False,
'attach_sender_info' : False,
+ 'set_original_from' : False,
}
class list_config(object):
--- a/remail/mail.py
+++ b/remail/mail.py
@@ -80,6 +80,7 @@ import re
'Content-Transfer-Encoding',
'Content-Language',
'Envelope-to',
+ 'X-Remail-Original-From',
]
# Get all headers and remove them from the message
@@ -106,7 +107,7 @@ import re
server.send_message(msg, sender, [to])
server.quit()
-def msg_deliver(msg, account, mfrom, sender, use_smtp):
+def msg_deliver(msg, account, mfrom, sender, use_smtp, origfrom):
'''
Deliver the message. Replace or set the mandatory headers, sanitize
and order them properly to make gmail happy.
@@ -116,6 +117,9 @@ import re
msg_set_header(msg, 'Return-path', sender)
msg_set_header(msg, 'Envelope-to', get_raw_email_addr(account.addr))
+ if origfrom:
+ msg_set_header(msg, 'X-Remail-Original-From', encode_addr(origfrom))
+
sanitize_headers(msg)
# Set unixfrom with the current date/time
@@ -128,7 +132,7 @@ import re
else:
print(msg.as_string())
-def send_mail(msg_out, account, mfrom, sender, listheaders, use_smtp):
+def send_mail(msg_out, account, mfrom, sender, listheaders, use_smtp, origfrom=None):
'''
Send mail to the account. Make sure that the message
is correct and all required headers and only necessary
@@ -138,7 +142,7 @@ import re
for key, val in listheaders.items():
msg_out[key] = val
- msg_deliver(msg_out, account, mfrom, sender, use_smtp)
+ msg_deliver(msg_out, account, mfrom, sender, use_smtp, origfrom)
# Minimal check for a valid email address
re_mail = re.compile('^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$')
--- a/remail/maillist.py
+++ b/remail/maillist.py
@@ -86,11 +86,16 @@ import os
self.gpg.encrypt(msg, account)
return msg
- def send_encrypted_mail(self, msg_plain, account, mfrom):
+ def send_encrypted_mail(self, msg_plain, account, mfrom, origfrom):
try:
msg_out = self.encrypt(msg_plain, account)
+
+ if not self.config.set_original_from:
+ origfrom = None
+
send_mail(msg_out, account, mfrom, self.config.listaddrs.bounce,
- self.config.listheaders, self.use_smtp)
+ self.config.listheaders, self.use_smtp, origfrom)
+
except (RemailGPGException, RemailSmimeException) as ex:
'''
GPG and S/MIME exceptions are not fatal. If they happen
@@ -268,7 +273,8 @@ import os
msgid = msg.get('Message-Id', '<No ID>')
msgto = msg.get('To')
- msgfrom = get_raw_email_addr(msg.get('From'))
+ origfrom = msg.get('From')
+ msgfrom = get_raw_email_addr(origfrom)
sinfo = sender_info(msg)
# Archive the incoming mail
@@ -298,7 +304,7 @@ import os
for account in dest.accounts.values():
if not account.enabled:
continue
- self.send_encrypted_mail(msg_plain, account, mfrom)
+ self.send_encrypted_mail(msg_plain, account, mfrom, origfrom)
return True
def handle_log(self):
More information about the Remail
mailing list