Bugzilla – Attachment 108548 Details for
Bug 22343
Add configuration options for SMTP servers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22343: Adapt runreport.pl
Bug-22343-Adapt-runreportpl.patch (text/plain), 3.88 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-08-18 19:42:34 UTC
(
hide
)
Description:
Bug 22343: Adapt runreport.pl
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-08-18 19:42:34 UTC
Size:
3.88 KB
patch
obsolete
>From 5ebf14e64a32c0a6c5dcd6269d61ac59938c6ec2 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 10 Aug 2020 09:48:57 -0300 >Subject: [PATCH] Bug 22343: Adapt runreport.pl > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > misc/cronjobs/runreport.pl | 64 +++++++++++++++++++++++++------------- > 1 file changed, 42 insertions(+), 22 deletions(-) > >diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl >index 1f50483190..478c96fafb 100755 >--- a/misc/cronjobs/runreport.pl >+++ b/misc/cronjobs/runreport.pl >@@ -27,15 +27,16 @@ use C4::Context; > use C4::Log; > use Koha::Email; > use Koha::DateUtils; >+use Koha::SMTP::Servers; > > use Getopt::Long qw(:config auto_help auto_version); > use Pod::Usage; >-use MIME::Lite; > use Text::CSV::Encoded; > use CGI qw ( -utf8 ); > use Carp; > use Encode; > use JSON qw( to_json ); >+use Try::Tiny; > > BEGIN { > # find Koha's Perl modules >@@ -176,7 +177,7 @@ Reports - Guided Reports > my $help = 0; > my $man = 0; > my $verbose = 0; >-my $email = 0; >+my $send_email = 0; > my $attachment = 0; > my $format = "text"; > my $to = ""; >@@ -201,7 +202,7 @@ GetOptions( > 'from=s' => \$from, > 'subject=s' => \$subject, > 'param=s' => \@params, >- 'email' => \$email, >+ 'email' => \$send_email, > 'a|attachment' => \$attachment, > 'username:s' => \$username, > 'password:s' => \$password, >@@ -226,8 +227,8 @@ if ($format eq 'tsv' || $format eq 'text') { > $separator = "\t"; > } > >-if ($to or $from or $email) { >- $email = 1; >+if ($to or $from or $send_email) { >+ $send_email = 1; > $from or $from = C4::Context->preference('KohaAdminEmailAddress'); > $to or $to = C4::Context->preference('KohaAdminEmailAddress'); > } >@@ -312,28 +313,47 @@ foreach my $report_id (@ARGV) { > my $json = to_json( \@rows_to_store ); > C4::Reports::Guided::store_results( $report_id, $json ); > } >- if ($email) { >- my $args = { to => $to, from => $from, subject => $subject }; >+ if ($send_email) { >+ >+ my $email = Koha::Email->new( >+ { >+ to => $to, >+ from => $from, >+ subject => $subject, >+ } >+ ); >+ > if ( $format eq 'html' ) { > $message = "<html><head><style>tr:nth-child(2n+1) { background-color: #ccc;}</style></head><body>$message</body></html>"; >- $args->{contenttype} = 'text/html'; >+ $email->html_body($message); >+ } >+ else { >+ $email->text_body($message); > } >- my $email = Koha::Email->create( $args ); >- my %headers = $email->header_pairs; >- $headers{Data} = $message; >- $headers{Auth} = { user => $username, pass => $password, method => $method } if $username; >- >- my $msg = MIME::Lite->new(%headers); >- >- $msg->attach( >- Type => "text/$format", >- Data => encode( 'utf8', $message ), >- Filename => "report$report_id-$date.$format", >- Disposition => 'attachment', >+ >+ $email->attach( >+ encode( 'utf8', $message ), >+ content_type => "text/$format", >+ name => "report$report_id-$date.$format", >+ disposition => 'attachment', > ) if $attachment; > >- $msg->send(); >- carp "Mail not sent" unless $msg->last_send_successful(); >+ my $smtp_server = Koha::SMTP::Servers->get_default; >+ $smtp_server->set( >+ { >+ user_name => $username, >+ password => $password, >+ } >+ ) >+ if $username; >+ >+ $email->transport( $smtp_server->transport ); >+ try { >+ $email->send_or_die; >+ } >+ catch { >+ carp "Mail not sent: $_"; >+ }; > } > else { > print $message; >-- >2.28.0
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 22343
:
107598
|
107599
|
107600
|
107601
|
107602
|
107603
|
107604
|
107605
|
107987
|
107988
|
107989
|
107990
|
107991
|
107992
|
107993
|
107994
|
107995
|
107996
|
107997
|
107998
|
107999
|
108009
|
108107
|
108108
|
108109
|
108110
|
108111
|
108112
|
108113
|
108114
|
108115
|
108116
|
108117
|
108118
|
108119
|
108131
|
108132
|
108133
|
108134
|
108135
|
108136
|
108137
|
108138
|
108139
|
108140
|
108141
|
108142
|
108143
|
108529
|
108537
|
108538
|
108539
|
108540
|
108541
|
108542
|
108543
|
108544
|
108545
|
108546
|
108547
|
108548
|
108549
|
108609
|
108638
|
108642
|
108643
|
108644
|
108645
|
108646
|
108647
|
108648
|
108649
|
108650
|
108651
|
108652
|
108653
|
108654
|
108655
|
108656
|
108715
|
108716
|
109003
|
109004
|
109005
|
109006
|
109007
|
109008
|
109009
|
109010
|
109011
|
109012
|
109013
|
109014
|
109015
|
109016
|
109017
|
109018
|
109155
|
109156
|
109157
|
109158
|
109159
|
109160
|
109161
|
109162
|
109163
|
109164
|
109165
|
109166
|
109167
|
109168
|
109169
|
109170
|
109601
|
109602
|
109603
|
109604
|
109605
|
109606
|
109607
|
109608
|
109609
|
109610
|
109611
|
109612
|
109613
|
109614
|
109615
|
109616
|
109723
|
109724
|
109725
|
109726
|
109727
|
109728
|
109729
|
109730
|
109731
|
109732
|
109733
|
109734
|
109735
|
109736
|
109737
|
109738
|
109739
|
109740
|
109787
|
109788
|
111048
|
111087
|
111088
|
111089
|
111090
|
111154
|
111165
|
111166
|
111175
|
111176
|
111213
|
111215
|
111216
|
111442
|
111482
|
113240
|
113827
|
113847