CLI move all emails to subfolder

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
Post Reply
sheshman
Posts: 17
Joined: Tue Mar 14, 2017 1:08 pm
ZCS/ZD Version: Release 8.8.15.GA.3829.UBUNTU14.64

CLI move all emails to subfolder

Post by sheshman »

Hi,

Using "Release 8.7.10.GA.1829.UBUNTU16.64 UBUNTU16_64 FOSS edition", we can move specific mails to subfolder with;

Code: Select all

zmmailbox -z -m user@domain.com moveMessage 2885 /INBOX/Testing
As you can see in code 2885 is mail id and it moves one mail only, i was wondering is it possible to move all mails to a sub folder with single command, i've tried " *, -1, %" instead of mail id but didn't worked.
jhurley
Zimbra Employee
Zimbra Employee
Posts: 34
Joined: Wed Apr 27, 2016 7:04 pm

Re: CLI move all emails to subfolder

Post by jhurley »

The best way to move more than one message at once is within the user web client.
The move message option is a single instance and requires the message id of each message. If you need to move a significant number of messages within the command line, you can script the move by first obtaining the message IDs using the search command like:

zmmailbox -z -m user@domain s -t message “/Inbox" -l 1000

Then loop the moveMessage request with each message ID.
sheshman
Posts: 17
Joined: Tue Mar 14, 2017 1:08 pm
ZCS/ZD Version: Release 8.8.15.GA.3829.UBUNTU14.64

[Resolved]Re: CLI move all emails to subfolder

Post by sheshman »

sharing the script if anyone needs in the future

move.sh

Code: Select all

#!/bin/bash
# Created by cristianovisk
# Github https://github.com/cristianovisk
# Site https://cristianovisk.github.io

folder="/inbox/Arsiv_$(date +%Y%m%d)"
email="$1"

echo "$folder klasörü oluşturuluyor..."
zmmailbox -z -m "$email" cf "$folder"
echo "INBOX içerisindeki iletiler $folder klasörüne taşınıyor..."
function moveMail {
    total=$(zmmailbox -z -m "$email" s -l 999 -t message "in:inbox" | grep mess | wc -l)
    append=0
    percent=$(echo "scale=2 ; $append / $total * 100" | bc)
    for msgid in `zmmailbox -z -m "$email" s -l 999 -t message "in:inbox" | grep mess | awk '{print $2}'`; do
        zmmailbox -z -m "$email" mm $msgid "$folder";
        append=$((append+1))
        percent=$(echo "scale=2 ; $append / $total * 100" | bc)
        echo $percent | pv -qL 40
    done;
}

moveMail

run as : bash ./move.sh mail@mydomain.com

pv module must be installed as : apt install pv -y
Post Reply