From 23098281c92c313d88ec58d159e56a342c825df2 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 19 Mar 2024 07:54:30 +0100 Subject: [PATCH] Starting with class PostfixLogchainInfo. --- lib/pp_admintools/postfix_chain.py | 115 +++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 lib/pp_admintools/postfix_chain.py diff --git a/lib/pp_admintools/postfix_chain.py b/lib/pp_admintools/postfix_chain.py new file mode 100644 index 0000000..5bbbd2f --- /dev/null +++ b/lib/pp_admintools/postfix_chain.py @@ -0,0 +1,115 @@ +# -*- coding: utf-8 -*- +""" +@summary: A class for encapsulating the information from a chain of Postfix log entries + +@author: Frank Brehm +@contact: frank.brehm@pixelpark.com +@copyright: © 2024 by Frank Brehm, Berlin +""" +from __future__ import absolute_import + +# Standard modules +import datetime +import logging +import re + +# Third party modules +from +from fb_tools.obj import FbGenericBaseObject + +__version__ = '0.1.0' + +LOG = logging.getLogger(__name__) + +UTC = utc = datetime.timezone(0, 'UTC') + + +# ============================================================================= +class PostfixLogchainInfo(FbGenericBaseObject): + """A class for encapsulating the information from a chain of Postfix log entries.""" + + # ------------------------------------------------------------------------- + def __init__( + self, client_host=None, client_addr=None, start=None, end=None, message_id=None, postfix_pid=None, + ehlo=None, starttls=None, quit=None, auth=None, commands=None, rcpt=None, data=None, + mail=None, from_address=None, to_address=None): + """Initialize this object.""" + self._auth = None + self._client_addr = None + self._client_host = None + self._commands = None + self._data = None + self._end = None + self._ehlo = None + self._from_address = None + self._mail = None + self._message_id = None + self._postfix_pid = None + self._quit = None + self._rcpt = None + self._start = None + self._starttls = None + self._to_address = None + + self.auth = auth + + # ----------------------------------------------------------- + @property + def auth(self): + """Return, whether an auth command was used in SMTP dialogue.""" + return self._auth + + @auth.setter + def auth(self, value): + if value is None: + self._auth = None + return + + val = str(value).strip() + if val == '': + self._auth = None + else: + self._auth = val + + + # ------------------------------------------------------------------------- + def __repr__(self): + """Typecast into a string for reproduction.""" + out = '<%s(' % (self.__class__.__name__) + + fields = [] + + if self.auth is not None: + fields.append('auth={!r}'.format(self.auth)) + + out += ', '.join(fields) + ')>' + return out + + # ------------------------------------------------------------------------- + def as_dict(self, short=True): + """ + Transform the elements of the object into a dict. + + @param short: don't include local properties in resulting dict. + @type short: bool + + @return: structure as dict + @rtype: dict + """ + res = super(PostfixLogchainInfo, self).as_dict(short=short) + + res['auth'] = self.auth + + return res + + + +# ============================================================================= + +if __name__ == '__main__': + + pass + +# ============================================================================= + +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 -- 2.39.5