Hello,
ish Support on 02.09.2008 3:12 wrote:HelloI have a client I wish to convert their mailboxes from plaintext to mdir for a variety of reasons. To complete this I am using the following script written by Roma.http://cgpro.servicemail24.com/index.php?main=view.php&subid=65
In that web page some long lines are broken; and the below broken line causes the error you're getting:die "*** Can't login to CGPro IMAP: $responseLine.\n" unless($responseLine =~ /^xOK/);I fill in all the variables as necessary and download the CLI, when I run the script I receive the following output:/ConvertMailboxes.pl* OK CommuniGate Pro IMAP Server 5.1.3 at scc.nsw.edu.au ready
Please upgrade to 5.2.6 <http://www.communigate.com/CommuniGatePro/History.html>*** Can't login to CGPro IMAP: x OK completed.It does not matter what I did I could not get it to work. I upped the logged on the imap listener and got this09:05:50.924 5 IMAP connection request from [127.0.0.1]:64169, socket=2509:05:50.924 5 IMAP new VStream created, n=809:05:50.924 5 IMAP stream thread started09:05:50.924 4 IMAP-031092([127.0.0.1]) got connection on [127.0.0.1]:143(scc.nsw.edu.au) from [127.0.0.1]:6416909:05:50.924 5 IMAP-031092([127.0.0.1]) out: * OK CommuniGate Pro IMAP Server 5.1.3 at scc.nsw.edu.au ready\r\n09:05:50.924 5 IMAP-031092([127.0.0.1]) inp: x LOGIN postmaster ter$12309:05:50.924 2 IMAP-031092([127.0.0.1]) 'postm...@scc.nsw.edu.au' connected from [127.0.0.1]:6416909:05:50.924 5 IMAP-031092([127.0.0.1]) out: x OK completed\r\n09:05:50.925 3 IMAP-031092([127.0.0.1]) read failed. Error Code=connection closed by peer09:05:50.925 2 IMAP-031092([127.0.0.1]) 'postm...@scc.nsw.edu.au' disconnected ([127.0.0.1]:64169)09:05:50.925 4 IMAP-031092([127.0.0.1]) closing connection09:05:50.925 4 IMAP-031092([127.0.0.1]) releasing streamCgate server version 5.1.3, running on FreeBSD 6.2.Thanks for your help to any clues on how I might get this running.Support.-------------------------->ishhttp://www.ish.com.auLevel 1, 30 Wilson Street Newtown 2042 Australiaphone +61 2 9550 5001 fax +61 2 9550 4001
--
Sincerely,
Roman
=======================================================================
When answering to letters sent to you by the tech.support staff, make
sure the original message you have received is included into your reply.
#!/usr/bin/perl -w
#
# ConvertMailboxes.pl
#
# The mailbox conversion script for CommuniGate Pro.
# version 1.1 Tue, Feb 22, 2005
# version 1.2 Tue, Jun 10, 2008
# version 1.3 Aug 28, 2008
#
#
# Using this script you can convert accounts' mailboxes from .box to .mdir
# format or vice versa.
#
# Unlike other scripts which convert files directly, this one
# doesn't require shutting down the serve.
#
# This script works with CGPro 5.1.0 or later.
#
# You can convert either one selected account, or all accounts in a domain,
# or all accounts in all domains; un-comment the proper line in the script text.
#
# Mail your comments to sup...@stalker.com
#
use strict;
use CLI; #get one from www.stalker.com/CGPerl
#### YOU SHOLD REDEFINE THESE VARIABLES !!!
my $CGServerAddress='127.0.0.1'; #IP or domain name;
my $Login='postmaster';
my $Password='pass';
my $destMailboxType='TextMailbox'; # 'MailDirMailbox' or 'TextMailbox';
# $useMailboxList values:
# 0 - convert all mailboxes, ignore the list
# 1 - convert only mailboxes included into convMailboxList
# 2 - convert all except included into convMailboxList
my $useMailboxList=0;
my @convMailboxList = ('INBOX','Sent Items','Trash' );
#### end of the customizeable variables list
my $imap = new IO::Socket::INET( PeerAddr => $CGServerAddress,
PeerPort => 143,
Timeout => 600
)
|| die "*** Can't connect to CGPro via IMAP.\n";
$imap->autoflush(1);
my $responseLine = <$imap>;
#print "$responseLine\n";
print $imap "x LOGIN $Login $Password\015\012";
do {
$responseLine = <$imap>;
}until($responseLine =~/^x /);
die "*** Can't login to CGPro IMAP: $responseLine.\n"
unless($responseLine =~ /^x OK/);
my $cli = new CGP::CLI( { PeerAddr => $CGServerAddress,
PeerPort => 106,
login => $Login,
password => $Password } )
|| die "*** Can't login to CGPro CLI: ".$CGP::ERR_STRING."\n";
# un-comment one of the below 3 lines
#processAccount('us...@company.com');
processDomain('company.com');
#processAllDomains();
print "Done\n";
$cli->Logout();
print $imap "x LOGOUT\015\012";
exit;
sub processAllDomains {
my $DomainList = $cli->ListDomains()
|| die "*** Can't get the domain list: ".$cli->getErrMessage.", quitting";
foreach(@$DomainList) {
processDomain($_);
}
}
sub processDomain {
my $domain=$_[0];
print "Domain: $domain\n";
my $accountList = $cli->ListAccounts($domain);
unless($accountList) {
print "*** Can't get accounts for $domain: ".$cli->getErrMessage."\n";
return;
}
foreach(keys %$accountList) {
processAccount("$_\@$domain");
}
}
sub processAccount {
my $account=$_[0];
my $mboxTypeSwitch=0;
print "Account: $account\n";
my $mailboxesList=$cli->ListMailboxes(accountName=>$account);
unless($mailboxesList) {
print "*** Can't list mailboxes for $account:".$cli->getErrMessage."\n";
return;
}
unless($cli->KillAccountSessions($account)) {
print "*** Can't kill sessions for $account: ".$cli->getErrMessage."\n";
return;
}
my $effSettings=$cli->GetAccountEffectiveSettings($account);
# Temporary renaming an account is necesary to disconnect active WebMail users.
# However, it doesn't work for IMAP users.
if(@$effSettings{'DefaultMailboxType'} ne $destMailboxType) {
$cli->UpdateAccountSettings($account,{ DefaultMailboxType => $destMailboxType });
$mboxTypeSwitch=1;
}
foreach(reverse sort keys %$mailboxesList) {
my $data=@$mailboxesList{$_};
if(ref $data eq 'ARRAY') {
$data=@$data[0];
}
if(ref $data eq 'HASH') {
my $mailbox=$_;
my $nMessages=@$data{'Messages'};
my $class=@$data{'Class'};
if($useMailboxList == 0) {
processMailbox($account,$mailbox,$nMessages,$class);
} elsif($useMailboxList == 1) {
foreach(@convMailboxList) {
if($_ eq $mailbox) {
processMailbox($account,$mailbox,$nMessages,$class);
last;
}
}
} elsif($useMailboxList == 2) {
my $found=0;
foreach(@convMailboxList) {
if($_ eq $mailbox) {
$found=1;
last;
}
}
processMailbox($account,$mailbox,$nMessages,$class) unless($found);
} else {
die "wrong value of \$useMailboxList";
}
}
}
if($mboxTypeSwitch) {
$cli->UpdateAccountSettings($account,{ DefaultMailboxType => 'default' });
}
}
sub processMailbox {
my ($account,$mailbox,$nMessages,$mboxClass)=@_;
my $tempMailbox="$mailbox--old--";
#return if($inboxOnly && $mailbox ne 'INBOX');
print "Mailbox: $mailbox\n";
my $acl = $cli->GetMailboxACL($account,$mailbox);
unless($cli->RenameMailboxes($account,$mailbox,$tempMailbox)) {
print "*** Can't rename ~$account/$mailbox: ".$cli->getErrMessage."\n";
return;
}
if($mailbox ne 'INBOX' && !$cli->CreateMailbox($account,$mailbox)) {
print "*** Can't create new ~$account/$mailbox: ".$cli->getErrMessage."\n";
return;
}
$cli->SetMailboxACL($account,$mailbox,$acl) if(%$acl);
$cli->SetMailboxClass($account,$mailbox,$mboxClass) if($mboxClass);
if($nMessages) {
print $imap qq{x SELECT "~$account/$tempMailbox"\015\012};
do {
$responseLine = <$imap>;
}until($responseLine =~/^x /);
unless($responseLine =~ /^x OK/) {
print "*** Can't select ~$account/$tempMailbox: ". $responseLine."\n";
$cli->RenameMailboxes($account,$tempMailbox,$mailbox);
return;
}
print $imap qq{x COPY 1:* "~$account/$mailbox"\015\012};
do {
$responseLine = <$imap>;
}until($responseLine =~/^x /);
unless($responseLine =~ /^x OK/) {
print "*** Can't move messages from ~$account/$tempMailbox: ". $responseLine."\n";
$cli->RenameMailboxes($account,$tempMailbox,$mailbox);
return;
}
print $imap "c CLOSE\015\012";
do {
$responseLine = <$imap>;
}until($responseLine =~/^c /);
unless($responseLine =~ /^c OK/) {
print "*** Can't close ~$account/$tempMailbox: $responseLine.\n";
# return;
}
}
unless($cli->DeleteMailbox($account,$tempMailbox)) {
print "*** Can't delete ~$account/$tempMailbox: ".$cli->getErrMessage."\n";
}
}
__END__;
-------------------------->
ish
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001 fax +61 2 9550 4001
Hello,
ish Support on 02.09.2008 4:55 wrote:RomanThanks, I copied the script you sent to me, and updated the server in question to 5.2.7 as it came out 15 minutes after you sent your email. :) I have just set it now to work on one email account only and I am receving the following:./ConvertMailboxesnew.pl* OK CommuniGate Pro IMAP Server 5.2.7 at scc.nsw.edu.au readyAccount: postm...@scc.nsw.edu.auUse of uninitialized value in pattern match (m//) at /usr/local/lib/perl5/5.8.8/BSDPAN/CLI.pm line 3358, <GEN1> line 4.
Please update the CLI.pm, get one from <http://www.communigate.com/CGPerl/>
Hello,
ish Support on 02.09.2008 6:49 wrote:RomanThe only download link I can find on that page is, http://www.communigate.com/CGPerl/CLI.pm. this is the same download I used this morning and its still not working. Is there a later version somewhere else? I have been unable to find it.
*** Can't kill sessions for postm...@scc.nsw.edu.au:
Use some other account for testing, not postmaster.
When it converts mailboxes it needs to be no open sessions with that account.