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, $out) = @_;
 
  50   $boundary = "SL-$self->{version}-$boundary";
 
  51   my $domain = $self->{from};
 
  52   $domain =~ s/(.*?\@|>)//g;
 
  53   my $msgid = "$boundary\@$domain";
 
  55   $self->{charset} = "ISO-8859-1" unless $self->{charset};
 
  58     if (!open(OUT, $out)) {
 
  59       $main::lxdebug->leave_sub();
 
  63     if (!open(OUT, ">-")) {
 
  64       $main::lxdebug->leave_sub();
 
  69   $self->{contenttype} = "text/plain" unless $self->{contenttype};
 
  72   $cc  = "Cc: $self->{cc}\n"   if $self->{cc};
 
  73   $bcc = "Bcc: $self->{bcc}\n" if $self->{bcc};
 
  75   foreach my $item (qw(to cc bcc)) {
 
  76     $self->{$item} =~ s/\</</g;
 
  77     $self->{$item} =~ s/\$<\$/</g;
 
  78     $self->{$item} =~ s/\>/>/g;
 
  79     $self->{$item} =~ s/\$>\$/>/g;
 
  82   print OUT qq|From: $self->{from}
 
  84 ${cc}${bcc}Subject: $self->{subject}
 
  86 X-Mailer: SQL-Ledger $self->{version}
 
  90   if ($self->{attachments}) {
 
  91     print OUT qq|Content-Type: multipart/mixed; boundary="$boundary"
 
  94     if ($self->{message}) {
 
  95       print OUT qq|--${boundary}
 
  96 Content-Type: $self->{contenttype}; charset="$self->{charset}"
 
 103     foreach my $attachment (@{ $self->{attachments} }) {
 
 106         ($attachment =~ /(^\w+$)|\.(html|text|txt|sql)$/)
 
 110       open(IN, $attachment);
 
 113         $main::lxdebug->leave_sub();
 
 114         return "$attachment : $!";
 
 117       my $filename = $attachment;
 
 120       $filename =~ s/(.*\/|$self->{fileid})//g;
 
 122       print OUT qq|--${boundary}
 
 123 Content-Type: $application/$self->{format}; name="$filename"; charset="$self->{charset}"
 
 124 Content-Transfer-Encoding: BASE64
 
 125 Content-Disposition: attachment; filename="$filename"\n\n|;
 
 132       print OUT &encode_base64($msg);
 
 137     print OUT qq|--${boundary}--\n|;
 
 140     print OUT qq|Content-Type: $self->{contenttype}; charset="$self->{charset}"
 
 148   $main::lxdebug->leave_sub();
 
 153 sub encode_base64 ($;$) {
 
 154   $main::lxdebug->enter_sub();
 
 156   # this code is from the MIME-Base64-2.12 package
 
 157   # Copyright 1995-1999,2001 Gisle Aas <gisle@ActiveState.com>
 
 161   $eol = "\n" unless defined $eol;
 
 162   pos($_[0]) = 0;    # ensure start at the beginning
 
 164   $res = join '', map(pack('u', $_) =~ /^.(\S*)/, ($_[0] =~ /(.{1,45})/gs));
 
 166   $res =~ tr|` -_|AA-Za-z0-9+/|;    # `# help emacs
 
 167                                     # fix padding at the end
 
 168   my $padding = (3 - length($_[0]) % 3) % 3;
 
 169   $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
 
 171   # break encoded string into lines of no more than 60 characters each
 
 173     $res =~ s/(.{1,60})/$1$eol/g;
 
 176   $main::lxdebug->leave_sub();