From 9949ce6fc51c37129c3b390a0715a8945cacc16a Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 13 Sep 2017 11:43:19 +0200 Subject: add new scripts Signed-off-by: Florian Pritz --- resend-mails.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 resend-mails.sh (limited to 'resend-mails.sh') diff --git a/resend-mails.sh b/resend-mails.sh new file mode 100644 index 0000000..c463c0e --- /dev/null +++ b/resend-mails.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e +shopt -s nullglob + +resend_mails() { + target_dir="$1"; shift + date=$(date +%s) + searchquery=(all) + + for user in "$@"; do + mailcount=$(doveadm search -u "$user" "${searchquery[@]}" | wc -l) + if ((mailcount > 0)); then + echo "dumping $mailcount mails from $user ..." >&2 + doveadm search -u "$user" "${searchquery[@]}" | while read guid uid; do + doveadm fetch -u "$user" text mailbox-guid "$guid" uid "$uid" | sed '/^text:$/d; s#^\f$##' | grep -v "^Delivered-To: " | sendmail -oi -f 'root@archlinux.org' "$user@archlinux.org" #> "$target_dir/$user-$date-$uid.msg" + doveadm expunge -u "$user" mailbox-guid "$guid" uid "$uid" + done + fi + done +} + + +resend_mails "UNUSED" userfoo userbar -- cgit v1.2.3-24-g4f1b