1 | <?php |
---|
2 | class imap_attachment |
---|
3 | { |
---|
4 | function get_attachment_info($mbox_stream, $msg_number) |
---|
5 | { |
---|
6 | $structure = imap_fetchstructure($mbox_stream,$msg_number,FT_UID); |
---|
7 | $contentParts = count($structure->parts); |
---|
8 | |
---|
9 | $msg_info['number_attachments'] = $contentParts -1; |
---|
10 | |
---|
11 | if($contentParts > 1) |
---|
12 | { |
---|
13 | for($i=1; $i<$contentParts; $i++) |
---|
14 | { |
---|
15 | $msg_info['attachment'][$i]['part_in_msg'] = ($i+1); |
---|
16 | $msg_info['attachment'][$i]['name'] = urlencode($structure->parts[$i]->dparameters[0]->value); |
---|
17 | $msg_info['attachment'][$i]['type'] = $structure->parts[$i]->subtype; |
---|
18 | $msg_info['attachment'][$i]['bytes'] = $structure->parts[$i]->bytes; |
---|
19 | } |
---|
20 | } |
---|
21 | return $msg_info; |
---|
22 | } |
---|
23 | |
---|
24 | function get_attachment_headerinfo($mbox, $msgno) |
---|
25 | { |
---|
26 | include_once("class.message_components.inc.php"); |
---|
27 | |
---|
28 | $msg =& new message_components($mbox); |
---|
29 | $msg->fetch_structure($msgno); |
---|
30 | |
---|
31 | $msg_info = array(); |
---|
32 | $msg_info['names'] = ''; |
---|
33 | |
---|
34 | $msg_info['number_attachments'] = count($msg->fname[$msgno]); |
---|
35 | |
---|
36 | if ($msg_info['number_attachments']) |
---|
37 | { |
---|
38 | foreach ($msg->fname[$msgno] as $fname) |
---|
39 | { |
---|
40 | $msg_info['names'] .= $this->flat_mime_decode($fname) . ', '; |
---|
41 | } |
---|
42 | } |
---|
43 | $msg_info['names'] = substr($msg_info['names'],0,(strlen($msg_info['names']) - 2)); |
---|
44 | |
---|
45 | return $msg_info; |
---|
46 | } |
---|
47 | |
---|
48 | function download_attachment($mbox, $msgno) |
---|
49 | { |
---|
50 | include_once("class.message_components.inc.php"); |
---|
51 | |
---|
52 | $msg =& new message_components($mbox); |
---|
53 | $msg->fetch_structure($msgno); |
---|
54 | $array_parts_attachments = array(); |
---|
55 | $array_parts_attachments['names'] = ''; |
---|
56 | |
---|
57 | //print_r($msg->fname[$msgno]); |
---|
58 | |
---|
59 | if (count($msg->fname[$msgno]) > 0) |
---|
60 | { |
---|
61 | $i = 0; |
---|
62 | foreach ($msg->fname[$msgno] as $index=>$fname) |
---|
63 | { |
---|
64 | $array_parts_attachments[$i]['pid'] = $msg->pid[$msgno][$index]; |
---|
65 | $array_parts_attachments[$i]['name'] = $this->decode_mimeheader($fname); |
---|
66 | //$array_parts_attachments[$i]['name'] = $this->flat_mime_decode($fname); |
---|
67 | $array_parts_attachments[$i]['name'] = $array_parts_attachments[$i]['name'] ? $array_parts_attachments[$i]['name'] : "attachment.bin"; |
---|
68 | $array_parts_attachments[$i]['encoding'] = $msg->encoding[$msgno][$index]; |
---|
69 | $array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', '; |
---|
70 | $array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index]; |
---|
71 | $i++; |
---|
72 | } |
---|
73 | } |
---|
74 | $array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); |
---|
75 | return $array_parts_attachments; |
---|
76 | } |
---|
77 | |
---|
78 | function decode_mimeheader($string) { |
---|
79 | return mb_decode_mimeheader($string); |
---|
80 | } |
---|
81 | function flat_mime_decode($string) { |
---|
82 | $array = imap_mime_header_decode($string); |
---|
83 | $str = ""; |
---|
84 | foreach ($array as $key => $part) |
---|
85 | $str .= @eregi_replace("\{", "[",@eregi_replace("\}", "]",$part->text)); |
---|
86 | |
---|
87 | return $str; |
---|
88 | } |
---|
89 | } |
---|