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