aliases
· 203 B · Text
Originalformat
# postfix aliases file `/etc/postfix/aliases`
# an excerpt
files: | /home/dominic/bin/savemail-files.sh
general: | /home/dominic/bin/savemail.sh
tech: | /home/dominic/bin/savemail.sh
| 1 | # postfix aliases file `/etc/postfix/aliases` |
| 2 | # an excerpt |
| 3 | |
| 4 | files: | /home/dominic/bin/savemail-files.sh |
| 5 | general: | /home/dominic/bin/savemail.sh |
| 6 | tech: | /home/dominic/bin/savemail.sh |
savemail-files.sh
· 780 B · Bash
Originalformat
#!/bin/sh
#
# Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com>
# License: MIT
date=`date +%Y%m%d-%H%M%S`
dated=`date +%Y%m%d`
tmpf="/tmp/fullmail-$(echo ${date} | sha1sum -zt | cut -d' ' -f1).tmp"
tmpfs="/tmp/stripped-$(echo ${date} | sha1sum -zt | cut -d' ' -f1).tmp"
folder="/srv/sites/files/repository/private/mails"
cat $* > ${tmpf}
subject="$(grep -i "^Subject:" ${tmpf} | cut -d: -f2- | sed "s/^\ //" | tr -Cs "[:alnum:]" "-" | sed "s/-$//" | qprint -d)"
to="$(grep -i "^Delivered-To:" ${tmpf} | cut -d: -f2- | cut -d@ -f1 | xargs)"
#: "${VARIABLE:=DEFAULT_VALUE}"
: "${subject:=NoSubjectGiven}"
: "${to:=unknown}"
mkdir -pm 755 ${folder}/${to}/${dated}
ripmime -i ${tmpf} -d ${folder}/${to}/${dated}/ --no-nameless
chmod -f 644 ${folder}/${to}/${dated}/*
| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com> |
| 4 | # License: MIT |
| 5 | |
| 6 | date=`date +%Y%m%d-%H%M%S` |
| 7 | dated=`date +%Y%m%d` |
| 8 | tmpf="/tmp/fullmail-$(echo ${date} | sha1sum -zt | cut -d' ' -f1).tmp" |
| 9 | tmpfs="/tmp/stripped-$(echo ${date} | sha1sum -zt | cut -d' ' -f1).tmp" |
| 10 | folder="/srv/sites/files/repository/private/mails" |
| 11 | |
| 12 | cat $* > ${tmpf} |
| 13 | |
| 14 | subject="$(grep -i "^Subject:" ${tmpf} | cut -d: -f2- | sed "s/^\ //" | tr -Cs "[:alnum:]" "-" | sed "s/-$//" | qprint -d)" |
| 15 | to="$(grep -i "^Delivered-To:" ${tmpf} | cut -d: -f2- | cut -d@ -f1 | xargs)" |
| 16 | |
| 17 | #: "${VARIABLE:=DEFAULT_VALUE}" |
| 18 | : "${subject:=NoSubjectGiven}" |
| 19 | : "${to:=unknown}" |
| 20 | |
| 21 | mkdir -pm 755 ${folder}/${to}/${dated} |
| 22 | ripmime -i ${tmpf} -d ${folder}/${to}/${dated}/ --no-nameless |
| 23 | chmod -f 644 ${folder}/${to}/${dated}/* |
savemail.sh
· 1.6 KiB · Bash
Originalformat
#!/bin/sh
#
# Saves an incoming email as plain text file (or .eml)
# somewhere in the webservers directories
#
# Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com>
# Lastmod: 2025-02-23 07:17
# License: MIT
date=`date +%Y%m%d-%H%M%S`
datey=`date +%Y`
datem=`date +%Y-%m_%B`
dated=`date +%Y-%m-%d`
tmpf="/tmp/fullmail-$(echo ${date} | sha1sum -zt | cut -d' ' -f1).tmp"
tmpfs="/tmp/stripped-$(echo ${date} | sha1sum -zt | cut -d' ' -f1).tmp"
folder="/srv/sites/files/repository/private/mails"
cat $* > ${tmpf}
subject="$(grep -m 1 -i "^Subject:" ${tmpf} | cut -d: -f2- | sed "s/^\ //" | tr -Cs "[:alnum:]" "-" | sed "s/-$//" | qprint -d)"
echo >&2 "found subject: $subject"
to="$(grep -i "^Delivered-To:" ${tmpf} | cut -d: -f2- | cut -d@ -f1 | head -n 1 | xargs)"
echo >&2 "found delivered-to: $to"
#: "${VARIABLE:=DEFAULT_VALUE}"
: "${subject:=NoSubjectGiven}"
: "${to:=unknown}"
echo >&2 "subject: $subject"
echo >&2 "delivered-to: $to"
while read line; do
case "${line}" in
From:*|To:*|C[Cc]:*|Delivered-To:*|Date:*|Subject:*|Received:*|Message-ID:*|Content-Type:*|Content-Transfer-Encoding:*|User-Agent:*) echo ${line} >> ${tmpfs};;
"") (echo && cat $*) >> ${tmpfs};;
*) ;;
esac
done < ${tmpf}
filename="${date}_${subject}.txt"
file="${folder}/${to}/${datem}/${filename}"
link="https://$URL/${to}/${filename}"
mkdir -pm 755 ${folder}/${to}/${datem}
mv "${tmpfs}" "${file}"
chmod 644 ${file}
echo >&2 "move to: $file"
echo -e "New mail in archives: ${subject}\n\n<${link}>\n\n-- \nMail sorting script \`${0}\` to your service.\n" | \
mail -s "New mail in archives: ${to}" -. contact@domain.local
| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Saves an incoming email as plain text file (or .eml) |
| 4 | # somewhere in the webservers directories |
| 5 | # |
| 6 | # Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com> |
| 7 | # Lastmod: 2025-02-23 07:17 |
| 8 | # License: MIT |
| 9 | |
| 10 | date=`date +%Y%m%d-%H%M%S` |
| 11 | datey=`date +%Y` |
| 12 | datem=`date +%Y-%m_%B` |
| 13 | dated=`date +%Y-%m-%d` |
| 14 | tmpf="/tmp/fullmail-$(echo ${date} | sha1sum -zt | cut -d' ' -f1).tmp" |
| 15 | tmpfs="/tmp/stripped-$(echo ${date} | sha1sum -zt | cut -d' ' -f1).tmp" |
| 16 | folder="/srv/sites/files/repository/private/mails" |
| 17 | |
| 18 | cat $* > ${tmpf} |
| 19 | |
| 20 | subject="$(grep -m 1 -i "^Subject:" ${tmpf} | cut -d: -f2- | sed "s/^\ //" | tr -Cs "[:alnum:]" "-" | sed "s/-$//" | qprint -d)" |
| 21 | echo >&2 "found subject: $subject" |
| 22 | to="$(grep -i "^Delivered-To:" ${tmpf} | cut -d: -f2- | cut -d@ -f1 | head -n 1 | xargs)" |
| 23 | echo >&2 "found delivered-to: $to" |
| 24 | |
| 25 | #: "${VARIABLE:=DEFAULT_VALUE}" |
| 26 | : "${subject:=NoSubjectGiven}" |
| 27 | : "${to:=unknown}" |
| 28 | |
| 29 | echo >&2 "subject: $subject" |
| 30 | echo >&2 "delivered-to: $to" |
| 31 | |
| 32 | while read line; do |
| 33 | case "${line}" in |
| 34 | From:*|To:*|C[Cc]:*|Delivered-To:*|Date:*|Subject:*|Received:*|Message-ID:*|Content-Type:*|Content-Transfer-Encoding:*|User-Agent:*) echo ${line} >> ${tmpfs};; |
| 35 | "") (echo && cat $*) >> ${tmpfs};; |
| 36 | *) ;; |
| 37 | esac |
| 38 | done < ${tmpf} |
| 39 | |
| 40 | filename="${date}_${subject}.txt" |
| 41 | file="${folder}/${to}/${datem}/${filename}" |
| 42 | link="https://$URL/${to}/${filename}" |
| 43 | |
| 44 | mkdir -pm 755 ${folder}/${to}/${datem} |
| 45 | |
| 46 | mv "${tmpfs}" "${file}" |
| 47 | chmod 644 ${file} |
| 48 | echo >&2 "move to: $file" |
| 49 | |
| 50 | echo -e "New mail in archives: ${subject}\n\n<${link}>\n\n-- \nMail sorting script \`${0}\` to your service.\n" | \ |
| 51 | mail -s "New mail in archives: ${to}" -. contact@domain.local |
| 52 |