2013/3/21 Ludovic Marcotte <[email protected]>:
> On 21/03/13 08:24, joris dedieu wrote:
>>
>> DESCRIPTION:- Détartrer la machine à café
>
> We should definitively do the same here.
Maybe because coffee has now a so great vinegar taste, I wrote a
preliminary script that mostly works. I still have many 404 errors due
to ICS and VCF formating (I think) and I'm not so sure to not miss
some resources.
It uses perl HTTP::DAV and imapsync.
Joris
#!/usr/bin/perl -w
use strict;
use HTTP::DAV;
use File::Temp;
use File::Basename;
use Data::Dumper;
use URI;
my $zurl;
my $surl;
my $zuser;
my $suser;
my $zpass;
my $spass;
my $source;
my $dest;
my $tmpdir;
sub usage() {
print "usage : z2s.pl OPTIONS
Where options are :
-zurl : zimbra url
-surl : sogo url
-zuser : zimbra user
-suser : sogo user
-zpass ; zimbra pass
-spass ; sogo pass\n";
die;
}
sub options (@) {
my @options = grep {/^-/} @_;
my @values = grep {/^[^-]/} @_;
foreach my $opt (@options) {
if ($opt eq "-zurl") { $zurl = shift @values; }
elsif ($opt eq "-surl") { $surl = shift @values; }
elsif ($opt eq "-zuser") { $zuser = shift @values; }
elsif ($opt eq "-suser") { $suser = shift @values; }
elsif ($opt eq "-zpass") { $zpass = shift @values; }
elsif ($opt eq "-spass") { $spass = shift @values; }
else { print "Uknown option $opt\n"; usage(); }
}
unless ($zurl and $surl and $zuser and $suser and $zpass and $spass) {
print "Missing options\n"; usage();
}
}
sub sync($$) {
my ($src_url, $dst_url) = @_;
print "syncing $src_url to $dst_url\n";
my $webdav;
$source->cwd("$src_url");
$dest->cwd("$dst_url");
if ($webdav = $source->propfind( -url => "$src_url", -depth => 1)){
foreach my $resource ( $webdav->get_resourcelist->get_resources()) {
unless ($resource->is_collection) {
my $file_url = $resource->get_uri;
my $file_name = "$tmpdir/".basename($file_url);
$source->get($file_url, $tmpdir);
if ($dest->put( -local => "$file_name", \
-url => $dst_url)) {
print "successfully sync $file_name\n";
unlink "$tmpdir/$file_name";
}
else {
print ERR " $src_url, $dst_url => $file_name : ".
$dest->message . "\n";
}
}
}
} else {
print("Propfind error :".$source->message . "\n");
}
}
sub imapsync() {
my $zhost = URI->new($zurl)->host();
my $shost = URI->new($surl)->host();
my $cmd = "imapsync";
$cmd .= " --host1 $zhost --user1 $zuser --password1 $zpass";
$cmd .= " --host2 $shost --user2 $suser --password2 $spass";
$cmd .= " --usecache --subscribe 2> $tmpdir/err.log";
system($cmd);
}
options(@ARGV);
$zurl="$zurl/$zuser/";
$surl="$surl/$suser/";
$source = HTTP::DAV->new();
$source->credentials(
-url=>$zurl,
-user=>$zuser,
-pass=>$zpass,
);
$source->open( -url => $zurl)
or die("Couldn't open source : ".$source->message . "\n");
$dest = HTTP::DAV->new();
$dest->credentials(
-url=>$surl,
-user=>$suser,
-pass=>$spass,
);
$dest->open( -url => $surl)
or die("Couldn't open dest : ".$dest->message . "\n");
$tmpdir = mkdtemp("temp-XXXXX");
open ERR,">$tmpdir/err.log";
print ERR "\n";
sync($zurl."Calendar/", $surl."Calendar/personal/");
sync($zurl."Contacts/", $surl."Contacts/personal/");
imapsync;
print "Sync complete\n";
print "You will find an error summary in $tmpdir/err.log\n";
close ERR;
>
> --
> Ludovic Marcotte
> +1.514.755.3630 :: www.inverse.ca
> Inverse inc. :: Leaders behind SOGo (www.sogo.nu) and PacketFence
> (www.packetfence.org)
>
> --
> [email protected]
> https://inverse.ca/sogo/lists
--
[email protected]
https://inverse.ca/sogo/lists