|
@@ -8,59 +8,45 @@ trap cleanup EXIT
|
|
|
|
|
|
cd "${WD}"
|
|
|
|
|
|
+MIME_INJECT=/opt/cropswap/mime-inject.py
|
|
|
DELIVERED=false
|
|
|
SENDMAIL="/usr/sbin/sendmail"
|
|
|
if ((DEBUG != 0)); then
|
|
|
SENDMAIL="$DEBUGMAIL"
|
|
|
fi
|
|
|
-cat - > original
|
|
|
+
|
|
|
+mk_subject(){
|
|
|
+ subject="$(cat subject)"
|
|
|
+ if [ "${subject/\[${SUBJECT}\]/}" == "${subject}" ]; then
|
|
|
+ subject="[${SUBJECT}] ${subject## }"
|
|
|
+ fi
|
|
|
+ echo "${subject}"
|
|
|
+}
|
|
|
+
|
|
|
+tee >(reformail -c -x "Subject:" >subject) original | "${MIME_INJECT}" "To unsubscribe, send an email to $MAILGROUP, with [UNSUBSCRIBE] as the subject (square brackets included)." "$(cat <<EOF
|
|
|
+<div class="banner"><span>To unsubscribe, click <a href="mailto:$MAILGROUP?subject=[UNSUBSCRIBE]">here</a> or send an email to $MAILGROUP, with [UNSUBSCRIBE] as the subject (square brackets included).</span></div>
|
|
|
+EOF
|
|
|
+)" "$(cat <<EOF
|
|
|
+.banner{position:sticky;top:0;background-color:#00f;color:#fff;height:2em;width:100vw;text-align:center;padding:0.5em;box-sizing:border-box;text-transform:uppercase;}
|
|
|
+EOF
|
|
|
+)" | reformime -s1 -e > body
|
|
|
reformail \
|
|
|
-X "Date:" \
|
|
|
-X "MIME-Version:" \
|
|
|
-X "Subject:" \
|
|
|
-X "Content-Type:" \
|
|
|
-< original > headers
|
|
|
-subject="$(reformail -c -x "Subject:" < headers)"
|
|
|
-if [ "${subject/\[${SUBJECT}\]/}" == "${subject}" ]; then
|
|
|
- subject="[${SUBJECT}] ${subject## }"
|
|
|
-fi
|
|
|
-
|
|
|
-banner="NOTICE:======== <<<"
|
|
|
-makemime \
|
|
|
- -c "text/plain" -C 'UTF-8' - <<< "${banner}" | reformail \
|
|
|
- -I 'Content-Disposition: inline;filename=NOTICE.txt' \
|
|
|
-> banner
|
|
|
-content_type="$(reformail -x 'Content-Type:' < headers | cut -d';' -f1)"
|
|
|
-if ! [ "${content_type}" == "text/plain" ]; then
|
|
|
- reformail \
|
|
|
- -X 'Content-Type:' \
|
|
|
- -X 'Content-Transfer-Encoding:' \
|
|
|
- < original | reformail \
|
|
|
- -a 'Content-Transfer-Encoding: 8bit' \
|
|
|
- -a 'Content-Disposition: inline' \
|
|
|
- > mime-headers
|
|
|
- reformime -s1 -e < original | cat mime-headers - > alternative
|
|
|
- makemime -m 'multipart/related' -C 'UTF-8' alternative > related
|
|
|
- makemime -j related banner > mixed
|
|
|
- makemime -m 'multipart/mixed' -a 'MIME-Version: 1.0' -C 'UTF-8' mixed | cat headers -
|
|
|
-else
|
|
|
- cat headers - <<-EOF
|
|
|
-
|
|
|
- $(reformime -s1 -e < original)
|
|
|
-
|
|
|
- ${banner}
|
|
|
- EOF
|
|
|
-fi | reformail \
|
|
|
+< original | reformail \
|
|
|
-U "MIME-Version:" \
|
|
|
- -U "Content-Type:" \
|
|
|
- -I "Subject: ${subject}" \
|
|
|
+ -U "Content-Type:" | reformail \
|
|
|
+ -I "Subject: $(mk_subject)" \
|
|
|
-I "List-Id: $MAILGROUP" \
|
|
|
-I "List-Unsubscribe: <mailto:$MAILGROUP?subject=[UNSUBSCRIBE]>" \
|
|
|
-I "List-Subscribe: <mailto:$MAILGROUP?subject=[SUBSCRIBE]>" \
|
|
|
-I "List-Post: <mailto:$MAILGROUP>" \
|
|
|
-I "List-Unsubscribe-Post: List-Unsubscribe=One-Click" \
|
|
|
-> mail.new
|
|
|
-mv mail{.new,}
|
|
|
+> headers
|
|
|
+cat headers body > mail
|
|
|
+
|
|
|
|
|
|
declare -A SUBSCRIBED
|
|
|
declare -a actions
|