#!/usr/local/bin/perl -w use strict; use warnings FATAL => 'all'; use Email::MIME::Attachment::Stripper; use HTML::TableExtract; use Text::Iconv; use Data::Dumper; my $mail = join '', ; my $stripper = Email::MIME::Attachment::Stripper->new($mail); my @attachments = $stripper->attachments; my $attachment = $attachments[0]; my $html = $attachment->{payload}; #print Dumper $html; my $iconv = Text::Iconv->new('utf-8', 'iso-8859-15'); $html = $iconv->convert($html); my $te = HTML::TableExtract->new; $te->parse($html); #foreach my $table ($te->tables) #{ # foreach my $row ($table->rows) # { # print Dumper $row; # } #} my $info = ($te->tables)[5]; my $datetime = 'n/a'; foreach my $row ($info->rows) { next unless defined $row->[1]; if ($row->[1] =~ /^(\d{2})\.(\d{2})\.(\d{4})\s+(\d{2}:\d{2}:\d{2})\s*$/) { $datetime = sprintf "[%s-%s-%s %s]", $3, $2, $1, $4; } } my $list = ($te->tables)[1]; my $i = 0; foreach my $row ($list->rows) { next unless defined $row->[0]; next unless defined $row->[2]; next if $row->[0] =~ /^(discount|pet\s+pudel.+)$/i; $row->[0] =~ s/[^[:print:]]/_/g; $row->[2] =~ s/[\s\xa4]//g; $row->[2] =~ s/,/./; if (defined $row->[1]) { $row->[1] =~ s/\xd7/*/; $row->[1] =~ s/[^[:print:]]/_/g; $row->[1] =~ s/,/./; $row->[1] =~ s/\s+$//; $row->[0] = sprintf "%s (%s)", $row->[0], $row->[1]; } printf "%s #%d %s = %s\n", $datetime, ++$i, $row->[0], $row->[2]; }