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

(-)a/basket/sendbasket.pl (-48 / +38 lines)
Lines 20-28 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 Try::Tiny;
24
use MIME::QuotedPrint;
25
use MIME::Base64;
26
24
27
use C4::Biblio;
25
use C4::Biblio;
28
use C4::Items;
26
use C4::Items;
Lines 43-52 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
43
    }
41
    }
44
);
42
);
45
43
46
my $bib_list     = $query->param('bib_list') || '';
44
my $bib_list  = $query->param('bib_list') || '';
47
my $email_add    = $query->param('email_add');
45
my $email_add = $query->param('email_add');
48
46
49
my $dbh          = C4::Context->dbh;
47
my $dbh = C4::Context->dbh;
50
48
51
if ( $email_add ) {
49
if ( $email_add ) {
52
    output_and_exit( $query, $cookie, $template, 'wrong_csrf_token' )
50
    output_and_exit( $query, $cookie, $template, 'wrong_csrf_token' )
Lines 54-62 if ( $email_add ) { Link Here
54
            session_id => scalar $query->cookie('CGISESSID'),
52
            session_id => scalar $query->cookie('CGISESSID'),
55
            token  => scalar $query->param('csrf_token'),
53
            token  => scalar $query->param('csrf_token'),
56
        });
54
        });
57
    my $email = Koha::Email->new();
55
    my $comment = $query->param('comment');
58
    my %mail = $email->create_message_headers({ to => $email_add });
59
    my $comment    = $query->param('comment');
60
56
61
    # Since we are already logged in, no need to check credentials again
57
    # Since we are already logged in, no need to check credentials again
62
    # when loading a second template.
58
    # when loading a second template.
Lines 108-172 if ( $email_add ) { Link Here
108
    my $template_res = $template2->output();
104
    my $template_res = $template2->output();
109
    my $body;
105
    my $body;
110
106
107
    my $subject;
111
    # Analysing information and getting mail properties
108
    # Analysing information and getting mail properties
112
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
109
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
113
        $mail{subject} = $1;
110
        $subject = $+{subject};
114
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
111
        $subject =~ s|\n?(.*)\n?|$1|;
115
        $mail{subject} = encode('MIME-Header',$mail{subject});
116
    }
112
    }
117
    else { $mail{'subject'} = "no subject"; }
113
    else {
114
        $subject = "no subject";
115
    }
116
117
    my $email = Koha::Email->create(
118
        {
119
            to      => $email_add,
120
            subject => $subject,
121
        }
122
    );
118
123
119
    my $email_header = "";
124
    my $email_header = "";
120
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
125
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
121
        $email_header = $1;
126
        $email_header = $1;
122
        $email_header =~ s|\n?(.*)\n?|$1|;
127
        $email_header =~ s|\n?(.*)\n?|$1|;
123
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
128
        $email_header = Encode::encode("UTF-8", $email_header);
124
    }
125
126
    my $email_file = "basket.txt";
127
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
128
        $email_file = $1;
129
        $email_file =~ s|\n?(.*)\n?|$1|;
130
    }
129
    }
131
130
132
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
131
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
133
        $body = $1;
132
        $body = $1;
134
        $body =~ s|\n?(.*)\n?|$1|;
133
        $body =~ s|\n?(.*)\n?|$1|;
135
        $body = encode_qp(Encode::encode("UTF-8", $body));
134
        $body = Encode::encode("UTF-8", $body);
136
    }
135
    }
137
136
138
    my $boundary = "====" . time() . "====";
137
    my $THE_body = <<END_OF_BODY;
139
140
    # Writing mail
141
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
142
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
143
    $boundary = '--' . $boundary;
144
    $mail{body} = <<END_OF_BODY;
145
$boundary
146
Content-Type: text/plain; charset="utf-8"
147
Content-Transfer-Encoding: quoted-printable
148
149
$email_header
138
$email_header
150
$body
139
$body
151
$boundary
152
Content-Type: application/octet-stream; name="basket.iso2709"
153
Content-Transfer-Encoding: base64
154
Content-Disposition: attachment; filename="basket.iso2709"
155
156
$isofile
157
$boundary--
158
END_OF_BODY
140
END_OF_BODY
159
141
160
    # Sending mail
142
    $email->text_body( $THE_body );
161
    if ( sendmail %mail ) {
143
    $email->attach(
162
        # do something if it works....
144
        $iso2709,
163
        $template->param( SENT      => "1" );
145
        content_type => 'application/octet-stream',
146
        name         => 'basket.iso2709',
147
        disposition  => 'attachment',
148
    );
149
150
    try {
151
        my $library = Koha::Patrons->find( $borrowernumber )->library;
152
        $email->send_or_die({ transport => $library->smtp_server->transport });
153
        $template->param( SENT => "1" );
164
    }
154
    }
165
    else {
155
    catch {
166
        # do something if it doesn't work....
156
        carp "Error sending mail: $_";
167
        carp "Error sending mail: $Mail::Sendmail::error \n";
168
        $template->param( error => 1 );
157
        $template->param( error => 1 );
169
    }
158
    };
159
170
    $template->param( email_add => $email_add );
160
    $template->param( email_add => $email_add );
171
    output_html_with_http_headers $query, $cookie, $template->output;
161
    output_html_with_http_headers $query, $cookie, $template->output;
172
}
162
}
(-)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 (-53 / +42 lines)
Lines 22-30 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 Try::Tiny;
26
use MIME::QuotedPrint;
27
use MIME::Base64;
28
26
29
use C4::Biblio;
27
use C4::Biblio;
30
use C4::Items;
28
use C4::Items;
Lines 56-62 if ( $email_add ) { Link Here
56
        session_id => scalar $query->cookie('CGISESSID'),
54
        session_id => scalar $query->cookie('CGISESSID'),
57
        token  => scalar $query->param('csrf_token'),
55
        token  => scalar $query->param('csrf_token'),
58
    });
56
    });
59
    my $email = Koha::Email->new();
60
    my $patron = Koha::Patrons->find( $borrowernumber );
57
    my $patron = Koha::Patrons->find( $borrowernumber );
61
    my $borcat = $patron ? $patron->categorycode : q{};
58
    my $borcat = $patron ? $patron->categorycode : q{};
62
    my $user_email = $patron->first_valid_email_address
59
    my $user_email = $patron->first_valid_email_address
Lines 65-77 if ( $email_add ) { Link Here
65
    my $email_replyto = $patron->firstname . " " . $patron->surname . " <$user_email>";
62
    my $email_replyto = $patron->firstname . " " . $patron->surname . " <$user_email>";
66
    my $comment    = $query->param('comment');
63
    my $comment    = $query->param('comment');
67
64
68
   # if you want to use the KohaAdmin address as from, that is the default no need to set it
69
    my %mail = $email->create_message_headers({
70
        to => $email_add,
71
        replyto => $email_replyto,
72
    });
73
    $mail{'X-Abuse-Report'} = C4::Context->preference('KohaAdminEmailAddress');
74
75
    # Since we are already logged in, no need to check credentials again
65
    # Since we are already logged in, no need to check credentials again
76
    # when loading a second template.
66
    # when loading a second template.
77
    my $template2 = C4::Templates::gettemplate(
67
    my $template2 = C4::Templates::gettemplate(
Lines 128-195 if ( $email_add ) { Link Here
128
    my $body;
118
    my $body;
129
119
130
    # Analysing information and getting mail properties
120
    # Analysing information and getting mail properties
131
121
    my $subject;
132
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
122
    if ( $template_res =~ /\<SUBJECT\>(?<subject>.*)\<END_SUBJECT\>/s ) {
133
        $mail{subject} = $1;
123
        $subject = $+{subject};
134
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
124
        $subject =~ s|\n?(.*)\n?|$1|;
135
        $mail{subject} = encode('MIME-Header',$mail{subject});
125
    }
126
    else {
127
        $subject = "no subject";
136
    }
128
    }
137
    else { $mail{'subject'} = "no subject"; }
129
130
    # if you want to use the KohaAdmin address as from, that is the default no need to set it
131
    my $email = Koha::Email->create({
132
        to       => $email_add,
133
        reply_to => $email_replyto,
134
        subject  => $subject,
135
    });
136
137
    $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') );
138
138
139
    my $email_header = "";
139
    my $email_header = "";
140
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
140
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
141
        $email_header = $1;
141
        $email_header = $1;
142
        $email_header =~ s|\n?(.*)\n?|$1|;
142
        $email_header =~ s|\n?(.*)\n?|$1|;
143
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
143
        $email_header = Encode::encode("UTF-8", $email_header);
144
    }
145
146
    my $email_file = "basket.txt";
147
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
148
        $email_file = $1;
149
        $email_file =~ s|\n?(.*)\n?|$1|;
150
    }
144
    }
151
145
152
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
146
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
153
        $body = $1;
147
        $body = $1;
154
        $body =~ s|\n?(.*)\n?|$1|;
148
        $body =~ s|\n?(.*)\n?|$1|;
155
        $body = encode_qp(Encode::encode("UTF-8", $body));
149
        $body = Encode::encode("UTF-8", $body);
156
    }
150
    }
157
151
158
    $mail{body} = $body;
152
    my $THE_body = <<END_OF_BODY;
159
160
    my $boundary = "====" . time() . "====";
161
162
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
163
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
164
    $boundary = '--' . $boundary;
165
    $mail{body} = <<END_OF_BODY;
166
$boundary
167
MIME-Version: 1.0
168
Content-Type: text/plain; charset="UTF-8"
169
Content-Transfer-Encoding: quoted-printable
170
171
$email_header
153
$email_header
172
$body
154
$body
173
$boundary
174
Content-Type: application/octet-stream; name="basket.iso2709"
175
Content-Transfer-Encoding: base64
176
Content-Disposition: attachment; filename="basket.iso2709"
177
178
$isofile
179
$boundary--
180
END_OF_BODY
155
END_OF_BODY
181
156
182
    # Sending mail (if not empty basket)
157
    $email->text_body( $THE_body );
183
    if ( defined($iso2709) && sendmail %mail ) {
158
    $email->attach(
184
    # do something if it works....
159
        $iso2709,
185
        $template->param( SENT      => "1" );
160
        content_type => 'application/octet-stream',
161
        name         => 'basket.iso2709',
162
        disposition  => 'attachment',
163
    );
164
165
    if ( !defined $iso2709 ) {
166
        carp "Error sending mail: empty basket";
167
        $template->param( error => 1 );
186
    }
168
    }
187
    else {
169
    else {
188
        # do something if it doesn't work....
170
        try {
189
    carp "Error sending mail: empty basket" if !defined($iso2709);
171
            my $library = $patron->library;
190
        carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
172
            $email->transport( $library->smtp_server->transport );
191
        $template->param( error => 1 );
173
            $email->send_or_die;
174
            $template->param( SENT => "1" );
175
        }
176
        catch {
177
            carp "Error sending mail: $_";
178
            $template->param( error => 1 );
179
        };
192
    }
180
    }
181
193
    $template->param( email_add => $email_add );
182
    $template->param( email_add => $email_add );
194
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
183
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
195
}
184
}
(-)a/opac/opac-sendshelf.pl (-53 / +35 lines)
Lines 22-31 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 Try::Tiny;
25
26
26
use Mail::Sendmail;
27
use MIME::QuotedPrint;
28
use MIME::Base64;
29
use C4::Auth;
27
use C4::Auth;
30
use C4::Biblio;
28
use C4::Biblio;
31
use C4::Items;
29
use C4::Items;
Lines 60-74 my $shelf = Koha::Virtualshelves->find( $shelfid ); Link Here
60
if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) {
58
if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) {
61
59
62
if ( $email ) {
60
if ( $email ) {
63
    my $message = Koha::Email->new();
64
    my $comment    = $query->param('comment');
61
    my $comment    = $query->param('comment');
65
62
66
    my %mail = $message->create_message_headers(
67
        {
68
            to => $email,
69
        }
70
    );
71
72
    my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
63
    my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
73
        {
64
        {
74
            template_name   => "opac-sendshelf.tt",
65
            template_name   => "opac-sendshelf.tt",
Lines 127-198 if ( $email ) { Link Here
127
    my $template_res = $template2->output();
118
    my $template_res = $template2->output();
128
    my $body;
119
    my $body;
129
120
121
    my $subject;
130
    # Analysing information and getting mail properties
122
    # Analysing information and getting mail properties
131
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
123
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
132
        $mail{subject} = $1;
124
        $subject = $+{subject};
133
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
125
        $subject =~ s|\n?(.*)\n?|$1|;
126
    }
127
    else {
128
        $subject = "no subject";
134
    }
129
    }
135
    else { $mail{'subject'} = "no subject"; }
130
136
    $mail{subject} = encode('MIME-Header', $mail{subject});
131
    my $email = Koha::Email->create(
132
        {
133
            to      => $email,
134
            subject => $subject,
135
        }
136
    );
137
137
138
    my $email_header = "";
138
    my $email_header = "";
139
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
139
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
140
        $email_header = $1;
140
        $email_header = $1;
141
        $email_header =~ s|\n?(.*)\n?|$1|;
141
        $email_header =~ s|\n?(.*)\n?|$1|;
142
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
142
        $email_header = Encode::encode("UTF-8", $email_header);
143
    }
144
145
    my $email_file = "list.txt";
146
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
147
        $email_file = $1;
148
        $email_file =~ s|\n?(.*)\n?|$1|;
149
    }
143
    }
150
144
151
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
145
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
152
        $body = $1;
146
        $body = $1;
153
        $body =~ s|\n?(.*)\n?|$1|;
147
        $body =~ s|\n?(.*)\n?|$1|;
154
        $body = encode_qp(Encode::encode("UTF-8", $body));
148
        $body = Encode::encode("UTF-8", $body);
155
    }
149
    }
156
150
157
    my $boundary = "====" . time() . "====";
151
    my $THE_body = <<END_OF_BODY;
158
159
    # We set and put the multipart content
160
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
161
162
    my $isofile = encode_base64(encode("UTF-8", $iso2709));
163
    $boundary = '--' . $boundary;
164
165
    $mail{body} = <<END_OF_BODY;
166
$boundary
167
MIME-Version: 1.0
168
Content-Type: text/plain; charset="utf-8"
169
Content-Transfer-Encoding: quoted-printable
170
171
$email_header
152
$email_header
172
$body
153
$body
173
$boundary
174
Content-Type: application/octet-stream; name="list.iso2709"
175
Content-Transfer-Encoding: base64
176
Content-Disposition: attachment; filename="list.iso2709"
177
178
$isofile
179
$boundary--
180
END_OF_BODY
154
END_OF_BODY
181
155
182
    # Sending mail
156
    $email->text_body( $THE_body );
183
    if ( sendmail %mail ) {
157
    $email->attach(
184
        # do something if it works....
158
        $iso2709,
185
        $template->param( SENT      => "1" );
159
        content_type => 'application/octet-stream',
160
        name         => 'list.iso2709',
161
        disposition  => 'attachment',
162
    );
163
164
    try {
165
        my $library = Koha::Patrons->find( $borrowernumber )->library;
166
        $email->transport( $library->smtp_server->transport );
167
        $email->send_or_die;
168
        $template->param( SENT => "1" );
186
    }
169
    }
187
    else {
170
    catch {
188
        # do something if it doesn't work....
171
        carp "Error sending mail: $_";
189
        carp "Error sending mail: $Mail::Sendmail::error \n";
190
        $template->param( error => 1 );
172
        $template->param( error => 1 );
191
    }
173
    };
192
174
193
    $template->param(
175
    $template->param(
194
        shelfid => $shelfid,
176
        shelfid => $shelfid,
195
        email => $email,
177
        email   => $email,
196
    );
178
    );
197
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
179
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
198
180
(-)a/virtualshelves/sendshelf.pl (-53 / +34 lines)
Lines 22-31 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 Try::Tiny;
25
26
26
use Mail::Sendmail;
27
use MIME::QuotedPrint;
28
use MIME::Base64;
29
use C4::Auth;
27
use C4::Auth;
30
use C4::Biblio;
28
use C4::Biblio;
31
use C4::Items;
29
use C4::Items;
Lines 44-62 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
44
    }
42
    }
45
);
43
);
46
44
47
my $shelfid = $query->param('shelfid');
45
my $shelfid    = $query->param('shelfid');
48
my $email   = $query->param('email');
46
my $to_address = $query->param('email');
49
47
50
my $dbh = C4::Context->dbh;
48
my $dbh = C4::Context->dbh;
51
49
52
if ($email) {
50
if ($to_address) {
53
    my $comment = $query->param('comment');
51
    my $comment = $query->param('comment');
54
    my $message = Koha::Email->new();
55
    my %mail    = $message->create_message_headers(
56
        {
57
            to => $email
58
        }
59
    );
60
52
61
    my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
53
    my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
62
        {
54
        {
Lines 106-173 if ($email) { Link Here
106
    my $template_res = $template2->output();
98
    my $template_res = $template2->output();
107
    my $body;
99
    my $body;
108
100
101
    my $subject;
109
    # Analysing information and getting mail properties
102
    # Analysing information and getting mail properties
110
    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
103
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
111
        $mail{subject} = $1;
104
        $subject = $+{subject};
112
        $mail{subject} =~ s|\n?(.*)\n?|$1|;
105
        $subject =~ s|\n?(.*)\n?|$1|;
106
    }
107
    else {
108
        $subject = "no subject";
113
    }
109
    }
114
    else { $mail{'subject'} = "no subject"; }
110
115
    $mail{subject} = encode( 'MIME-Header', $mail{subject} );
111
    my $email = Koha::Email->create(
112
        {
113
            to      => $to_address,
114
            subject => $subject,
115
        }
116
    );
116
117
117
    my $email_header = "";
118
    my $email_header = "";
118
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
119
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
119
        $email_header = $1;
120
        $email_header = $1;
120
        $email_header =~ s|\n?(.*)\n?|$1|;
121
        $email_header =~ s|\n?(.*)\n?|$1|;
121
        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
122
        $email_header = Encode::encode("UTF-8", $email_header);
122
    }
123
124
    my $email_file = "list.txt";
125
    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
126
        $email_file = $1;
127
        $email_file =~ s|\n?(.*)\n?|$1|;
128
    }
123
    }
129
124
130
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
125
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
131
        $body = $1;
126
        $body = $1;
132
        $body =~ s|\n?(.*)\n?|$1|;
127
        $body =~ s|\n?(.*)\n?|$1|;
133
        $body = encode_qp(Encode::encode("UTF-8", $body));
128
        $body = Encode::encode("UTF-8", $body);
134
    }
129
    }
135
130
136
    my $boundary = "====" . time() . "====";
131
    my $THE_body = <<END_OF_BODY;
137
138
    # We set and put the multipart content
139
    $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
140
141
    my $isofile = encode_base64( encode( "UTF-8", $iso2709 ) );
142
    $boundary = '--' . $boundary;
143
144
    $mail{body} = <<END_OF_BODY;
145
$boundary
146
Content-Type: text/plain; charset="utf-8"
147
Content-Transfer-Encoding: quoted-printable
148
149
$email_header
132
$email_header
150
$body
133
$body
151
$boundary
152
Content-Type: application/octet-stream; name="shelf.iso2709"
153
Content-Transfer-Encoding: base64
154
Content-Disposition: attachment; filename="shelf.iso2709"
155
156
$isofile
157
$boundary--
158
END_OF_BODY
134
END_OF_BODY
159
135
160
    # Sending mail
136
    $email->text_body( $THE_body );
161
    if ( sendmail %mail ) {
137
    $email->attach(
138
        $iso2709,
139
        content_type => 'application/octet-stream',
140
        name         => 'shelf.iso2709',
141
        disposition  => 'attachment',
142
    );
162
143
163
        # do something if it works....
144
    try {
145
        my $library = Koha::Patrons->find( $borrowernumber )->library;
146
        $email->send_or_die({ transport => $library->smtp_server->transport });
164
        $template->param( SENT => "1" );
147
        $template->param( SENT => "1" );
165
    }
148
    }
166
    else {
149
    catch {
167
        # do something if it doesn't work....
150
        carp "Error sending mail: $_";
168
        carp "Error sending mail: $Mail::Sendmail::error \n";
169
        $template->param( error => 1 );
151
        $template->param( error => 1 );
170
    }
152
    };
171
153
172
    $template->param( email => $email );
154
    $template->param( email => $email );
173
    output_html_with_http_headers $query, $cookie, $template->output;
155
    output_html_with_http_headers $query, $cookie, $template->output;
174
- 

Return to bug 22343