CC: | michael.stevens [...] dianomi.com,michael.smith [...] dianomi.com |
Subject: | failure on short and simple bounce message |
Fails with error:
Can't call method "stringify_body" on an undefined
value at
/opt/dianomi/perl/lib/site_perl/5.12.2/Mail/DeliveryStatus/BounceParser.pm
line
187.
On nearly empty bounce message.
Patch attached and in gitorious repo at
http://gitorious.org/mail-deliverystatus-bounceparser-fork/mail-deliverystatus-bounceparser-fork/commit/68a997980c74f73ad84e5b6331f0a2d0f677a025
Subject: | 0001-Fix-failure-for-nearly-empty-bounce-message.patch |
From 68a997980c74f73ad84e5b6331f0a2d0f677a025 Mon Sep 17 00:00:00 2001
From: Michael Stevens <mstevens@etla.org>
Date: Sun, 30 Jan 2011 17:33:24 +0000
Subject: [PATCH] Fix failure for nearly empty bounce message.
---
MANIFEST | 2 ++
lib/Mail/DeliveryStatus/BounceParser.pm | 6 +++---
t/corpus/no-message-collected.msg | 26 ++++++++++++++++++++++++++
t/no-message-collected.t | 25 +++++++++++++++++++++++++
4 files changed, 56 insertions(+), 3 deletions(-)
create mode 100644 t/corpus/no-message-collected.msg
create mode 100644 t/no-message-collected.t
diff --git a/MANIFEST b/MANIFEST
index 79afd72..6dcd6b2 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -46,6 +46,7 @@ t/corpus/message-too-large.msg
t/corpus/misidentified-recipient.msg
t/corpus/msn-via-sendmail.unknown.msg
t/corpus/no-such-domain.msg
+t/corpus/no-message-collected.msg
t/corpus/nomailbox.msg
t/corpus/non-autoreply.msg
t/corpus/not-a-relay.msg
@@ -108,6 +109,7 @@ t/junkemailfilter.t
t/malformed-dns.t
t/message-too-large.t
t/misidentified-recipient.t
+t/no-message-collected.t
t/non-autoreply.t
t/not-a-relay.t
t/orig-message.t
diff --git a/lib/Mail/DeliveryStatus/BounceParser.pm b/lib/Mail/DeliveryStatus/BounceParser.pm
index fc96d04..a483349 100644
--- a/lib/Mail/DeliveryStatus/BounceParser.pm
+++ b/lib/Mail/DeliveryStatus/BounceParser.pm
@@ -184,7 +184,7 @@ sub parse {
}
{
- last unless $first_part->stringify_body =~ /Your server requires confirmation/;
+ last unless defined $first_part and $first_part->stringify_body =~ /Your server requires confirmation/;
$self->log("Looks like a challenge/response autoresponse; ignoring.");
$self->{type} = "Challenge / Response system autoreply";
$self->{is_bounce} = 0;
@@ -192,14 +192,14 @@ sub parse {
}
{
- last unless $first_part->stringify_body =~ /Please add yourself to my Boxbe Guest List/;
+ last unless defined $first_part and $first_part->stringify_body =~ /Please add yourself to my Boxbe Guest List/;
$self->log("Looks like a challenge/response autoresponse; ignoring.");
$self->{type} = "Challenge / Response system autoreply";
$self->{is_bounce} = 0;
}
{
- last unless $first_part->stringify_body =~ /This\s+is\s+a\s+one-time\s+automated\s+message\s+to\s+confirm\s+that\s+you're\s+listed\s+on\s+my\s+Boxbe\s+Guest\s+List/;
+ last unless defined $first_part and $first_part->stringify_body =~ /This\s+is\s+a\s+one-time\s+automated\s+message\s+to\s+confirm\s+that\s+you're\s+listed\s+on\s+my\s+Boxbe\s+Guest\s+List/;
$self->log("Looks like a challenge/response autoresponse; ignoring.");
$self->{type} = "Challenge / Response system autoreply";
$self->{is_bounce} = 0;
diff --git a/t/corpus/no-message-collected.msg b/t/corpus/no-message-collected.msg
new file mode 100644
index 0000000..77b0acc
--- /dev/null
+++ b/t/corpus/no-message-collected.msg
@@ -0,0 +1,26 @@
+Delivered-To: automated-bounces+e4c44af6-2220-11e0-b356-66b7dd31f8f5@email.example.com
+Received: by 10.100.96.14 with SMTP id t14cs99365anb;
+ Mon, 17 Jan 2011 02:02:47 -0800 (PST)
+Received: by 10.216.19.66 with SMTP id m44mr2936409wem.86.1295258563409;
+ Mon, 17 Jan 2011 02:02:43 -0800 (PST)
+Return-Path: <>
+Received: from srv3.test.net (mail.test.net [81.101.85.189])
+ by mx.google.com with ESMTPS id n13si5973036wej.22.2011.01.17.02.02.42
+ (version=TLSv1/SSLv3 cipher=RC4-MD5);
+ Mon, 17 Jan 2011 02:02:43 -0800 (PST)
+Received-SPF: pass (google.com: domain of srv3.test.net designates 81.101.85.189 as permitted sender) client-ip=81.101.85.189;
+Authentication-Results: mx.google.com; spf=pass (google.com: domain of srv3.test.net designates 81.101.85.189 as permitted sender) smtp.mail=
+Received: from localhost (localhost)
+ by srv3.test.net (8.13.1/8.13.1) id p0H9UVoq032290;
+ Mon, 17 Jan 2011 09:30:32 GMT
+Date: Mon, 17 Jan 2011 09:30:32 GMT
+From: Mail Delivery Subsystem <MAILER-DAEMON@srv3.test.net>
+Message-Id: <201101170930.p0H9UVoq032290@srv3.test.net>
+To: <automated-bounces+e4c44af6-2220-11e0-b356-66b7dd31f8f5@email.example.com>
+MIME-Version: 1.0
+Content-Type: multipart/report; report-type=delivery-status;
+ boundary="p0H9UVoq032290.1295256632/srv3.test.net"
+Subject: Returned mail: see transcript for details
+Auto-Submitted: auto-generated (failure)
+
+<<< No Message Collected >>>
diff --git a/t/no-message-collected.t b/t/no-message-collected.t
new file mode 100644
index 0000000..5a75ecd
--- /dev/null
+++ b/t/no-message-collected.t
@@ -0,0 +1,25 @@
+#!perl -wT
+use strict;
+
+use Test::More tests => 2;
+
+use Mail::DeliveryStatus::BounceParser;
+
+# FH because we're being backcompat to pre-lexical
+sub readfile {
+ my $fn = shift;
+ open FH, "$fn" or die $!;
+ local $/;
+ my $text = <FH>;
+ close FH;
+ return $text;
+}
+
+my $message = readfile('t/corpus/no-message-collected.msg');
+
+my $bounce = Mail::DeliveryStatus::BounceParser->new($message);
+
+isa_ok($bounce, 'Mail::DeliveryStatus::BounceParser');
+
+ok($bounce->is_bounce, "it's a bounce, alright");
+
--
1.7.3.5