Net-SMTPS-0.09/000755 000765 000024 00000000000 13177612045 013223 5ustar00tomostaff000000 000000 Net-SMTPS-0.09/Changes000644 000765 000024 00000002006 13177605575 014526 0ustar00tomostaff000000 000000 Revision history for Perl extension Net::SMTPS. 0.01 Thu Feb 14 23:20:47 2013 - original version; created by h2xs 1.23 with options -AXn Net::SMTPS 0.02 Thu Feb 15 01:20:07 2013 - add README 0.03 Thu Mar 25 18:00:00 2013 - fix new() for multiple call 0.04 Thu Oct 24 18:15:00 2014 - fix new() for Ticket #99743 "problem with ipv6/v4 autodetection on win32 ... (thanks, ) 0.05 Thu Feb 16 10:00:00 2017 - fix auth() for Ticket #120261 "When passing in Authen::SASL, mechanism should not be (thanks, ) 0.06 Thu Apr 08 20:00:00 2017 - fix on Ticket #121006 "Timeout option doesn't work" (thanks, ) 0.07 Mon Sep 11 23:00:00 2017 - fix on Ticket #123006 "STARTTLS fails" (thanks, ) 0.08 Wed Sep 13 07:00:00 2017 - move starttls code from constructor and enabling starttls() as a method. 0.09 Sun Nov 05 22:00:00 2017 - fix on Ticket #123360; Debug option also sets $IO::Socket::SSL::DEBUG. Net-SMTPS-0.09/lib/000755 000765 000024 00000000000 13155750764 014000 5ustar00tomostaff000000 000000 Net-SMTPS-0.09/Makefile.PL000644 000765 000024 00000001207 13155517724 015201 0ustar00tomostaff000000 000000 #use 5.012003; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'Net::SMTPS', VERSION_FROM => 'lib/Net/SMTPS.pm', # finds $VERSION PREREQ_PM => { 'Net::SMTP' => 2.0, 'IO::Socket::SSL' => 1.0, 'Authen::SASL' => 2.0, }, NO_MYMETA => 'true', ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/Net/SMTPS.pm', # retrieve abstract from module AUTHOR => 'Tomo.M ') : ()), LICENSE => 'perl', ); Net-SMTPS-0.09/MANIFEST000644 000765 000024 00000000121 12107210110 014321 0ustar00tomostaff000000 000000 Changes Makefile.PL MANIFEST META.json META.yml README t/smtp.t lib/Net/SMTPS.pm Net-SMTPS-0.09/META.json000644 000765 000024 00000001653 13177605625 014657 0ustar00tomostaff000000 000000 { "abstract" : "SSL/STARTTLS support for Net::SMTP", "author" : [ "Tomo.M " ], "dynamic_config" : 0, "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.120351", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Net-SMTPS", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Authen::SASL" : "2", "IO::Socket::SSL" : "1", "Net::SMTP" : "2" } } }, "release_status" : "stable", "version" : "0.09" } Net-SMTPS-0.09/META.yml000644 000765 000024 00000001007 13177605642 014477 0ustar00tomostaff000000 000000 --- abstract: 'SSL/STARTTLS support for Net::SMTP' author: - 'Tomo.M ' build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 0 generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.120351' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Net-SMTPS no_index: directory: - t - inc requires: Authen::SASL: 2 IO::Socket::SSL: 1 Net::SMTP: 2 version: 0.09 Net-SMTPS-0.09/README000644 000765 000024 00000002356 13177610537 014115 0ustar00tomostaff000000 000000 Net-SMTPS version 0.09 ====================== This module implements a wrapper for Net::SMTP, enabling over-SSL/STARTTLS support. This module inherits all the methods from Net::SMTP. You may use all the friendly options that came bundled with Net::SMTP. You can control the SSL usage with the options of new() constructor method. 'doSSL' option is the switch, and, If you would like to control detailed SSL settings, you can set SSL_* options that are brought from IO::Socket::SSL. Please see the document of IO::Socket::SSL about these options detail. Just one method difference from the Net::SMTP, you may select SMTP AUTH mechanism as the third option of auth() method. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Net::SMTP IO::Socket::SSL Authen::SASL COPYRIGHT AND LICENCE Put the correct copyright and licence information here. Copyright (C) 2017 by Tomo.M This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.3 or, at your option, any later version of Perl 5 you may have available. Net-SMTPS-0.09/t/000755 000765 000024 00000000000 13175756337 013501 5ustar00tomostaff000000 000000 Net-SMTPS-0.09/t/smtp.t000644 000765 000024 00000001300 12107205664 014625 0ustar00tomostaff000000 000000 # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl smtp.t' ######################### use strict; use warnings; use Test::More; use Net::Config; BEGIN { require_ok('Socket') or diag("I don't believe that the missing of Socket"); } BEGIN { use_ok('Net::SMTPS'); } ######################### SKIP: { skip "No suitable testing server given (NetConfig).", 3 unless (@{$NetConfig{smtp_hosts}} && $NetConfig{test_hosts}); my $smtp = Net::SMTPS->new(Debug => 0); ok( defined($smtp), 'create Net::SMTPS object'); ok( $smtp->domain, 'getting sever reply'); ok ( $smtp->quit, 'closing connection'); } done_testing; Net-SMTPS-0.09/lib/Net/000755 000765 000024 00000000000 13177611454 014522 5ustar00tomostaff000000 000000 Net-SMTPS-0.09/lib/Net/SMTPS.pm000644 000765 000024 00000015567 13177611441 016000 0ustar00tomostaff000000 000000 # ==== # SSL/STARTTLS extention for G.Barr's Net::SMTP. # plus, enable arbitrary SMTP auth mechanism selection. # IO::Socket::SSL (also Net::SSLeay openssl), # Authen::SASL, MIME::Base64 should be installed. # package Net::SMTPS; use vars qw ( $VERSION @ISA ); $VERSION = '0.09'; use strict; use base qw ( Net::SMTP ); use Net::Cmd; # import CMD_OK, CMD_MORE, ... use Net::Config; eval { require IO::Socket::IP and unshift @ISA, 'IO::Socket::IP'; } or eval { require IO::Socket::INET6 and unshift @ISA, 'IO::Socket::INET6'; } or do { require IO::Socket::INET and unshift @ISA, 'IO::Socket::INET'; }; # Override to support SSL/TLS. sub new { my $self = shift; my $type = ref($self) || $self; my ($host, %arg); if (@_ % 2) { $host = shift; %arg = @_; } else { %arg = @_; $host = delete $arg{Host}; } my $ssl = delete $arg{doSSL}; if ($ssl =~ /ssl/i) { $arg{Port} ||= 465; } my $hosts = defined $host ? $host : $NetConfig{smtp_hosts}; my $obj; # eliminate IO::Socket::SSL from @ISA for multiple call of new. @ISA = grep { !/IO::Socket::SSL/ } @ISA; my %_args = map { +"$_" => $arg{$_} } grep {! /^SSL/} keys %arg; my $h; $_args{PeerPort} = $_args{Port} || 'smtp(25)'; $_args{Proto} = 'tcp'; $_args{Timeout} = defined $_args{Timeout} ? $_args{Timeout} : 120; foreach $h (@{ref($hosts) ? $hosts : [$hosts]}) { $_args{PeerAddr} = ($host = $h); #if ($_args{Debug}) { # foreach my $i (keys %_args) { # print STDERR "$type>>> arg $i: $_args{$i}\n"; # } #} $obj = $type->SUPER::new( %_args ) and last; } return undef unless defined $obj; $obj->autoflush(1); $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef); ${*$obj}{'net_smtp_arg'} = \%arg; # OverSSL if (defined($ssl) && $ssl =~ /ssl/i) { $obj->ssl_start() or do { $obj->set_status(500, ["Cannot start SSL"]); $obj->close; return undef; }; } unless ($obj->response() == CMD_OK) { $obj->close(); return undef; } ${*$obj}{'net_smtp_exact_addr'} = $arg{ExactAddresses}; ${*$obj}{'net_smtp_host'} = $host; (${*$obj}{'net_smtp_banner'}) = $obj->message; (${*$obj}{'net_smtp_domain'}) = $obj->message =~ /\A\s*(\S+)/; unless ($obj->hello($arg{Hello} || "")) { $obj->close(); return undef; } # STARTTLS if (defined($ssl) && $ssl =~ /starttls/i && defined($obj->supports('STARTTLS')) ) { #123006 $obj->supports('STARTTLS') returns '' issue. unless ($obj->starttls()) { return undef; } $obj->hello($arg{Hello} || ""); } $obj; } sub ssl_start { my $self = shift; my $type = ref($self); my %arg = %{ ${*$self}{'net_smtp_arg'} }; my %ssl_args = map { +"$_" => $arg{$_} } grep {/^SSL/} keys %arg; eval { require IO::Socket::SSL; } or do { $self->set_status(500, ["Need working IO::Socket::SSL"]); $self->close; return undef; }; my $ssl_debug = (exists $arg{Debug} ? $arg{Debug} : undef); $ssl_debug = (exists $arg{Debug_SSL} ? $arg{Debug_SSL} : $ssl_debug); local $IO::Socket::SSL::DEBUG = $ssl_debug; (unshift @ISA, 'IO::Socket::SSL' and IO::Socket::SSL->start_SSL($self, %ssl_args, @_) and $self->isa('IO::Socket::SSL') and bless $self, $type # re-bless 'cause IO::Socket::SSL blesses himself. ) or return undef; } sub starttls { my $self = shift; ( $self->_STARTTLS() and $self->ssl_start(@_) ) or do { $self->set_status(500, ["Cannot start SSL session"]); $self->close(); return undef; }; } # Override to specify a certain auth mechanism. sub auth { my ($self, $username, $password, $mech) = @_; if ($mech) { $self->debug_print(1, "AUTH-my favorite: ". $mech . "\n") if $self->debug; my @cl_mech = split /\s+/, $mech; my @matched = (); if (exists ${*$self}{'net_smtp_esmtp'}->{'AUTH'}) { my $sv = ${*$self}{'net_smtp_esmtp'}->{'AUTH'}; $self->debug_print(1, "AUTH-server offerred: ". $sv . "\n") if $self->debug; foreach my $i (@cl_mech) { if (index($sv, $i) >= 0 && grep(/$i/i, @matched) == () ) { push @matched, uc($i); } } } if (@matched) { ## override AUTH mech as specified. ## if multiple mechs are specified, priority is still up to Authen::SASL module. ${*$self}{'net_smtp_esmtp'}->{'AUTH'} = join " ", @matched; $self->debug_print(1, "AUTH-negotiated: ". ${*$self}{'net_smtp_esmtp'}->{'AUTH'} . "\n") if $self->debug; } } $self->SUPER::auth($username, $password); } # Fix #121006 no timeout issue. sub getline { my $self = shift; $self->Net::Cmd::getline(@_); } sub _STARTTLS { shift->command("STARTTLS")->response() == CMD_OK } 1; __END__ =head1 NAME Net::SMTPS - SSL/STARTTLS support for Net::SMTP =head1 SYNOPSYS use Net::SMTPS; my $ssl = 'starttls'; # 'ssl' / 'starttls' / undef my $smtp = Net::SMTPS->new("smtp.example.com", Port => 587, doSSL => $ssl); =head1 DESCRIPTION This module implements a wrapper for Net::SMTP, enabling over-SSL/STARTTLS support. This module inherits most of all the methods from Net::SMTP(2.X). You may use all the friendly options that came bundled with Net::SMTP. You can control the SSL usage with the options of new() constructor method. 'doSSL' option is the switch, and, If you would like to control detailed SSL settings, you can set SSL_* options that are brought from IO::Socket::SSL. Please see the document of IO::Socket::SSL about these options detail. Just one method difference from the Net::SMTP, you can select SMTP AUTH mechanism as the third option of auth() method. As of Version 3.10 of Net::SMTP(libnet) includes SSL/STARTTLS capabilities, so this wrapper module's significance disappareing. =head1 CONSTRUCTOR =over 4 =item new ( [ HOST ] [, OPTIONS ] ) A few options added to Net::SMTP(2.X). B { C | C | undef } - to specify SSL connection type. C makes connection wrapped with SSL, C uses SMTP command C. =back =head1 METHODS Most of all methods of Net::SMTP are inherited as is, except auth(). =over 4 =item auth ( USERNAME, PASSWORD [, AUTHMETHOD]) Attempt SASL authentication through Authen::SASL module. AUTHMETHOD is your required method of authentication, like 'CRAM-MD5', 'LOGIN', ... etc. If your selection does not match the server-offerred AUTH mechanism, authentication negotiation may fail. =item starttls ( SSLARGS ) Upgrade existing plain connection to SSL. =back =head1 BUGS Constructor option 'Debug => (N)' (for Net::Cmd) also sets $IO::Socket::SSL::DEBUG when SSL is enabled. You can set 'Debug_SSL => {0-3}' separately. =head1 SEE ALSO L, L, L =head1 AUTHOR Tomo.M =head1 COPYRIGHT Copyright (c) 2017 Tomo.M All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut