Skip to content

Instantly share code, notes, and snippets.

@noah
Created February 20, 2016 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noah/0626c9d550e19db57d62 to your computer and use it in GitHub Desktop.
Save noah/0626c9d550e19db57d62 to your computer and use it in GitHub Desktop.
offlineimap-rm: remove mail directories, including offlineimap metadata
#!/bin/sh
user=noah
MDIR=~/mail
ODIR=~/.offlineimap
A=Account-$user/LocalStatus
RL=Repository-Local/FolderValidity
RR=Repository-Remote/FolderValidity
for mf; do
if [ ! -d "$mf" ]; then
echo "$mf does not exist or is not a directory"
exit -1
fi
read -p "Delete the mail folder \`$mf\` from offlineimap cache? [y/n] " -n 1 -r
echo
mf=$(basename "$mf")
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "$ODIR/$A/$mf"
rm -rf "$ODIR/$RL/$mf"
rm -rf "$ODIR/$RR/$mf"
rm -rf "$MDIR/$mf"
echo "NOTE: delete \`$mf\` from remote IMAP server before syncing."
else
echo "skipped \`$mf\`"
fi
done
echo; echo; echo "Final step: empty IMAP trash and run offlineimap."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment