+}
+
+sub _create_attachment_part {
+ my ($self, $attachment) = @_;
+
+ my %attributes = (
+ disposition => 'attachment',
+ encoding => 'base64',
+ );
+
+ my $attachment_content;
+ my $file_id = 0;
+ my $email_journal = $::instance_conf->get_email_journal;
+
+ $::lxdebug->message(LXDebug->DEBUG2(), "mail5 att=" . $attachment . " email_journal=" . $email_journal . " id=" . $attachment->{id});
+
+ if (ref($attachment) eq "HASH") {
+ $attributes{filename} = $attachment->{name};
+ $file_id = $attachment->{id} || '0';
+ $attributes{content_type} = $attachment->{type} || 'application/pdf';
+ $attachment_content = $attachment->{content};
+ $attachment_content = eval { read_file($attachment->{path}) } if !$attachment_content;
+
+ } else {
+ $attributes{filename} = $attachment;
+ $attributes{filename} =~ s:.*\Q$self->{fileid}\E:: if $self->{fileid};
+ $attributes{filename} =~ s:.*/::g;
+
+ my $application = ($attachment =~ /(^\w+$)|\.(html|text|txt|sql)$/) ? 'text' : 'application';
+ $attributes{content_type} = File::MimeInfo::Magic::magic($attachment);
+ $attributes{content_type} ||= "${application}/$self->{format}" if $self->{format};
+ $attributes{content_type} ||= 'application/octet-stream';
+ $attachment_content = eval { read_file($attachment) };
+ }
+
+ return undef if $email_journal > 1 && !defined $attachment_content;
+
+ $attachment_content ||= ' ';
+ $attributes{charset} = $self->{charset} if $self->{charset} && ($attributes{content_type} =~ m{^text/});
+
+ $::lxdebug->message(LXDebug->DEBUG2(), "mail6 mtype=" . $attributes{content_type} . " filename=" . $attributes{filename});
+
+ my $ent;
+ if ( $attributes{content_type} eq 'message/rfc822' ) {
+ $ent = Email::MIME->new($attachment_content);
+ $ent->header_str_set('Content-disposition' => 'attachment; filename='.$attributes{filename});
+ } else {
+ $ent = Email::MIME->create(
+ attributes => \%attributes,
+ body => $attachment_content,
+ );
+ }
+
+ push @{ $self->{mail_attachments}} , SL::DB::EmailJournalAttachment->new(
+ name => $attributes{filename},
+ mime_type => $attributes{content_type},
+ content => ( $email_journal > 1 ? $attachment_content : ' '),
+ file_id => $file_id,
+ );
+
+ return $ent;
+}
+
+sub _create_message {
+ my ($self) = @_;
+
+ my @parts;
+
+ push @{ $self->{headers} }, (Type => "multipart/mixed");
+
+ if ($self->{message}) {
+ push @parts, Email::MIME->create(
+ attributes => {
+ content_type => $self->{contenttype},
+ charset => $self->{charset},
+ encoding => 'quoted-printable',
+ },
+ body_str => $self->{message},
+ );