+ $main::lxdebug->message(LXDebug->DEBUG2(),"action_oldfile=" . $self->{action_oldfile}." action_nofile=".$self->{action_nofile});
+ if (!$self->{"do_not_attach"} && !$self->{action_nofile}) {
+ my $attachment_name = $self->{attachment_filename} || $self->{tmpfile};
+ $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format);
+ if ( $self->{action_oldfile} ) {
+ $main::lxdebug->message(LXDebug->DEBUG2(),"object_id =>". $self->{id}." object_type =>". $self->{formname});
+ my ( $attfile ) = SL::File->get_all(object_id => $self->{id},
+ object_type => $self->{formname},
+ file_type => 'document');
+ $main::lxdebug->message(LXDebug->DEBUG2(), "old file obj=".$attfile);
+ push @attfiles, $attfile if $attfile;
+ } else {
+ push @{ $mail->{attachments} }, { path => $self->{tmpfile},
+ id => $self->{print_file_id},
+ type => "application/pdf",
+ name => $attachment_name };
+ }
+ }
+ }
+ if (!$self->{"do_not_attach"}) {
+ for my $i (1 .. $self->{attfile_count}) {
+ if ( $self->{"attsel_$i"} ) {
+ my $attfile = SL::File->get(id => $self->{"attfile_$i"});
+ $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile);
+ push @attfiles, $attfile if $attfile;
+ }
+ }
+ for my $i (1 .. $self->{attfile_cv_count}) {
+ if ( $self->{"attsel_cv_$i"} ) {
+ my $attfile = SL::File->get(id => $self->{"attfile_cv_$i"});
+ $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile);
+ push @attfiles, $attfile if $attfile;
+ }
+ }
+ for my $i (1 .. $self->{attfile_part_count}) {
+ if ( $self->{"attsel_part_$i"} ) {
+ my $attfile = SL::File->get(id => $self->{"attfile_part_$i"});
+ $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile);
+ push @attfiles, $attfile if $attfile;
+ }
+ }
+ foreach my $attfile ( @attfiles ) {
+ push @{ $mail->{attachments} }, { path => SL::File->get_file_path(dbfile => $attfile),
+ id => $attfile->id,
+ type => $attfile->file_mime_type,
+ name => $attfile->file_name };
+ }
+ }
+ $mail->{message} =~ s/\r//g;
+ $mail->{message} .= $full_signature;
+ $self->{emailerr} = $mail->send();
+ # $self->error($self->cleanup . "$err") if $self->{emailerr};
+ $self->{email_journal_id} = $mail->{journalentry};
+ $self->{snumbers} = "emailjournal" . "_" . $self->{email_journal_id};
+ $self->{what_done} = $::form->{type};
+ $self->{addition} = "MAILED";
+ $self->save_history;