diff options
author | Florian Pritz <bluewind@xinu.at> | 2017-09-13 11:43:19 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2017-09-13 11:43:19 +0200 |
commit | 9949ce6fc51c37129c3b390a0715a8945cacc16a (patch) | |
tree | 88b6ca4a1b39dfaff41c6dd570c89b3d328861ca /resend-mails.sh | |
parent | ba38291a468363fe3267313b760ae0522616254b (diff) | |
download | bin-9949ce6fc51c37129c3b390a0715a8945cacc16a.tar.gz bin-9949ce6fc51c37129c3b390a0715a8945cacc16a.tar.xz |
add new scripts
Signed-off-by: Florian Pritz <bluewind@xinu.at>
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 |