Abusing the sync protocol for fun and profit.

Bron Gondwana brong at fastmail.fm
Tue Feb 19 20:51:49 EST 2008


Attached are three perl modules,

Cyrus/SyncClient.pm
Cyrus/ImapReplica.pm
Mail/IMAPTalk.pm

I'm including this copy of Mail::IMAPTalk because without it, the clever
'literal' stuff doesn't work properly.  I'll prod Rob to clean it up and
re-package it and push it to CPAN so I can depend on that version and
have things all be happier.

You'll also need Authen::SASL::Perl to make the authentication work, then
you can just run up a syncserver instance on your Cyrus master machine
(even if you aren't running replication for anything else), and:

use Cyrus::ImapReplica;

# yes, you do need the IMAP passwords for each user, or you can fiddle
# the authentication options on your source IMAP server to allow all
# users to log in with the same password...
my %users =  (
  username => 'password',
  username2 => 'password2',
  ...
);
my $sourceserver = 'mail.brong.net';
my $destsyncserver = 'store35m.internal';

foreach my $u (sort keys %users) {
  my $replica = Cyrus::ImapReplica->new();

  # if you want to see IO statements to the sync server
  $replica->{verbose} = 1;

  $replica->source($sourceserver, $u, $users{$u});
  $replica->target($u, $destsyncserver, 'repluser', 'replpass');

  # if you don't want to copy all their Trash folders
  $replica->imap_filter(sub {
    my $name = shift;
    return $name ne 'INBOX.Trash';
  });

  $replica->run();
}


NOTE: this stuff isn't really finished and polished ready for the world to
use as-is yet, but I've successfully just used it to move all the users from
my old external IMAP (Courier) server into FastMail, without changing UIDs,
UIDVALIDITY, losing flags, etc.

It reads information via IMAP, and makes the "replica" the same via the sync
server protocol which allows it to specify the UID, INTERNALDATE, etc on the
messages it gets.  Folder subscription (LSUB) is also copied.  Sieve scripts
aren't, since this thing doesn't talk timsieved protocol, and I didn't bother
with annotations or modseq because I don't use them!

Enjoy,

Bron ( this is sort of a first pass for my later plans of building something
       even more powerful.  Muahaha )
-- 
  Bron Gondwana
  brong at fastmail.fm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: SyncClient.pm
Type: application/x-perl
Size: 10359 bytes
Desc: not available
Url : http://lists.andrew.cmu.edu/pipermail/info-cyrus/attachments/20080220/7218bed0/attachment-0003.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ImapReplica.pm
Type: application/x-perl
Size: 9223 bytes
Desc: not available
Url : http://lists.andrew.cmu.edu/pipermail/info-cyrus/attachments/20080220/7218bed0/attachment-0004.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: IMAPTalk.pm
Type: application/x-perl
Size: 109522 bytes
Desc: not available
Url : http://lists.andrew.cmu.edu/pipermail/info-cyrus/attachments/20080220/7218bed0/attachment-0005.bin 


More information about the Info-cyrus mailing list