diff options
Diffstat (limited to 'resend-mails.sh')
-rw-r--r-- | resend-mails.sh | 24 |
1 files changed, 24 insertions, 0 deletions
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 |