| 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.
|  | 
11-16-2005, 02:32 AM
| | | [SOLVED] Using zmlmtpinject I have the zimbra store directory containing the email messages as a backup. What is the best way to reinject the messages back into zimbra using zmlmtpinject? Is there documentation other than the command line help? | 
11-16-2005, 11:37 AM
| | Zimbra Employee | |
Posts: 4,784
| | See Dan's post below.
Last edited by KevinH : 11-16-2005 at 12:50 PM.
| 
11-16-2005, 12:20 PM
| | | So there is no way to re-inject the messages from the zimbra store directory back into zimbra? Quote: |
Originally Posted by KevinH EDITED... See Dan's response below. |
Last edited by KevinH : 11-16-2005 at 12:54 PM.
| 
11-16-2005, 12:38 PM
| | Zimbra Employee | |
Posts: 1,434
| | zmlmtpinject *should* work Check out this thread for zmlmtpinject syntax.
Your message store should be structured like this: Code: /opt/zimbra/store/{hash}/{mailbox-id}/msg/{hash}/{item}.msg In other words, all messages in an on-disk directory belong to the same user. So, once you've determined whose mailbox the messages correspond to, just use zmlmtpinject to inject them into the new Zimbra M2 server. You'll lose tags, contacts, folder structure, received dates, and read/unread status, but it should work.
If you want to be extra-tricky, before you run zmlmtpinject you can write a perl script to add an extra "X-Zimbra-Received" header to each message, with the value being the same as the "Date:" header's value. Then zmlmtpinject will use that date as the "received date" when re-injecting the messages. | 
11-16-2005, 04:27 PM
| | | Thank you. I followed your direction and wrote a little perl script to insert the X-Zimbra-Received header and zmlmtpinject worked.
Can you share with us the hashing algorithm that zimbra uses so that it would make locating a user's mail directory much easier? Quote: |
Originally Posted by dkarp Check out this thread for zmlmtpinject syntax.
Your message store should be structured like this: Code: /opt/zimbra/store/{hash}/{mailbox-id}/msg/{hash}/{item}.msg In other words, all messages in an on-disk directory belong to the same user. So, once you've determined whose mailbox the messages correspond to, just use zmlmtpinject to inject them into the new Zimbra M2 server. You'll lose tags, contacts, folder structure, received dates, and read/unread status, but it should work.
If you want to be extra-tricky, before you run zmlmtpinject you can write a perl script to add an extra "X-Zimbra-Received" header to each message, with the value being the same as the "Date:" header's value. Then zmlmtpinject will use that date as the "received date" when re-injecting the messages. |
Last edited by tron : 11-16-2005 at 05:10 PM.
| 
11-16-2005, 05:17 PM
| | Zimbra Employee | |
Posts: 1,434
| | You want the ID, not the hash. Quote: |
Originally Posted by tron Can you share with us the hashing algorithm that zimbra uses so that it would make locating a user's mail directory much easier? | Mailboxes are assigned increasing numeric IDs when they're created. The account ID -> mailbox ID mapping is in the ZIMBRA.MAILBOX table in the old install's database, which you may or may not any longer have access to. (There's a COMMENT field in that table that by default holds the email address of the mailbox owner.)
The "hash" is just what you get by right-shifting the mailbox ID by N bits, so for your system all mailboxes will hash to 0. | 
11-18-2005, 09:14 AM
| | | Using zmlmtpinject I have successfully used zmlmtpinject to import mail into Zimbra. The X-Zimbra-Received header was exactly what I needed. One more question on this topic:
Messages sent by the user aren't being imported quite right. They go to the Inbox, which is not a problem, but when I move them to the Sent Items folder, it shows the sender in the "To" field, not the recipient. Are there any other "X-Zimbra-" headers that may be useful in importing mail?
Below is the procedure I used to successfully import mail using zmlmtpinject. I wrote a bash script called zimdates to add the "X-Zimbra-Received" header. I will include the script at the end of this post. I put the script in my home directory (/home/user1) and ran the following commands as root: Code: cd /home/user1
./zimdates /path/to/user1/maildir/
cd /path/to/user1/maildir/
/opt/zimbra/bin/zmlmtpinject -d ./ -r user1@example.com \
-s root@example.com zimdates: Code: #!/bin/bash
#
# zimdates
# Chris Gitzlaff 2005-11-16
#
# 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 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
done | 
11-18-2005, 12:39 PM
| | Zimbra Employee | |
Posts: 1,434
| | X-Zimbra-Received is all we've got Unfortunately, at present there are no headers that will do what you want. We mark a message as "sent by me" -- the criterion used to decide whether to display the sender or the recipients in the Sent folder -- only at send time, and only if it's automatically saved to sent. | 
02-26-2009, 02:30 AM
| | Intermediate Member | |
Posts: 19
| | Thanks! This post REALLY saved my bacon. Thanks for the script. | | Thread Tools | | | | Display Modes | Linear Mode | | Why Join? Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.  |