1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger Accounting
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  17 # This program is free software; you can redistribute it and/or modify
 
  18 # it under the terms of the GNU General Public License as published by
 
  19 # the Free Software Foundation; either version 2 of the License, or
 
  20 # (at your option) any later version.
 
  22 # This program is distributed in the hope that it will be useful,
 
  23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  25 # GNU General Public License for more details.
 
  26 # You should have received a copy of the GNU General Public License
 
  27 # along with this program; if not, write to the Free Software
 
  28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  29 #======================================================================
 
  34   $main::lxdebug->enter_sub();
 
  39   $main::lxdebug->leave_sub();
 
  45   $main::lxdebug->enter_sub();
 
  47   my ($self, $text, $chars_left) = @_;
 
  49   my $q_start = "=?$self->{charset}?Q?";
 
  50   my $l_start = length($q_start);
 
  52   my $new_text = "$q_start";
 
  53   $chars_left -= $l_start;
 
  55   for (my $i = 0; $i < length($text); $i++) {
 
  56     my $char = ord(substr($text, $i, 1));
 
  58     if (($char < 32) || ($char > 127) ||
 
  59         ($char == ord('?')) || ($char == ord('_'))) {
 
  60       if ($chars_left < 5) {
 
  61         $new_text .= "?=\n $q_start";
 
  62         $chars_left = 75 - $l_start;
 
  65       $new_text .= sprintf("=%02X", $char);
 
  69       $char = ord('_') if ($char == ord(' '));
 
  70       if ($chars_left < 5) {
 
  71         $new_text .= "?=\n $q_start";
 
  72         $chars_left = 75 - $l_start;
 
  75       $new_text .= chr($char);
 
  82   $main::lxdebug->leave_sub();
 
  88   $main::lxdebug->enter_sub();
 
  90   my ($self, $out) = @_;
 
  93   $boundary = "LxOffice-$self->{version}-$boundary";
 
  94   my $domain = $self->{from};
 
  95   $domain =~ s/(.*?\@|>)//g;
 
  96   my $msgid = "$boundary\@$domain";
 
  98   $self->{charset} = "ISO-8859-15" unless $self->{charset};
 
 101     if (!open(OUT, $out)) {
 
 102       $main::lxdebug->leave_sub();
 
 106     if (!open(OUT, ">-")) {
 
 107       $main::lxdebug->leave_sub();
 
 108       return "STDOUT : $!";
 
 112   $self->{contenttype} = "text/plain" unless $self->{contenttype};
 
 115   $cc  = "Cc: $self->{cc}\n"   if $self->{cc};
 
 116   $bcc = "Bcc: $self->{bcc}\n" if $self->{bcc};
 
 118   foreach my $item (qw(to cc bcc)) {
 
 119     $self->{$item} =~ s/\</</g;
 
 120     $self->{$item} =~ s/\$<\$/</g;
 
 121     $self->{$item} =~ s/\>/>/g;
 
 122     $self->{$item} =~ s/\$>\$/>/g;
 
 125   my $subject = $self->mime_quote_text($self->{subject}, 60);
 
 127   print OUT qq|From: $self->{from}
 
 129 ${cc}${bcc}Subject: $subject
 
 131 X-Mailer: Lx-Office $self->{version}
 
 135   if ($self->{attachments}) {
 
 136     print OUT qq|Content-Type: multipart/mixed; boundary="$boundary"
 
 139     if ($self->{message}) {
 
 140       print OUT qq|--${boundary}
 
 141 Content-Type: $self->{contenttype}; charset="$self->{charset}"
 
 148     foreach my $attachment (@{ $self->{attachments} }) {
 
 151         ($attachment =~ /(^\w+$)|\.(html|text|txt|sql)$/)
 
 155       open(IN, $attachment);
 
 158         $main::lxdebug->leave_sub();
 
 159         return "$attachment : $!";
 
 162       my $filename = $attachment;
 
 165       $filename =~ s/(.*\/|$self->{fileid})//g;
 
 167       print OUT qq|--${boundary}
 
 168 Content-Type: $application/$self->{format}; name="$filename"; charset="$self->{charset}"
 
 169 Content-Transfer-Encoding: BASE64
 
 170 Content-Disposition: attachment; filename="$filename"\n\n|;
 
 177       print OUT &encode_base64($msg);
 
 182     print OUT qq|--${boundary}--\n|;
 
 185     print OUT qq|Content-Type: $self->{contenttype}; charset="$self->{charset}"
 
 193   $main::lxdebug->leave_sub();
 
 198 sub encode_base64 ($;$) {
 
 199   $main::lxdebug->enter_sub();
 
 201   # this code is from the MIME-Base64-2.12 package
 
 202   # Copyright 1995-1999,2001 Gisle Aas <gisle@ActiveState.com>
 
 206   $eol = "\n" unless defined $eol;
 
 207   pos($_[0]) = 0;    # ensure start at the beginning
 
 209   $res = join '', map(pack('u', $_) =~ /^.(\S*)/, ($_[0] =~ /(.{1,45})/gs));
 
 211   $res =~ tr|` -_|AA-Za-z0-9+/|;    # `# help emacs
 
 212                                     # fix padding at the end
 
 213   my $padding = (3 - length($_[0]) % 3) % 3;
 
 214   $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
 
 216   # break encoded string into lines of no more than 60 characters each
 
 218     $res =~ s/(.{1,60})/$1$eol/g;
 
 221   $main::lxdebug->leave_sub();