mirror of
https://github.com/imapsync/imapsync.git
synced 2025-08-02 15:11:49 +02:00
1.836
This commit is contained in:
parent
3afeea4a16
commit
8d76e44c5e
243 changed files with 57452 additions and 10330 deletions
14
W/learn/digest
Executable file
14
W/learn/digest
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict ;
|
||||
use warnings ;
|
||||
|
||||
|
||||
|
||||
|
||||
require Digest ;
|
||||
|
||||
my $digest ;
|
||||
eval { $digest = Digest->new( 'Whirlpool' ) ; } ;
|
||||
$digest->add( '' ) ;
|
||||
print $digest->hexdigest( ) . "\n" ;
|
81
W/learn/oauth2
Executable file
81
W/learn/oauth2
Executable file
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use HTTP::Request::Common qw(POST);
|
||||
use LWP::UserAgent;
|
||||
use Data::Dumper;
|
||||
use Mail::IMAPClient;
|
||||
use URI::Escape;
|
||||
use MIME::Base64;
|
||||
|
||||
print "\n\nType your email address here: ";
|
||||
$username = "gilles.lamiral@gmail.com" ;
|
||||
chomp($username);
|
||||
|
||||
print "\n\nPaste the client_id here: ";
|
||||
$client_id = '108687549524-86sjq07f3ch8otl9fnr56mjnniltdrvn.apps.googleusercontent.com' ;
|
||||
chomp($client_id);
|
||||
|
||||
print "\n\nPaste the client_secret here: ";
|
||||
$client_secret = 'zAJO4PLxzeJ4yOaiJRk6f69k' ;
|
||||
chomp($client_secret);
|
||||
|
||||
$scope_string = "https%3A%2F%2Fmail.google.com%2F";
|
||||
|
||||
print "Please open the following in your web browser:\n\nhttps://accounts.google.com/o/oauth2/auth?scope=$scope_string&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=$client_id";
|
||||
|
||||
print "\n\nPaste the code here: ";
|
||||
$code = '4/-e6wojtOSXCjZnwZKKhvg3AdDqDjGLOF0nXxfAFcdmk';
|
||||
#
|
||||
chomp($code);
|
||||
|
||||
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
|
||||
my $ua = LWP::UserAgent->new;
|
||||
$ua->timeout(10);
|
||||
$ua->env_proxy;
|
||||
|
||||
print "Exchanging the code for an access token and refresh token...\n";
|
||||
my $exchange_response = $ua->request(POST 'https://accounts.google.com/o/oauth2/token',
|
||||
'Content_Type' => 'application/x-www-form-urlencoded',
|
||||
'Content' => [
|
||||
'code' => $code,
|
||||
'client_id' => $client_id,
|
||||
'client_secret' => $client_secret,
|
||||
'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob',
|
||||
'grant_type' => 'authorization_code',
|
||||
],
|
||||
);
|
||||
|
||||
my ($access_token) = ($exchange_response->decoded_content =~ m/access_token"."(.)"/);
|
||||
my ($refresh_token) = ($exchange_response->decoded_content =~ m/refresh_token"."(.)"/);
|
||||
|
||||
|
||||
print "exchange_response: ", $exchange_response->decoded_content, "\n" ;
|
||||
|
||||
print "access token: $access_token\n";
|
||||
print "refresh token: $refresh_token\n";
|
||||
|
||||
print "Refreshing the access token...\n";
|
||||
my $auth_response = $ua->request(POST 'https://accounts.google.com/o/oauth2/token',
|
||||
'Host' => 'accounts.google.com',
|
||||
'Content_Type' => 'application/x-www-form-urlencoded',
|
||||
'Content' => [
|
||||
'client_id' => $client_id,
|
||||
'client_secret' => $client_secret,
|
||||
'refresh_token' => $refresh_token,
|
||||
'grant_type' => 'refresh_token',
|
||||
],
|
||||
);
|
||||
|
||||
my ($access_token) = ($auth_response->decoded_content =~ m/access_token"."(.)"/);
|
||||
|
||||
my $oauth_sign = encode_base64("user=". $username ."\x01auth=Bearer ". $access_token ."\x01\x01", '');
|
||||
|
||||
my $imap = Mail::IMAPClient->new(
|
||||
Server => 'imap.gmail.com',
|
||||
Port => 993,
|
||||
Ssl => 1,
|
||||
Uid => 1,
|
||||
) or die("Can't connect to imap server.");
|
||||
$imap->authenticate('XOAUTH2', sub { return $oauth_sign }) or die("Auth error: ". $imap->LastError);
|
||||
|
||||
print join(", ",$imap->folders),".\n" or die("List folders error: ". $imap->LastError);
|
53
W/learn/resolvme
Executable file
53
W/learn/resolvme
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
|
||||
use strict ;
|
||||
use warnings ;
|
||||
use English ;
|
||||
|
||||
use Socket qw( SOCK_STREAM AI_CANONNAME NI_NUMERICHOST NIx_NOSERV getaddrinfo getnameinfo );
|
||||
#use Socket::GetAddrInfo qw( getaddrinfo getnameinfo );
|
||||
use IO::Socket;
|
||||
|
||||
|
||||
check_name_and_service( @ARGV ) ;
|
||||
|
||||
sub check_name_and_service {
|
||||
|
||||
my ( $name, $service ) = @ARG ;
|
||||
|
||||
my %hints = ( socktype => SOCK_STREAM, flags => AI_CANONNAME );
|
||||
my ( $err, @res ) = getaddrinfo( $name, $service, \%hints );
|
||||
|
||||
print "Cannot resolve name - $err\n" if $err;
|
||||
|
||||
my $sock;
|
||||
|
||||
foreach my $ai ( @res ) {
|
||||
my $candidate = IO::Socket->new();
|
||||
$candidate->timeout( 2 ) ;
|
||||
|
||||
print "family: ", $ai->{family},
|
||||
"\nsocktype: ", $ai->{socktype},
|
||||
"\nprotocol: ", $ai->{protocol},
|
||||
"\ncanonname: ", $ai->{canonname},
|
||||
"\ntimeout: ", $candidate->timeout,
|
||||
"\n" ;
|
||||
$candidate->socket( $ai->{family}, $ai->{socktype}, $ai->{protocol} )
|
||||
or next ;
|
||||
|
||||
$candidate->connect( $ai->{addr} ) or next ;
|
||||
|
||||
$sock = $candidate;
|
||||
|
||||
if( $sock ) {
|
||||
my ( $err, $host, $service ) = getnameinfo( $sock->peername );
|
||||
print "Connected to $host:$service\n" if !$err;
|
||||
my ($err, $ipaddr) = getnameinfo($ai->{addr}, NI_NUMERICHOST, NIx_NOSERV);
|
||||
print "ipaddr: $ipaddr\n";
|
||||
$sock->close ;
|
||||
#last ;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue