zmlmtpinject : a gift and a question

Looking to migrate to ZCS? Ask here. Got a great tip or script that helped you migrate? Post it here.
underdog
Posts: 46
Joined: Fri Sep 12, 2014 10:34 pm

zmlmtpinject : a gift and a question

Postby underdog » Wed Jun 16, 2010 3:51 am

Hi There,

I recently had a rather foolish problem which came up through the digital equivalent of self harming. See my woes over here:


Anyway">http://www.zimbra.com/forums/administrators/40856-deleted-ldap-logs-please-help.html
Anyway
, I wasn't able to gracefully fix it and restore however I did manage to create a handy little bash script which will help anyone else attempting disaster recovery from the /opt/zimbra/store directory and I though I should share it.
I had around 100 accounts in the store and then probably 100 folders in each of the accounts so the basic zmlmtpinject function was really a bit cumbersome as it will only do a single directory at a time and not drill down into child directories parsing all xxxx.msg files it finds. Also it won't carry the original date once it's restored, i.e. it will insist that the date of reciept is the date it is re-injected into the new mailbox.

So I adapted the script by gitzc here:



http://www.zimbra.com/forums/administrators/729-solved-using-zmlmtpinject.html#post4017


so that basically it can run a first pass to do all the dates of every .msg file inside of all child directories of the specified directory.

Heres the new script, save as "zimdates.sh":



#!/bin/bash

#

# zimdates

# Chris Gitzlaff 2005-11-16

# Adapted by Underdog Ltd. 2010-06-10

#

# This script inserts an X-Zimbra-Received header into each message

# immediately after the Date header.

#
SCRIPTDIR=`pwd`

TMPFILE="$SCRIPTDIR/zimdates.tmp"
show_usage() {

echo "Usage: zimdates DIRECTORY"

echo "Inserts the X-Zimbra-Received header into a directory of messages"

echo

echo "Example: zimdates ./mail/"

}
# check for correct usage: 1 argument (directory)

if [ $# -eq 1 ]; then

MSGDIR=$1

if [ ! -d $MSGDIR ]; then

show_usage

exit 1

fi

else

show_usage

exit 1

fi
# if the temporary file exists, delete it

if [ -f $TMPFILE ]; then

rm -f $TMPFILE

fi
#cd $MSGDIR
for i in $( ls -1 $MSGDIR); do

cd $MSGDIR/$i

for file in *

do



grep "^Date: " $file > $TMPFILE

# use the first Date occurrence

datestring=`sed -n '1p' $TMPFILE`

# remove the 'Date: ' prefix

datestring=${datestring#* }



sed -n '1,/^Date: /p' $file > $TMPFILE

echo "X-Zimbra-Received: $datestring" >> $TMPFILE

sed '1,/^Date: /d' $file >> $TMPFILE



mv $TMPFILE $file



echo $MSGDIR/$i/$file

done

done
echo "Done"


and call it like:

./zimdates.sh /path/to/users/store/folder/number/
Next

We needed to do the same recursive thing with the zmlmtpinject function that basically you can use zmlmtpinject to iterate through folders inject them into the new mailbox:
Here's some code (in this case saved as: "zmlmtpinject-all.sh")



#!/bin/bash

#

# This script uses zmlmtpinject but loops through child directories. adapted from zmdates by Chris Gitzlaff.

#
SCRIPTDIR=`pwd`

TMPFILE="$SCRIPTDIR/zimdates.tmp"
show_usage() {

echo "Usage: zimdates DIRECTORY"

echo "Inserts the X-Zimbra-Received header into a directory of messages"

echo

echo "Example: zimdates ./mail/"

}
# check for correct usage: 1 argument (directory)

if [ $# -eq 2 ]; then

MSGDIR=$1

if [ ! -d $MSGDIR ]; then

show_usage

exit 1

fi

else

show_usage

exit 1

fi
# if the temporary file exists, delete it

if [ -f $TMPFILE ]; then

rm -f $TMPFILE

fi
#cd $MSGDIR
for i in $( ls -1 $MSGDIR); do

cd $MSGDIR/$i

for file in *

do



/opt/zimbra/bin/zmlmtpinject -d $MSGDIR/$i -r $2 -s $2



echo $MSGDIR/$i/$2

done

done
echo "Done"


and use it like this:


./zmlmtpinject-all.sh /path/to/user/store users.em@il.addre.ss




Now for my Question:
I have injected some email but didn't get the scripts right first time. Is there any way to force zmlmtpinject to re-inject the same message as it seems that once injected you cannot inject again?


Thanks


Return to “Migration”

Who is online

Users browsing this forum: No registered users and 4 guests