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

Return to bug 22343