-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdecodemail.php
86 lines (80 loc) · 3.19 KB
/
decodemail.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
require_once "Mail/mimeDecode.php";
function get_body_plain($obj,$params='') {
static $return;
if (is_object($obj)) {
if (strtolower($obj->ctype_primary)=='multipart' && strtolower($obj->ctype_secondary)=='digest') {
// if object is a mail digest, parse each part of the digest recursivly
while(list($key,$value) = each($obj->parts)) {
$decoder = new Mail_mimeDecode($value->body);
get_body_plain($decoder->decode($params),$params);
}
}
// if object has 'readable' body text, attach to output
if ((strtolower($obj->ctype_primary)=='text') and (strtolower($obj->ctype_secondary)!='x-vcard')) {
$text = preg_replace('=<br */?>=i', "\n", $obj->body);
$text = iconv($obj->ctype_parameters['charset'], 'UTF-8//IGNORE', $text);
$return .= $text;
}
else {
// if object has no 'readable' body text, parse object recursivly
get_body_plain(get_object_vars($obj),$params);
}
}
else {
if (is_array($obj)) {
// if this is part of 'multipart/alternative', only parse the first one
if (strtolower($obj['ctype_secondary'])=="alternative") {
get_body_plain($obj['parts'][0],$params);
}
else {
// otherwise parse array values recursivly
while(list($key,$value) = each($obj)) {
get_body_plain($value,$params);
}
}
} else if (is_bool($obj) and $obj)
$return = '';
}
return $return;
}
function get_body_html($obj,$params='') {
static $return;
if (is_object($obj)) {
if (strtolower($obj->ctype_primary)=='multipart' && strtolower($obj->ctype_secondary)=='digest') {
// if object is a mail digest, parse each part of the digest recursivly
while(list($key,$value) = each($obj->parts)) {
$decoder = new Mail_mimeDecode($value->body);
get_body_html($decoder->decode($params),$params);
}
}
// if object has 'readable' body text, attach to output
if ((strtolower($obj->ctype_primary)=='text') and (strtolower($obj->ctype_secondary)=='html')) {
//$text = html_entity_decode($obj->body, ENT_QUOTES, 'UTF-8');
$text = $obj->body;
$text = iconv($obj->ctype_parameters['charset'], 'UTF-8//IGNORE', $text);
$return .= $text;
}
else {
// if object has no 'readable' body text, parse object recursivly
get_body_html(get_object_vars($obj),$params);
}
}
else {
if (is_array($obj)) {
// if this is part of 'multipart/alternative', only parse the second one
if (strtolower($obj['ctype_secondary'])=="alternative") {
get_body_html($obj['parts'][1],$params);
}
else {
// otherwise parse array values recursivly
while(list($key,$value) = each($obj)) {
get_body_html($value,$params);
}
}
} else if (is_bool($obj) and $obj)
$return = '';
}
return $return;
}
?>