source: trunk/expressoMail1_2/inc/class.imap_attachment.inc.php @ 1040

Revision 1040, 2.9 KB checked in by amuller, 15 years ago (diff)

Ticket #559 - Atualização de download de arquivos e sessão

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