-
Notifications
You must be signed in to change notification settings - Fork 0
/
pop3.php
49 lines (49 loc) · 1.68 KB
/
pop3.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
<?php
// the pop3 server, username, password, and port
require_once 'pop3.inc';
function extract_attachments($connection, $message_number) {
$attachments = array();
$structure = imap_fetchstructure($connection, $message_number);
$msg_parts = buildparts($structure);
$parts_array = explode("|", $msg_parts);
for ($sub_part = 0; $sub_part < count($parts_array); $sub_part++) {
$sub_part_array = explode("=", $parts_array[$sub_part]);
// $sub_part_array[0] - part number string (section)
// $sub_part_array[1] - encoding
$attachments[$sub_part] = imap_fetchbody($connection, $message_number, $sub_part_array[0]);
if ($sub_part_array[1] == 3) { // 3 = BASE64
$attachments[$sub_part] = base64_decode($attachments[$sub_part]);
}
if ($sub_part_array[1] == 4) { // 4 = QUOTED-PRINTABLE
$attachments[$sub_part] = quoted_printable_decode($attachments[$sub_part]);
}
}
return $attachments;
}
function buildparts(&$struct, $part_number = "") {
switch ($struct->type):
case 1: /* multipart */
$scan = array ();
$i = 1;
foreach ($struct->parts as $part)
$scan[] = buildparts ($part, $part_number.".".$i++);
return implode("|", $scan);
break;
/* case 2:
return "{".buildparts ($struct->parts[0], $part_number)."}"; */
default:
$str = substr($part_number, 1);
if (strlen($str) == 0 ) $str = "1";
return $str . "=" . $struct->encoding;
break;
endswitch;
}
function decode_imap_text($str){
$result = '';
$decode_header = imap_mime_header_decode($str);
foreach ($decode_header AS $obj) {
$result .= htmlspecialchars(rtrim($obj->text, "\t"));
}
return $result;
}
?>