--- a/ex/mails/unsigned Wed Nov 09 14:58:33 2011 +0100
+++ b/ex/mails/unsigned Wed Nov 09 16:50:16 2011 +0100
@@ -2,8 +2,8 @@
Envelope-to: heiko@localhost,
heiko@localhost
Received: from heiko by jumper.schlittermann.de with local (Exim 4.72)
- (envelope-from <hs@schlittermann.de>)
- id 1RO7TQ-00023m-ES; Wed, 09 Nov 2011 13:41:48 +0100
+ (envelope-from <hs@schlittermann.de>)
+ id 1RO7TQ-00023m-ES; Wed, 09 Nov 2011 13:41:48 +0100
Date: Wed, 9 Nov 2011 13:41:48 +0100
From: Heiko Schlittermann <hs@schlittermann.de>
To: heiko@localhost
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Message/2822.pm Wed Nov 09 16:50:16 2011 +0100
@@ -0,0 +1,58 @@
+package Message::2822;
+
+use 5.010;
+use strict;
+use warnings;
+use IO::File;
+use if $ENV{DEBUG} => "Smart::Comments";
+
+my %DATA;
+
+sub new {
+ my $class = ref $_[0] ? ref shift : shift;
+ my $this = bless \(my $x) => $class;
+ my %arg = @_;
+
+ $DATA{$this}{file} = $arg{file};
+ $DATA{$this}{fh} = IO::File->new($DATA{$this}{file})
+ or die "Can't open $DATA{$this}{file}: $!\n";
+
+ local $/ = "";
+ my $_ = $DATA{$this}{fh}->getline();
+
+ foreach (split /\n(?=\S)/, $_) {
+ my (undef, $k, $v) = split /(^(?:\S+:|(?i:from )))/, $_;
+ push @{$DATA{$this}{header_fields}}, $k;
+ $DATA{$this}{header}{$k} = $v;
+ }
+
+ return $this;
+}
+
+sub header_fields {
+ my $this = shift;
+ return @{$DATA{$this}{header_fields}};
+}
+
+sub header_content {
+ my $this = shift;
+ my $field = shift;
+
+ my $_ = $DATA{$this}{header}{$field};
+
+ if (not defined) {
+ ($field) = grep /^$field$/i => $this->header_fields();
+ $_ = $DATA{$this}{header}{$field}
+ }
+
+ /^\s*(.*?)\s*$/m;
+ return $1;
+}
+
+sub DESTROY {
+ my $this = shift;
+ delete $DATA{$this};
+}
+
+
+1;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/scratch/sign Wed Nov 09 16:50:16 2011 +0100
@@ -0,0 +1,12 @@
+#! /usr/bin/perl
+
+use 5.010;
+use strict;
+use warnings;
+
+use lib "lib";
+use Message::2822;
+
+my $message = Message::2822->new(file => shift);
+
+say join "\n", $message->header_content("content-type:");