Mail-MIMEDefang
view release on metacpan or search on metacpan
* mimedefang-filter.5.in: Corrected an error in one of the examples
* mimedefang.c: Add IP address of scanning host to X-Scanned-By:
header.
* SECURITY FIX: mimedefang.c: Tempfail message if RESULTS file
doesn't terminate with 'F' line. (Detects disk-full condition.)
* mimedefang.pl.in (rebuild_entity): Add a Content-Type: header
if MIME part lacks one. Some marginal e-mail software chokes on
a part with a missing content-type header.
* mimedefang.pl.in: flatten_mime removed. Support for
$Stupidity{"flatten"} removed. *** NOTE INCOMPATIBILITY ***
* action_add_part revamped completely; we try to preserve original
multipart type of message. action_add_part now simply keeps a list
of parts to be added. At the end:
a) If original message was multipart/mixed, we simply add
the part.
mimedefang.c view on Meta::CPAN
int write_header = 1;
dynamic_buffer dbuf;
DEBUG_ENTER("header");
if (!data) {
syslog(LOG_WARNING, "header: Unable to obtain private data from milter context");
DEBUG_EXIT("header", "SMFIS_TEMPFAIL");
return SMFIS_TEMPFAIL;
}
/* Check for multiple content-type headers */
if (!strcasecmp(headerf, "content-type")) {
data->numContentTypeHeaders++;
/* If more than one content-type header, only write the first one
to ensure reliable interpretation by filter! */
if (data->numContentTypeHeaders > 1) write_header = 0;
} else if (!strcasecmp(headerf, "mime-version")) {
/* We have seen a MIME-Version: header? */
data->seenMimeVersionHeader = 1;
}
if (write_header) {
/* Write the header to the message file */
dbuf_init(&dbuf);
mimedefang.c view on Meta::CPAN
}
while ((j=read(fd, chunk, CHUNK)) > 0) {
MD_SMFI_TRY(smfi_replacebody, (ctx, (unsigned char *) chunk, j));
}
close(fd);
}
break;
case 'M':
if (!rejecting) {
/* New content-type header */
percent_decode(rptr+1);
if (strlen(rptr+1) > 0) {
MD_SMFI_TRY(smfi_chgheader, (ctx, "Content-Type", 1, rptr+1));
}
if (!data->seenMimeVersionHeader) {
/* No MIME-Version: header. Add one. */
MD_SMFI_TRY(smfi_chgheader, (ctx, "MIME-Version", 1, "1.0"));
}
}
break;
mimedefang.pl.in view on Meta::CPAN
while ((lc($rebuilt->head->mime_type) eq "multipart/mixed" ||
lc($rebuilt->head->mime_type) eq "multipart/alternative") &&
$rebuilt->parts == 1 && defined($rebuilt->parts(0))) {
$rebuilt->make_singlepart();
}
push_status_tag("Writing new body");
$rebuilt->print_body($fh);
pop_status_tag();
$fh->close;
# Write new content-type header in case we've changed the type.
my $ct = $rebuilt->head->get('Content-Type');
if (!defined($ct)) {
my $type;
$type = $rebuilt->mime_type;
$boundary = $rebuilt->head->multipart_boundary;
if (defined($boundary)) {
$ct = "$type; boundary=\"$boundary\"";
} else {
$ct = "$type";
}
}
if (defined($ct)) {
chomp($ct);
write_result_line("M", $ct);
}
# Write out all the other MIME headers associated with the rebuilt
# entity.
my($hdr);
foreach my $tag (grep {/^content-/i} $rebuilt->head->tags) {
# Already done content-type
next if ($tag =~ /^content-type$/i);
if ($tag =~ /^content-transfer-encoding$/i) {
# If it is now multipart, but wasn't before, we will
# delete any content-transfer-encoding header.
if ($rebuilt->head->mime_type =~ m+^multipart/+i &&
!$WasMultiPart) {
next;
}
}
$hdr = $rebuilt->head->get($tag);
if (defined($hdr) && $hdr ne "") {
mimedefang.pl.in view on Meta::CPAN
my @parts = $in->parts;
my($type) = $in->mime_type;
$type =~ tr/A-Z/a-z/;
my($body) = $in->bodyhandle;
my($fname) = takeStabAtFilename($in);
$fname = "" unless defined($fname);
my $extension = "";
$extension = $1 if $fname =~ /(\.[^.]*)$/;
# If no Content-Type: header, add one
if (!$in->head->mime_attr('content-type')) {
$in->head->mime_attr('Content-Type', $type);
}
if (!defined($body)) {
$Action = "accept";
if (defined(&filter_multipart)) {
push_status_tag("In filter_multipart routine");
filter_multipart($in, $fname, $extension, $type);
pop_status_tag();
}
t/data/arc2.eml view on Meta::CPAN
Authentication-Results: sa-test.spamassassin.org;
dkim=pass (768-bit key) header.d=sa-test.spamassassin.org header.b=oRxHoP0Y;
spf=none (domain of test@sa-test.spamassassin.org doesn't specify if 1.2.3.4 is a permitted sender) smtp.mailfrom=test@sa-test.spamassassin.org;
DKIM-Signature: v=1; a=rsa-sha1; d=sa-test.spamassassin.org; h=from:to
:subject:message-id:date:mime-version:content-type; s=t0768; bh=
vxHXq7bMZ9+UHGuKBsbQKsDHmmk=; b=oRxHoP0YN5LfqwKiqM0iFIeG6J0odmtG
bttw9VPWjmTouQl15+EEPNfmWNyKqbXYSs0BbmfkWZuYHSf56lj1F89xqbf62w2h
cnelgVK2HSbyD8kzbAAGR/yPWamnRhne
From: SpamAssassin Test <test@sa-test.spamassassin.org>
To: undisclosed-recipients:;
Subject: test message 1
Message-ID: <4A294538.10002@spamassassin.org>
Date: Mon, 08 Jun 2009 12:00:00 +0000
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
t/data/dkim1.eml view on Meta::CPAN
DKIM-Signature: v=1; a=rsa-sha1; d=sa-test.spamassassin.org; h=from:to
:subject:message-id:date:mime-version:content-type; s=t0768; bh=
vxHXq7bMZ9+UHGuKBsbQKsDHmmk=; b=oRxHoP0YN5LfqwKiqM0iFIeG6J0odmtG
bttw9VPWjmTouQl15+EEPNfmWNyKqbXYSs0BbmfkWZuYHSf56lj1F89xqbf62w2h
cnelgVK2HSbyD8kzbAAGR/yPWamnRhne
BIMI-Selector: v=BIMI1; s=brand1;
From: SpamAssassin Test <test@sa-test.spamassassin.org>
To: undisclosed-recipients:;
Subject: test message 1
Message-ID: <4A294538.10002@spamassassin.org>
Date: Mon, 08 Jun 2009 12:00:00 +0000
MIME-Version: 1.0
t/data/dkim2.eml view on Meta::CPAN
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=
sa-test.spamassassin.org; h=from:to:subject:message-id:date
:mime-version:content-type; s=t0768; t=1244419200; bh=15pFrAvOGi
+eHKJgB6psh6iIBCbvYSuhPj+wQn6C7Ss=; b=mIrAui3j2XnmatMmIz4LaV02wt
OY7v3zJAq+pIdOjyhqgSehCByD0/+DJWjOHXFjul0ZLSqMd+M+13ZQo/5Z0OValm
FTva44EC7CPc1ZvZn7S9WpDyBW5pz7qGD4d8q3
From: SpamAssassin Test FAKE <test@sa-test.spamassassin.org>
To: undisclosed-recipients:;
Subject: test message (should fail) 2
Message-ID: <4A294538.10002@spamassassin.org>
Date: Mon, 08 Jun 2009 12:00:00 +0000
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
t/data/dkim_sig.txt view on Meta::CPAN
v=1; a=rsa-sha1; c=relaxed/simple; d=example.org; h=from
:to:subject:mime-version:content-type; s=default; bh=MAUU+6+KlDJ
QzCqO71VN08xBlF4=; b=O1Fi9OF6Z/TEaNWjJNQtFYElD30NEkPk7kfgbyt52KM
/T5f/rqX4tIazFvOuJRLhHqav/ZqYcrp2HtuO5XfVSt54ysMSU4aMbXC19akJlv2
G+rtNYpXz6qhlwC+crYA01k0PUrfBeLTiigl+ofMJKNzkZmjB3QisxMKkgIZ1Kgo
SFMyuNiKCD24FimsjkgpLA4n2CYjyIU6oixVSb5TZGOFGCVlpks1Jjgo1x5ZJCEp
O7YDi1J5t+oiQdaZjnXKNLBm4IqTtaB2yQIeuVZnPHmzq7bO5jQEojQZm7oZox54
5U/fCjl5tG52YaiTd1gyH5MJrFb0y+0pCUnjqaeHTEA==
t/data/dkim_sig2.txt view on Meta::CPAN
v=1; a=rsa-sha256; c=relaxed/simple; d=example.com; h=
from:to:subject:mime-version:content-type; s=selector; bh=xWkDNG
dajbyHmdMPMgjYBPaKILYNC1EIC1dFBnpM8Ck=; b=FvlYrU75ffEDsAcwK1pOj0
Lk7hrJXfw3KE/lyK4pqaeQlzwGt9b/Xg5ZxLJvtiCjQ2JECjYXtxdk1ZjVBMxvGH
OQQ4lv6dN4KJy7jKdlLwn1SH5959shaRSPl4sje73C1c22RTMwdU7N5xbi6uRyR6
Zmyc6MIkmo/WL48uQHIKOftP5MR16hrmeDqXrwxYDS+DwNatC9CO0Bt8c86rBSI1
KG7H5Lry35yV0Fl9K7IxQUnvI/eloyNsEeDqkIXTZckYTPceA4g6l9Stc3i3XYJN
pnMUcH8imjsmBmjpc5coe3sTsCiJwO8bcnWmgmArQsWmmSevz1PCs+kg5zpSrlFg
==
t/data/dkim_sig2a.txt view on Meta::CPAN
v=1; a=rsa-sha256; c=relaxed; d=example.com; h=from:to:subject:mime-version:content-type; s=selector; bh=xWkDNGdajbyHmdMPMgjYBPaKILYNC1EIC1dFBnpM8Ck=; b=ZA2V0LNWS/UHPfOfMfkzZPxjydsnBJSo/ouxA2+WQp/UwbCQauA4ar4glykCTU1xoHu02BAtI/Wpw1oOjVHrzU5FBm2mASzfW...
t/data/tgz.eml view on Meta::CPAN
Content-Transfer-Encoding: 7bit
Test
--------------02Tj3lGNeKJ1fcXPjVb9IeWa
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
Test
</body>
</html>
--------------02Tj3lGNeKJ1fcXPjVb9IeWa--
--------------62ATfdiTB07G9boOgpgkRqfH
Content-Type: application/x-compressed-tar; name="test.tgz"
Content-Disposition: attachment; filename="test.tgz"
t/data/zip.eml view on Meta::CPAN
Content-Transfer-Encoding: 7bit
Test
--------------02Tj3lGNeKJ1fcXPjVb9IeWa
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
Test
</body>
</html>
--------------02Tj3lGNeKJ1fcXPjVb9IeWa--
--------------62ATfdiTB07G9boOgpgkRqfH
Content-Type: application/zip; name="test.zip"
Content-Disposition: attachment; filename="test.zip"
$parser->extract_nested_messages(1);
$parser->output_to_core(0);
$parser->tmp_to_core(0);
my $filer = MIME::Parser::FileInto->new('t/tmp');
$filer->ignore_filename(1);
$parser->filer($filer);
my $entity = $parser->parse_open('t/data/multipart.eml');
ok(defined find_part($entity, 'text/plain', 0), 'find_part finds text/plain part');
ok(defined find_part($entity, 'application/octet-stream', 0), 'find_part finds application/octet-stream part');
ok(!defined find_part($entity, 'text/x-nonexistent', 0), 'find_part returns undef for missing content-type');
system('rm', '-rf', 't/tmp');
}
sub t_collect_parts : Test(1)
{
system('rm', '-rf', 't/tmp');
mkdir('t/tmp', 0755);
my $parser = MIME::Parser->new();
( run in 2.550 seconds using v1.01-cache-2.11-cpan-800906f7e73 )