Compare commits

...

5 Commits

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

@ -3,3 +3,37 @@
## Description ## Description
Fetches IMAP inboxes via fetchmail and forwards recieved mails to a list of Fetches IMAP inboxes via fetchmail and forwards recieved mails to a list of
recipients. 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: spec:
containers: containers:
- name: pmml - name: pmml
image: torarg/pmml:0.1.3 image: torarg/pmml:0.1.5
volumeMounts: volumeMounts:
- mountPath: "/.pmmlrc" - mountPath: "/.pmmlrc"
subPath: ".pmmlrc" subPath: ".pmmlrc"

@ -1,8 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import click import click
import sys import sys
import os
import email
import email.parser import email.parser
import smtplib import smtplib
import json import json
@ -17,6 +15,7 @@ def read_config_file(config_file_path):
config = json.load(f) config = json.load(f)
return config return config
def setup_smtp_session(smtp_server, smtp_port, smtp_user, smtp_pass): def setup_smtp_session(smtp_server, smtp_port, smtp_user, smtp_pass):
smtp_client = smtplib.SMTP(host=smtp_server, port=smtp_port) smtp_client = smtplib.SMTP(host=smtp_server, port=smtp_port)
smtp_client.ehlo() 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) smtp_client.login(smtp_user, smtp_pass)
return smtp_client return smtp_client
@click.command() @click.command()
@click.option("-f", "--config-file", default=DEFAULT_CONFIG_FILE_PATH) @click.option("-f", "--config-file", default=DEFAULT_CONFIG_FILE_PATH)
@click.argument("mailing-list-address") @click.argument("mailing-list-address")
def cli(config_file, mailing_list_address): def cli(config_file, mailing_list_address):
ignore_subjects = ("Undelivered Mail Returned to Sender",)
input = sys.stdin input = sys.stdin
config = read_config_file(config_file)[mailing_list_address] config = read_config_file(config_file)[mailing_list_address]
msg = email.parser.Parser().parse(input) msg = email.parser.Parser().parse(input)
smtp_client = setup_smtp_session(config['smtp_server'], config['smtp_port'],
config['smtp_user'], config['smtp_pass']) if msg["Subject"] in ignore_subjects:
smtp_client.sendmail(mailing_list_address, config['recipients'], msg.as_string()) 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() smtp_client.quit()
if __name__ == '__main__':
if __name__ == "__main__":
cli() cli()

Loading…
Cancel
Save