CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Need Help with Perl MAIL::IMAPClient

 



perlleaner
New User

Sep 6, 2013, 4:13 PM

Post #1 of 2 (779 views)
Need Help with Perl MAIL::IMAPClient Can't Post

Hi Perl Gurus,

I'm new to Perl. I need help with a Perl script (already written by someone) to make it work with IMAP server login without password for migration purpose.

My IMAP server is already been set to talk on port 143 with NULL password if Authmechanism is EXTERNAL. I tried to put in a code from other working script (imapsync) but gives all sorts of error. Can you please help to fix the code. I'm not too familier with perl. Any quick help is greatly appreciated.

Here is the error -
-------------------

"my" variable $imap masks earlier declaration in same scope at attachment_parser.pl line 213.
"my" variable $port masks earlier declaration in same scope at attachment_parser.pl line 214.
"my" variable $user masks earlier declaration in same scope at attachment_parser.pl line 214.
"my" variable $authmech masks earlier declaration in same attachment_parser.pl line 216.
Undefined subroutine &main::check_capability called at attachment_parser.pl line 219.
at attachment_parser.pl line 219
Undefined subroutine &main::check_capability called at attachment_parser.pl line 219.
print() on closed filehandle LOGFILE at ./start_migration.pl line 38.

The original code no longer working as the IMAP serer and Auth Mechanism changed

The New IMAP Server needs :

Authmechanism EXTERNAL to make it work.
Any help is greatly appreciated. I'm in a time bound project and need to be done quicker.

Thank you for reading this.

Original Code
---------------

use warnings;

## Show stack traces
use Carp ();
local $SIG{ __WARN__ } = \&Carp::cluck;
local $SIG{ __DIE__ } = \&Carp::cluck;

use Mail::IMAPClient;
use Mail::IMAPClient::BodyStructure;
use Data:umper;
use Net::IMAP::Simple;
use File::Path;
use Net::IMAP::Client;
#use MIME::Parser;


## Default vars
## Use special (twisted) proxy for access
#my $port = '143';
unless (defined($ARGV[0])) { die "No user specified!\n"; }
my $user = "$ARGV[0]";
unless (defined($ARGV[1])) { die "No user specified!\n"; }
my $server = "$ARGV[1]";
my $port = '2112';
#my $port = '143';
my $pass = 'none';
my $msgSizeLimit = 31457280; # Remove attachments from messages > 30 MB
my $debug = 1; # 0=false, 1=true, 2=verbose

## Connect to the server
my $start_time = time_stamp();
if ($debug == 1) { print time_stamp() . " Start\n";}
print time_stamp() . " Connecting to $server... ";
#my $imap = Mail::IMAPClient->new(
# #Fast_io => 'True',
# #Buffer => '51200',
# #Debug => 'True',

Server => $server,
Port => $port,
User => $user,
Password => $pass,
#Debug => ( $debug ? 'true' : 'false' ),
# ShowCredentials => 'true',
# ) or die "Cannot connect to $server as $user: $@";
#$imap->login or die "Could not login: $@\n";
#print "Connected.\n";


Modified version of code from other script (Connect to the server section modified)
--------------------------------------------
## Added Variables ##
my $port = '143';
my $pass = 'NULL';
my $authmech = 'EXTERNAL';
## Added Variables Completed##

### Modified Connect to the server

my $imap = Mail::IMAPClient->new();
my($imap,
$host, $port, $user, $domain, $password,
$mydebugimap, $mytimeout, $fastio,
$ssl, $tls, $authmech, $authuser, $reconnectretry,
$proxyauth, $uid, $split, $Side ) = @_ ;

check_capability( $imap, $authmech, $Side ) ;

if ( $proxyauth ) {
$imap->Authmechanism("") ;
$imap->User($authuser) ;
} else {
$imap->Authmechanism( $authmech ) unless ( $authmech eq 'LOGIN' or $authmech eq 'PREAUTH' ) ;
$imap->User($user) ;
}

$imap->Authcallback(\&xoauth) if $authmech eq "XOAUTH" ;
$imap->Authcallback(\&plainauth) if $authmech eq "PLAIN" || ($authmech eq "EXTERNAL") ;

if ($proxyauth) {
$imap->User($authuser);
$imap->Domain($domain) if (defined($domain));
$imap->Authuser($authuser);
if ($authmech eq "EXTERNAL") {$password = "NULL"};
$imap->Password($password);
} else {
$imap->User($user);
$imap->Domain($domain) if (defined($domain));
$imap->Authuser($authuser);
if ($authmech eq "EXTERNAL") {$password = "NULL"};
$imap->Password($password);
}

### Modification Completed


Laurent_R
Veteran / Moderator

Sep 7, 2013, 2:21 AM

Post #2 of 2 (771 views)
Re: [perlleaner] Need Help with Perl MAIL::IMAPClient [In reply to] Can't Post

Please look at the answer I provided on your crosspost on the Devshed forum.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives