source: trunk/expressoAdmin1_2/inc/class.imap_functions.inc.php @ 414

Revision 414, 7.9 KB checked in by niltonneto, 16 years ago (diff)

Alterações feitas por João Alfredo.
Email: jakjr@…

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2
3include_once('class.functions.inc.php');
4
5class imap_functions
6{
7        var $functions;
8        var $imap;
9        var $imapDelimiter;
10        var $imap_admin;
11        var $imap_passwd;
12        var $imap_server;
13        var $imap_port;
14    var $imap_trashfolder;
15    var $imap_sentfolder;
16    var $imap_draftsfolder;
17    var $imap_spamfolder;
18       
19        function imap_functions(){
20                $this->imap_admin       = $_SESSION['phpgw_info']['expresso']['email_server']['imapAdminUsername'];
21                $this->imap_passwd      = $_SESSION['phpgw_info']['expresso']['email_server']['imapAdminPW'];
22                $this->imap_server      = $_SESSION['phpgw_info']['expresso']['email_server']['imapServer'];
23                $this->imap_port        = $_SESSION['phpgw_info']['expresso']['email_server']['imapPort'];
24                $this->imap_trashfolder         = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultTrashFolder'];
25                $this->imap_sentfolder          = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultSentFolder'];
26                $this->imap_draftsfolder        = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultDraftsFolder'];
27                $this->imap_spamfolder          = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultSpamFolder'];
28                $this->imapDelimiter= $_SESSION['phpgw_info']['expresso']['email_server']['imapDelimiter'];
29                $this->imap             = imap_open('{'.$this->imap_server.':'.$this->imap_port.'/novalidate-cert}', $this->imap_admin, $this->imap_passwd, OP_HALFOPEN);
30                $this->functions        = new functions;
31        }
32       
33        function create($uid, $mailquota)
34        {
35                if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid))
36                {
37                        $error = imap_errors();
38                        if ($error[0] == 'Mailbox already exists')
39                        {
40                                $result['status'] = true;
41                        }
42                        else
43                        {
44                                $result['status'] = false;
45                                $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(INBOX) ($uid):" . $error[0];
46                        }
47                        return $result;
48                }
49                if ( (!empty($this->imap_sentfolder)) && (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_sentfolder)) )
50                {
51                        $error = imap_errors();
52                        $result['status'] = false;
53                        $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_sentfolder."):" . $error[0];
54                        return $result;
55                }
56                if ( (!empty($this->imap_draftsfolder)) && (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_draftsfolder)) )
57                {
58                        $error = imap_errors();
59                        $result['status'] = false;
60                        $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_draftsfolder."):" . $error[0];
61                        return $result;
62                }
63                if ( (!empty($this->imap_trashfolder)) && (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_trashfolder)) )
64                {
65                        $error = imap_errors();
66                        $result['status'] = false;
67                        $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_trashfolder."):" . $error[0];
68                        return $result;
69                }
70                if (!empty($this->imap_sentfolder))
71                {
72                    if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_spamfolder))
73                        {
74                            $error = imap_errors();
75                            $result['status'] = false;
76                            $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_spamfolder."):" . $error[0];
77                            return $result;
78                        }
79                }
80
81                if (!imap_set_quota($this->imap,"user" . $this->imapDelimiter . $uid, ($mailquota*1024)))
82                {
83                        $error = imap_errors();
84                        $result['status'] = false;
85                        $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(imap_set_quota):" . $error[0];
86                        return $result;
87                }
88               
89                $result['status'] = true;
90                return $result;
91        }
92       
93        function get_user_info($uid)
94        {
95                $get_quota = @imap_get_quotaroot($this->imap,"user" . $this->imapDelimiter . $uid);
96               
97                if (count($get_quota) == 0)
98                {
99                        $quota['mailquota'] = '-1';
100                        $quota['mailquota_used'] = '-1';
101                }       
102                else
103                {
104                        $quota['mailquota'] = round (($get_quota['limit'] / 1024), 2);
105                        $quota['mailquota_used'] = round (($get_quota['usage'] / 1024), 2);
106                }
107                       
108                return $quota;
109        }
110       
111        function change_user_quota($uid, $quota)
112        {
113                $set_quota = imap_set_quota($this->imap,"user" . $this->imapDelimiter . $uid, ($quota*1024));
114                return true;
115        }
116       
117        function delete_user($uid)
118        {
119                $result['status'] = true;
120               
121                //Seta acl imap para poder deletar o user.
122                // Esta sem tratamento de erro, pois o retorno da funcao deve ter um bug.
123                imap_setacl($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, 'c');
124               
125                if (!imap_deletemailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid))
126                {
127                        $result['status'] = false;
128                        $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->delete_user.\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
129                }
130               
131                return $result;
132        }
133       
134        function rename_mailbox($old_mailbox, $new_mailbox)
135        {
136                $quota = @imap_get_quotaroot($this->imap, '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $old_mailbox);
137                $limit = $quota['STORAGE']['limit'];
138               
139                @imap_set_quota($this->imap, '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $old_mailbox, -1);
140                       
141                $result_rename = @imap_renamemailbox($this->imap,
142                                                '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $old_mailbox,
143                                                '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $new_mailbox);
144               
145                @imap_set_quota($this->imap, '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $new_mailbox, $limit);
146               
147                if (!$result_rename)
148                {
149                        $result['status'] = false;
150                        $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->rename_mailbox.\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
151                }
152                else
153                {
154                        $result['status'] = true;
155                }
156               
157                return $result;
158        }
159       
160        function empty_inbox($params)
161        {
162                // Verifica o acesso do gerente
163                if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_user_inbox'))
164                {
165                        $result['status'] = false;
166                        $result['msg'] = $this->functions->lang('You do not have access to clean an user inbox');
167                        return $result;
168                }
169               
170                if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes')
171                {
172                        $imap_options = '/tls/novalidate-cert';
173                }
174                else
175                {
176                        $imap_options = '/notls/novalidate-cert';
177                }
178
179               
180                $result['status'] = true;
181                $uid = $params['uid'];
182               
183                $return_setacl = imap_setacl($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, 'lrswipcda');
184               
185                if ($return_setacl)
186                {
187                        $mbox_stream = imap_open('{'.$this->imap_server.':'.$this->imap_port.$imap_options .'}user'. $this->imapDelimiter . $uid, $this->imap_admin, $this->imap_passwd);
188                       
189                        $check = imap_mailboxmsginfo($mbox_stream);
190                        $inbox_size = (string)(round ((($check->Size)/(1024*1024)), 2));
191                       
192                        $return_imap_delete = imap_delete($mbox_stream,'1:*');
193                        imap_close($mbox_stream, CL_EXPUNGE);
194                       
195                        imap_setacl ($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, '');
196                       
197                        if ($return_imap_delete)
198                        {
199                                $result['inbox_size'] = $inbox_size;
200                               
201                                $get_user_quota = @imap_get_quotaroot($this->imap,"user" . $this->imapDelimiter . $uid);
202                                $result['mailquota_used'] = (string)(round(($get_user_quota['usage']/1024), 2));
203                        }
204                        else
205                        {
206                                $result['status'] = false;
207                                $result['msg'] = $this->functions->lang('It was not possible clean the users inbox') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
208                        }
209                }
210                else
211                {
212                        $result['status'] = false;
213                        $result['msg'] = $this->functions->lang('It was not possible to modify the users acl') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
214                }
215                return $result;
216        }
217}
Note: See TracBrowser for help on using the repository browser.