Skip to content

Commit

Permalink
Add docs on parsing mail in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Aug 14, 2024
1 parent 04f0dbf commit e3e4654
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/docs/services/email/mail-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,29 @@ Ideal use-cases for service mail are:
Anything that is sensitive or otherwise not suited should instead be implemented
as a feature on King Arthur or any other system with fine-grained access
control.

### Parsing Mail

In scripts, you should use
[`mblaze`](https://manpages.ubuntu.com/manpages/focal/en/man7/mblaze.7.html)
utilities to parse inbound mail to scripts to avoid issues that may arise from
manually parsing email files.

As an example, from the `[email protected]` service:

```sh
# Read the entire email into a variable
EMAIL=$(cat)

# Extract the sender's email address
SENDER=$(echo "$EMAIL" | maddr -a -h from -)

# Extract the Message-ID of the original email
MESSAGE_ID=$(echo "$EMAIL" | mhdr -h message-id -)

# Extract the original Subject and prefix it with "Re: " if necessary
ORIGINAL_SUBJECT=$(echo "$EMAIL" | mhdr -h subject -)

# Construct the reply subject
REPLY_SUBJECT="Re: $ORIGINAL_SUBJECT"
```

0 comments on commit e3e4654

Please sign in to comment.