Email-Abuse-Investigator

 view release on metacpan or  search on metacpan

lib/Email/Abuse/Investigator.pm  view on Meta::CPAN

	}
	$self->{_headers}  = \@headers;

	# Collect all Received: header values (most-recent first, as in message)
	$self->{_received} = [
		map  { $_->{value} }
		grep { $_->{name} eq 'received' } @headers
	];

	# Determine content type and transfer encoding from top-level headers
	my ($ct_h)  = grep { $_->{name} eq 'content-type' }              @headers;
	my ($cte_h) = grep { $_->{name} eq 'content-transfer-encoding' } @headers;
	my $ct  = defined $ct_h  ? $ct_h->{value}  : '';
	my $cte = defined $cte_h ? $cte_h->{value} : '';

	# Decode multipart or single-part body as appropriate
	if ($ct =~ /multipart/i) {
		my ($boundary) = $ct =~ /boundary="?([^";]+)"?/i;
		# Pass depth=0 to enforce the MAX_MULTIPART_DEPTH recursion guard
		$self->_decode_multipart($body_raw, $boundary, 0) if $boundary;
	} else {

lib/Email/Abuse/Investigator.pm  view on Meta::CPAN


		# Unfold continuation header lines within this part
		$phdr_block =~ s/\r?\n([ \t]+)/ $1/g;

		# Parse this part's headers into a simple hash
		my %phdr;
		for my $line (split /\r?\n/, $phdr_block) {
			$phdr{ lc($1) } = $2 if $line =~ /^([\w-]+)\s*:\s*(.*)/;
		}

		my $pct  = $phdr{'content-type'}              // '';
		my $pcte = $phdr{'content-transfer-encoding'} // '';

		# Nested multipart/* must be recursed into; without this URLs in
		# multipart/alternative inside multipart/mixed would be missed.
		if ($pct =~ /multipart/i) {
			my ($inner_boundary) = $pct =~ /boundary\s*=\s*"?([^";]+)"?/i;
			if ($inner_boundary) {
				$inner_boundary =~ s/\s+$//;
				# Increment depth counter for the recursion guard
				$self->_decode_multipart($pbody, $inner_boundary, $depth + 1);

t/function.t  view on Meta::CPAN

# 3. _split_message — all body-type branches
# ===========================================================================
note '=== 3. _split_message ===';
{
	# Plain text
	my $a = Email::Abuse::Investigator->new();
	$a->parse_email(make_email(body => "Hello\nworld"));
	is $a->{_body_plain}, "Hello\nworld", 'plain text stored';
	is $a->{_body_html},  '',			 'html empty for plain email';

	# HTML content-type
	my $b = Email::Abuse::Investigator->new();
	$b->parse_email(make_email(ct => 'text/html', body => '<b>Hi</b>'));
	is $b->{_body_html},  '<b>Hi</b>', 'html body stored';
	is $b->{_body_plain}, '',		  'plain empty for html email';

	# QP decode
	my $qp = encode_qp("Caf\xE9 menu");
	my $c = Email::Abuse::Investigator->new();
	$c->parse_email(make_email(ct => 'text/plain', cte => 'quoted-printable',
							   body => $qp));



( run in 2.553 seconds using v1.01-cache-2.11-cpan-524268b4103 )