Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output generated PDFs to a folder #25

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,42 @@ The following parameters are used (defaults in parentheses):
* `IMAP_USERNAME`
* `IMAP_PASSWORD`
* `IMAP_FOLDER` Which folder to watch for unread emails
* `SMTP_URL`
* `MAIL_SENDER`: Address the mail with pdf should be sent from
* `MAIL_DESTINATION`: Where to send the resulting pdf
* `SMTP_PORT`: (587)
* `SMTP_TLS`: (True)
* `INTER_RUN_INTERVAL`: Time in seconds that the system should wait between running the script
* `PRINT_FAILED_MSG`: Flag to control printing of error messages
* `HOSTS`: [Semicolon separated list of hosts](https://github.com/rob-luke/emails-html-to-pdf/pull/12) that should be added to /etc/hosts to prevent dns lookup failures
* `WKHTMLTOPDF_OPTIONS`: Python dict (json) representation of wkhtmltopdf_options that can be passed to the used pdfkit library
* `MAIL_MESSAGE_FLAG`: Flag to apply to email after processing.
Must be one of [imap-tools flags](https://github.com/ikvk/imap_tools/blob/7f8fd5e4f3976bbd2efa507843c577affa61d996/imap_tools/consts.py#L10). Values: SEEN (default), ANSWERED, FLAGGED, DELETED, DRAFT, RECENT
* `OUTPUT_TYPE`: (`mailto`) See Outputs section below.

### Outputs

#### Send Email (Default)

Output Type: `mailto`

This output will send the generated PDF files attached as an email.

| Argument | Default | Description |
|---|---|---|
| `SMTP_SERVER` | | The address of the SMTP server. |
| `SMTP_PORT` | 587 | The port number for the SMTP server. |
| `SMTP_USERNAME` | Same as IMAP | The username to use for authentication. |
| `SMTP_PASSWORD` | Same as IMAP | The password to use for authentication. |
| `SMTP_ENCRYPTION` | `STARTTLS` | The encryption used for the SMTP connection. Valid options are `STARTTLS` and `SSL`. All other values will attempt to connect without encryption. |
| `MAIL_SENDER` | SMTP Username | The address which mail should be sent from. This can be in either `[email protected]` or `Name <[email protected]>` format. |
| `MAIL_DESTINATION` | | The address which mail should be sent to. This can be in either `[email protected]` or `Name <[email protected]>` format. |
| `SMTP_URL` | | Deprecated. Use `SMTP_SERVER` instead. |

#### Output to Folder

Output Type: `folder`

This output will copy the generate PDFs into the specified folder.

| Argument | Default | Description |
|---|---|---|
| `OUTPUT_FOLDER` | | The folder to output PDFs to. This can be either relative or absolute. Paths are relative to the working directory. |

### Docker-Compose

Expand Down
22 changes: 22 additions & 0 deletions src/filenameutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
BAD_CHARS = ["/", "*", ":", "<", ">", "|", '"', "’", "–"]


def replace_bad_chars(string, replace_char="_"):
"""Replaces characters in the given string which are not valid for some filesystems.

Args:
string (str): The string to perfom the replacement on
replace_char (char): The character to replace the bad characters with
"""
for char in BAD_CHARS:
string = string.replace(char, replace_char)
return string


def replace_unpleasant_chars(string):
"""Replaces characters which are considered unpleasant in filenames (space and period).

Args:
string (str): The string to perfom the replacement on
"""
return string.replace(".", "_").replace(" ", "-")
Loading