Abusing the sync protocol for fun and profit.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx

Attachment: SyncClient.pm
Description: Perl program

Attachment: ImapReplica.pm
Description: Perl program

Attachment: IMAPTalk.pm
Description: Perl program

----
Cyrus Home Page: http://cyrusimap.web.cmu.edu/
Cyrus Wiki/FAQ: http://cyrusimap.web.cmu.edu/twiki
List Archives/Info: http://asg.web.cmu.edu/cyrus/mailing-list.html

[Index of Archives]     [Cyrus SASL]     [Squirrel Mail]     [Asterisk PBX]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [KDE]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux