Skip to content
Browse files

Switch to Net::SMTP::TLS.

No longer use Net::SMTP or Net::STMP_auth, as ::TLS can handle all of that. It's an independent implementation that does not inherit from Net::STMP, but since it does all that stuff it seems like the better choice at this point (but watch [RT #40478](https://rt.cpan.org/Ticket/Display.html?id=40478) for changes to Net::SMTP).

This change also deprecates the `--smtp-authtype` option, which is now a no-op, and adds `--smtp-tls` for obvious reasons.

Based on a patch from Marino Miculan. Resolves RT#40188.
  • Loading branch information...
1 parent 3466784 commit cb9237914235d3bef4f88e61324204179ef8b7eb @theory committed Aug 31, 2011
Showing with 53 additions and 39 deletions.
  1. +1 −2 Build.PL
  2. +8 −0 Changes
  3. +23 −24 lib/SVN/Notify.pm
  4. +1 −0 t/options.t
  5. +3 −0 t/pod-spelling.t
  6. +17 −13 t/smtp.t
View
3 Build.PL
@@ -48,8 +48,7 @@ my $build = $class->new(
recommends => {
'Pod::Usage' => '1.33',
'HTML::Entities' => 0,
- 'Net::SMTP' => 0,
- 'Net::SMTP_auth' => 0,
+ 'Net::SMTP::TLS' => 0,
'Test::Pod' => 1.41,
'Test::Pod::Coverage' => 1.06,
'File::Spec' => 0,
View
8 Changes
@@ -3,6 +3,14 @@ Revision history for Perl extension SVN::Notify
2.83
- Added the `smtp_port` parameter and accompanying `--smtp-port` option.
Patch from Gustavo Leite de Mendonça Chaves.
+ - Switched from Net::SMTP and Net::SMTP_auth to Net::SMTP::TLS, which
+ handles TLS and non TLS and auth and non-auth in any combintation.
+ Based on patches from Dawood Sangameshwari and Marino Miculan (RT #
+ 40188).
+ - Added `--smtp-tls` option to enable TLS. Based on patch from Marino
+ Miculan.
+ - Deprecated `--smtp-authtype`, which is now a no-op. Net::SMTP::TLS
+ determins the auth type to use by asking the SMTP server.
2.82 2011-06-26T05:12:04
- Moved the repository to
View
47 lib/SVN/Notify.pm
@@ -265,6 +265,13 @@ If unspecified, SVN::Notify will use F<sendmail> to send the message. If
F<sendmail> is not installed locally (such as on Windows boxes!), you I<must>
specify an SMTP server.
+=item smtp_tls
+
+ svnnotify --smtp-tls
+
+Use TLS authentication and encrypted channels for connecting with the server.
+Usually, TLS servers will require user/password authentication.
+
=item smtp_user
svnnotify --smtp-user myuser
@@ -290,10 +297,9 @@ default port is 25.
svnnotify --smtp-authtype authtype
-The authentication method to use for authenticating to the SMTP server. The
-available authentication types include "PLAIN", "NTLM", "CRAM_MD5", and
-others. Consult the L<Authen::SASL|Authen::SASL> documentation for a complete
-list. Defaults to "PLAIN".
+Deprecated in SVN::Notify 2.83, where it has become a no-op. The auth type is
+determined by the contents returned by the SMTP server's response to the
+C<EHLO> command. See L<Net::SMTP::TLS/TLS and AUTHentication> for details.
=item encoding
@@ -722,7 +728,6 @@ sub new {
$params{encoding} ||= $params{charset} || 'UTF-8';
$params{svn_encoding} ||= $params{encoding};
$params{diff_encoding} ||= $params{svn_encoding};
- $params{smtp_authtype} ||= 'PLAIN';
$params{sendmail} ||= $ENV{SENDMAIL} || $class->find_exe('sendmail')
unless $params{smtp};
@@ -867,6 +872,7 @@ sub get_options {
'set-sender|E' => \$opts->{set_sender},
'smtp=s' => \$opts->{smtp},
'smtp-port=i' => \$opts->{smtp_port},
+ 'smtp-tls!' => \$opts->{smtp_tls},
'encoding|charset|c=s'=> \$opts->{encoding},
'diff-encoding=s' => \$opts->{diff_encoding},
'svn-encoding=s' => \$opts->{svn_encoding},
@@ -954,6 +960,7 @@ sub get_options {
svnlook
sendmail
smtp
+ smtp_tls
smtp_port
diff_switches
reply_to
@@ -965,7 +972,6 @@ sub get_options {
footer
smtp_user
smtp_pass
- smtp_authtype
revision_url
ticket_url
), @to_decode ) {
@@ -2362,25 +2368,18 @@ package SVN::Notify::SMTP;
sub get_handle {
my ($class, $notifier) = @_;
- # Load Net::SMTP or the appropriate subclass.
- my $smtp_class = do {
- if ($notifier->{smtp_user}) {
- require Net::SMTP_auth;
- 'Net::SMTP_auth';
- } else {
- require Net::SMTP;
- 'Net::SMTP';
- }
- };
-
- my $smtp = $smtp_class->new(
+ # Load Net::SMTP::TLS.
+ require Net::SMTP::TLS;
+ require Sys::Hostname;
+ my $smtp = Net::SMTP::TLS->new(
$notifier->{smtp},
- ( $notifier->{smtp_port} ? ( Port => $notifier->{smtp_port} ) : ()),
- ( $notifier->{verbose} > 1 ? ( Debug => 1 ) : ())
- ) or die "Unable to create $smtp_class object: $!";
-
- $smtp->auth( @{ $notifier }{qw(smtp_authtype smtp_user smtp_pass)} )
- if $notifier->{smtp_user};
+ Hello => Sys::Hostname::hostname(),
+ ( $notifier->{smtp_port} ? ( Port => $notifier->{smtp_port} ) : () ),
+ ( $notifier->{smtp_tls} ? () : (NoTLS => 1) ),
+ ( $notifier->{smtp_user} ? ( User => $notifier->{smtp_user} ) : () ),
+ ( $notifier->{smtp_pass} ? ( Password => $notifier->{smtp_pass} ) : () ),
+ ( $notifier->{verbose} ? ( Debug => 1 ) : () )
+ ) or die "Unable to create SMTP object: $!";
$smtp->mail($notifier->{from});
$smtp->to(map { split /\s*,\s*/ } @{ $notifier->{to} });
View
1 t/options.t
@@ -23,6 +23,7 @@ my %params = (
smtp_user => undef,
smtp_pass => undef,
smtp_port => undef,
+ smtp_tls => undef,
smtp_authtype => undef,
to_regex_map => undef,
to_email_map => undef,
View
3 t/pod-spelling.t
@@ -52,3 +52,6 @@ login
username
HOWTO
TortoiseSVN
+GitHub
+TLS
+auth
View
30 t/smtp.t
@@ -1,7 +1,7 @@
#!perl -w
use strict;
-use Test::More tests => 38;
+use Test::More tests => 37;
use File::Spec::Functions;
use_ok 'SVN::Notify' or die;
@@ -41,8 +41,11 @@ do {
local $^W;
ok $notifier->execute, 'Execute notifier';
};
-is_deeply $smtp->{new}, ['smtp.example.com'],
- 'The SMTP object should have been instantiated with the SMTP address';
+is_deeply $smtp->{new}, [
+ 'smtp.example.com',
+ 'Hello' => Sys::Hostname::hostname(),
+ NoTLS => 1,
+], 'The SMTP::TLS object should have been instantiated with the SMTP address';
is $smtp->{mail}, 'theory', 'Mail should be initiated by user "theory"';
is_deeply $smtp->{to}, $args{to}, 'Mail should be from the right addresses';
ok $smtp->{data}, 'data() should have been called';
@@ -105,18 +108,24 @@ do {
ok $notifier->execute, 'Execute notifier';
};
-is_deeply $smtp->{new}, ['smtp.example.com', Port => 1234, Debug => 1],
- 'The SMTP object should be instantiated with SMTP address and Debug on';
+is_deeply $smtp->{new}, [
+ 'smtp.example.com',
+ Hello => Sys::Hostname::hostname(),
+ Port => 1234,
+ NoTLS => 1,
+ User => 'theory',
+ Password => 'w00t!',
+ Debug => 1,
+], 'The SMTP::TLSx object should be instantiated with SMTP address and Debug on';
is $smtp->{mail}, 'theory', 'Mail should be initiated by user "theory"';
is_deeply $smtp->{to}, $args{to}, 'Mail should be from the right addresses';
ok $smtp->{data}, 'data() should have been called';
ok $smtp->{dataend}, 'dataend() should have been called';
ok $smtp->{quit}, 'quit() should have been called';
-is $smtp->{auth}, 'NTLM,theory,w00t!', 'auth() should have been called';
# This class mocks Net::SMTP for testing purposes.
-package Net::SMTP;
-BEGIN { $INC{'Net/SMTP.pm'} = __FILE__; }
+package Net::SMTP::TLS;
+BEGIN { $INC{'Net/SMTP/TLS.pm'} = __FILE__; }
sub new {
my $class = shift;
@@ -134,8 +143,3 @@ sub tied_fh {
$smtp->{tied_fh} = 1;
return \local *STDOUT;
}
-
-package Net::SMTP_auth;
-use base 'Net::SMTP';
-BEGIN { $INC{'Net/SMTP_auth.pm'} = __FILE__; }
-sub auth { shift; $smtp->{auth} = join ',', @_ }

0 comments on commit cb92379

Please sign in to comment.
Something went wrong with that request. Please try again.