from __future__ import absolute_import
# Standard modules
+import copy
import datetime
import ipaddress
import logging
_ = XLATOR.gettext
ngettext = XLATOR.ngettext
-__version__ = '0.3.0'
+__version__ = '0.4.0'
LOG = logging.getLogger(__name__)
out += ', '.join(fields) + ')>'
return out
+ # -------------------------------------------------------------------------
+ def __copy__(self):
+ """Copy the current data pair into a new object."""
+ return self.__class__(self.value, total=self.total)
# =============================================================================
class PostfixLogchainInfo(FbGenericBaseObject):
# -------------------------------------------------------------------------
def __init__(
self, client_host=None, client_addr=None, start=None, end=None, message_id=None,
- postfix_pid=None, ehlo=None, starttls=None, sent_quit=None, auth=None, commands=None,
- rcpt=None, data=None, mail=None, from_address=None, to_address=None):
+ postfix_id=None, ehlo=None, starttls=None, sent_quit=None, auth=None, commands=None,
+ rcpt=None, data=None, mail=None, from_address=None, to_address=None, smtpd_pid=None):
"""Initialize this object."""
self._auth = None
self._client_addr = None
self._from_address = None
self._mail = None
self._message_id = None
- self._postfix_pid = None
+ self._postfix_id = None
self._rcpt = None
self._sent_quit = None
+ self._smtpd_pid = None
self._start = None
self._starttls = None
self._to_address = None
self.auth = auth
self.client_addr = client_addr
self.client_host = client_host
+ self.ehlo = ehlo
self.end = end
+ self.message_id = message_id
+ self.postfix_id = postfix_id
+ self.sent_quit = sent_quit
self.start = start
+ self.starttls = starttls
# -------------------------------------------------------------------------
@classmethod
return
if isinstance(value, int):
- return DataPair(value)
+ self._auth = DataPair(value)
+ return
+ if isinstance(value, DataPair):
+ self._auth = copy.copy(value)
+ return
val = str(value).strip()
if val == '':
self._auth = None
return None
return self.end - self.start
+ # -----------------------------------------------------------
+ @property
+ def ehlo(self):
+ """Return statistics about the EHLO command in SMTP dialogue."""
+ return self._ehlo
+
+ @ehlo.setter
+ def ehlo(self, value):
+ if value is None:
+ self._ehlo = None
+ return
+
+ if isinstance(value, int):
+ self._ehlo = DataPair(value)
+ return
+ if isinstance(value, DataPair):
+ self._ehlo = copy.copy(value)
+ return
+ val = str(value).strip()
+ if val == '':
+ self._ehlo = None
+ return
+ else:
+ self._ehlo = DataPair.from_str(val)
+
# -----------------------------------------------------------
@property
def end(self):
self._end = None
return
- ts_end = self.date_fromisoformat(val)
+ if hasattr(datetime.datetime, 'fromisoformat'):
+ ts_end = datetime.datetime.fromisoformat(val)
+ else:
+ ts_end = self.date_fromisoformat(val)
if ts_end:
self._end = ts_end
return
self._end = val
+ # -----------------------------------------------------------
+ @property
+ def message_id(self):
+ """Return the message ID of the mail, which the Pastfix chain is covering."""
+ return self._message_id
+
+ @message_id.setter
+ def message_id(self, value):
+ if value is None:
+ self._message_id = None
+ return
+
+ val = str(value).strip()
+ if val == '':
+ self._message_id = None
+ return
+ self._message_id = val
+
+ # -----------------------------------------------------------
+ @property
+ def postfix_id(self):
+ """Return the Postfix ID of the mail, which the Pastfix chain is covering."""
+ return self._postfix_id
+
+ @postfix_id.setter
+ def postfix_id(self, value):
+ if value is None:
+ self._postfix_id = None
+ return
+
+ val = str(value).strip().upper()
+ if val == '':
+ self._postfix_id = None
+ return
+ self._postfix_id = val
+
+ # -----------------------------------------------------------
+ @property
+ def sent_quit(self):
+ """Return statistics about the quit command in SMTP dialogue."""
+ return self._sent_quit
+
+ @sent_quit.setter
+ def sent_quit(self, value):
+ if value is None:
+ self._sent_quit = None
+ return
+
+ if isinstance(value, int):
+ self._sent_quit = DataPair(value)
+ return
+ if isinstance(value, DataPair):
+ self._sent_quit = copy.copy(value)
+ return
+ val = str(value).strip()
+ if val == '':
+ self._sent_quit = None
+ return
+ else:
+ self._sent_quit = DataPair.from_str(val)
+
# -----------------------------------------------------------
@property
def start(self):
self._start = None
return
- ts_start = self.date_fromisoformat(val)
+ if hasattr(datetime.datetime, 'fromisoformat'):
+ ts_start = datetime.datetime.fromisoformat(val)
+ else:
+ ts_start = self.date_fromisoformat(val)
if ts_start:
self._start = ts_start
return
self._start = val
+ # -----------------------------------------------------------
+ @property
+ def starttls(self):
+ """Return statistics about the starttls command in SMTP dialogue."""
+ return self._starttls
+
+ @starttls.setter
+ def starttls(self, value):
+ if value is None:
+ self._starttls = None
+ return
+
+ if isinstance(value, int):
+ self._starttls = DataPair(value)
+ return
+ if isinstance(value, DataPair):
+ self._starttls = copy.copy(value)
+ return
+ val = str(value).strip()
+ if val == '':
+ self._starttls = None
+ return
+ else:
+ self._starttls = DataPair.from_str(val)
+
# -------------------------------------------------------------------------
def __repr__(self):
"""Typecast into a string for reproduction."""
fields = []
- if self.auth is not None:
- fields.append('auth={!r}'.format(str(self.auth)))
+ if self.client_host is not None:
+ fields.append('client_host={!r}'.format(self.client_host))
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 self.end is not None:
- if isinstance(self.end, datetime.datetime):
- ts = self.end.isoformat(' ')
- else:
- ts = self.end
- fields.append('end={!r}'.format(ts))
if self.start is not None:
if isinstance(self.start, datetime.datetime):
ts = self.start.isoformat(' ')
else:
ts = self.start
fields.append('start={!r}'.format(ts))
+ if self.end is not None:
+ if isinstance(self.end, datetime.datetime):
+ ts = self.end.isoformat(' ')
+ else:
+ ts = self.end
+ fields.append('end={!r}'.format(ts))
+ if self.message_id is not None:
+ fields.append('message_id={!r}'.format(self.message_id))
+ if self.postfix_id is not None:
+ fields.append('postfix_id={!r}'.format(self.postfix_id))
+ if self.ehlo is not None:
+ fields.append('ehlo={!r}'.format(str(self.ehlo)))
+ if self.starttls is not None:
+ fields.append('starttls={!r}'.format(str(self.starttls)))
+ if self.sent_quit is not None:
+ fields.append('sent_quit={!r}'.format(str(self.sent_quit)))
+ if self.auth is not None:
+ fields.append('auth={!r}'.format(str(self.auth)))
if fields:
out += ', '.join(fields)
res['client_addr'] = self.client_addr
res['client_host'] = self.client_host
res['duration'] = self.duration
+ res['ehlo'] = self.ehlo
res['end'] = self.end
+ res['message_id'] = self.message_id
+ res['postfix_id'] = self.postfix_id
+ res['sent_quit'] = self.sent_quit
res['start'] = self.start
+ res['starttls'] = self.starttls
return res