Skip to content

Instantly share code, notes, and snippets.

@raoulbhatia
Created January 25, 2020 20:59
Show Gist options
  • Save raoulbhatia/03f6a39ba6e8ea95329f04873efc5c87 to your computer and use it in GitHub Desktop.
Save raoulbhatia/03f6a39ba6e8ea95329f04873efc5c87 to your computer and use it in GitHub Desktop.
Unzip Dovecot emails crypted using zlib plugin
#!/bin/bash
# Unzip /var/vmail
find /var/vmail/ -type f -regextype egrep -regex '.*S=.*W=.*' | while read -r file; do
if [[ $(head -c11 "$file") == "Dovecot-LZ4" ]]; then
doveadm fs get compress lz4:0:posix:prefix=/ \
"$file" > "/tmp/$(basename "$file")"
if [[ -s "/tmp/$(basename "$file")" ]]; then
chmod 600 "/tmp/$(basename "$file")"
chown 5000:5000 "/tmp/$(basename "$file")"
mv "/tmp/$(basename "$file")" "$file"
else
rm "/tmp/$(basename "$file")"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment