-
Notifications
You must be signed in to change notification settings - Fork 3
/
parse-mime.php
63 lines (47 loc) · 1.62 KB
/
parse-mime.php
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
<?php
$str = file_get_contents('mime-mixed-related-alternative.eml');
preg_match_all('/((?<=(Content-Type: multipart\/mixed; boundary="))(.*)?(?=(")))|((?<=(Content-Type: multipart\/related; boundary="))(.*)?(?=(")))|((?<=(Content-Type: multipart\/alternative; boundary="))(.*)?(?=(")))/', $str, $boundary);
echo "<pre>";
// print_r($boundary);
$AllPartsUnique = "";
$j=0;
foreach ($boundary[0] as $key => $v) {
if($key >= 0){
echo "\n\n\nBoundary " . $v . "\r\n";
// cut boundary content
preg_match_all('/(?<=(--'.$v.'))(| |.*|[\s\S]+|\<|\>|\.|\r|\n|\0|@|\w+)?(?=(--'.$v.'--))/', $str, $part);
$bname = $v;
foreach ($part[0] as $v) {
// echo "PART " . $bname . " " . $v . "\r\n";
$parts = explode("--".$bname, $v);
echo "<pre>";
foreach ($parts as $v) {
// echo "\r\nSINGLE PART " . $v . "\r\n";
// $AllPartsUnique[$j] = $v;
// with html visible on page
$AllPartsUnique[$j] = htmlentities($v);
$j++;
}
}
}
}
echo "<pre>";
// print_r($AllPartsUnique);
foreach($AllPartsUnique as $key => $one) {
foreach ($boundary[0] as $find) {
if(strpos($one, $find) !== false){
unset($AllPartsUnique[$key]);
}
}
}
echo "<pre>";
print_r($AllPartsUnique);
preg_match_all('/(?<=((\n)To: )|(^To: ))(.*)+?(?=())/', $str, $to);
echo "To " . $to[0][0];
preg_match_all('/(?<=((\n)From: )|(^From: ))(.*)+?(?=())/', $str, $from);
echo "From " . $from[0][0];
preg_match_all('/(?<=((\n)Subject: )|(^Subject: ))(.*)+?(?=())/', $str, $subject);
echo "Subject " . $subject[0][0];
// end script
die();
?>