Revision 31d1d9af
Von Tamino Steinert vor 26 Tagen hinzugefügt
SL/Helper/EmailProcessing.pm | ||
---|---|---|
6 | 6 |
use Carp; |
7 | 7 |
|
8 | 8 |
use XML::LibXML; |
9 |
use Archive::Zip; |
|
10 |
use File::MimeInfo::Magic; |
|
9 | 11 |
|
10 | 12 |
use SL::ZUGFeRD; |
11 | 13 |
use SL::Locale::String qw(t8); |
... | ... | |
89 | 91 |
return 0; |
90 | 92 |
} |
91 | 93 |
|
94 |
sub process_attachments_extract_zip_file { |
|
95 |
my ($self, $email_journal, $attachment, %params) = @_; |
|
96 |
|
|
97 |
my $mime_type = $attachment->mime_type; |
|
98 |
if($mime_type eq 'application/octet-stream') { |
|
99 |
$mime_type = File::MimeInfo::Magic::mimetype($attachment->name); |
|
100 |
} |
|
101 |
return unless $mime_type eq 'application/zip'; |
|
102 |
|
|
103 |
my $zip = Archive::Zip->new; |
|
104 |
open my $fh, "+<", \$attachment->content; |
|
105 |
$zip->readFromFileHandle($fh); |
|
106 |
use Data::Dumper; |
|
107 |
use Archive::Zip::MemberRead; |
|
108 |
|
|
109 |
my @new_attachments; |
|
110 |
foreach my $member ($zip->members) { |
|
111 |
my $member_fh = Archive::Zip::MemberRead->new($zip, $member); |
|
112 |
my $member_content = ''; |
|
113 |
while (defined(my $line = $member_fh->getline())) { |
|
114 |
$member_content .= $line . "\n"; |
|
115 |
} |
|
116 |
my $new_attachment = SL::DB::EmailJournalAttachment->new( |
|
117 |
name => $member->fileName, |
|
118 |
content => $member_content, |
|
119 |
mime_type => File::MimeInfo::Magic::mimetype($member->fileName) || 'text/plain', |
|
120 |
email_journal_id => $email_journal->id, |
|
121 |
)->save; |
|
122 |
$email_journal->add_attachments($new_attachment); |
|
123 |
push @new_attachments, $new_attachment; |
|
124 |
} |
|
125 |
$attachment->update_attributes(processed => 1); |
|
126 |
|
|
127 |
return 0; |
|
128 |
} |
|
129 |
|
|
130 |
|
|
92 | 131 |
sub _add_attachment_to_record { |
93 | 132 |
my ($self, $email_journal, $attachment, $record) = @_; |
94 | 133 |
|
Auch abrufbar als: Unified diff
S:H:EmailProcessing: automatisches Entpacken von Zip-Dateien