thunderbird copy old messages from other dirs

Brian brian at brianwhalen.net
Mon Apr 5 02:04:06 EEST 2021


Is there a known documented way to copy messages from backup folders 
into the cur folder and have them not make a mess of the dates. What I 
see is if I copy several year old messages to the cur folder on an 
ubuntu box the massages when viewed on an android phone appear out of 
order. I tried deleting the dovecot index and cache files and restarting 
the service, I also tried running these 2 scripts I found. I added some 
echoes to see what was occurring. Still, messages appear out of order 
and some do not appear at all on the droid.

I tried copying the actual message files out of various cur dirs and 
still some were very out of date. The second script seemed to be 
adjusting the dates of the files properly, but I am not sure what 
android gmail actually uses to sort.

#!/bin/bash

for i in `ls /home/brian/Maildir/cur/`
do
   # Find the date field and then remove up to the first space (Date: )
   DATE=$(grep '^Date:' $i | head -1 | cut -d' ' -f1 --complement)

   # Create a timestamp from the date above
   STAMP=$(date --date="$DATE" +%Y%m%d%H%M)

   # touch the file with the correct timestamp
   touch -t $STAMP $i

   echo "$i stamped"
   echo "$DATE"
   echo "$STAMP"

done

------------


#!/bin/bash
# Fix emails with bad timestamps in a maildir
# This script reads the date from the email header and set its UNIX 
timestamp and renames it with the proper date
# e.g. this:
# dec.  05  2017 
1512499812.M908995P21566.ip-111-11-11-11,S=16331,W=16746:2,S
# becomes that (the email Date header is "Date: Tue, 22 Oct 2013 
10:07:21 +0100"):
# oct.  22  2013 
1382432841.M908995P21566.ip-111-11-11-11,S=16331,W=16746:2,S

cd "/home/brian/Maildir/cur";

for i in `ls  1482809425.M277770P17438*`
do
   echo "$i"
   # We extract the date from the email headers
   DATE=$(grep '^Date:' $i | head -1 | cut -d' ' -f1 --complement)

   # We compute a touch-compatible timestamp as well as the real timestamp
   TOUCHSTAMP=$(date --date="$DATE" +%Y%m%d%H%M)
   TIMESTAMP=$(date --date="$DATE" +%s)

   # We set the file timestamp
   touch -t $TOUCHSTAMP $i

   # We rename the file with preprending timestamp
   newfilename="$TIMESTAMP.${i#*.}"
   mv "$i" "$newfilename"
   echo "$newfilename"
   echo "******"
done



More information about the dovecot mailing list