aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2024-08-14 23:14:42 +0100
committerGravatar Joe Banks <[email protected]>2024-08-14 23:14:42 +0100
commite3e4654507f089ba626dbe34151dec8a45dc0662 (patch)
treeaf6cf0483aa4fd8ea05dbeae4c8a2cf384dec64f /docs
parentRemove readthedocs config file (diff)
Add docs on parsing mail in scripts
Diffstat (limited to 'docs')
-rw-r--r--docs/docs/services/email/mail-services.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/docs/docs/services/email/mail-services.md b/docs/docs/services/email/mail-services.md
index 134ab39..1c98821 100644
--- a/docs/docs/services/email/mail-services.md
+++ b/docs/docs/services/email/mail-services.md
@@ -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"
+```