Skip to content

ossobv/emlbounce2rmq

Repository files navigation

emlbounce2rmq

Internal tool.

Example emlbounce2rmq.sh:

#!/bin/sh
PYTHONPATH=/usr/local/bin /usr/bin/env python3 -m emlbounce2rmq "$@"

Example run:

emlbounce2rmq.sh --keep /path/to/eml/file

Example run with multiple filenames fed through stdin:

find /var/mail/example.com/bounces/new \
     /var/mail/example.com/bounces/cur \
  -regex '.*/[0-9].*' -type f | sort | emlbounce2rmq.sh --keep

Example published message:

{"first_seen": "2020-01-02",
 "last_seen": "2020-01-31",
 "count": 173,
 "from": "[email protected]",
 "to": "[email protected]"}

Example settings.py:

PUBLISH_API = (
  'rmqs://USER:PASSWORD@'
  'HOSTNAME:PORT/VHOST/cas.mail.exchange')
# you'll configure a cas.mail.queue that binds to this exchange in RabbitMQ

Current "production" configuration:

#-- /etc/crontab

55 0 * * * root
  find /var/mail/example.com/bounces -mtime +180 -regex '.*/[0-9]+[.].*'
    -type f -delete

45 12 * * * root
  find /var/mail/example.com/bounces/new /var/mail/example.com/bounces/cur
    -regex '.*/[0-9].*' -type f | /usr/local/bin/emlbounce2rmq.sh


#-- /etc/postfix/sender_canonical_maps

# Rewrite some Example.com stuff to their own. This is not something we can
# solve. They should use authenticated senders and actually *read* the
# responses.
/^(bounces[+].*@example[.]com)$/        $1
/^(jira)@(example[.]com)$/              [email protected]
/^(noreply|timeline)@(example[.]nl)$/   [email protected]


#-- /usr/local/bin/emlbounce2rmq/settings.py

ACC_PUBLISH_API = (
  'rmqs://xxx:xxx@acceptance:5671/acc2/cas.mail.exchange')
PROD_PUBLISH_API = (
  'rmqs://xxx:xxx@production:5671//cas.mail.exchange#email')
PUBLISH_API = PROD_PUBLISH_API

Requirements:

pika>=0.10  # python3-pika

If pika 1.0+ complains that the certificate is invalid, you may place a <HOSTNAME>.ca file in this directory.

Releases

No releases published

Packages

No packages published