Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Installation

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-13-2010, 12:24 PM
Starter Member
 
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 04-16-2010, 12:12 AM
Starter Member
 
Posts: 2
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.
Reply With Quote
  #3 (permalink)  
Old 09-22-2010, 08:18 AM
Starter Member
 
Posts: 1
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..
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.