#!/usr/bin/perl use strict; use MIME::Parser; die "Usage makeCSV Filename\n" if $#ARGV != 0; my $infile = $ARGV[0]; my $top_entity; my $pfad = "/csv"; my $prefix = "Message"; my $filename; # Datei mit MIME-Nachricht einlesen und parsen $top_entity = &parse_MIME_Stream($infile); # MIME-Nachricht rekursiv durchlaufen &walk($top_entity); exit; sub parse_MIME_Stream { my $file = shift; my $parser = ''; die "NO FILE $!" unless defined $file; $parser = MIME::Parser->new(); $parser->output_to_core('NONE'); $parser->output_dir($pfad); $parser->output_prefix($prefix); open(INPUT,$file) or die $!; my $top_entity = $parser->read(\*INPUT); close(INPUT) or die $!; return $top_entity; } sub walk #(Entity) { my $entity = shift if @_; return unless defined $entity; my $head = $entity->head(); if ($head->mime_type() =~ m/multipart/i) { # mehrteilige Nachricht my $i; my $num_alt_parts = $entity->parts(); my $current_entity; # alle Teile der Nachricht rekursiv abarbeiten for ($i = 0; $i < $num_alt_parts; $i++) { $current_entity = $entity->parts($i); &walk($current_entity); } } else { # einteilige Nachricht &handle_head($head) if (defined $head); } } sub handle_head #(Header) { my $current_head = shift; $current_head->decode; $current_head->unfold; if ( $current_head->recommended_filename() =~ m/\.csv/i ) { print $current_head->recommended_filename()."\n"; } }