Bug 12040: Add 3 parameters to runreport.pl for SMTP authentication
authorChris Nighswonger <cnighswonger@foundations.edu>
Mon, 7 Apr 2014 15:55:35 +0000 (11:55 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 11 Apr 2014 16:11:52 +0000 (16:11 +0000)
This patch adds three optional parameters to runreport.pl
to allow authentication with the SMTP server.

--username -> Username to pass to the SMTP server for
              authentication
--password -> Password to pass to the SMTP server for
              authentication
--method   -> Method is the type of authentication.
              Ie. LOGIN, DIGEST-MD5, etc.

Test Plan
---------
As for testing manually using a Gmail account:

1. Set up your sendmail as shown in
    misc/cronjobs/CONFIGURE.gmail

2. Before applying this patch, run misc/cronjobs/runreports.pl
    on your favorite report including the proper email parameters
    against your gmail account.

3. Note the failure message stating the authentication
    requirement.

4. Apply this patch, and return the script including the
    additional parameters and specifying "LOGIN" for the method.

5. Note the successful send.

6. perldoc misc/cronjobs/runreport.pl

7. Run the koha qa test tool.

Signed-off-by: Chris Nighswonger <cnighswonger@foundations.edu>
Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
misc/cronjobs/runreport.pl

index 41e9761..0725767 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 #
 # Copyright 2008 Liblime
+# Copyright 2014 Foundations Bible College, Inc.
 #
 # This file is part of Koha.
 #
@@ -57,6 +58,9 @@ runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ]
    --format=s      selects format. Choice of text, html, csv, or tsv
 
    -e --email      whether to use e-mail (implied by --to or --from)
+   --username      username to pass to the SMTP server for authentication
+   --password      password to pass to the SMTP server for authentication
+   --method        method is the type of authentication. Ie. LOGIN, DIGEST-MD5, etc.
    --to=s          e-mail address to send report to
    --from=s        e-mail address to send report from
    --subject=s     subject for the e-mail
@@ -69,11 +73,11 @@ runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ]
 
 =over
 
-=item B<-help>
+=item B<--help>
 
 Print a brief help message and exits.
 
-=item B<-man>
+=item B<--man>
 
 Prints the manual page and exits.
 
@@ -81,23 +85,35 @@ Prints the manual page and exits.
 
 Verbose. Without this flag set, only fatal errors are reported.
 
-=item B<-format>
+=item B<--format>
 
 Current options are text, html, csv, and tsv. At the moment, text and tsv both produce tab-separated tab-separated output.
 
-=item B<-email>
+=item B<--email>
 
 Whether to use e-mail (implied by --to or --from).
 
-=item B<-to>
+=item B<--username>
+
+Username to pass to the SMTP server for authentication
+
+=item B<--password>
+
+Password to pass to the SMTP server for authentication
+
+=item B<--method>
+
+Method is the type of authentication. Ie. LOGIN, DIGEST-MD5, etc.
+
+=item B<--to>
 
 E-mail address to send report to. Defaults to KohaAdminEmailAddress.
 
-=item B<-from>
+=item B<--from>
 
 E-mail address to send report from. Defaults to KohaAdminEmailAddress.
 
-=item B<-subject>
+=item B<--subject>
 
 Subject for the e-mail message. Defaults to "Koha Saved Report"
 
@@ -150,15 +166,23 @@ my $subject = 'Koha Saved Report';
 my $separator = ',';
 my $quote = '"';
 
+my $username = undef;
+my $password = undef;
+my $method = 'LOGIN';
+
 GetOptions(
-    'help|?'     => \$help,
-    'man'        => \$man,
-    'verbose'    => \$verbose,
-    'format=s'   => \$format,
-    'to=s'       => \$to,
-    'from=s'     => \$from,
-    'subject=s'  => \$subject,
-    'email'      => \$email,
+    'help|?'            => \$help,
+    'man'               => \$man,
+    'verbose'           => \$verbose,
+    'format=s'          => \$format,
+    'to=s'              => \$to,
+    'from=s'            => \$from,
+    'subject=s'         => \$subject,
+    'email'             => \$email,
+    'username:s'        => \$username,
+    'password:s'        => \$password,
+    'method:s'          => \$method,
+
 ) or pod2usage(2);
 pod2usage( -verbose => 2 ) if ($man);
 pod2usage( -verbose => 2 ) if ($help and $verbose);
@@ -260,6 +284,7 @@ foreach my $report_id (@ARGV) {
               Message => encode('utf8', $message )
           );
         }
+        $mail{'Auth'} = {user => $username, pass => $password, method => $method} if $username;
         sendmail(%mail) or carp 'mail not sent:' . $Mail::Sendmail::error;
     } else {
         print $message;