forked from cfortune/PHP-Bounce-Handler
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMake_statuscodes.php
More file actions
105 lines (92 loc) · 3.43 KB
/
Make_statuscodes.php
File metadata and controls
105 lines (92 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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 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);
$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, ',', '"');
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($file2_name, 'r');
if ($fh !== FALSE) {
$a = fgets($fh); # 1st line is titles
while (!feof($fh)) {
$a = fgetcsv($fh, 0, ',', '"');
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);
}
?>