diff --git a/.metadata b/.metadata index 25b1fd1..9799819 100644 Binary files a/.metadata and b/.metadata differ diff --git a/.utils/mail/README.md b/.utils/mail/README.md index 9b9c331..dd3d2c9 100644 --- a/.utils/mail/README.md +++ b/.utils/mail/README.md @@ -1,3 +1,7 @@ -# Wrapper scripts to various mail transfer agents. -Only needed if your system does not provide the POSIX mailx compatible mail command. If sending email is prohibited from your environment use *mail.dummy* to avoid warnings from cron, etc. -To activate, choose a suitable one then place it somewhere in the path (~/bin or /usr/local/bin are recommended), name it mail and give it execute permission. +# Wrapper scripts to various mail agents + +Only needed if your system does not provide a local MTA (e.g *sendmail*) and/or a POSIX *mailx* compatible mail command. + +To activate, choose a suitable one then place it somewhere in the path (*/usr/local/bin* is recommended), name or symlink it to *mail* and give it execute permission to anyone. + +To use them with *crond*, you may need the *cronmail* converter script, which can accept sendmail-formatted mail and convert it into a suitable *mailx* call. You can usually set this script as a mail sender for *crond* using the *CRONDARGS* environment variable. diff --git a/.utils/mail/cronmail b/.utils/mail/cronmail new file mode 100755 index 0000000..90040f2 --- /dev/null +++ b/.utils/mail/cronmail @@ -0,0 +1,52 @@ +#!/bin/bash +# +# This is a sendmail to mailx format converter script. +# It receives a well-formed email text from standard input, parses it, +# and invokes a POSIX mailx compliant mail user agent with the result. +# +# It is primarily designed to use with crond. To activate +# use CRONDARGS="-m pathname_to_cronmail" in/etc/default/cron or +# /etc/sysconfig/crond configuration. +# +# Author: Kovács Zoltán +# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html) +# 2026-05-02 v0.1 Initila release. + +# Initialisations. +# +SUBJECT="" +RECIPIENT="$USER" # Default recipient. +MESSAGE="" +MUA="/usr/local/bin/mail" # Custom mail user agent script. + +# Parsing the stdin line by line. +# +while IFS= read -r line +do + # Parses the recipient. + if [[ "$line" =~ ^(T|t)o:\ .*$ ]]; then + RECIPIENT="${line#*: }" + # Parses the subject line. + elif [[ "$line" =~ ^(S|s)ubject:\ .*$ ]]; then + SUBJECT="${line#*: }" + # Message body starts with an empty line. + elif [[ "$line" =~ ^$ ]]; then + MESSAGE+="\n" + # Collects the message body lines. + # The first empty line will be stripped. + elif [ -n "$MESSAGE" ]; then + [[ "$MESSAGE" = "\n" ]] \ + && MESSAGE="$line\n" \ + || MESSAGE+="$line\n" + fi +done + +# Calls the mail user agent. +# +if [ -x "$MUA" ]; then + if [ -n "$SUBJECT" -o -n "$MESSAGE" ]; then + echo -e "$MESSAGE" | "$MUA" -s "$SUBJECT" "$RECIPIENT" + fi +fi + +# That's all, Folks! :) diff --git a/.utils/mail/mail.dummy b/.utils/mail/mail.dummy deleted file mode 100644 index 9985fd4..0000000 --- a/.utils/mail/mail.dummy +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -# -# Dummy file to met the dependencies. Does nothing. diff --git a/.utils/mail/mail.s-nail b/.utils/mail/s-nail old mode 100644 new mode 100755 similarity index 77% rename from .utils/mail/mail.s-nail rename to .utils/mail/s-nail index 58c4dd6..ccc4857 --- a/.utils/mail/mail.s-nail +++ b/.utils/mail/s-nail @@ -20,7 +20,7 @@ SMTP_PASS="topsecret" # s-nail call. # -if [ -x "$(which s-nail 2>/dev/null)" ]; then +if [ -x "/bin/s-nail" ]; then # The recipient's address is the last argument. recipient="${@: -1}" set -- "${@: 1: $#-1}" @@ -29,10 +29,10 @@ if [ -x "$(which s-nail 2>/dev/null)" ]; then [[ "$recipient" = "$USER" ]] && recipient="$TO" [[ "$recipient" = "$USER@$HOSTNAME" ]] && recipient="$TO" if [ -n "$recipient" ]; then - "$(which s-nail)" -S from="$FROM" -S v15-compat \ - -S smtp-auth="login" -S smtp-use-starttls \ - -S mta="$SMTP_PROTO://$SMTP_USER:$SMTP_PASS@$SMTP_SERVER" \ - -S record="/var/mail/$USER" \ - "${@}" $recipient + "/bin/s-nail" -S from="$FROM" -S v15-compat \ + -S smtp-auth="login" $([[ "$SMTP_PROTO" = "submission" ]] && echo "-S smtp-use-starttls") \ + -S mta="$SMTP_PROTO://$SMTP_USER:$SMTP_PASS@$SMTP_SERVER" \ + -S record="/var/mail/$USER" \ + "${@}" $recipient fi fi