summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kaufmann <astra@ionic.at>2025-03-11 02:05:32 +0100
committerDavid Kaufmann <astra@ionic.at>2025-03-11 02:05:32 +0100
commit7eeb7e9e56792a5b420efb07d6bee05c73cc6018 (patch)
tree55bc3b1943440cf3258618e482885393a8cb8fe3
parent3a323ca53d99c1f77150c637e8b43712af45fc69 (diff)
downloadscripts-7eeb7e9e56792a5b420efb07d6bee05c73cc6018.tar.gz
update script
-rwxr-xr-xget_zammad_ham_spam.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/get_zammad_ham_spam.py b/get_zammad_ham_spam.py
index 410845d..9e60349 100755
--- a/get_zammad_ham_spam.py
+++ b/get_zammad_ham_spam.py
@@ -11,14 +11,14 @@ valid_destinations = [
]
-def send_to_rspamd(ticketid, spamflag, maildata):
+def send_to_rspamd(ticketid, title, spamflag, maildata):
# send the mail to rspamc to process as ham/spam
with subprocess.Popen(['/usr/bin/rspamc', f"learn_{spamflag}"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as rspamd:
stdout, stderr = rspamd.communicate(input=maildata)
if len(stdout) > 0:
- print(f"Ticket {ticketid} stdout: {stdout.decode('utf-8')}")
+ print(f"Ticket {ticketid}:\nSubject: {title}\nstdout: {stdout.decode('utf-8')}")
if len(stderr) > 0:
- print(f"Ticket {ticketid} stderr: {stderr.decode('utf-8')}")
+ print(f"Ticket {ticketid}:\nSubject: {title}\n stderr: {stderr.decode('utf-8')}")
# Send mails from zammad to rspamc to learn already processed mails
@@ -29,7 +29,7 @@ if __name__ == '__main__':
last_week = (datetime.datetime.now() - datetime.timedelta(days=7)).date()
# fetch all current tickets, which are in state closed and take its' first article
- cur.execute("SELECT tickets.id AS ticket, tags.tag_item_id AS flag, MIN(ticket_articles.id) AS article \
+ cur.execute("SELECT tickets.id AS ticket, tickets.title AS title, tags.tag_item_id AS flag, MIN(ticket_articles.id) AS article \
FROM tickets LEFT JOIN tags ON tags.o_id=tickets.id \
LEFT JOIN ticket_articles ON tickets.id=ticket_articles.ticket_id \
WHERE tickets.state_id=4 \
@@ -39,7 +39,7 @@ if __name__ == '__main__':
tickets = cur.fetchall()
for ticketrow in tickets:
- ticket, flag, article = ticketrow
+ ticket, title, flag, article = ticketrow
# fetch the associated mail file from db, there should only be one with store_object_id=2 (Ticket::Article::Mail)
cur.execute("SELECT stores.filename AS filename, store_provider_dbs.data AS data \
FROM stores LEFT JOIN store_provider_dbs ON store_provider_dbs.id=store_file_id \
@@ -62,9 +62,9 @@ if __name__ == '__main__':
if not has_been_delivered_to_me:
print(f"ERROR: mail for ticket {ticket} does not contain Delivered-To header field")
elif flag == 1:
- send_to_rspamd(ticket, 'spam', mailbytes)
+ send_to_rspamd(ticket, title, 'spam', mailbytes)
elif flag is None:
- send_to_rspamd(ticket, 'ham', mailbytes)
+ send_to_rspamd(ticket, title, 'ham', mailbytes)
else:
print(f"ERROR: mail flag in ticket {ticket} undefined: {flag}")