From 7807cff4ade05067e8ece19ad9ea557957076f13 Mon Sep 17 00:00:00 2001 From: Felix Schwarz Date: Thu, 29 Aug 2024 08:52:45 +0200 Subject: [PATCH] add `.msg` property to `BaseMsg` This attribute is already assumed to be present by some methods. An explicit parameter in `__init__()` makes the code for `InMemoryMsg` more readable. --- schwarz/mailqueue/message_handler.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/schwarz/mailqueue/message_handler.py b/schwarz/mailqueue/message_handler.py index 249bdcd..d1a65db 100644 --- a/schwarz/mailqueue/message_handler.py +++ b/schwarz/mailqueue/message_handler.py @@ -104,7 +104,8 @@ def _msg_metadata(self, msg, **kwargs): class BaseMsg(object): - def __init__(self): + def __init__(self, msg: Optional[MsgInfo]=None): + self._msg = msg self._from = None self._to_addrs = None self._retries = None @@ -120,6 +121,10 @@ def delivery_failed(self, discard=False): def delivery_successful(self): pass + @property + def msg(self): + return self._msg + @property def from_addr(self): if self._from is not None: @@ -160,9 +165,9 @@ def retries(self, value): class InMemoryMsg(BaseMsg): def __init__(self, from_addr, to_addrs, msg_bytes): - super(InMemoryMsg, self).__init__() msg_fp = BytesIO(msg_as_bytes(msg_bytes)) - self.msg = MsgInfo(from_addr, to_addrs, msg_fp) + msg = MsgInfo(from_addr, to_addrs, msg_fp) + super().__init__(msg=msg) def start_delivery(self): return True