mirror of
https://github.com/chatmail/relay.git
synced 2026-05-11 00:14:36 +00:00
Compare commits
1 Commits
try-ns-851
...
link2xt/an
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b164c4d1b2 |
@@ -24,6 +24,7 @@ chatmail-metadata = "chatmaild.metadata:main"
|
||||
chatmail-expire = "chatmaild.expire:daily_expire_main"
|
||||
chatmail-quota-expire = "chatmaild.expire:quota_expire_main"
|
||||
chatmail-fsreport = "chatmaild.fsreport:main"
|
||||
chatmail-deferred = "chatmaild.deferred:main"
|
||||
lastlogin = "chatmaild.lastlogin:main"
|
||||
turnserver = "chatmaild.turnserver:main"
|
||||
|
||||
|
||||
37
chatmaild/src/chatmaild/deferred.py
Normal file
37
chatmaild/src/chatmaild/deferred.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
Analyze deferred mails and print most common failing destinations.
|
||||
|
||||
Example:
|
||||
|
||||
python -m chatmaild.deferred
|
||||
"""
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
from collections import Counter, defaultdict
|
||||
|
||||
|
||||
def main():
|
||||
p = subprocess.Popen(["postqueue", "-j"], text=True, stdout=subprocess.PIPE)
|
||||
domain_reasons = defaultdict(Counter)
|
||||
domain_total = Counter()
|
||||
|
||||
for line in p.stdout:
|
||||
item = json.loads(line)
|
||||
if item["queue_name"] != "deferred":
|
||||
continue
|
||||
|
||||
for recipient in item["recipients"]:
|
||||
_, domain = recipient["address"].rsplit("@", 1)
|
||||
reason = recipient["delay_reason"]
|
||||
domain_total[domain] += 1
|
||||
domain_reasons[domain][reason] += 1
|
||||
|
||||
for domain, total in reversed(domain_total.most_common()):
|
||||
print(f"{domain} ({total} recipients)")
|
||||
for reason, count in domain_reasons[domain].most_common():
|
||||
print(f" {count}: {reason}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user