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

Revision 5509, 3.4 KB checked in by gustavo, 12 years ago (diff)

Ticket #2488 - Adicionar cabecalho de licenca em arquivos que nao o possuem

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
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               
12class 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
38                $msg = new message_components($mbox);
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
62                $msg = new message_components($mbox);
63                $msg->fetch_structure($msgno);
64                $array_parts_attachments = array();             
65                //$array_parts_attachments['names'] = '';
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];
75                                $array_parts_attachments[$i]['name'] = $this->decode_mimeheader($fname);
76                                //$array_parts_attachments[$i]['name'] = $this->flat_mime_decode($fname);
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];
79                                //$array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', ';
80                                $array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index];
81                                $i++;
82                        }
83                }
84                //$array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2));
85                return $array_parts_attachments;
86        }
87       
88        function decode_mimeheader($string) {
89        return mb_decode_mimeheader($string);
90    }
91        function flat_mime_decode($string) {
92                $array = imap_mime_header_decode($string);
93                $str = "";
94                foreach ($array as $key => $part)
95                        $str .= @eregi_replace("\{", "[",@eregi_replace("\}", "]",$part->text));
96               
97                return $str;
98        }
99}
Note: See TracBrowser for help on using the repository browser.