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

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

Return to bug 22343