Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages
Mail::DeliveryStatus::BounceParser(3) User Contributed Perl Documentation Mail::DeliveryStatus::BounceParser(3)

Mail::DeliveryStatus::BounceParser - Perl extension to analyze bounce messages

  use Mail::DeliveryStatus::BounceParser;
  # $message is \*io or $fh or "entire\nmessage" or \@lines
  my $bounce = eval { Mail::DeliveryStatus::BounceParser->new($message); };
  if ($@) {
    # couldn't parse.
  my @addresses       = $bounce->addresses;       # email address strings
  my @reports         = $bounce->reports;         # Mail::Header objects
  my $orig_message_id = $bounce->orig_message_id; # <>
  my $orig_message    = $bounce->orig_message;    # Mail::Internet object

Mail::DeliveryStatus::BounceParser analyzes RFC822 bounce messages and returns a structured description of the addresses that bounced and the reason they bounced; it also returns information about the original returned message including the Message-ID. It works best with RFC1892 delivery reports, but will gamely attempt to understand any bounce message no matter what MTA generated it.

Meng Wong wrote this for the Listbox v2 project; good mailing list managers handle bounce messages so listowners don't have to. The best mailing list managers figure out exactly what is going on with each subscriber so the appropriate action can be taken.

  my $bounce = Mail::DeliveryStatus::BounceParser->parse($message, \%arg);
OPTIONS. If you pass BounceParser->new(..., {log=>sub { ... }}) That will be used as a logging callback. If $message is undefined, will parse STDIN.
NON-BOUNCES. If the message is recognizably a vacation autoresponse, or is a report of a transient nonfatal error, or a spam or virus autoresponse, you'll still get back a $bounce, but its "$bounce->is_bounce()" will return false.
It is possible that some bounces are not really bounces; such as anything that appears to have a 2XX status code. To include such non-bounces in the reports, pass the option {report_non_bounces=>1}.
For historical reasons, "new" is an alias for the "parse" method.

If a logging callback has been given, the message will be passed to it.

  if ($bounce->is_bounce) { ... }
This method returns true if the bounce parser thought the message was a bounce, and false otherwise.

Each $report returned by $bounce-> reports() is basically a Mail::Header object with a few modifications. It includes the email address bouncing, and the reason for the bounce.
Consider an RFC1892 error report of the form
 Reporting-MTA: dns;
 Arrival-Date: Fri,  4 Oct 2002 16:49:32 -0400 (EDT)
 Final-Recipient: rfc822;
 Action: failed
 Status: 5.0.0
 Diagnostic-Code: X-Postfix; host[] said: 550
  <>: Nonexistent Mailbox
Each "header" above is available through the usual get() mechanism.
  print $report->get('reporting_mta');   # ''
  print $report->get('arrival-date');    # 'Fri,  4 Oct 2002 16:49:32 -0400 (EDT)'
  print $report->get('final-recipient'); # 'rfc822;'
  print $report->get('action');          # "failed"
  print $report->get('status');          # "5.0.0"
  print $report->get('diagnostic-code'); # X-Postfix; ...
  # BounceParser also inserts a few interpretations of its own:
  print $report->get('email');           # ''
  print $report->get('std_reason');      # 'user_unknown'
  print $report->get('reason');          # host [] said: 550 5.1.1 unknown or illegal user:
  print $report->get('host');            #
  print $report->get('smtp_code');       # 550
  print $report->get('raw') ||           # the original unstructured text
        $report->as_string;              # the original   structured text
Probably the two most useful fields are "email" and "std_reason", the standardized reason. At this time BounceParser returns the following standardized reasons:
The "spam" standard reason indicates that the message bounced because the recipient considered it spam.
(no_problemo will only appear if you set {report_non_bounces=>1})
If the bounce message is not structured according to RFC1892, BounceParser will still try to return as much information as it can; in particular, you can count on "email" and "std_reason" to be present.

Returns a list of the addresses which appear to be bouncing. Each member of the list is an email address string of the form ''.

If possible, returns the message-id of the original message as a string.

If the original message was included in the bounce, it'll be available here as a message/rfc822 MIME entity.
  my $orig_message    = $bounce->orig_message;

If only the original headers were returned in the text/rfc822-headers chunk, they'll be available here as a Mail::Header entity.

If the bounce message was poorly structured, the above two methods won't return anything --- instead, you get back a block of text that may or may not approximate the original message. No guarantees. Good luck.

Bounce messages are generally meant to be read by humans, not computers. A poorly formatted bounce message may fool BounceParser into spreading its net too widely and returning email addresses that didn't actually bounce. Before you do anything with the email addresses you get back, confirm that it makes sense that they might be bouncing --- for example, it doesn't make sense for the sender of the original message to show up in the addresses list, but it could if the bounce message is sufficiently misformatted.
Still, please report all bugs!

Some bizarre MTAs construct bounce messages using the original headers of the original message. If your application relies on the assumption that all Message-IDs are unique, you need to watch out for these MTAs and program defensively; before doing anything with the Message-ID of a bounce message, first confirm that you haven't already seen it; if you have, change it to something else that you make up on the spot, such as "<antibogus-TIMESTAMP-PID-COUNT@LOCALHOST>".

BounceParser assumes a sanely constructed bounce message. Input from the real world may cause BounceParser to barf and die horribly when we violate one of MIME::Entity's assumptions; this is why you should always call it inside an eval { }.

Provide some translation of the SMTP and DSN error codes into English. Review RFC1891 and RFC1893.

We understand bounce messages generated by the following MTAs / organizations:
 AOL's AirMail sender-blocking
 Microsoft Exchange*
 Novell Groupwise*
 * Items marked with an asterisk currently may return incomplete information.

  Used by --- if you like BounceParser and you know it,
  consider Listbox for your mailing list needs!
  SVN repository and email list information at:
  RFC1892 and RFC1894

Schwern's modules have the Alexandre Dumas property.

Original author: Meng Weng Wong, <>
Current maintainer: Ricardo SIGNES, <>
Massive contributions to the 1.5xx series were made by William Yardley and Michael Stevens. Ricardo mostly just helped out and managed releases.

  Copyright (C) 2003-2006, IC Group, Inc. permanent email forwarding with spam filtering mailing list services for announcements and discussion
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

  coraline, Fletch, TorgoX, mjd, a-mused, Masque, gbarr,
  sungo, dngor, and all the other hoopy froods on #perl
2016-01-29 perl v5.28.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.