Last active
November 21, 2024 19:15
-
-
Save bamthomas/05549637b6397eef036e2d719751f77a to your computer and use it in GitHub Desktop.
delete mailboxes from cyrus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# -*- coding: UTF8 -*- | |
if [ $# -eq 0 ] | |
then | |
echo "usage: $0 <mailbox_pattern>" | |
exit 1 | |
fi | |
PATTERN=$1 | |
read -s -p "cyrus password: " CYRUS_PASSWORD | |
echo | |
sudo ctl_mboxlist -d | jq -r '.[] | "\(.acl) \(.uniqueid)"' | grep $PATTERN > mailboxes.txt | |
rm -f imap_commands.txt | |
touch imap_commands.txt | |
for email in `cat mailboxes.txt | awk -F ':' '{print $1}' | sed 's/^{"\(.*\)\"$/\1/' | sort | uniq` | |
do | |
DB_EMAIL=$(psql -qAt -h localhost -U iroco iroco2 -c "select email from \"user\" where email='$email'") | |
if [[ -z "$DB_EMAIL" ]]; then | |
echo X SETACL user/$email cyrus x >> imap_commands.txt | |
echo Y DELETE user/$email >> imap_commands.txt | |
fi | |
done | |
double_mails=$(wc -l < imap_commands.txt) | |
nb_mails=$(($double_mails/2)) | |
echo "Found $nb_mails mails to delete" | |
read -p "Press enter to remove them in cyrus" | |
imtest -m LOGIN -u cyrus -a cyrus -H 127.0.0.1 -w $CYRUS_PASSWORD -f imap_commands.txt > imap_results.txt | |
read -p "Press enter to call cyr_expire -X 0 -v -a" | |
sudo cyr_expire -X 0 -v -a 2>> imap_results.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment