Em nosso servidor IMAP com o Dovecot, eu faço assim, para copiar uma hierarquia inteira do Maildir em uma subpasta da caixa de correio de outro usuário:
Defina variáveis para que o restante possa ser copiado / colado
olduser=martina
olddir=/home/$olduser/Maildir
newuser=jasmin
newgroup=users
newdir=/home/$newuser/Maildir
newfolder="Martina"
newdest="$newdir/.$newfolder"
Mova todas as pastas e subpastas para uma subpasta de outro usuário
mkdir -v "$newdest"
for d in cur new tmp; do mv -vi "$olddir/$d" "$newdest/"; done
# Move only folders which contain mails,
# and exclude some special folders like Trash, etc.
cd $olddir
for d in .??*; do
if [[ "$d" =~ ^.(Junk|Trash)$ ]] || [ -z "$(find "$d"/{cur,new,tmp} -type f)" ]; then
echo ignore "$d"; continue;
fi;
mv -vi "$d" "$newdest/$d";
done
# subscribe new user to new folders
find "$newdir" -maxdepth 1 -type d -name ".$newfolder*" -printf "%f\n"
| while read d; do echo ${d/#./}; done
| cat - "$newdir/subscriptions"
| sort -u > "$newdir/subscriptions.new"
mv "$newdir/subscriptions.new" "$newdir/subscriptions"
# fix ownership/permissions
chmod -R u=rwX,go= "$newdir"
chown -R $newuser:$newgroup "$newdir"
# Check ownership/permissions
find "$newdir" -not -perm 700 -type d -ls
find "$newdir" -not -perm 600 -type f -ls
find "$newdir" -not -user $newuser -ls
find "$newdir" -not -group $newgroup -ls