Compare commits

...

5 Commits

  1. 34
      README.md
  2. 2
      example_configs/pmml_deployment.yml
  3. 28
      pmml.py

@ -3,3 +3,37 @@
## Description
Fetches IMAP inboxes via fetchmail and forwards recieved mails to a list of
recipients.
# Usage
First you will need to write configuration files for pmml and fetchmail. Feel
free to use the supplied examples as starting point:
- example_configs/pmmlrc
- example_configs/fetchmailrc
## Docker
```
$ docker run -v $(pwd)/example_configs/fetchmailrc:/.fetchmailrc -v $(pwd)/example_configs/pmmlrc:/.pmmlrc -it pmml:0.1.4
```
## Kubernetes
If using kubernetes the configuration files should be injected as secret into
the pod executing pmml.
First create the secrets:
```
$ kubectl create secret generic pmml-pmmlrc --from-file example_configs/pmmlrc -n pmml
$ kubectl create secret generic pmml-fetchmailrc --from-file example_configs/fetchmailrc -n pmml
```
Afterwards create the deployment:
```
$ kubectl -n pmml apply -f example_configs/pmml_deployment.yml
```
## Updating secrets
After updating either of the supplied secrets you will need to restart the
pmml pod:
```
$ kubectl -n pmml delete pod $(kubectl -n pmml get pods | tail -1 | awk '{print $1}')
```

@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: pmml
image: torarg/pmml:0.1.3
image: torarg/pmml:0.1.5
volumeMounts:
- mountPath: "/.pmmlrc"
subPath: ".pmmlrc"

@ -1,15 +1,13 @@
#!/usr/bin/env python3
import click
import sys
import os
import email
import email.parser
import smtplib
import json
from pathlib import Path
DEFAULT_CONFIG_FILE_PATH=Path.home() / ".pmmlrc"
DEFAULT_CONFIG_FILE_PATH = Path.home() / ".pmmlrc"
def read_config_file(config_file_path):
@ -17,6 +15,7 @@ def read_config_file(config_file_path):
config = json.load(f)
return config
def setup_smtp_session(smtp_server, smtp_port, smtp_user, smtp_pass):
smtp_client = smtplib.SMTP(host=smtp_server, port=smtp_port)
smtp_client.ehlo()
@ -24,17 +23,30 @@ def setup_smtp_session(smtp_server, smtp_port, smtp_user, smtp_pass):
smtp_client.login(smtp_user, smtp_pass)
return smtp_client
@click.command()
@click.option("-f", "--config-file", default=DEFAULT_CONFIG_FILE_PATH)
@click.argument("mailing-list-address")
def cli(config_file, mailing_list_address):
ignore_subjects = ("Undelivered Mail Returned to Sender",)
input = sys.stdin
config = read_config_file(config_file)[mailing_list_address]
msg = email.parser.Parser().parse(input)
smtp_client = setup_smtp_session(config['smtp_server'], config['smtp_port'],
config['smtp_user'], config['smtp_pass'])
smtp_client.sendmail(mailing_list_address, config['recipients'], msg.as_string())
smtp_client.quit()
if __name__ == '__main__':
if msg["Subject"] in ignore_subjects:
print(f"Skipping processing because auf subject: {msg['Subject']}")
else:
smtp_client = setup_smtp_session(
config["smtp_server"],
config["smtp_port"],
config["smtp_user"],
config["smtp_pass"],
)
smtp_client.sendmail(
mailing_list_address, config["recipients"], msg.as_string()
)
smtp_client.quit()
if __name__ == "__main__":
cli()

Loading…
Cancel
Save