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

Revision 438, 8.5 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->functions        = new functions;
21                $this->imap_admin       = $_SESSION['phpgw_info']['expresso']['email_server']['imapAdminUsername'];
22                $this->imap_passwd      = $_SESSION['phpgw_info']['expresso']['email_server']['imapAdminPW'];
23                $this->imap_server      = $_SESSION['phpgw_info']['expresso']['email_server']['imapServer'];
24                $this->imap_port        = $_SESSION['phpgw_info']['expresso']['email_server']['imapPort'];
25                $this->imap_trashfolder  = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultTrashFolder']  ? $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultTrashFolder']  : str_replace("*","", $this->functions->lang("trash"));
26                $this->imap_sentfolder   = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultSentFolder']   ? $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultSentFolder']   : str_replace("*","", $this->functions->lang("sent"));
27                $this->imap_draftsfolder = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultDraftsFolder'] ? $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultDraftsFolder'] : str_replace("*","", $this->functions->lang("drafts"));
28                $this->imap_spamfolder   = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultSpamFolder']   ? $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultSpamFolder']   : str_replace("*","", $this->functions->lang("spam"));
29                $this->imapDelimiter= $_SESSION['phpgw_info']['expresso']['email_server']['imapDelimiter'];
30                $this->imap             = imap_open('{'.$this->imap_server.':'.$this->imap_port.'/novalidate-cert}', $this->imap_admin, $this->imap_passwd, OP_HALFOPEN);
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                /* Esperando correção do william (prognus) sobre a utilização do DSPAM
71                if (!empty($this->imap_sentfolder))
72                {
73                    if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_spamfolder))
74                        {
75                            $error = imap_errors();
76                            $result['status'] = false;
77                            $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_spamfolder."):" . $error[0];
78                            return $result;
79                        }
80                }
81                */
82
83                if (!imap_set_quota($this->imap,"user" . $this->imapDelimiter . $uid, ($mailquota*1024)))
84                {
85                        $error = imap_errors();
86                        $result['status'] = false;
87                        $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(imap_set_quota):" . $error[0];
88                        return $result;
89                }
90               
91                $result['status'] = true;
92                return $result;
93        }
94       
95        function get_user_info($uid)
96        {
97                $get_quota = @imap_get_quotaroot($this->imap,"user" . $this->imapDelimiter . $uid);
98               
99                if (count($get_quota) == 0)
100                {
101                        $quota['mailquota'] = '-1';
102                        $quota['mailquota_used'] = '-1';
103                }       
104                else
105                {
106                        $quota['mailquota'] = round (($get_quota['limit'] / 1024), 2);
107                        $quota['mailquota_used'] = round (($get_quota['usage'] / 1024), 2);
108                }
109                       
110                return $quota;
111        }
112       
113        function change_user_quota($uid, $quota)
114        {
115                $set_quota = imap_set_quota($this->imap,"user" . $this->imapDelimiter . $uid, ($quota*1024));
116                return true;
117        }
118       
119        function delete_user($uid)
120        {
121                $result['status'] = true;
122               
123                //Seta acl imap para poder deletar o user.
124                // Esta sem tratamento de erro, pois o retorno da funcao deve ter um bug.
125                imap_setacl($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, 'c');
126               
127                if (!imap_deletemailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid))
128                {
129                        $result['status'] = false;
130                        $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->delete_user.\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
131                }
132               
133                return $result;
134        }
135       
136        function rename_mailbox($old_mailbox, $new_mailbox)
137        {
138                $quota = @imap_get_quotaroot($this->imap, '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $old_mailbox);
139                $limit = $quota['STORAGE']['limit'];
140               
141                @imap_set_quota($this->imap, '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $old_mailbox, -1);
142                       
143                $result_rename = @imap_renamemailbox($this->imap,
144                                                '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $old_mailbox,
145                                                '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $new_mailbox);
146               
147                @imap_set_quota($this->imap, '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $new_mailbox, $limit);
148               
149                if (!$result_rename)
150                {
151                        $result['status'] = false;
152                        $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->rename_mailbox.\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
153                }
154                else
155                {
156                        $result['status'] = true;
157                }
158               
159                return $result;
160        }
161       
162        function empty_inbox($params)
163        {
164                // Verifica o acesso do gerente
165                if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_user_inbox'))
166                {
167                        $result['status'] = false;
168                        $result['msg'] = $this->functions->lang('You do not have access to clean an user inbox');
169                        return $result;
170                }
171               
172                if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes')
173                {
174                        $imap_options = '/tls/novalidate-cert';
175                }
176                else
177                {
178                        $imap_options = '/notls/novalidate-cert';
179                }
180
181               
182                $result['status'] = true;
183                $uid = $params['uid'];
184               
185                $return_setacl = imap_setacl($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, 'lrswipcda');
186               
187                if ($return_setacl)
188                {
189                        $mbox_stream = imap_open('{'.$this->imap_server.':'.$this->imap_port.$imap_options .'}user'. $this->imapDelimiter . $uid, $this->imap_admin, $this->imap_passwd);
190                       
191                        $check = imap_mailboxmsginfo($mbox_stream);
192                        $inbox_size = (string)(round ((($check->Size)/(1024*1024)), 2));
193                       
194                        $return_imap_delete = imap_delete($mbox_stream,'1:*');
195                        imap_close($mbox_stream, CL_EXPUNGE);
196                       
197                        imap_setacl ($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, '');
198                       
199                        if ($return_imap_delete)
200                        {
201                                $result['inbox_size'] = $inbox_size;
202                               
203                                $get_user_quota = @imap_get_quotaroot($this->imap,"user" . $this->imapDelimiter . $uid);
204                                $result['mailquota_used'] = (string)(round(($get_user_quota['usage']/1024), 2));
205                        }
206                        else
207                        {
208                                $result['status'] = false;
209                                $result['msg'] = $this->functions->lang('It was not possible clean the users inbox') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
210                        }
211                }
212                else
213                {
214                        $result['status'] = false;
215                        $result['msg'] = $this->functions->lang('It was not possible to modify the users acl') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
216                }
217                return $result;
218        }
219}
Note: See TracBrowser for help on using the repository browser.