Ostatnio aktywny 2 weeks ago

Save incoming emails as plain text (with stripped headers) or place attached files in subdirectories.

dominic zrewidował ten Gist 2 weeks ago. Przejdź do rewizji

3 files changed, 80 insertions

aliases(stworzono plik)

@@ -0,0 +1,6 @@
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(stworzono plik)

@@ -0,0 +1,23 @@
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(stworzono plik)

@@ -0,0 +1,51 @@
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
Nowsze Starsze