Skip to content

Commit

Permalink
add .msg property to BaseMsg
Browse files Browse the repository at this point in the history
This attribute is already assumed to be present by some methods.

An explicit parameter in `__init__()` makes the code for `InMemoryMsg` more readable.
  • Loading branch information
FelixSchwarz committed Aug 29, 2024
1 parent e64e0e8 commit 7807cff
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions schwarz/mailqueue/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 7807cff

Please sign in to comment.