[1036] | 1 | <?php |
---|
[5509] | 2 | /*************************************************************************** |
---|
| 3 | * Expresso Livre * |
---|
| 4 | * http://www.expressolivre.org * |
---|
| 5 | * -------------------------------------------- * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \**************************************************************************/ |
---|
| 11 | |
---|
[2] | 12 | class imap_attachment |
---|
| 13 | { |
---|
| 14 | function get_attachment_info($mbox_stream, $msg_number) |
---|
| 15 | { |
---|
| 16 | $structure = imap_fetchstructure($mbox_stream,$msg_number,FT_UID); |
---|
| 17 | $contentParts = count($structure->parts); |
---|
| 18 | |
---|
| 19 | $msg_info['number_attachments'] = $contentParts -1; |
---|
| 20 | |
---|
| 21 | if($contentParts > 1) |
---|
| 22 | { |
---|
| 23 | for($i=1; $i<$contentParts; $i++) |
---|
| 24 | { |
---|
| 25 | $msg_info['attachment'][$i]['part_in_msg'] = ($i+1); |
---|
| 26 | $msg_info['attachment'][$i]['name'] = urlencode($structure->parts[$i]->dparameters[0]->value); |
---|
| 27 | $msg_info['attachment'][$i]['type'] = $structure->parts[$i]->subtype; |
---|
| 28 | $msg_info['attachment'][$i]['bytes'] = $structure->parts[$i]->bytes; |
---|
| 29 | } |
---|
| 30 | } |
---|
| 31 | return $msg_info; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | function get_attachment_headerinfo($mbox, $msgno) |
---|
| 35 | { |
---|
| 36 | include_once("class.message_components.inc.php"); |
---|
| 37 | |
---|
[5134] | 38 | $msg = new message_components($mbox); |
---|
[2] | 39 | $msg->fetch_structure($msgno); |
---|
| 40 | |
---|
| 41 | $msg_info = array(); |
---|
| 42 | $msg_info['names'] = ''; |
---|
| 43 | |
---|
| 44 | $msg_info['number_attachments'] = count($msg->fname[$msgno]); |
---|
| 45 | |
---|
| 46 | if ($msg_info['number_attachments']) |
---|
| 47 | { |
---|
| 48 | foreach ($msg->fname[$msgno] as $fname) |
---|
| 49 | { |
---|
| 50 | $msg_info['names'] .= $this->flat_mime_decode($fname) . ', '; |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | $msg_info['names'] = substr($msg_info['names'],0,(strlen($msg_info['names']) - 2)); |
---|
| 54 | |
---|
| 55 | return $msg_info; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | function download_attachment($mbox, $msgno) |
---|
| 59 | { |
---|
| 60 | include_once("class.message_components.inc.php"); |
---|
| 61 | |
---|
[5134] | 62 | $msg = new message_components($mbox); |
---|
[2] | 63 | $msg->fetch_structure($msgno); |
---|
| 64 | $array_parts_attachments = array(); |
---|
[3289] | 65 | //$array_parts_attachments['names'] = ''; |
---|
[2] | 66 | |
---|
| 67 | //print_r($msg->fname[$msgno]); |
---|
| 68 | |
---|
| 69 | if (count($msg->fname[$msgno]) > 0) |
---|
| 70 | { |
---|
| 71 | $i = 0; |
---|
| 72 | foreach ($msg->fname[$msgno] as $index=>$fname) |
---|
| 73 | { |
---|
| 74 | $array_parts_attachments[$i]['pid'] = $msg->pid[$msgno][$index]; |
---|
[271] | 75 | $array_parts_attachments[$i]['name'] = $this->decode_mimeheader($fname); |
---|
| 76 | //$array_parts_attachments[$i]['name'] = $this->flat_mime_decode($fname); |
---|
[2] | 77 | $array_parts_attachments[$i]['name'] = $array_parts_attachments[$i]['name'] ? $array_parts_attachments[$i]['name'] : "attachment.bin"; |
---|
| 78 | $array_parts_attachments[$i]['encoding'] = $msg->encoding[$msgno][$index]; |
---|
[3289] | 79 | //$array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', '; |
---|
[2] | 80 | $array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index]; |
---|
| 81 | $i++; |
---|
| 82 | } |
---|
| 83 | } |
---|
[3289] | 84 | //$array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); |
---|
[2] | 85 | return $array_parts_attachments; |
---|
| 86 | } |
---|
| 87 | |
---|
[271] | 88 | function decode_mimeheader($string) { |
---|
| 89 | return mb_decode_mimeheader($string); |
---|
| 90 | } |
---|
[2] | 91 | function flat_mime_decode($string) { |
---|
| 92 | $array = imap_mime_header_decode($string); |
---|
| 93 | $str = ""; |
---|
| 94 | foreach ($array as $key => $part) |
---|
[6037] | 95 | $str .= @preg_replace('/\{\/i', '['',@preg_replace('\/\}/i', ']',$part->text)); |
---|
[2] | 96 | |
---|
| 97 | return $str; |
---|
| 98 | } |
---|
| 99 | } |
---|