|
22 | 22 | print "OBS! dryRunMode active, will not actually move any files!\n";
|
23 | 23 | }
|
24 | 24 |
|
25 |
| -my $fileTypeFilter = ".msg"; |
26 |
| - |
27 | 25 | # Service og action kombinasjoner som skal flyttes
|
28 | 26 | my %messageTypes = (
|
29 | 27 | 'behandlerKrav' => ["BehandlerKrav", "OppgjorsMelding"],
|
30 | 28 | 'testType' => ["testService", "testAction"]
|
31 | 29 | );
|
32 | 30 |
|
33 |
| -printf "Checking directory %s...\n", $inputDirectory; |
| 31 | +printf "Input directory: %s\n", $inputDirectory; |
| 32 | +printf "New eMottak directory: %s\n", $newEmottakDirectory; |
| 33 | +printf "Old eMottak directory: %s\n", $oldEmottakDirectory; |
| 34 | + |
34 | 35 | opendir(DIR, $inputDirectory) or die "Can't open $inputDirectory: $!";
|
35 |
| -printf "Moving files to directory %s...\n", $newEmottakDirectory; |
36 | 36 |
|
37 | 37 | my $moveCounter = 0;
|
38 | 38 | my $fileCounter = 0;
|
39 | 39 |
|
40 | 40 | foreach my $filename (readdir(DIR)) {
|
41 |
| - if ($filename =~ m/$fileTypeFilter/) { |
| 41 | + if (length($filename) > 2) { |
42 | 42 | $fileCounter++;
|
43 | 43 | my $parser = MIME::Parser->new;
|
44 | 44 | $parser->output_to_core(1); #ikke skriv fil til disk
|
45 | 45 |
|
46 | 46 | # Leser epost
|
47 | 47 | my $entity = $parser->parse_open("$inputDirectory/$filename");
|
| 48 | + # $entity->dump_skeleton(); |
48 | 49 | my $first_part = $entity->parts(0);
|
49 |
| - my $body = $first_part->bodyhandle->as_string; |
| 50 | + my $body = (defined $first_part) ? $first_part->bodyhandle->as_string : $entity->bodyhandle->as_string; |
50 | 51 |
|
51 | 52 | # Leser ebxml dokument
|
52 | 53 | my $xml_parser = XML::LibXML->new;
|
|
62 | 63 |
|
63 | 64 | my $messageMatched = 0;
|
64 | 65 | foreach my $key (keys %messageTypes) {
|
65 |
| - my @serviceAction = @{%messageTypes{$key}}; |
| 66 | + my @serviceAction = @{$messageTypes{$key}}; |
66 | 67 | if ($serviceAction[0] eq $service and $serviceAction[1] eq $action) {
|
67 | 68 | $messageMatched = 1;
|
68 | 69 | }
|
|
85 | 86 | }
|
86 | 87 | }
|
87 | 88 |
|
88 |
| -printf "%s of %s files of type %s moved\n", $moveCounter, $fileCounter, $fileTypeFilter; |
| 89 | +printf "%s of %s files moved\n", $moveCounter, $fileCounter; |
89 | 90 |
|
90 | 91 | closedir(DIR);
|
0 commit comments