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

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 11-16-2005, 01:32 AM
Senior Member
 
Posts: 52
Default [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?
Reply With Quote
  #2 (permalink)  
Old 11-16-2005, 10:37 AM
Zimbra Employee
 
Posts: 4,792
Default

See Dan's post below.

Last edited by KevinH; 11-16-2005 at 11:50 AM..
Reply With Quote
  #3 (permalink)  
Old 11-16-2005, 11:20 AM
Senior Member
 
Posts: 52
Default

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 11:54 AM..
Reply With Quote
  #4 (permalink)  
Old 11-16-2005, 11:38 AM
Zimbra Employee
 
Posts: 1,434
Default 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.
Reply With Quote
  #5 (permalink)  
Old 11-16-2005, 03:27 PM
Senior Member
 
Posts: 52
Default

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 04:10 PM..
Reply With Quote
  #6 (permalink)  
Old 11-16-2005, 04:17 PM
Zimbra Employee
 
Posts: 1,434
Default 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.
Reply With Quote
  #7 (permalink)  
Old 11-18-2005, 08:14 AM
Starter Member
 
Posts: 1
Default 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
Reply With Quote
  #8 (permalink)  
Old 11-18-2005, 11:39 AM
Zimbra Employee
 
Posts: 1,434
Default 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.
Reply With Quote
  #9 (permalink)  
Old 02-26-2009, 01:30 AM
Intermediate Member
 
Posts: 23
Default Thanks!

This post REALLY saved my bacon. Thanks for the script.
Reply With Quote
  #10 (permalink)  
Old 12-03-2009, 07:46 PM
Junior Member
 
Posts: 5
Default mailbox parse wrapper

I usually back up my mysql when I do zimbra backups and I took the liberty of wrapping your script with this other snippet to auto parse all folders simultanously. Usually this works if I keep a full backup and only do incremental message store backups to sort out new messages. I full backup every week (turn off zimbra and tar the whole /opt/zimbra) and then rsync the message store periodically.

asuming you are able to dump the mysql table with something like

Code:
mysql $> use zimbra;
mysql $> select id,description from mailbox;
and save that to list.txt (or something). I wrapped it up with this.

Code:
#!/bin/bash


for x in `awk '{print "/opt/zimbra/store/0/"$1"/msg"}' /opt/list.txt`; do
        for i in `ls $x`; do
                echo Zimdates::: sh /opt/zimdates.sh $x"/"$i;
                sh /opt/zimdates.sh $x"/"$i;
        done;
done;

for k in `awk '{print $1":::"$2}' /opt/list.txt`; do

        echo "TEST::: /opt/zimbra/bin/zmlmtpinject `echo $k | awk '{ split($0, a, ":::"); print "-d /opt/zimbra/store/0/"a[1]"/msg -r "a[2]" -s "a[2]; exit}'`";
        /opt/zimbra/bin/zmlmtpinject `echo $k | awk '{ split($0, a, ":::"); print "-d /opt/zimbra/store/0/"a[1]"/msg/* -r "a[2]" -s "a[2]; exit}'`;
done;

just a thought.

Last edited by RageLink; 12-03-2009 at 08:12 PM..
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.