# Third party modules
from fb_tools.common import pp
+from fb_tools.errors import InvalidMailAddressError
+from fb_tools.mailaddress import MailAddress
from fb_tools.obj import FbGenericBaseObject
# Own modules
self.client_addr = client_addr
self.client_host = client_host
self.commands = commands
+ self.data = data
self.ehlo = ehlo
self.end = end
+ self.from_address = from_address
self.message_id = message_id
+ self.mail = mail
self.postfix_id = postfix_id
self.rcpt = rcpt
self.sent_quit = sent_quit
+ self.smtpd_pid = smtpd_pid
self.start = start
self.starttls = starttls
+ self.to_address = to_address
# -------------------------------------------------------------------------
@classmethod
return
self._client_host = val
+ # -----------------------------------------------------------
+ @property
+ def data(self):
+ """Return statistics about the DATA command in SMTP dialogue."""
+ return self._data
+
+ @data.setter
+ def data(self, value):
+ if value is None:
+ self._data = None
+ return
+
+ if isinstance(value, int):
+ self._data = DataPair(value)
+ return
+ if isinstance(value, DataPair):
+ self._data = copy.copy(value)
+ return
+ val = str(value).strip()
+ if val == '':
+ self._data = None
+ return
+ else:
+ self._data = DataPair.from_str(val)
+
# -----------------------------------------------------------
@property
def commands(self):
return
self._end = val
+ # -----------------------------------------------------------
+ @property
+ def from_address(self):
+ """Return the MAIL FROM address in the SMTP dialogue envelope."""
+ return self._from_address
+
+ @from_address.setter
+ def from_address(self, value):
+ if value is None:
+ self._from_address = None
+ return
+
+ if isinstance(value, MailAddress):
+ self._from_address = copy.copy(value)
+ return
+ val = str(value).strip()
+ if val == '':
+ self._from_address = None
+ return
+
+ try:
+ self._from_address = MailAddress(val)
+ except InvalidMailAddressError as e:
+ msg = _('Could not interprete from address {a!r}: {e}').format(a=val, e=e)
+ if self.warn_on_parse_error:
+ LOG.warn(msg)
+ else:
+ LOG.debug(msg)
+ self._from_address = val
+
+ # -----------------------------------------------------------
+ @property
+ def mail(self):
+ """Return statistics about mails in SMTP dialogue."""
+ return self._mail
+
+ @mail.setter
+ def mail(self, value):
+ if value is None:
+ self._mail = None
+ return
+
+ if isinstance(value, int):
+ self._mail = DataPair(value)
+ return
+ if isinstance(value, DataPair):
+ self._mail = copy.copy(value)
+ return
+ val = str(value).strip()
+ if val == '':
+ self._mail = None
+ return
+ else:
+ self._mail = DataPair.from_str(val)
+
# -----------------------------------------------------------
@property
def message_id(self):
else:
self._sent_quit = DataPair.from_str(val)
+ # -----------------------------------------------------------
+ @property
+ def smtpd_pid(self):
+ """Return statistics about the quit command in SMTP dialogue."""
+ return self._smtpd_pid
+
+ @smtpd_pid.setter
+ def smtpd_pid(self, value):
+ if value is None:
+ self._smtpd_pid = None
+ return
+
+ if isinstance(value, (float, int)):
+ self._smtpd_pid = int(value)
+ return
+ val = str(value).strip()
+ if val == '':
+ self._smtpd_pid = None
+ return
+
+ try:
+ self._smtpd_pid = int(val)
+ except ValueError as e:
+ msg = _('Could not interprete PID of smtpd {a!r}: {e}').format(a=value, e=e)
+ if self.warn_on_parse_error:
+ LOG.warn(msg)
+ else:
+ LOG.debug(msg)
+ self._smtpd_pid = val
+
# -----------------------------------------------------------
@property
def start(self):
else:
self._starttls = DataPair.from_str(val)
+ # -----------------------------------------------------------
+ @property
+ def to_address(self):
+ """Return the RCPT TO address in the SMTP dialogue envelope."""
+ return self._to_address
+
+ @to_address.setter
+ def to_address(self, value):
+ if value is None:
+ self._to_address = None
+ return
+
+ if isinstance(value, MailAddress):
+ self._to_address = copy.copy(value)
+ return
+ val = str(value).strip()
+ if val == '':
+ self._to_address = None
+ return
+
+ try:
+ self._to_address = MailAddress(val)
+ except InvalidMailAddressError as e:
+ msg = _('Could not interprete to address {a!r}: {e}').format(a=val, e=e)
+ if self.warn_on_parse_error:
+ LOG.warn(msg)
+ else:
+ LOG.debug(msg)
+ self._to_address = val
+
# -------------------------------------------------------------------------
def __str__(self):
"""Typecast into a string object.
atribs = (
'client_host', 'client_addr', 'start', 'end', 'message_id', 'postfix_id', 'ehlo',
- 'starttls', 'sent_quit', 'auth', 'commands', 'rcpt')
+ 'starttls', 'sent_quit', 'auth', 'commands', 'rcpt', 'data', 'mail', 'from_address',
+ 'to_address', 'smtpd_pid')
for attrib in atribs:
if not hasattr(self, attrib):
continue
if isinstance(value, datetime.datetime):
res[attrib] = value.isoformat(' ') if exportable else value
continue
- if isinstance(value, DataPair):
+ if isinstance(value, (DataPair, MailAddress)):
res[attrib] = str(value) if exportable else value
continue