Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 70 additions & 24 deletions Make_statuscodes.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,105 @@
<?php

#+++
# Make_statuscodes.php
# create the include file with all of the latest IANA standards RFC3463 + changes

#+++
# Command Line Options
#
# -k keep

$options = getopt("k");

# Links and filenames
$csv_url_1 = "https://www.iana.org/assignments/smtp-enhanced-status-codes/smtp-enhanced-status-codes-1.csv";
$file1_name = 'file1.csv';
$csv_url_2 = "https://www.iana.org/assignments/smtp-enhanced-status-codes/smtp-enhanced-status-codes-3.csv";
$file2_name = 'file2.csv';

print "<?php\n";
print "#Generated by Make_statuscodes.php\n\n";
print "#from http://www.iana.org/assignments/smtp-enhanced-status-codes/smtp-enhanced-status-codes-1.csv\n";
print "#and smtp-enhanced-status-codes-3.csv\n\n";
print "# Generated by Make_statuscodes.php on ". date('c'). "\n\n";
print "# from $csv_url_1\n";
print "# and $csv_url_2\n\n";

$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $csv_url_1,
CURLOPT_USERAGENT => 'PHP-Bounce-Handler (Make_statuscodes.php)'
));
$csv_raw_content = curl_exec($ch);
curl_close($ch);

$fh = fopen("http://www.iana.org/assignments/smtp-enhanced-status-codes/smtp-enhanced-status-codes-1.csv", "r");
$file1 = fopen($file1_name,'w');
fwrite($file1,$csv_raw_content);
fclose($file1);

$fh = fopen($file1_name, 'r');
if ($fh !== FALSE) {
$a = fgets($fh); # 1st line is titles
while (!feof($fh)) {
$a = fgetcsv($fh, 0, ',', '"');
$a[0] = preg_replace('/\..*/', '', $a[0]); # 5.x.x -> 5
$a[1] = preg_replace('/\n\s*/', ' ', $a[1]); #remove line breaks
$a[1] = preg_replace('/\s\s+/', ' ', $a[1]); #remove double spaces
$a[1] = preg_replace('/"/', '\\"', $a[1]); #requote quotes
$a[2] = preg_replace('/\n\s*/', ' ', $a[2]); #remove line breaks
$a[2] = preg_replace('/\s\s+/', ' ', $a[2]); #remove double spaces
$a[2] = preg_replace('/"/', '\\"', $a[2]); #requote quotes
print "\$status_code_classes['$a[0]']['title'] = \"". $a[1]. "\"; # $a[3]\n";
print "\$status_code_classes['$a[0]']['descr'] = \"". $a[2]. "\";\n";
if ($a[0]) {
$a[0] = preg_replace('/\..*/', '', $a[0]); # 5.x.x -> 5
$a[1] = preg_replace('/\n\s*/', ' ', $a[1]); #remove line breaks
$a[1] = preg_replace('/\s\s+/', ' ', $a[1]); #remove double spaces
$a[1] = preg_replace('/"/', '\\"', $a[1]); #requote quotes
$a[2] = preg_replace('/\n\s*/', ' ', $a[2]); #remove line breaks
$a[2] = preg_replace('/\s\s+/', ' ', $a[2]); #remove double spaces
$a[2] = preg_replace('/"/', '\\"', $a[2]); #requote quotes
print "\$status_code_classes['$a[0]']['title'] = \"". $a[1]. "\"; # $a[3]\n";
print "\$status_code_classes['$a[0]']['descr'] = \"". $a[2]. "\";\n";
}
}
fclose ($fh);
}
print "\n";


#X.7.17,Mailbox owner has changed,5XX,"This status code is returned when a message is
#received with a Require-Recipient-Valid-Since
#field or RRVS extension and the receiving
#system is able to determine that the intended
#recipient mailbox has not been under
#continuous ownership since the specified date.",[RFC-ietf-appsawg-rrvs-header-field-10] (Standards Track),M. Kucherawy,IESG

$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $csv_url_2,
CURLOPT_USERAGENT => 'PHP-Bounce-Handler (Make_statuscodes.php)'
));
$csv_raw_content = curl_exec($ch);
curl_close($ch);
$file2 = fopen($file2_name,'w');
fwrite($file2,$csv_raw_content);
fclose($file2);

$fh = fopen("http://www.iana.org/assignments/smtp-enhanced-status-codes/smtp-enhanced-status-codes-3.csv", "r");
$fh = fopen($file2_name, 'r');
if ($fh !== FALSE) {
$a = fgets($fh); # 1st line is titles
while (!feof($fh)) {
$a = fgetcsv($fh, 0, ',', '"');
$a[0] = preg_replace('/^X./i', '', $a[0]); #X.5.0 -> 5.0
$a[1] = preg_replace('/\n\s*/', ' ', $a[1]); #remove line breaks
$a[1] = preg_replace('/\s\s+/', ' ', $a[1]); #remove double spaces
$a[1] = preg_replace('/"/', '\\"', $a[1]); #requote quotes
$a[3] = preg_replace('/\n\s*/', ' ', $a[3]); #remove line breaks
$a[3] = preg_replace('/\s\s+/', ' ', $a[3]); #remove double spaces
$a[3] = preg_replace('/"/', '\\"', $a[3]); #requote quotes
print "\$status_code_subclasses['$a[0]']['title'] = \"". $a[1]. "\"; # $a[4]\n";
print "\$status_code_subclasses['$a[0]']['descr'] = \"". $a[3]. "\";\n";
if ($a[0]) {
$a[0] = preg_replace('/^X./i', '', $a[0]); #X.5.0 -> 5.0
$a[1] = preg_replace('/\n\s*/', ' ', $a[1]); #remove line breaks
$a[1] = preg_replace('/\s\s+/', ' ', $a[1]); #remove double spaces
$a[1] = preg_replace('/"/', '\\"', $a[1]); #requote quotes
$a[3] = preg_replace('/\n\s*/', ' ', $a[3]); #remove line breaks
$a[3] = preg_replace('/\s\s+/', ' ', $a[3]); #remove double spaces
$a[3] = preg_replace('/"/', '\\"', $a[3]); #requote quotes
print "\$status_code_subclasses['$a[0]']['title'] = \"". $a[1]. "\"; # $a[4]\n";
print "\$status_code_subclasses['$a[0]']['descr'] = \"". $a[3]. "\";\n";
}
}
fclose ($fh);
}
print "\n\n?>";

# Unless -k (keep flap is passed)
if (!array_key_exists('k',$options)) {
unlink($file1_name);
unlink($file2_name);
}

?>
34 changes: 29 additions & 5 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,41 @@ PHP Bounce Handler
INSTALL
-------
Upload to a website, and open testdriver1.php in a web browser
for normal operation only
bounce_driver_class.php and bounce_statuscodes.php are required



RELEASE HISTORY
---------------
v7.4 SB June 19, 2014
v7.5.1 WP Jan 14, 2025
- PHP7/8 php moderizations

v7.5.0 WP May 18, 2019
- Switch to curl from fopen.
- Add -k (keep flag) for optionally keeping the original csv files.

v7.4.3 SB Dec 2014
- add a softlink for rfc1893.error.codes.php -> bounce_statuscodes.php
- fix a fatal error with format_status_code returning the wrong datatype
- remove zip from distro (github will do that automagically)
- more autoresponse catchers
- handler broken MTAs better

v7.4.2 SB Oct 24, 2014
- slightly less agressive bounce detection; only calls last chance if we
see specific from/return-path
- added a couple more autoreponder subject line checks
- allows it to find email addresses new TLDs that are more than 4 chararters
- more supression for php notifications on undefined data

v7.4.1 SB Oct 22, 2014
- fix autoresponder detection. A lot of bounces were incorrectly being
caught as autoresponders
- added vacation/autoresponder examples
- minor fix in command line test tool

v7.4 SB June 19, 2014
- make auto-responder identification table driven
- make bounce_statuscodes.php (prev rfc1893_status_codes.php) generated from IANA list
- make bounce_statuscodes.php (prev rfc1893_status_codes.php) generated from IANA list
php Make_statuscodes.php >bounce_statuscodes.php
- allow for rfc status codes with 2 digits in the 3rd paramater
- more supression for php notifications on undefined data
Expand All @@ -26,7 +50,7 @@ v7.4 SB June 19, 2014
v7.3 CF July 4, 2013

- Replaced deprecated split() function.
- Added auto-responder identification filter.
- Added auto-responder identification filter.
- Suppressed php Notice errors.


Loading