Results 1 to 3 of 3

Thread: [SOLVED] move messages from one folder to another for N users

  1. #1
    MarioG is offline Starter Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    5

    Cool [SOLVED] move messages from one folder to another for N users

    Hi.

    I have the following isssue, I need to move messages from one Folder to the Sent Folder, (we migrate from a sendmail/dovecot to zimbra) and Now we need to move messages from the migrated sent-email folder to our Sent Email
    for all the users.

    I think taht with zmmailbox its possible, but I need advise to obtain the messages idīs to move

    Do you have any suggestion? we are using ZCS Opensource 6

    thanks

  2. #2
    MarioG is offline Starter Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    5

    Default sample script to move message from one folder to another on batch

    Responding to my self:

    I make something like this.

    #!/bin/bash
    #Obtain accounts with zmprov -l gaa dominio > file
    #Delete from file the system accounts:
    #admin@domain
    #wiki@domain
    #spam.xxxxxxxx@domain
    #ham.xxxxxxxx@domain

    FOLDER=Test
    FILE=/tmp/accounts.txt
    cat $FILE|while read ACCOUNT
    do
    echo Working with $ACCOUNT
    MESSAGES=$(zmmailbox -z -m $ACCOUNT gaf | awk -v folder="/$FOLDER" '$2 ~/mess/ && $5 ~folder {print $4}')
    echo TOTAL MESSAGES: $MESSAGES
    while [ "$MESSAGES" -gt "0" ]
    do
    IDS=$(zmmailbox -z -m $ACCOUNT search -t message in:$FOLDER | awk 'BEGIN{ORS=","}; NR > 4 {print $2}'|sed 's/,,//i')
    zmmailbox -z -m $ACCOUNT mm $IDS /Sent
    MESSAGES=$(zmmailbox -z -m $ACCOUNT gaf | awk -v folder=$FOLDER '$2 ~/mess/ && $5 ~folder {print $4}')
    echo $MESSAGES to MOVE ...
    done
    done

    Itīs no perfect but work.

  3. #3
    ltrappett is offline Starter Member
    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    4

    Default Script to move contents of folder to another folder respecting recursion

    #!/bin/bash
    # Created by Leon Trappett Sept. 2010 - ltrappett@mtnmedical.com
    #Make a backup before running.
    #
    #USE AT YOUR OWN RISK!
    #
    # This script was designed to move the contents of one folder to another folder without using the Web GUI and retaining recursion of the folder structures. This script is very helpful when
    # an IMAP account is mounted at a particular mount point to move the contents of it to a folder on the actual Zimbra account.

    # The below variables need to be modified for source and destination folder names
    sourceFolder="/Groupwise"
    destinationFolder="/FromGroupwise"

    # The below variables need to be modified for the locations of where the temporary files are stored
    # Verify the correct permissions are assigned below to these folders so the zimbra account can write to them
    emailTemp="/tmp/zimbra-groupwise/emails"
    scriptsTemp="/tmp/zimbra-groupwise/scripts"


    who=`whoami`
    if [ "$who" != "zimbra" ]
    then
    echo
    echo "Please su to the zimbra user before running this script"
    echo
    exit
    fi

    if [ -z "$1" ]; then
    echo
    echo -e "\nUsage: name-of-script emailaddress"
    echo
    exit
    fi

    echo -e "\nUsage: Migrate Emails from a Source Folder to a Destination Folder"

    # Gathers a list of email accounts in the mtnmedical.com domain
    #zmprov gqu zimbra.mtnmedical.com | grep "@mtnmedical.com" | cut -f 1 -d' '> /tmp/zimbra-groupwise/emails/listaccounts
    echo $1 > $emailTemp/listaccounts

    # Read the email addresses one line at a time into the following loop
    while read emailaddress
    do
    echo "Currently working on: $emailaddress"
    echo "-----------------------------------"
    echo -e "\n"
    echo "Below is a list of all folders in the users email account"
    zmmailbox -z -m $emailaddress gaf
    echo -e "\n"
    echo "The following folders have Messages that need to be Transfered"
    echo -e "\n"
    zmmailbox -z -m $emailaddress gaf | grep " $sourceFolder" | awk '{print $4 " " $5 " " $6 " " $7 " " $8 " " $9 " " $10 " " $11 " " $12 " " $13 " " $14 " " $15}' | grep -v "^0 " | awk '{print $2 " " $3 " " $4 " " $5 " " $6 " " $7 " " $8 " " $9 " " $10 " " $11 " " $12 " " $13}'
    echo -e "\n"
    zmmailbox -z -m $emailaddress gaf | grep " $sourceFolder" | awk '{print $4 " " $5 " " $6 " " $7 " " $8 " " $9 " " $10 " " $11 " " $12 " " $13 " " $14 " " $15}' | grep -v "^0 " | awk '{print $2 " " $3 " " $4 " " $5 " " $6 " " $7 " " $8 " " $9 " " $10 " " $11 " " $12 " " $13}' > $emailTemp/$emailaddress.folders
    cat $emailTemp/$emailaddress.folders | sed -e "s@$sourceFolder@$destinationFolder@" > $emailTemp/$emailaddress.newfolders

    zmmailbox -z -m $emailaddress cf $destinationFolder &> /dev/null
    echo "Creating Folders to Transfer Emails Into"
    rm -f $emailTemp/$emailaddress.error
    while read foldername
    do

    errorCreateFolder=`zmmailbox -z -m $emailaddress cf "$foldername"`
    if [ "$errorCreateFolder" -ge 0 ]
    then
    echo -e "\n"
    else
    echo $errorCreateFolder
    echo "If the error is stating unknown folder create the folder by executing the following command with the name of the folder placed in the script."
    echo "zmmailbox -z -m $emailaddress cf unknownfolder"
    echo "After the folder has been created execute the script again."
    exit
    fi
    echo "Created: $foldername"
    done < "$emailTemp/$emailaddress.newfolders"


    # Create the script to Move the messages from Source Folder to Destination Folder
    rm -f $emailTemp/$emailaddress.zmmailbox.raw &> /dev/null
    while read originalfoldername
    do
    echo -e "\n"
    echo "Getting the messages from: $originalfoldername"
    echo "The following messages are being added to a script to be moved:"
    echo "---------------------------------------------------------------"
    zmmailbox -z -m $emailaddress search -t message -l 999999 "(in:\"$originalfoldername\")"
    for messageid in $(zmmailbox -z -m $emailaddress search -t message -l 999999 "(in:\"$originalfoldername\")"|awk {'print $2'}|grep [0-9]|grep -v , )
    do
    statusMessage="echo 'The next message is being moved.'"
    echo $statusMessage >> $emailTemp/$emailaddress.zmmailbox.raw
    echo 'zmmailbox -z -m ' $emailaddress 'mm ' $messageid ' "'$originalfoldername'"' >> $emailTemp/$emailaddress.zmmailbox.raw
    done

    done < "$emailTemp/$emailaddress.folders"

    cat $emailTemp/$emailaddress.zmmailbox.raw | sed -e "s@$sourceFolder@$destinationFolder@" > $emailTemp/$emailaddress.zmmailbox

    mv $emailTemp/$emailaddress.zmmailbox $scriptsTemp/$emailaddress-zmmailbox.script
    chmod 700 $scriptsTemp/*

    echo "The following script was created for you to run to move the folders for the following email address:"
    echo "Script Name: " $scriptsTemp/$emailaddress-zmmailbox.script
    echo "Email Address of User: " $emailaddress

    done < "$emailTemp/listaccounts"
    Last edited by ltrappett; 09-22-2010 at 09:28 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. nohup: appending output to `nohup.out'
    By artproject-2004 in forum Error Reports
    Replies: 14
    Last Post: 08-22-2010, 08:00 PM
  2. Error when Using Outlook PST Importer
    By chh in forum Zimbra Connector for Outlook
    Replies: 1
    Last Post: 01-19-2009, 05:20 AM
  3. Error with NAS
    By Drox in forum Installation
    Replies: 4
    Last Post: 11-06-2008, 11:32 AM
  4. Replies: 1
    Last Post: 08-28-2008, 08:13 AM
  5. Replies: 3
    Last Post: 10-30-2007, 09:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •