aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJ08nY2017-07-18 19:06:19 +0200
committerJ08nY2017-07-18 19:06:19 +0200
commitb988b47192eb8ccda1a2713e6488a4207a61c239 (patch)
tree43704d258fbbd5e66fe90340f6ff90235a1f7610 /src
parent23db01a1762c056a75c94d44177462dea0a383a1 (diff)
downloadmailman-pgp-b988b47192eb8ccda1a2713e6488a4207a61c239.tar.gz
mailman-pgp-b988b47192eb8ccda1a2713e6488a4207a61c239.tar.zst
mailman-pgp-b988b47192eb8ccda1a2713e6488a4207a61c239.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman_pgp/utils/email.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/mailman_pgp/utils/email.py b/src/mailman_pgp/utils/email.py
index 80cf83f..d1efc40 100644
--- a/src/mailman_pgp/utils/email.py
+++ b/src/mailman_pgp/utils/email.py
@@ -36,11 +36,31 @@ def copy_headers(from_msg, to_msg, overwrite=False):
del to_msg[key]
if key not in to_msg:
to_msg[key] = value
- if to_msg.get_unixfrom() is None:
+ if to_msg.get_unixfrom() is None or overwrite:
to_msg.set_unixfrom(from_msg.get_unixfrom())
@public
+def overwrite_message(from_msg, to_msg):
+ """
+ Overwrite message data of `to_msg` with that of `from_msg`.
+
+ :param from_msg: The source `Message`.
+ :type from_msg: email.message.Message
+ :param to_msg: The destination `Message`.
+ :type to_msg: email.message.Message
+ """
+ del to_msg[:]
+ for key, value in from_msg.items():
+ to_msg[key] = value
+ to_msg.set_unixfrom(from_msg.get_unixfrom())
+ to_msg.set_payload(from_msg.get_payload(), from_msg.get_charset())
+ to_msg.preamble = from_msg.preamble
+ to_msg.epilogue = from_msg.epilogue
+ to_msg.set_default_type(from_msg.get_default_type())
+
+
+@public
def get_email(msg):
display_name, email = parseaddr(msg['from'])
# Address could be None or the empty string.