domainaware / parsedmarc

A Python package and CLI for parsing aggregate and forensic DMARC reports
https://domainaware.github.io/parsedmarc/
Apache License 2.0
981 stars 212 forks source link

Repeated messages (duplicates) while using mailbox watch and syslog #380

Closed dudukakz closed 1 year ago

dudukakz commented 1 year ago
$ .local/bin/parsedmarc -v
8.3.2

Probably, connected to #289 , yet no mention of mailbox watching there. While examining a single report with parsedmarc in mailbox test mode (same with test = False), I found out that the UDP connections count to my syslog server keeps increasing. Every watch timeout one more connection. In the end, it reaches the open files connection limit. I.e., when parsedmarc reads a report from the mailbox, it sends to syslog not a single report but identical reports.

It looks to me the problem is in creating one more syslog class object every time the mailbox is checked.

I added a destructor in the SyslogClient class. At the end of the process_reports function, I now destroy syslog_client object (if there is any). I'm not sure if this is the right way to fix it though

parsedmarc.ini ```ini [general] save_aggregate = True save_forensic = True nameservers = my.ns offline = True n_procs = 2 log_file = /var/log/parsedmarc.log [imap] host = imap.host user = my@mail.box password = pass [mailbox] watch = True delete = False reports_folder = INBOX.dmarc archive_folder = INBOX.dmarc_processed test = True batch_size = 0 [syslog] server = my.syslog port = 1143 ```
syslog.py ```python def __del__(self): for handler in self.logger.handlers: if isinstance(handler, logging.handlers.SysLogHandler): self.logger.handlers.remove(handler) ```
cli.py ```python # end of def process_reports(reports_): try: del syslog_client except NameError: print("syslog_client isn't defined") ```