Hi,

current version of courier migration script courier-dovecot-migrate.pl preserve order of POP3 UIDLs, but it keep IMAP UIDs not in order which cause problems with clients using IMAP along with POP3 in some cases.

Attached patch use MAIL_FETCH_POP3_ORDER feature added in version 2.0.13 to keep POP3 and IMAP UID[L]s in order.

--
[ Ohodnotte kvalitu mailu: http://nicereply.com/websupport/4afafd34/ ]

Pavel Stano | admin team

http://WebSupport.sk
*** TAKE AND ENJOY ***

--- courier-dovecot-migrate.pl.orig	2012-03-04 15:08:08.000000000 +0100
+++ courier-dovecot-migrate.pl	2012-07-18 16:34:55.000000000 +0200
@@ -311,12 +311,13 @@
     }
     
     # POP3 clients may want to get POP3 UIDLs in the same order always.
-    # Preserve the order even if it causes IMAP UIDs to change.
+    # Preserve the order with O flag supported in dovecot 2.0.13+ and dont change order of IMAP UIDs.
     my %order_map;
     foreach my $fname ( keys %{$filename_map} ) {
         my $order = $filename_map->{$fname}->[4];
-        $order_map{$order} = $fname if ($order != 0);
+	$filename_map->{$fname}->[5]=$order;
     }
+
     my $prev_uid = 0;
     foreach my $order ( sort { $a <=> $b } keys %order_map ) {
         my $file_ar = $filename_map->{ $order_map{$order} };
@@ -332,20 +333,14 @@
         }
     }
     
-    # Sort POP3 messages by their Courier-POP3 order.
-    my @pop3 = sort {
-        $filename_map->{$a}[4] <=> $filename_map->{$b}[4]
-    } grep { $filename_map->{$_}[4] } keys %$filename_map;
-
-    # Sort non-POP3 messages by their UID.
-    # Those that have UID==0 come last since they have been marked to get a new UID.
-    my @imaponly = sort {
-        ($filename_map->{$a}[0] || 'inf') <=> ($filename_map->{$b}[0] || 'inf')
-    } grep { ! $filename_map->{$_}[4] } keys %$filename_map;
+    # sort all messages by their imap UID
+    my @all =  sort {
+       ($filename_map->{$a}[0] || 'inf') <=> ($filename_map->{$b}[0] || 'inf')
+    } keys %$filename_map;
 
     $prev_uid = 0;
     my %uidlist_map;
-    foreach my $fname ( @pop3, @imaponly ) {
+    foreach my $fname ( @all ) {
         my $file_ar = $filename_map->{ $fname };
         my $uid = $file_ar->[0];
         if ($uid == 0 # only in pop3 list or marked for new UID
@@ -365,6 +360,9 @@
     foreach my $uid ( sort { $a <=> $b } keys %uidlist_map ) {
         my $file_ar = $filename_map->{ $uidlist_map{$uid} };
         print $dovecot_uidlist_fh "$uid ";
+	if ($file_ar->[5]) {
+		print $dovecot_uidlist_fh "O".$file_ar->[5]." ";
+	}
         print $dovecot_uidlist_fh 'P' . $file_ar->[1] . ' ' if ( $file_ar->[1] ne "" );
         print $dovecot_uidlist_fh 'W' . $file_ar->[2] . ' ' if ( $file_ar->[2] > 0 );
         print $dovecot_uidlist_fh ':' . $file_ar->[3] . "\n";

Reply via email to