View | Details | Raw Unified | Return to bug 22343
Collapse All | Expand All

(-)a/basket/sendbasket.pl (-22 / +29 lines)
Lines 20-26 use Modern::Perl; Link Here
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
use Encode qw(encode);
21
use Encode qw(encode);
22
use Carp;
22
use Carp;
23
use Mail::Sendmail;
23
use Email::Sender::Simple qw(sendmail);
24
use MIME::QuotedPrint;
24
use MIME::QuotedPrint;
25
use MIME::Base64;
25
use MIME::Base64;
26
26
Lines 30-35 use C4::Auth; Link Here
30
use C4::Output;
30
use C4::Output;
31
use C4::Templates ();
31
use C4::Templates ();
32
use Koha::Email;
32
use Koha::Email;
33
use Koha::SMTP::Servers;
33
use Koha::Token;
34
use Koha::Token;
34
35
35
my $query = new CGI;
36
my $query = new CGI;
Lines 44-53 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
44
    }
45
    }
45
);
46
);
46
47
47
my $bib_list     = $query->param('bib_list') || '';
48
my $bib_list  = $query->param('bib_list') || '';
48
my $email_add    = $query->param('email_add');
49
my $email_add = $query->param('email_add');
49
50
50
my $dbh          = C4::Context->dbh;
51
my $dbh = C4::Context->dbh;
51
52
52
if ( $email_add ) {
53
if ( $email_add ) {
53
    output_and_exit( $query, $cookie, $template, 'wrong_csrf_token' )
54
    output_and_exit( $query, $cookie, $template, 'wrong_csrf_token' )
Lines 55-63 if ( $email_add ) { Link Here
55
            session_id => scalar $query->cookie('CGISESSID'),
56
            session_id => scalar $query->cookie('CGISESSID'),
56
            token  => scalar $query->param('csrf_token'),
57
            token  => scalar $query->param('csrf_token'),
57
        });
58
        });
58
    my $email = Koha::Email->new();
59
    my $email = Koha::Email->create({ to => $email_add });
59
    my %mail = $email->create_message_headers({ to => $email_add });
60
    my $comment = $query->param('comment');
60
    my $comment    = $query->param('comment');
61
61
62
    # Since we are already logged in, no need to check credentials again
62
    # Since we are already logged in, no need to check credentials again
63
    # when loading a second template.
63
    # when loading a second template.
Lines 109-121 if ( $email_add ) { Link Here
109
    my $template_res = $template2->output();
109
    my $template_res = $template2->output();
110
    my $body;
110
    my $body;
111
111
112
    my $subject;
112
    # Analysing information and getting mail properties
113
    # Analysing information and getting mail properties
113
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
114
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
114
        $mail{subject} = $1;
115
        $subject = $+{subject};
115
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
116
        $subject =~ s|\n?(.*)\n?|$1|;
116
        $mail{subject} = encode('MIME-Header',$mail{subject});
117
    }
118
    else {
119
        $subject = "no subject";
117
    }
120
    }
118
    else { $mail{'subject'} = "no subject"; }
121
122
    $email->header_set( 'Subject', encode('MIME-Header', $subject) );
119
123
120
    my $email_header = "";
124
    my $email_header = "";
121
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
125
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
Lines 139-148 if ( $email_add ) { Link Here
139
    my $boundary = "====" . time() . "====";
143
    my $boundary = "====" . time() . "====";
140
144
141
    # Writing mail
145
    # Writing mail
142
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
146
    $email->header_set( 'content-type', "multipart/mixed; boundary=\"$boundary\"" );
143
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
147
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
144
    $boundary = '--' . $boundary;
148
    $boundary = '--' . $boundary;
145
    $mail{body} = <<END_OF_BODY;
149
    my $THE_body = <<END_OF_BODY;
146
$boundary
150
$boundary
147
Content-Type: text/plain; charset="utf-8"
151
Content-Type: text/plain; charset="utf-8"
148
Content-Transfer-Encoding: quoted-printable
152
Content-Transfer-Encoding: quoted-printable
Lines 158-173 $isofile Link Here
158
$boundary--
162
$boundary--
159
END_OF_BODY
163
END_OF_BODY
160
164
161
    # Sending mail
165
    $email->body_set( $THE_body );
162
    if ( sendmail %mail ) {
166
163
        # do something if it works....
167
    try {
164
        $template->param( SENT      => "1" );
168
        my $library = Koha::Patrons->find( $borrowernumber )->library;
169
        my $smtp_server = Koha::SMTP::Servers->get_effective_server({ library => $library });
170
        Email::Sender::Simple::sendmail( $email, { transport => $smtp_server->transport } );
171
        $template->param( SENT => "1" );
165
    }
172
    }
166
    else {
173
    catch {
167
        # do something if it doesn't work....
174
        carp "Error sending mail: $_";
168
        carp "Error sending mail: $Mail::Sendmail::error \n";
169
        $template->param( error => 1 );
175
        $template->param( error => 1 );
170
    }
176
    };
177
171
    $template->param( email_add => $email_add );
178
    $template->param( email_add => $email_add );
172
    output_html_with_http_headers $query, $cookie, $template->output;
179
    output_html_with_http_headers $query, $cookie, $template->output;
173
}
180
}
(-)a/misc/cronjobs/runreport.pl (-5 / +5 lines)
Lines 318-329 foreach my $report_id (@ARGV) { Link Here
318
            $message = "<html><head><style>tr:nth-child(2n+1) { background-color: #ccc;}</style></head><body>$message</body></html>";
318
            $message = "<html><head><style>tr:nth-child(2n+1) { background-color: #ccc;}</style></head><body>$message</body></html>";
319
            $args->{contenttype} = 'text/html';
319
            $args->{contenttype} = 'text/html';
320
        }
320
        }
321
        my $email = Koha::Email->new();
321
        my $email = Koha::Email->create( $args );
322
        my %mail  = $email->create_message_headers($args);
322
        my %headers = $email->header_pairs;
323
        $mail{Data} = $message;
323
        $headers{Data} = $message;
324
        $mail{Auth} = { user => $username, pass => $password, method => $method } if $username;
324
        $headers{Auth} = { user => $username, pass => $password, method => $method } if $username;
325
325
326
        my $msg = MIME::Lite->new(%mail);
326
        my $msg = MIME::Lite->new(%headers);
327
327
328
        $msg->attach(
328
        $msg->attach(
329
            Type        => "text/$format",
329
            Type        => "text/$format",
(-)a/opac/opac-sendbasket.pl (-23 / +34 lines)
Lines 22-28 use Modern::Perl; Link Here
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use Encode qw(encode);
23
use Encode qw(encode);
24
use Carp;
24
use Carp;
25
use Mail::Sendmail;
25
use Email::Sender::Simple qw(sendmail);
26
use MIME::QuotedPrint;
26
use MIME::QuotedPrint;
27
use MIME::Base64;
27
use MIME::Base64;
28
28
Lines 34-39 use C4::Members; Link Here
34
use C4::Templates ();
34
use C4::Templates ();
35
use Koha::Email;
35
use Koha::Email;
36
use Koha::Patrons;
36
use Koha::Patrons;
37
use Koha::SMTP::Servers;
37
use Koha::Token;
38
use Koha::Token;
38
39
39
my $query = new CGI;
40
my $query = new CGI;
Lines 57-63 if ( $email_add ) { Link Here
57
        session_id => scalar $query->cookie('CGISESSID'),
58
        session_id => scalar $query->cookie('CGISESSID'),
58
        token  => scalar $query->param('csrf_token'),
59
        token  => scalar $query->param('csrf_token'),
59
    });
60
    });
60
    my $email = Koha::Email->new();
61
    my $patron = Koha::Patrons->find( $borrowernumber );
61
    my $patron = Koha::Patrons->find( $borrowernumber );
62
    my $borcat = $patron ? $patron->categorycode : q{};
62
    my $borcat = $patron ? $patron->categorycode : q{};
63
    my $user_email = $patron->first_valid_email_address
63
    my $user_email = $patron->first_valid_email_address
Lines 67-77 if ( $email_add ) { Link Here
67
    my $comment    = $query->param('comment');
67
    my $comment    = $query->param('comment');
68
68
69
   # if you want to use the KohaAdmin address as from, that is the default no need to set it
69
   # if you want to use the KohaAdmin address as from, that is the default no need to set it
70
    my %mail = $email->create_message_headers({
70
    my $email = Koha::Email->create({
71
        to => $email_add,
71
        to      => $email_add,
72
        replyto => $email_replyto,
72
        replyto => $email_replyto,
73
    });
73
    });
74
    $mail{'X-Abuse-Report'} = C4::Context->preference('KohaAdminEmailAddress');
74
75
    $email->header_set( 'X-Abuse-Report', C4::Context->preference('KohaAdminEmailAddress') );
75
76
76
    # Since we are already logged in, no need to check credentials again
77
    # Since we are already logged in, no need to check credentials again
77
    # when loading a second template.
78
    # when loading a second template.
Lines 129-141 if ( $email_add ) { Link Here
129
    my $body;
130
    my $body;
130
131
131
    # Analysing information and getting mail properties
132
    # Analysing information and getting mail properties
132
133
    my $subject;
133
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
134
    if ( $template_res =~ /\<SUBJECT\>(?<subject>.*)\<END_SUBJECT\>/s ) {
134
        $mail{subject} = $1;
135
        $subject = $+{subject};
135
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
136
        $subject =~ s|\n?(.*)\n?|$1|;
136
        $mail{subject} = encode('MIME-Header',$mail{subject});
137
    }
138
    else {
139
        $subject = "no subject";
137
    }
140
    }
138
    else { $mail{'subject'} = "no subject"; }
141
142
    $email->header_set( 'Subject', encode('MIME-Header', $subject) );
139
143
140
    my $email_header = "";
144
    my $email_header = "";
141
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
145
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
Lines 156-169 if ( $email_add ) { Link Here
156
        $body = encode_qp(Encode::encode("UTF-8", $body));
160
        $body = encode_qp(Encode::encode("UTF-8", $body));
157
    }
161
    }
158
162
159
    $mail{body} = $body;
160
161
    my $boundary = "====" . time() . "====";
163
    my $boundary = "====" . time() . "====";
162
164
163
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
165
    $email->header_set( 'content-type', "multipart/mixed; boundary=\"$boundary\"" );
166
164
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
167
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
165
    $boundary = '--' . $boundary;
168
    $boundary = '--' . $boundary;
166
    $mail{body} = <<END_OF_BODY;
169
    my $THE_body = <<END_OF_BODY;
167
$boundary
170
$boundary
168
MIME-Version: 1.0
171
MIME-Version: 1.0
169
Content-Type: text/plain; charset="UTF-8"
172
Content-Type: text/plain; charset="UTF-8"
Lines 180-196 $isofile Link Here
180
$boundary--
183
$boundary--
181
END_OF_BODY
184
END_OF_BODY
182
185
183
    # Sending mail (if not empty basket)
186
    $email->body_set( $THE_body );
184
    if ( defined($iso2709) && sendmail %mail ) {
187
185
    # do something if it works....
188
    if ( !defined $iso2709 ) {
186
        $template->param( SENT      => "1" );
189
        carp "Error sending mail: empty basket";
190
        $template->param( error => 1 );
187
    }
191
    }
188
    else {
192
    else {
189
        # do something if it doesn't work....
193
        try {
190
    carp "Error sending mail: empty basket" if !defined($iso2709);
194
            my $library = $patron->library;
191
        carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
195
            my $smtp_server = Koha::SMTP::Servers->get_effective_server({ library => $library });
192
        $template->param( error => 1 );
196
            Email::Sender::Simple::sendmail( $email, { transport => $smtp_server->transport } );
197
            $template->param( SENT => "1" );
198
        }
199
        catch {
200
            carp "Error sending mail: $_";
201
            $template->param( error => 1 );
202
        };
193
    }
203
    }
204
194
    $template->param( email_add => $email_add );
205
    $template->param( email_add => $email_add );
195
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
206
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
196
}
207
}
(-)a/opac/opac-sendshelf.pl (-18 / +25 lines)
Lines 23-29 use CGI qw ( -utf8 ); Link Here
23
use Encode qw( encode );
23
use Encode qw( encode );
24
use Carp;
24
use Carp;
25
25
26
use Mail::Sendmail;
26
use Email::Sender::Simple qw(sendmail);
27
use MIME::QuotedPrint;
27
use MIME::QuotedPrint;
28
use MIME::Base64;
28
use MIME::Base64;
29
use C4::Auth;
29
use C4::Auth;
Lines 33-38 use C4::Output; Link Here
33
use C4::Members;
33
use C4::Members;
34
use Koha::Email;
34
use Koha::Email;
35
use Koha::Patrons;
35
use Koha::Patrons;
36
use Koha::SMTP::Servers;
36
use Koha::Virtualshelves;
37
use Koha::Virtualshelves;
37
38
38
my $query = new CGI;
39
my $query = new CGI;
Lines 61-70 my $shelf = Koha::Virtualshelves->find( $shelfid ); Link Here
61
if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) {
62
if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) {
62
63
63
if ( $email ) {
64
if ( $email ) {
64
    my $message = Koha::Email->new();
65
    my $comment    = $query->param('comment');
65
    my $comment    = $query->param('comment');
66
66
67
    my %mail = $message->create_message_headers(
67
    my $email = Koha::Email->create(
68
        {
68
        {
69
            to => $email,
69
            to => $email,
70
        }
70
        }
Lines 128-140 if ( $email ) { Link Here
128
    my $template_res = $template2->output();
128
    my $template_res = $template2->output();
129
    my $body;
129
    my $body;
130
130
131
    my $subject;
131
    # Analysing information and getting mail properties
132
    # Analysing information and getting mail properties
132
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
133
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
133
        $mail{subject} = $1;
134
        $subject = $+{subject};
134
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
135
        $subject =~ s|\n?(.*)\n?|$1|;
135
    }
136
    }
136
    else { $mail{'subject'} = "no subject"; }
137
    else {
137
    $mail{subject} = encode('MIME-Header', $mail{subject});
138
        $subject = "no subject";
139
    }
140
141
    $email->header_set( 'Subject', encode('MIME-Header', $subject) );
138
142
139
    my $email_header = "";
143
    my $email_header = "";
140
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
144
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
Lines 158-169 if ( $email ) { Link Here
158
    my $boundary = "====" . time() . "====";
162
    my $boundary = "====" . time() . "====";
159
163
160
    # We set and put the multipart content
164
    # We set and put the multipart content
161
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
165
    $email->header_set( 'content-type', "multipart/mixed; boundary=\"$boundary\"" );
162
166
163
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
167
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
164
    $boundary = '--' . $boundary;
168
    $boundary = '--' . $boundary;
165
169
166
    $mail{body} = <<END_OF_BODY;
170
    my $THE_body = <<END_OF_BODY;
167
$boundary
171
$boundary
168
MIME-Version: 1.0
172
MIME-Version: 1.0
169
Content-Type: text/plain; charset="utf-8"
173
Content-Type: text/plain; charset="utf-8"
Lines 181-199 $boundary-- Link Here
181
END_OF_BODY
185
END_OF_BODY
182
186
183
    # Sending mail
187
    # Sending mail
184
    if ( sendmail %mail ) {
188
    $email->body_set( $THE_body );
185
        # do something if it works....
189
186
        $template->param( SENT      => "1" );
190
    try {
191
        my $library = Koha::Patrons->find( $borrowernumber )->library;
192
        my $smtp_server = Koha::SMTP::Servers->get_effective_server({ library => $library });
193
        Email::Sender::Simple::sendmail( $email, { transport => $smtp_server->transport } );
194
        $template->param( SENT => "1" );
187
    }
195
    }
188
    else {
196
    catch {
189
        # do something if it doesn't work....
197
        carp "Error sending mail: $_";
190
        carp "Error sending mail: $Mail::Sendmail::error \n";
191
        $template->param( error => 1 );
198
        $template->param( error => 1 );
192
    }
199
    };
193
200
194
    $template->param(
201
    $template->param(
195
        shelfid => $shelfid,
202
        shelfid => $shelfid,
196
        email => $email,
203
        email   => $email,
197
    );
204
    );
198
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
205
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
199
206
(-)a/virtualshelves/sendshelf.pl (-21 / +26 lines)
Lines 23-29 use CGI qw ( -utf8 ); Link Here
23
use Encode qw( encode );
23
use Encode qw( encode );
24
use Carp;
24
use Carp;
25
25
26
use Mail::Sendmail;
26
use Email::Sender::Simple qw(sendmail);
27
use MIME::QuotedPrint;
27
use MIME::QuotedPrint;
28
use MIME::Base64;
28
use MIME::Base64;
29
use C4::Auth;
29
use C4::Auth;
Lines 31-36 use C4::Biblio; Link Here
31
use C4::Items;
31
use C4::Items;
32
use C4::Output;
32
use C4::Output;
33
use Koha::Email;
33
use Koha::Email;
34
use Koha::SMTP::Servers;
34
use Koha::Virtualshelves;
35
use Koha::Virtualshelves;
35
36
36
my $query = new CGI;
37
my $query = new CGI;
Lines 45-61 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
45
    }
46
    }
46
);
47
);
47
48
48
my $shelfid = $query->param('shelfid');
49
my $shelfid    = $query->param('shelfid');
49
my $email   = $query->param('email');
50
my $to_address = $query->param('email');
50
51
51
my $dbh = C4::Context->dbh;
52
my $dbh = C4::Context->dbh;
52
53
53
if ($email) {
54
if ($to_address) {
54
    my $comment = $query->param('comment');
55
    my $comment = $query->param('comment');
55
    my $message = Koha::Email->new();
56
    my $email    = Koha::Email->create(
56
    my %mail    = $message->create_message_headers(
57
        {
57
        {
58
            to => $email
58
            to => $to_address
59
        }
59
        }
60
    );
60
    );
61
61
Lines 108-120 if ($email) { Link Here
108
    my $template_res = $template2->output();
108
    my $template_res = $template2->output();
109
    my $body;
109
    my $body;
110
110
111
    my $subject;
111
    # Analysing information and getting mail properties
112
    # Analysing information and getting mail properties
112
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
113
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
113
        $mail{subject} = $1;
114
        $subject = $+{subject};
114
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
115
        $subject =~ s|\n?(.*)\n?|$1|;
115
    }
116
    }
116
    else { $mail{'subject'} = "no subject"; }
117
    else {
117
    $mail{subject} = encode( 'MIME-Header', $mail{subject} );
118
        $subject = "no subject";
119
    }
120
121
    $email->header_set( 'Subject', encode('MIME-Header', $subject) );
118
122
119
    my $email_header = "";
123
    my $email_header = "";
120
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
124
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
Lines 138-149 if ($email) { Link Here
138
    my $boundary = "====" . time() . "====";
142
    my $boundary = "====" . time() . "====";
139
143
140
    # We set and put the multipart content
144
    # We set and put the multipart content
141
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
145
    $email->header_set( 'content-type', "multipart/mixed; boundary=\"$boundary\"" );
142
146
143
    my $isofile = encode_base64( encode( "UTF-8", $iso2709 ) );
147
    my $isofile = encode_base64( encode( "UTF-8", $iso2709 ) );
144
    $boundary = '--' . $boundary;
148
    $boundary = '--' . $boundary;
145
149
146
    $mail{body} = <<END_OF_BODY;
150
    my $THE_body = <<END_OF_BODY;
147
$boundary
151
$boundary
148
Content-Type: text/plain; charset="utf-8"
152
Content-Type: text/plain; charset="utf-8"
149
Content-Transfer-Encoding: quoted-printable
153
Content-Transfer-Encoding: quoted-printable
Lines 160-175 $boundary-- Link Here
160
END_OF_BODY
164
END_OF_BODY
161
165
162
    # Sending mail
166
    # Sending mail
163
    if ( sendmail %mail ) {
167
    $email->body_set( $THE_body );
164
168
165
        # do something if it works....
169
    try {
170
        my $library = Koha::Patrons->find( $borrowernumber )->library;
171
        my $smtp_server = Koha::SMTP::Servers->get_effective_server({ library => $library });
172
        Email::Sender::Simple::sendmail( $email, { transport => $smtp_server->transport } );
166
        $template->param( SENT => "1" );
173
        $template->param( SENT => "1" );
167
    }
174
    }
168
    else {
175
    catch {
169
        # do something if it doesn't work....
176
        carp "Error sending mail: $_";
170
        carp "Error sending mail: $Mail::Sendmail::error \n";
171
        $template->param( error => 1 );
177
        $template->param( error => 1 );
172
    }
178
    };
173
179
174
    $template->param( email => $email );
180
    $template->param( email => $email );
175
    output_html_with_http_headers $query, $cookie, $template->output;
181
    output_html_with_http_headers $query, $cookie, $template->output;
176
- 

Return to bug 22343