From b3ead0d27758dd8933d4b4ecade3132b677530b8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Nov 2021 14:07:40 +0100 Subject: mail/envelope: replace string literals with named constants --- alot/mail/envelope.py | 22 ++++++++++++---------- alot/mail/headers.py | 7 +++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/alot/mail/envelope.py b/alot/mail/envelope.py index 447cd671..d3cace18 100644 --- a/alot/mail/envelope.py +++ b/alot/mail/envelope.py @@ -13,6 +13,8 @@ from urllib.parse import unquote import gpg +from . import headers as HDR + from .attachment import Attachment from .. import __version__ from .. import helper @@ -361,21 +363,21 @@ class Envelope: headers = self.headers.copy() # add Date header - if 'Date' not in headers: - headers['Date'] = email.utils.formatdate(localtime=True) + if HDR.DATE not in headers: + headers[HDR.DATE] = email.utils.formatdate(localtime=True) # add Message-ID - if 'Message-ID' not in headers: + if HDR.MESSAGE_ID not in headers: domain = settings.get('message_id_domain') - headers['Message-ID'] = email.utils.make_msgid(domain=domain) + headers[HDR.MESSAGE_ID] = email.utils.make_msgid(domain=domain) - if 'User-Agent' in headers: - uastring_format = headers['User-Agent'] + if HDR.USER_AGENT in headers: + uastring_format = headers[HDR.USER_AGENT] else: uastring_format = settings.get('user_agent').strip() uastring = uastring_format.format(version=__version__) if uastring: - headers['User-Agent'] = uastring + headers[HDR.USER_AGENT] = uastring # copy headers from envelope to mail for k, v in headers.items(): @@ -383,8 +385,8 @@ class Envelope: # as we are using MIMEPart instead of EmailMessage, set the # MIME version manually - del mail['MIME-Version'] - mail['MIME-Version'] = '1.0' + del mail[HDR.MIME_VERSION] + mail[HDR.MIME_VERSION] = '1.0' return mail @@ -440,7 +442,7 @@ class Envelope: self.body = raw[headerEndPos:].strip() _MAILTO_PREFIX = 'mailto:' - _MAILTO_SAFE_HEADERS = ('Subject', 'Cc', 'Keywords') + _MAILTO_SAFE_HEADERS = (HDR.SUBJECT, HDR.CC, HDR.KEYWORDS) @classmethod def from_mailto(cls, mailto): diff --git a/alot/mail/headers.py b/alot/mail/headers.py index fa7f6414..d3e47e88 100644 --- a/alot/mail/headers.py +++ b/alot/mail/headers.py @@ -10,6 +10,13 @@ MAIL_REPLY_TO = 'Mail-Reply-To' MAIL_FOLLOWUP_TO = 'Mail-Followup-To' SUBJECT = 'Subject' +DATE = 'Date' +KEYWORDS = 'Keywords' + +MESSAGE_ID = 'Message-ID' +USER_AGENT = 'User-Agent' + +MIME_VERSION = 'MIME-Version' IN_REPLY_TO = 'In-Reply-To' REFERENCES = 'References' -- cgit v1.2.3