Skip to content

Commit

Permalink
filtermail: count encrypted and unencrypted mails
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Oct 11, 2024
1 parent 205732e commit b959e57
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion chatmaild/src/chatmaild/filtermail.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,21 @@ def check_DATA(self, envelope):
mail_encrypted = check_encrypted(message)

_, from_addr = parseaddr(message.get("from").strip())
envelope_from_domain = from_addr.split("@").pop()

logging.info(f"mime-from: {from_addr} envelope-from: {envelope.mail_from!r}")
if envelope.mail_from.lower() != from_addr.lower():
return f"500 Invalid FROM <{from_addr!r}> for <{envelope.mail_from!r}>"

if mail_encrypted:
print("Filtering encrypted mail.", file=sys.stderr)
else:
print("Filtering unencrypted mail.", file=sys.stderr)

if envelope.mail_from in self.config.passthrough_senders:
return

passthrough_recipients = self.config.passthrough_recipients
envelope_from_domain = from_addr.split("@").pop()
for recipient in envelope.rcpt_tos:
if envelope.mail_from == recipient:
# Always allow sending emails to self.
Expand Down
15 changes: 15 additions & 0 deletions cmdeploy/src/cmdeploy/mtail/delivered_mail.mtail
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ counter warning_count
/warning/ {
warning_count++
}


counter filtered_mail_count

counter encrypted_mail_count
/Filtering encrypted mail\./ {
encrypted_mail_count++
filtered_mail_count++
}

counter unencrypted_mail_count
/Filtering unencrypted mail\./ {
unencrypted_mail_count++
filtered_mail_count++
}

0 comments on commit b959e57

Please sign in to comment.