Bugzilla – Attachment 44342 Details for
Bug 12544
Send scheduled reports as an attachment
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12544 - Send scheduled reports as an attachment
Bug-12544---Send-scheduled-reports-as-an-attachmen.patch (text/plain), 4.70 KB, created by
Kyle M Hall
on 2015-11-03 19:46:29 UTC
(
hide
)
Description:
Bug 12544 - Send scheduled reports as an attachment
Filename:
MIME Type:
Creator:
Kyle M Hall
Created:
2015-11-03 19:46:29 UTC
Size:
4.70 KB
patch
obsolete
>From 8796b2ff70d95a7995fffbdb9cdc2ba6148035d4 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Tue, 3 Nov 2015 14:43:17 -0500 >Subject: [PATCH] Bug 12544 - Send scheduled reports as an attachment > >This patch adds the ability to add the report as an attached file >to the sent email. > >Test Plan: >1) Email yourself a test report >2) Apply this patch >3) Repeat step 1, note there is no difference >4) Add the -a parameter, note your also recieve the report as an attachment > >Sponsored-by: Briar Cliff University > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > misc/cronjobs/runreport.pl | 69 ++++++++++++++++++++++++++----------------- > 1 files changed, 42 insertions(+), 27 deletions(-) > >diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl >index 5cc000d..265b558 100755 >--- a/misc/cronjobs/runreport.pl >+++ b/misc/cronjobs/runreport.pl >@@ -28,7 +28,7 @@ use C4::Log; > > use Getopt::Long qw(:config auto_help auto_version); > use Pod::Usage; >-use Mail::Sendmail; >+use MIME::Lite; > use Text::CSV_XS; > use CGI qw ( -utf8 ); > use Carp; >@@ -60,6 +60,7 @@ 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) >+ -a --attachment additionally attach the report as a file. cannot be used with html format > --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. >@@ -161,6 +162,7 @@ my $help = 0; > my $man = 0; > my $verbose = 0; > my $email = 0; >+my $attachment = 0; > my $format = "text"; > my $to = ""; > my $from = ""; >@@ -181,6 +183,7 @@ GetOptions( > 'from=s' => \$from, > 'subject=s' => \$subject, > 'email' => \$email, >+ 'a|attachment' => \$attachment, > 'username:s' => \$username, > 'password:s' => \$password, > 'method:s' => \$method, >@@ -269,35 +272,47 @@ foreach my $report_id (@ARGV) { > $message .= $csv->string() . "\n"; > } > } >- if ($email){ >+ >+ if ($email) { > my $email = Koha::Email->new(); > my %mail; >- if ($format eq 'html') { >- $message = "<html><head><style>tr:nth-child(2n+1) { background-color: #ccc;}</style></head><body>$message</body></html>"; >- %mail = $email->create_message_headers({ >- to => $to, >- from => $from, >- contenttype => 'text/html', >- subject => encode('utf8', $subject ), >- message => encode('utf8', $message ) >- } >- ); >- } else { >- %mail = $email->create_message_headers ({ >- to => $to, >- from => $from, >- subject => encode('utf8', $subject ), >- message => encode('utf8', $message ) >- } >- ); >+ if ( $format eq 'html' ) { >+ $message = "<html><head><style>tr:nth-child(2n+1) { background-color: #ccc;}</style></head><body>$message</body></html>"; >+ %mail = $email->create_message_headers( >+ { >+ to => $to, >+ from => $from, >+ contenttype => 'text/html', >+ subject => encode( 'utf8', $subject ), >+ } >+ ); >+ } >+ else { >+ %mail = $email->create_message_headers( >+ { >+ to => $to, >+ from => $from, >+ subject => encode( 'utf8', $subject ), >+ } >+ ); > } >- $mail{'Auth'} = {user => $username, pass => $password, method => $method} if $username; >- sendmail(%mail) or carp 'mail not sent:' . $Mail::Sendmail::error; >- } else { >+ >+ $mail{Data} = encode( 'utf8', $message ); >+ $mail{Auth} = { user => $username, pass => $password, method => $method } if $username; >+ >+ my $msg = MIME::Lite->new(%mail); >+ >+ $msg->attach( >+ Type => "text/$format", >+ Data => encode( 'utf8', $message ), >+ Filename => "report.$format", >+ Disposition => 'attachment', >+ ) if $attachment; >+ >+ $msg->send(); >+ carp "Mail not sent" unless $msg->last_send_successful(); >+ } >+ else { > print $message; > } >- # my @xmlarray = ... ; >- # my $url = "/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&id=$id"; >- # my $xml = XML::Dumper->new()->pl2xml( \@xmlarray ); >- # store_results($id,$xml); > } >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12544
:
44341
|
44342
|
44521
|
44560
|
44562
|
45382