aboutsummaryrefslogtreecommitdiffstats
path: root/t/delivert
blob: 63c3864f472a36c51d20315083e8a55b6ad83dc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl

use Email::Simple;
use IO::File;

use strict;
use warnings;

die usage() unless $#ARGV == 0;
my $path = shift;

local $/;
my $email = Email::Simple->new(<>);

my $msgid = $email->header('Message-ID');
$msgid =~ s/<(.*)@.*>/$1/;

my $fh = IO::File->new(">$path/$msgid") ||
  die "Couldn't write to $path/$msgid: $!\n";
print $fh $email->as_string;
$fh->close;

sub usage {
  "Usage: $0 path\n";
}