Hi there,
I'm in the process of migrating users from Pegasus Mail to Zimbra.
My boss wrote a handy script which converted the not-quite-standard Pegasus mailbox format to MBOX which works great. He's also written a script to upload the MBOX files into Zimbra but keeps getting errors. I was wondering if anyone could shed some light on why this may not be working.
NOTE: Our zimbra server is just called 'zimbra'.
The script:
Code:
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
if (!@ARGV) {
die "usage: perl upload-mbox-to-zimbra.pl <user> <upload-user> <password> <mbox-files>";
}
my ($user, $pwd, $upload_user, @mbox_files) = @ARGV;
my $n = 0;
my $n_ok = 0;
my $n_errors = 0;
sub do_files {
for my $file (@mbox_files) {
do_file ($user, $pwd, $upload_user, $file);
}
}
sub do_file {
my ($user, $pwd, $upload_user, $file) = @_;
if (!(open IN, '<', $file)) {
print "Couldn't open $file";
return 0;
}
my $folder = $file;
$folder =~ s|^.*/||;
$folder =~ s/\.[A-Z]+$//i;
$folder =~ s/[^\w-]//g;
my $url = "http://zimbra/zimbra/home/$upload_user/$folder";
print "Uploading $file to $folder ($url)\n";
sub upload_message {
my ($lines) = @_;
do_message($user, $pwd, $url, $lines);
}
do_messages(\&upload_message);
close IN;
}
sub do_messages {
my ($handler) = @_;
my @lines = ();
while (my $line = <IN>) {
if (@lines && ($line =~ m/^From /)) {
&$handler(\@lines);
@lines = ();
print "DEBUGGING: Only doing 1 message\n";
return 1;
}
push @lines, $line;
}
if ($#lines) {
&$handler(\@lines);
}
}
my $ua = LWP::UserAgent->new;
sub do_message {
my ($user, $pwd, $url, $lines) = @_;
$n++;
print "\nMESSAGE $n: $#$lines lines\n";
#print join('', @$lines) , "\n";
my $req = HTTP::Request->new(POST => $url);
$req->authorization_basic($user, $pwd);
$req->content_type('application/x-www-form-urlencoded');
$req->content(join('', @$lines));
my $res = $ua->request($req);
if ($res->as_string =~ /Client-Response-Num: (\d+)/) {
print "Result: " , $1, "\n";
if (!$1) {
$n_ok++;
} else {
$n_errors++;
my $html = $res->as_string;
$html =~ s/.*\<body\>//is;
$html =~ s/\<[^>]*\>/ /g;
$html =~ s/\s\s+/ /g;
print "DEBUGGING: " . $html . "\n";
}
} else {
print $res->as_string, "\n";
$n_errors++;
}
}
do_files();
print "$n messages\n$n_ok OK\n$n_errors errors\n"; The error that occurs when running this script:
Quote:
MESSAGE 1: 785521 lines
500 Server closed connection without sending any data back
Content-Type: text/plain
Client-Date: Tue, 15 Apr 2008 14:04:58 GMT
Client-Warning: Internal response
500 Server closed connection without sending any data back
1 messages
0 OK
1 errors
|
at one point there was also this error:
Quote:
MESSAGE 1: 785521 lines
500 syswrite: Unknown error
Content-Type: text/plain
Client-Date: Tue, 15 Apr 2008 11:56:07 GMT
Client-Warning: Internal response
500 syswrite: Unknown error
1 messages
0 OK
1 errors
|
If someone could shed some light I'd be extremely greatful!
