23 if (!class_exists(
'FUNC4')) require_once
'FUNC4.php';
37 var
$hencarr = array(
'quoted-printable' =>
'',
'base64' =>
'');
38 var
$mencarr = array(
'7bit' =>
'',
'8bit' =>
'',
'quoted-printable' =>
'',
'base64' =>
'',
'binary' =>
'');
41 "\x00",
"\x01",
"\x02",
"\x03",
"\x04",
"\x05",
"\x06",
"\x07",
42 "\x08",
"\x09",
"\x0A",
"\x0B",
"\x0C",
"\x0D",
"\x0E",
"\x0F",
43 "\x10",
"\x11",
"\x12",
"\x13",
"\x14",
"\x15",
"\x16",
"\x17",
44 "\x18",
"\x19",
"\x1A",
"\x1B",
"\x1C",
"\x1D",
"\x1E",
"\x1F",
45 "\x7F",
"\x80",
"\x81",
"\x82",
"\x83",
"\x84",
"\x85",
"\x86",
46 "\x87",
"\x88",
"\x89",
"\x8A",
"\x8B",
"\x8C",
"\x8D",
"\x8E",
47 "\x8F",
"\x90",
"\x91",
"\x92",
"\x93",
"\x94",
"\x95",
"\x96",
48 "\x97",
"\x98",
"\x99",
"\x9A",
"\x9B",
"\x9C",
"\x9D",
"\x9E",
49 "\x9F",
"\xA0",
"\xA1",
"\xA2",
"\xA3",
"\xA4",
"\xA5",
"\xA6",
50 "\xA7",
"\xA8",
"\xA9",
"\xAA",
"\xAB",
"\xAC",
"\xAD",
"\xAE",
51 "\xAF",
"\xB0",
"\xB1",
"\xB2",
"\xB3",
"\xB4",
"\xB5",
"\xB6",
52 "\xB7",
"\xB8",
"\xB9",
"\xBA",
"\xBB",
"\xBC",
"\xBD",
"\xBE",
53 "\xBF",
"\xC0",
"\xC1",
"\xC2",
"\xC3",
"\xC4",
"\xC5",
"\xC6",
54 "\xC7",
"\xC8",
"\xC9",
"\xCA",
"\xCB",
"\xCC",
"\xCD",
"\xCE",
55 "\xCF",
"\xD0",
"\xD1",
"\xD2",
"\xD3",
"\xD4",
"\xD5",
"\xD6",
56 "\xD7",
"\xD8",
"\xD9",
"\xDA",
"\xDB",
"\xDC",
"\xDD",
"\xDE",
57 "\xDF",
"\xE0",
"\xE1",
"\xE2",
"\xE3",
"\xE4",
"\xE5",
"\xE6",
58 "\xE7",
"\xE8",
"\xE9",
"\xEA",
"\xEB",
"\xEC",
"\xED",
"\xEE",
59 "\xEF",
"\xF0",
"\xF1",
"\xF2",
"\xF3",
"\xF4",
"\xF5",
"\xF6",
60 "\xF7",
"\xF8",
"\xF9",
"\xFA",
"\xFB",
"\xFC",
"\xFD",
"\xFE",
64 "=00",
"=01",
"=02",
"=03",
"=04",
"=05",
"=06",
"=07",
65 "=08",
"=09",
"=0A",
"=0B",
"=0C",
"=0D",
"=0E",
"=0F",
66 "=10",
"=11",
"=12",
"=13",
"=14",
"=15",
"=16",
"=17",
67 "=18",
"=19",
"=1A",
"=1B",
"=1C",
"=1D",
"=1E",
"=1F",
68 "=7F",
"=80",
"=81",
"=82",
"=83",
"=84",
"=85",
"=86",
69 "=87",
"=88",
"=89",
"=8A",
"=8B",
"=8C",
"=8D",
"=8E",
70 "=8F",
"=90",
"=91",
"=92",
"=93",
"=94",
"=95",
"=96",
71 "=97",
"=98",
"=99",
"=9A",
"=9B",
"=9C",
"=9D",
"=9E",
72 "=9F",
"=A0",
"=A1",
"=A2",
"=A3",
"=A4",
"=A5",
"=A6",
73 "=A7",
"=A8",
"=A9",
"=AA",
"=AB",
"=AC",
"=AD",
"=AE",
74 "=AF",
"=B0",
"=B1",
"=B2",
"=B3",
"=B4",
"=B5",
"=B6",
75 "=B7",
"=B8",
"=B9",
"=BA",
"=BB",
"=BC",
"=BD",
"=BE",
76 "=BF",
"=C0",
"=C1",
"=C2",
"=C3",
"=C4",
"=C5",
"=C6",
77 "=C7",
"=C8",
"=C9",
"=CA",
"=CB",
"=CC",
"=CD",
"=CE",
78 "=CF",
"=D0",
"=D1",
"=D2",
"=D3",
"=D4",
"=D5",
"=D6",
79 "=D7",
"=D8",
"=D9",
"=DA",
"=DB",
"=DC",
"=DD",
"=DE",
80 "=DF",
"=E0",
"=E1",
"=E2",
"=E3",
"=E4",
"=E5",
"=E6",
81 "=E7",
"=E8",
"=E9",
"=EA",
"=EB",
"=EC",
"=ED",
"=EE",
82 "=EF",
"=F0",
"=F1",
"=F2",
"=F3",
"=F4",
"=F5",
"=F6",
83 "=F7",
"=F8",
"=F9",
"=FA",
"=FB",
"=FC",
"=FD",
"=FE",
92 if (!is_string($str))
FUNC4::trace($debug,
'invalid argument type');
95 $contain = implode(
'', $_mime->qpkeys);
96 return (strcspn($str, $contain) == strlen($str));
100 function qp_encode($str = null, $len = null, $end = null, $debug = null) {
104 if (!is_string($str)) $err[] =
'invalid argument type';
105 if ($len == null) $len = $_mime->MLEN;
106 else if (!(is_int($len) && $len > 1)) $err[] =
'invalid line length value';
107 if ($end == null) $end = $_mime->LE;
108 else if (!is_string($end)) $err[] =
'invalid line end value';
109 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
111 if ($str ==
'')
return $str;
114 foreach (explode($end, $str) as $line) {
115 if ($line ==
'') $out[] =
'';
117 $line = str_replace(
'=',
'=3D', $line);
118 $line = str_replace($_mime->qpkeys, $_mime->qpvrep, $line);
119 preg_match_all(
'/.{1,'.$len.
'}([^=]{0,2})?/', $line, $match);
120 $mcnt = count($match[0]);
121 for ($i = 0; $i < $mcnt; $i++) {
122 $line = (substr($match[0][$i], -1) ==
' ') ? substr($match[0][$i], 0, -1).
'=20' : $match[0][$i];
123 if (($i+1) < $mcnt) $line .=
'=';
128 return implode($end, $out);
133 function encode_header($str = null, $charset = null, $encoding = null, $len = null, $end = null, $debug = null) {
137 if (!is_string($str)) $err[] =
'invalid argument type';
138 if ($charset == null) $charset = $_mime->HCHARSET;
139 else if (!is_string($charset)) $err[] =
'invalid charset type';
140 else if (!(strlen($charset) >= 2 &&
FUNC4::is_alpha($charset,
true,
'-'))) $err[] =
'invalid charset value';
141 if ($encoding == null) $encoding = $_mime->HENCDEF;
142 else if (!is_string($encoding)) $err[] =
'invalid encoding type';
145 if (!isset($_mime->hencarr[$encoding])) $err[] =
'invalid encoding value';
147 if ($len == null) $len = $_mime->HLEN;
148 else if (!(is_int($len) && $len > 1)) $err[] =
'invalid line length value';
149 if ($end == null) $end = $_mime->LE;
150 else if (!is_string($end)) $err[] =
'invalid line end value';
151 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
153 if ($str ==
'')
return $str;
156 $dif = $len - strlen(
'=?'.$charset.
'?X??=');
157 if ($encoding ==
'quoted-printable') {
159 $new = (($dif-4) > 2) ? ($dif-4) : $len;
161 $enc = str_replace(array(
'?',
' ',
'='.$end), array(
'=3F',
'_', $end), $enc);
163 }
else if ($encoding ==
'base64') {
164 $new = ($dif > 3) ? $dif : $len;
166 for ($i = $new; $i > 2; $i--) {
168 for ($j = 0; $j <= $i; $j++) $crt .=
'x';
169 if (strlen(base64_encode($crt)) <= $new) {
175 $cnk = rtrim(chunk_split($str, $new, $end));
177 foreach (explode($end, $cnk) as $line)
if ($line !=
'') $imp[] = base64_encode($line);
178 $enc = implode($end, $imp);
182 $chr = ($encoding ==
'base64') ?
'B' :
'Q';
183 foreach (explode($end, $enc) as $val)
if ($val !=
'') $res[] =
'=?'.$charset.
'?'.$chr.
'?'.$val.
'?=';
185 $cnk = rtrim(chunk_split($str, $len, $end));
186 foreach (explode($end, $cnk) as $val)
if ($val !=
'') $res[] = $val;
188 return implode($end.
"\t", $res);
195 if (!is_string($str))
FUNC4::trace($debug,
'invalid argument type');
200 if ($str ==
'') $arr[] = array(
'charset' => $_mime->HCHARSET,
'value' =>
'');
202 foreach (preg_split(
'/(?<!\\?(?i)q)\\?\\=/', $str, -1, PREG_SPLIT_NO_EMPTY) as $str1) {
203 foreach (explode(
'=?', $str1, 2) as $str2) {
205 if (count($exp = explode(
'?B?', $str2)) == 2) {
206 if (strlen($exp[0]) >= 2 &&
FUNC4::is_alpha($exp[0],
true,
'-') && trim($exp[1]) !=
'') $def = array(
'charset' => $exp[0],
'value' => base64_decode(trim($exp[1])));
207 }
else if (count($exp = explode(
'?b?', $str2)) == 2) {
208 if (strlen($exp[0]) >= 2 &&
FUNC4::is_alpha($exp[0],
true,
'-') && trim($exp[1]) !=
'') $def = array(
'charset' => $exp[0],
'value' => base64_decode(trim($exp[1])));
209 }
else if (count($exp = explode(
'?Q?', $str2)) == 2) {
210 if (strlen($exp[0]) >= 2 &&
FUNC4::is_alpha($exp[0],
true,
'-') && $exp[1] !=
'') $def = array(
'charset' => $exp[0],
'value' => quoted_printable_decode(str_replace(
'_',
' ', $exp[1])));
211 }
else if (count($exp = explode(
'?q?', $str2)) == 2) {
212 if (strlen($exp[0]) >= 2 &&
FUNC4::is_alpha($exp[0],
true,
'-') && $exp[1] !=
'') $def = array(
'charset' => $exp[0],
'value' => quoted_printable_decode(str_replace(
'_',
' ', $exp[1])));
215 if ($def[
'value'] !=
'') $arr[] = array(
'charset' => $def[
'charset'],
'value' => $def[
'value']);
217 if ($str2 !=
'') $arr[] = array(
'charset' => $_mime->HCHARSET,
'value' => $str2);
229 if (!is_string($str)) $err[] =
'invalid content type';
230 if ($encoding == null) $encoding =
'7bit';
231 else if (!is_string($encoding)) $err[] =
'invalid encoding type';
234 $encoding = strtolower($encoding);
235 if (!isset($_mime->mencarr[$encoding])) $err[] =
'invalid encoding value';
237 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
239 if ($encoding ==
'base64') {
241 return base64_decode($str);
242 }
else if ($encoding ==
'quoted-printable') {
243 return quoted_printable_decode($str);
248 function message($content = null, $type = null, $name = null, $charset = null, $encoding = null, $disposition = null,
$id = null, $len = null, $end = null, $debug = null) {
252 if (!(is_string($content) && $content !=
'')) $err[] =
'invalid content type';
253 if ($type == null) $type =
'application/octet-stream';
254 else if (is_string($type)) {
256 if (strlen($type) < 4) $err[] =
'invalid type value';
257 }
else $err[] =
'invalid type';
258 if (is_string($name)) {
260 if ($name ==
'') $err[] =
'invalid name value';
261 }
else if ($name != null) $err[] =
'invalid name type';
262 if ($charset == null) $charset = $_mime->MCHARSET;
263 else if (!is_string($charset)) $err[] =
'invalid charset type';
264 else if (!(strlen($charset) >= 2 &&
FUNC4::is_alpha($charset,
true,
'-'))) $err[] =
'invalid charset value';
265 if ($encoding == null) $encoding = $_mime->MENCDEF;
266 else if (!is_string($encoding)) $err[] =
'invalid encoding type';
269 if (!isset($_mime->mencarr[$encoding])) $err[] =
'invalid encoding value';
271 if ($disposition == null) $disposition =
'inline';
272 else if (is_string($disposition)) {
274 if (!($disposition ==
'inline' || $disposition ==
'attachment')) $err[] =
'invalid disposition value';
275 }
else $err[] =
'invalid disposition type';
276 if (is_string(
$id)) {
278 if (
$id ==
'') $err[] =
'invalid id value';
279 }
else if (
$id != null) $err[] =
'invalid id type';
280 if ($len == null) $len = $_mime->MLEN;
281 else if (!(is_int($len) && $len > 1)) $err[] =
'invalid line length value';
282 if ($end == null) $end = $_mime->LE;
283 else if (!is_string($end)) $err[] =
'invalid line end value';
284 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
287 'Content-Type: '.$type.
';'.$end.
"\t".
'charset="'.$charset.
'"'.
288 (($name == null) ?
'' :
';'.$end.
"\t".
'name="'.$name.
'"').$end.
289 'Content-Transfer-Encoding: '.$encoding.$end.
290 'Content-Disposition: '.$disposition.
291 (($name == null) ?
'' :
';'.$end.
"\t".
'filename="'.$name.
'"').
292 ((
$id == null) ?
'' : $end.
'Content-ID: <'.
$id.
'>');
293 if ($encoding ==
'7bit' || $encoding ==
'8bit') $content = wordwrap(
MIME4::fix_eol($content), $len, $end,
true);
294 else if ($encoding ==
'base64') $content = rtrim(chunk_split(base64_encode($content), $len, $end));
296 return array(
'header' => $header,
'content' => $content);
300 function compose(
$text = null,
$html = null, $attach = null, $uniq = null, $end = null, $debug = null) {
304 if (
$text == null &&
$html == null) $err[] =
'message is not set';
307 if (!(is_array(
$text) && isset(
$text[
'header'],
$text[
'content']) && is_string(
$text[
'header']) && is_string(
$text[
'content']) &&
MIME4::isset_header(
$text[
'header'],
'content-type',
'text/plain', $debug))) $err[] =
'invalid text message type';
310 if (!(is_array(
$html) && isset(
$html[
'header'],
$html[
'content']) && is_string(
$html[
'header']) && is_string(
$html[
'content']) &&
MIME4::isset_header(
$html[
'header'],
'content-type',
'text/html', $debug))) $err[] =
'invalid html message type';
313 if ($attach != null) {
314 if (is_array($attach) && count($attach) > 0) {
315 foreach ($attach as $arr) {
316 if (!(is_array($arr) && isset($arr[
'header'], $arr[
'content']) && is_string($arr[
'header']) && is_string($arr[
'content']) && (
MIME4::isset_header($arr[
'header'],
'content-disposition',
'inline', $debug) ||
MIME4::isset_header($arr[
'header'],
'content-disposition',
'attachment', $debug)))) {
317 $err[] =
'invalid attachment type';
321 }
else $err[] =
'invalid attachment format';
323 if ($end == null) $end = $_mime->LE;
324 else if (!is_string($end)) $err[] =
'invalid line end value';
325 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
329 if ($attach) $multipart =
true;
330 $header =
$body = array();
331 $header[] =
'Date: '.date(
'r');
332 $header[] = base64_decode(
'WC1NYWlsZXI6IFhQTTQgdi4wLjUgPCB3d3cueHBlcnRtYWlsZXIuY29tID4=');
334 $uniq = ($uniq == null) ? 0 : intval($uniq);
335 $boundary1 =
'=_1.'.MIME4::unique($uniq++);
336 $boundary2 =
'=_2.'.MIME4::unique($uniq++);
337 $boundary3 =
'=_3.'.MIME4::unique($uniq++);
338 $disp[
'inline'] = $disp[
'attachment'] =
false;
339 if ($attach != null) {
340 foreach ($attach as $darr) {
341 if (
MIME4::isset_header($darr[
'header'],
'content-disposition',
'inline', $debug)) $disp[
'inline'] =
true;
342 else if (
MIME4::isset_header($darr[
'header'],
'content-disposition',
'attachment', $debug)) $disp[
'attachment'] =
true;
345 $hstr =
'Content-Type: multipart/%s;'.$end.
"\t".
'boundary="%s"';
346 $bstr =
'--%s'.$end.
'%s'.$end.$end.
'%s';
347 $body[] =
'This is a message in MIME Format. If you see this, your mail reader does not support this format.'.$end;
349 if ($disp[
'inline'] && $disp[
'attachment']) {
350 $header[] = sprintf($hstr,
'mixed', $boundary1);
351 $body[] =
'--'.$boundary1;
352 $body[] = sprintf($hstr,
'related', $boundary2).$end;
353 $body[] =
'--'.$boundary2;
354 $body[] = sprintf($hstr,
'alternative', $boundary3).$end;
355 $body[] = sprintf($bstr, $boundary3,
$text[
'header'],
$text[
'content']);
356 $body[] = sprintf($bstr, $boundary3,
$html[
'header'],
$html[
'content']);
357 $body[] =
'--'.$boundary3.
'--';
358 foreach ($attach as $desc)
if (
MIME4::isset_header($desc[
'header'],
'content-disposition',
'inline', $debug))
$body[] = sprintf($bstr, $boundary2, $desc[
'header'], $desc[
'content']);
359 $body[] =
'--'.$boundary2.
'--';
360 foreach ($attach as $desc)
if (
MIME4::isset_header($desc[
'header'],
'content-disposition',
'attachment', $debug))
$body[] = sprintf($bstr, $boundary1, $desc[
'header'], $desc[
'content']);
361 $body[] =
'--'.$boundary1.
'--';
362 }
else if ($disp[
'inline']) {
363 $header[] = sprintf($hstr,
'related', $boundary1);
364 $body[] =
'--'.$boundary1;
365 $body[] = sprintf($hstr,
'alternative', $boundary2).$end;
366 $body[] = sprintf($bstr, $boundary2,
$text[
'header'],
$text[
'content']);
367 $body[] = sprintf($bstr, $boundary2,
$html[
'header'],
$html[
'content']);
368 $body[] =
'--'.$boundary2.
'--';
369 foreach ($attach as $desc)
$body[] = sprintf($bstr, $boundary1, $desc[
'header'], $desc[
'content']);
370 $body[] =
'--'.$boundary1.
'--';
371 }
else if ($disp[
'attachment']) {
372 $header[] = sprintf($hstr,
'mixed', $boundary1);
373 $body[] =
'--'.$boundary1;
374 $body[] = sprintf($hstr,
'alternative', $boundary2).$end;
375 $body[] = sprintf($bstr, $boundary2,
$text[
'header'],
$text[
'content']);
376 $body[] = sprintf($bstr, $boundary2,
$html[
'header'],
$html[
'content']);
377 $body[] =
'--'.$boundary2.
'--';
378 foreach ($attach as $desc)
$body[] = sprintf($bstr, $boundary1, $desc[
'header'], $desc[
'content']);
379 $body[] =
'--'.$boundary1.
'--';
381 $header[] = sprintf($hstr,
'alternative', $boundary1);
382 $body[] = sprintf($bstr, $boundary1,
$text[
'header'],
$text[
'content']);
383 $body[] = sprintf($bstr, $boundary1,
$html[
'header'],
$html[
'content']);
384 $body[] =
'--'.$boundary1.
'--';
387 $header[] = sprintf($hstr,
'mixed', $boundary1);
388 $body[] = sprintf($bstr, $boundary1,
$text[
'header'],
$text[
'content']);
389 foreach ($attach as $desc)
$body[] = sprintf($bstr, $boundary1, $desc[
'header'], $desc[
'content']);
390 $body[] =
'--'.$boundary1.
'--';
392 if ($disp[
'inline'] && $disp[
'attachment']) {
393 $header[] = sprintf($hstr,
'mixed', $boundary1);
394 $body[] =
'--'.$boundary1;
395 $body[] = sprintf($hstr,
'related', $boundary2).$end;
396 $body[] = sprintf($bstr, $boundary2,
$html[
'header'],
$html[
'content']);
397 foreach ($attach as $desc)
if (
MIME4::isset_header($desc[
'header'],
'content-disposition',
'inline', $debug))
$body[] = sprintf($bstr, $boundary2, $desc[
'header'], $desc[
'content']);
398 $body[] =
'--'.$boundary2.
'--';
399 foreach ($attach as $desc)
if (
MIME4::isset_header($desc[
'header'],
'content-disposition',
'attachment', $debug))
$body[] = sprintf($bstr, $boundary1, $desc[
'header'], $desc[
'content']);
400 $body[] =
'--'.$boundary1.
'--';
401 }
else if ($disp[
'inline']) {
402 $header[] = sprintf($hstr,
'related', $boundary1);
403 $body[] = sprintf($bstr, $boundary1,
$html[
'header'],
$html[
'content']);
404 foreach ($attach as $desc)
$body[] = sprintf($bstr, $boundary1, $desc[
'header'], $desc[
'content']);
405 $body[] =
'--'.$boundary1.
'--';
406 }
else if ($disp[
'attachment']) {
407 $header[] = sprintf($hstr,
'mixed', $boundary1);
408 $body[] = sprintf($bstr, $boundary1,
$html[
'header'],
$html[
'content']);
409 foreach ($attach as $desc)
$body[] = sprintf($bstr, $boundary1, $desc[
'header'], $desc[
'content']);
410 $body[] =
'--'.$boundary1.
'--';
415 $header[] =
$text[
'header'];
418 $header[] =
$html[
'header'];
422 $header[] =
'MIME-Version: 1.0';
423 return array(
'header' => implode($end, $header),
'content' => implode($end,
$body));
427 function isset_header($str = null, $name = null, $value = null, $debug = null) {
430 if (!(is_string($str) && $str !=
'')) $err[] =
'invalid header type';
431 if (!(is_string($name) && strlen($name) > 1 &&
FUNC4::is_alpha($name,
true,
'-'))) $err[] =
'invalid name type';
432 if ($value != null && !is_string($value)) $err[] =
'invalid value type';
433 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
437 foreach ($exp as $harr) {
438 if (strtolower($harr[
'name']) == strtolower($name)) {
439 if ($value != null) $ret = (strtolower($harr[
'value']) == strtolower($value)) ? $harr[
'value'] :
false;
440 else $ret = $harr[
'value'];
451 if (!(is_string($str) && $str !=
''))
FUNC4::trace($debug,
'invalid header value');
453 $str = str_replace(array(
";\r\n\t",
"; \r\n\t",
";\r\n ",
"; \r\n "),
'; ', $str);
454 $str = str_replace(array(
";\n\t",
"; \n\t",
";\n ",
"; \n "),
'; ', $str);
455 $str = str_replace(array(
"\r\n\t",
"\r\n "),
'', $str);
456 $str = str_replace(array(
"\n\t",
"\n "),
'', $str);
458 foreach (explode(
"\n", $str) as $line) {
461 if (count($exp1 = explode(
':', $line, 2)) == 2) {
462 $name = rtrim($exp1[0]);
463 $val1 = ltrim($exp1[1]);
464 if (strlen($name) > 1 &&
FUNC4::is_alpha($name,
true,
'-') && $val1 !=
'') {
465 $name = ucfirst($name);
467 if (substr(strtolower($name), 0, 8) ==
'content-') {
468 $exp2 = explode(
'; ', $val1);
469 $cnt2 = count($exp2);
471 for ($i = 1; $i < $cnt2; $i++) {
472 if (count($exp3 = explode(
'=', $exp2[$i], 2)) == 2) {
473 $hset = trim($exp3[0]);
474 $hval = trim($exp3[1],
' "');
475 if ($hset !=
'' && $hval !=
'') $hadd[strtolower($hset)] = $hval;
480 $val2 = (count($hadd) > 0) ? trim($exp2[0]) : $val1;
481 $arr[] = array(
'name' => $name,
'value' => $val2,
'content' => $hadd);
486 if (count($arr) > 0)
return $arr;
493 if (!(is_string($str) && $str !=
''))
FUNC4::trace($debug,
'invalid message value');
496 if (strpos($str,
"\r\n\r\n")) $ret = explode(
"\r\n\r\n", $str, 2);
497 else if (strpos($str,
"\n\n")) $ret = explode(
"\n\n", $str, 2);
498 if ($ret)
return array(
'header' => trim($ret[0]),
'content' => $ret[1]);
505 $headers =
$body =
false;
508 $type = $boundary =
false;
509 foreach ($harr as $hnum) {
510 if (strtolower($hnum[
'name']) ==
'content-type') {
511 $type = strtolower($hnum[
'value']);
512 foreach ($hnum[
'content'] as $hnam => $hval) {
513 if (strtolower($hnam) ==
'boundary') {
518 if ($boundary)
break;
523 if (substr($type, 0, strlen(
'multipart/')) ==
'multipart/' && $boundary && strstr($part[
'content'],
'--'.$boundary.
'--'))
$body =
MIME4::_parts($part[
'content'], $boundary, strtolower(substr($type, strlen(
'multipart/'))), $debug);
527 function _parts($str = null, $boundary = null, $multipart = null, $debug = null) {
530 if (!(is_string($str) && $str !=
'')) $err[] =
'invalid content value';
531 if (!(is_string($boundary) && $boundary !=
'')) $err[] =
'invalid boundary value';
532 if (!(is_string($multipart) && $multipart !=
'')) $err[] =
'invalid multipart value';
533 if (count($err) > 0)
FUNC4::trace($debug, implode(
', ', $err));
536 if (count($exp = explode(
'--'.$boundary.
'--', $str)) == 2) {
537 if (count($exp = explode(
'--'.$boundary, $exp[0])) > 2) {
539 foreach ($exp as
$split) {
543 $type = $newb =
false;
544 foreach ($harr as $hnum) {
545 if (strtolower($hnum[
'name']) ==
'content-type') {
546 $type = strtolower($hnum[
'value']);
547 foreach ($hnum[
'content'] as $hnam => $hval) {
548 if (strtolower($hnam) ==
'boundary') {
556 if (substr($type, 0, strlen(
'multipart/')) ==
'multipart/' && $newb && strstr($part[
'content'],
'--'.$newb.
'--')) $ret =
MIME4::_parts($part[
'content'], $newb, $multipart.
'|'.strtolower(substr($type, strlen(
'multipart/'))), $debug);
559 $res[
'multipart'] = $multipart;
573 if (!(is_string($str) && $str !=
''))
FUNC4::trace($debug,
'invalid content value');
578 $clen = strlen(
'content-');
580 foreach ($harr as $hnum) {
581 if (substr(strtolower($hnum[
'name']), 0, $clen) ==
'content-') {
582 $name = strtolower(substr($hnum[
'name'], $clen));
583 if ($name ==
'transfer-encoding') $encoding = strtolower($hnum[
'value']);
584 else if ($name ==
'id')
$body[$name] = array(
'value' => trim($hnum[
'value'],
'<>'),
'extra' => $hnum[
'content']);
585 else $body[$name] = array(
'value' => $hnum[
'value'],
'extra' => $hnum[
'content']);
588 if ($encoding ==
'base64' || $encoding ==
'quoted-printable')
$body[
'content'] =
MIME4::decode_content($part[
'content'], $encoding, $debug);
590 if ($encoding)
$body[
'transfer-encoding'] = $encoding;
591 $body[
'content'] = $part[
'content'];
593 if (substr(
$body[
'content'], -2) ==
"\r\n")
$body[
'content'] = substr(
$body[
'content'], 0, -2);
594 else if (substr(
$body[
'content'], -1) ==
"\n")
$body[
'content'] = substr(
$body[
'content'], 0, -1);
599 function fix_eol($str = null, $debug = null) {
601 if (!(is_string($str) && $str !=
''))
FUNC4::trace($debug,
'invalid content value');
604 $str = str_replace(
"\r\n",
"\n", $str);
605 $str = str_replace(
"\r",
"\n", $str);
606 if ($_mime->LE !=
"\n") $str = str_replace(
"\n", $_mime->LE, $str);