Permalink
Browse files

More work in progress on preserving raw header form

But it might be easier to just scrub this branch and try again
  • Loading branch information...
1 parent d5bf725 commit 37c61146d448aad6454786ecb1ad61ebc23c915e @autarch autarch committed Jul 22, 2013
View
@@ -435,9 +435,9 @@ sub _parse_headers {
}
{
- my $fake_ct = Courriel::Header::ContentType->new_from_value(
- name => 'Content-Type',
- value => 'text/plain'
+ my $fake_ct = Courriel::Header::ContentType->new(
+ name => 'Content-Type',
+ mime_type => 'text/plain'
);
sub _parse_parts {
View
@@ -23,17 +23,16 @@ has name => (
);
has value => (
- is => 'ro',
- isa => Str,
- lazy => 1,
- builder => '_build_value',
+ is => 'ro',
+ isa => Str,
+ required => 1,
);
-has raw_value => (
+has raw_header => (
is => 'ro',
isa => Str,
lazy => 1,
- builder => '_build_raw_value',
+ builder => '_build_raw_header',
);
sub new_from_raw_line {
@@ -46,34 +45,6 @@ sub new_from_raw_line {
return $class->new( $class->_parse_header($raw) );
}
-{
- my @spec = (
- output => { isa => Streamable, coerce => 1 },
- );
-
- sub stream_to {
- my $self = shift;
- my ($output) = validated_list(
- \@_,
- @spec
- );
-
- $output->( $self->raw_value() );
-
- return;
- }
-}
-
-sub as_string {
- my $self = shift;
-
- my $string = q{};
-
- $self->stream_to( output => $self->_string_output( \$string ), @_ );
-
- return $string;
-}
-
sub _parse_header {
my $class = shift;
my $raw = shift;
@@ -96,8 +67,9 @@ sub _parse_header {
}
return (
- name => $name,
- value => $class->_mime_decode($value),
+ name => $name,
+ value => $value,
+ raw_header => $raw,
);
}
@@ -165,7 +137,7 @@ sub _parse_header {
}
}
-sub _build_raw_value {
+sub _build_raw_header {
my $self = shift;
my $raw = $self->name();
@@ -259,6 +231,34 @@ sub _mime_encode {
return join q{ }, @result;
}
+{
+ my @spec = (
+ output => { isa => Streamable, coerce => 1 },
+ );
+
+ sub stream_to {
+ my $self = shift;
+ my ($output) = validated_list(
+ \@_,
+ @spec
+ );
+
+ $output->( $self->raw_header() );
+
+ return;
+ }
+}
+
+sub as_string {
+ my $self = shift;
+
+ my $string = q{};
+
+ $self->stream_to( output => $self->_string_output( \$string ), @_ );
+
+ return $string;
+}
+
__PACKAGE__->meta()->make_immutable();
1;
@@ -293,11 +293,11 @@ The header name as passed to the constructor.
The header value as passed to the constructor.
-=head2 $header->raw_value()
+=head2 $header->raw_header()
-The full header, encoded and folded as needed. If this header was created by
-parsing an email, this will return the header as it was in the original, byte
-for byte.
+The full header (with a name and value), encoded and folded as needed. If this
+header was created by parsing an email, this will return the header as it was
+in the original, byte for byte.
=head2 $header->as_string()
View
@@ -76,7 +76,8 @@ override BUILDARGS => sub {
next unless defined $name;
- $headers->[$i] = $class->_inflate_header( $name, $headers->[$i] );
+ $headers->[$i] = $class->_inflate_header( $name, $headers->[$i] )
+ unless blessed $headers->[$i];
}
}
@@ -104,9 +104,9 @@ sub _maybe_set_disposition_in_headers {
}
{
- my $fake_disp = Courriel::Header::Disposition->new_from_value(
- name => 'Content-Disposition',
- value => 'inline',
+ my $fake_disp = Courriel::Header::Disposition->new(
+ name => 'Content-Disposition',
+ disposition => 'inline',
);
sub _build_disposition {
@@ -140,7 +140,7 @@ role {
$p{name} //= $name;
$p{raw_value} = delete $p{value};
- return $class->new_from_raw_value(%p);
+ return $class->new(%p);
};
};
@@ -73,9 +73,9 @@ sub _stream_to {
}
{
- my $fake_ct = Courriel::Header::ContentType->new_from_value(
- name => 'Content-Type',
- value => 'text/plain'
+ my $fake_ct = Courriel::Header::ContentType->new(
+ name => 'Content-Type',
+ mime_type => 'text/plain'
);
sub _build_content_type {

0 comments on commit 37c6114

Please sign in to comment.