We tried various method for moving folders between accounts
  • shared folder => zimbra does not allow to move folders from / to a shared folder not owned by you
  • zimbra desktop with 2 zimbra accounts => required a full sync of both accounts, would take way too long
  • thunderbird with 2 imap accounts =>would download + upload each message, would take way too long


In the end we ended up with writing a commandline script which does the following things:
  • create folder structure in destination account
  • share the source folder with the destination account
  • mount the shared folder in the destination account
  • copy all messages from the shared folder (and it's subfolder) to the right destination folder
  • remove the mountpount + remove the share


Below you'll find the bash script we used. I hope this saves someone a few hours of frustration ..

Code:
#!/bin/bash

admin="admin@domain"
password="XXXXXXX"
account1="src@domain"
account2="dst@domain"
folder1="source/folder"
folder2="destination/folder"
mountpoint="/tmp_move"
mailbox_cmd="/opt/zimbra/bin/zmmailbox -a \"$admin\" -p \"$password\""
batch_size=100

$mailbox_cmd -m "${account1}" modifyFolderGrant "$folder1" account "$account2" rwidx
$mailbox_cmd -m "${account2}" createMountPoint --view message "$mountpoint" "$account1" "$folder1"
$mailbox_cmd -m "${account1}" getAllFolders | grep "${folder1}" | tr -s ' ' | cut -d' ' -f6- > folders.txt

while read f; do
  new_folder=$(echo "$f" | sed -e "s@^$folder1@$folder2@")
  echo "createFolder \"${new_folder}\""
done < folders.txt | $mailbox_cmd -m "${account2}"

while read f; do
  num=0
  new_folder=$(echo "$f" | sed -e "s@^$folder1@$folder2@")
  mounted_folder=$(echo "$f" | sed -e "s@^$folder1@$mountpoint@")
  echo "Moving messages from $f ($mounted_folder) to $new_folder"
  while true; do
    let num=$num+$batch_size
    message_ids=$($mailbox_cmd -m "${account2}" search -t message -l $batch_size "(in:\"${mounted_folder}\")" |awk {'print $2'} | grep "[0-9]" | grep -v "," | tr "\n" ",")
    echo "..$num"
    if [ -n "$message_ids" ]; then
      $mailbox_cmd -m "${account2}" moveMessage $message_ids "${new_folder}"
    else
      break
    fi
  done
done < folders.txt

$mailbox_cmd -m "${account2}" deleteFolder "$mountpoint"
$mailbox_cmd -m "${account1}" modifyFolderGrant "$folder1" account "$account2" none