View Single Post
  #10 (permalink)  
Old 04-30-2009, 03:09 AM
ChaosFreak ChaosFreak is offline
Member
 
Posts: 11
Smile Must Change Timestamp of Flatfile!!

Got it to work with a shell script!

I was having the same problem, and I must admit this post was very helpful along with some other posts I found on Google regarding how to use imapsync.

However, I tried all of the suggestions here and still I was getting the wrong date on all my imported e-mails. Basically, they were assigned a timestamp of when I actually performed the import.

I did a lot of testing, and I figured out that you actually have to change the timestamp of the file itself. In Linux, you can use the touch -d "date/time string" command.

I wrote a shell script that recursively goes through all of the e-mails in the mail store, extracts the data from the "Date:" header, and then changes the timestamp of the file. Please see the code below:

Code:
#!/bin/bash

# This script changes the file timestamp to be the same as the date/time
# in the Date: header of the email.  This solves problems on mail systems
# such as Zimbra where the date/time is changed to the current date/time
# when you import mail using imapsync.

# Questions/Comments: Jim Ryan <morpheus@post.harvard.edu>

ROOTDIR=""

if [ -n "$1" ]; then
        $ROOTDIR="\$*"
fi

printf "Enter mailbox root directory [%s]: " "$ROOTDIR" > /dev/stdout
read ROOTDIR

while [ ! -d "$ROOTDIR" ]; do
        echo "Not a valid directory."
        printf "Enter mailbox root directory [%s]: " "$ROOTDIR" > /dev/stdout
        read ROOTDIR
done

TMPFILE=`mktemp /tmp/fix_imap_dates.XXXXXXXXX` || exit 1
printf "Temporary file %s created.\n" "$TMPFILE"

find $ROOTDIR -type f -printf "%p\n" 2>/dev/null > "$TMPFILE"

exec 3< "$TMPFILE"        echo "Grep Result is: $GREPRESULT"
        if [ -z "$GREPRESULT" ]; then
                printf "File not an email or has no Date header: %s\n" "$FILENAME"
        else
                DATETIME=`echo "$GREPRESULT" | sed 's/^Date: *//g'`
                printf "Date for Timestamp is: %s\n" "$DATETIME"
                touch -d "$DATETIME" "$FILENAME"
        fi
done
After this, I simply used imapsync without the "/tb" option but with the --syncinternaldates option.

Code:
sudo imapsync --nosyncacls --subscribe --syncinternaldates --host1 localhost --user1 xxxx --host2 www.xxxx.com --user2 xxx --ssl2 --port2 993 --noauthmd5
This all worked perfectly!
Reply With Quote