# Standard modules
import datetime
+import ipaddress
import logging
import re
# Third party modules
from fb_tools.obj import FbGenericBaseObject
+# Own modules
+from .xlate import XLATOR
+
+_ = XLATOR.gettext
+ngettext = XLATOR.ngettext
+
__version__ = '0.1.0'
LOG = logging.getLogger(__name__)
-UTC = utc = datetime.timezone(0, 'UTC')
+UTC = utc = datetime.timezone(datetime.timedelta(), 'UTC')
# =============================================================================
re_isodatetime = re.compile(
pattern_isodate + r'[T\s]' + pattern_isotime + pattern_isotimezone)
+ warn_on_parse_error = True
+
# -------------------------------------------------------------------------
def __init__(
self, client_host=None, client_addr=None, start=None, end=None, message_id=None,
self._to_address = None
self.auth = auth
+ self.client_addr = client_addr
+ self.client_host = client_host
# -----------------------------------------------------------
@property
else:
self._auth = val
+ # -----------------------------------------------------------
+ @property
+ def client_addr(self):
+ """Return the IP address of the SMTP client."""
+ return self._client_addr
+
+ @client_addr.setter
+ def client_addr(self, value):
+ if value is None:
+ self._client_addr = None
+ return
+
+ val = str(value).strip()
+ if val == '':
+ self._client_addr = None
+ return
+ try:
+ addr = ipaddress.ip_address(val)
+ self._client_addr = addr
+ except ValueError as e:
+ msg = _('Could not interprete client address {a!r}: {e}').format(a=val, e=e)
+ if self.warn_on_parse_error:
+ LOG.warn(msg)
+ else:
+ LOG.debug(msg)
+ self._client_addr = val
+
+ # -----------------------------------------------------------
+ @property
+ def client_host(self):
+ """Return the hostname of the SMTP client."""
+ return self._client_host
+
+ @client_host.setter
+ def client_host(self, value):
+ if value is None:
+ self._client_host = None
+ return
+
+ val = str(value).strip()
+ if val == '':
+ self._client_host = None
+ return
+ self._client_host = val
+
# -------------------------------------------------------------------------
def __repr__(self):
"""Typecast into a string for reproduction."""
if self.auth is not None:
fields.append('auth={!r}'.format(self.auth))
+ if self.client_addr is not None:
+ fields.append('client_addr={!r}'.format(str(self.client_addr)))
+ if self.client_host is not None:
+ fields.append('client_host={!r}'.format(str(self.client_host)))
+
+ if fields:
+ out += ', '.join(fields)
- out += ', '.join(fields) + ')>'
+ out += ')>'
return out
# -------------------------------------------------------------------------
res = super(PostfixLogchainInfo, self).as_dict(short=short)
res['auth'] = self.auth
+ res['client_addr'] = self.client_addr
+ res['client_host'] = self.client_host
return res