[3471] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | include_once('class.functions.inc.php');
|
---|
| 4 |
|
---|
| 5 | class 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 | // $this->imap = imap_open('{'.$this->imap_server.':'.$this->imap_port, $this->imap_admin, $this->imap_passwd, OP_HALFOPEN);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | function create($uid, $mailquota)
|
---|
| 35 | {
|
---|
| 36 | if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid))
|
---|
| 37 | {
|
---|
| 38 | $error = imap_errors();
|
---|
| 39 | if ($error[0] == 'Mailbox already exists')
|
---|
| 40 | {
|
---|
| 41 | $result['status'] = true;
|
---|
| 42 | }
|
---|
| 43 | else
|
---|
| 44 | {
|
---|
| 45 | $result['status'] = false;
|
---|
| 46 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(INBOX) ($uid):" . $error[0];
|
---|
| 47 | }
|
---|
| 48 | return $result;
|
---|
| 49 | }
|
---|
| 50 | if ( (!empty($this->imap_sentfolder)) && (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_sentfolder)) )
|
---|
| 51 | {
|
---|
| 52 | $error = imap_errors();
|
---|
| 53 | $result['status'] = false;
|
---|
| 54 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_sentfolder."):" . $error[0];
|
---|
| 55 | return $result;
|
---|
| 56 | }
|
---|
| 57 | if ( (!empty($this->imap_draftsfolder)) && (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_draftsfolder)) )
|
---|
| 58 | {
|
---|
| 59 | $error = imap_errors();
|
---|
| 60 | $result['status'] = false;
|
---|
| 61 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_draftsfolder."):" . $error[0];
|
---|
| 62 | return $result;
|
---|
| 63 | }
|
---|
| 64 | if ( (!empty($this->imap_trashfolder)) && (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_trashfolder)) )
|
---|
| 65 | {
|
---|
| 66 | $error = imap_errors();
|
---|
| 67 | $result['status'] = false;
|
---|
| 68 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_trashfolder."):" . $error[0];
|
---|
| 69 | return $result;
|
---|
| 70 | }
|
---|
| 71 | /* Esperando correção do william (prognus) sobre a utilização do DSPAM
|
---|
| 72 | if (!empty($this->imap_sentfolder))
|
---|
| 73 | {
|
---|
| 74 | if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_spamfolder))
|
---|
| 75 | {
|
---|
| 76 | $error = imap_errors();
|
---|
| 77 | $result['status'] = false;
|
---|
| 78 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_spamfolder."):" . $error[0];
|
---|
| 79 | return $result;
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 | */
|
---|
| 83 |
|
---|
| 84 | if (!imap_set_quota($this->imap,"user" . $this->imapDelimiter . $uid, ($mailquota*1024)))
|
---|
| 85 | {
|
---|
| 86 | $error = imap_errors();
|
---|
| 87 | $result['status'] = false;
|
---|
| 88 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(imap_set_quota):" . $error[0];
|
---|
| 89 | return $result;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | $result['status'] = true;
|
---|
| 93 | return $result;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | function get_user_info($uid)
|
---|
| 97 | {
|
---|
| 98 | $get_quota = @imap_get_quotaroot($this->imap,"user" . $this->imapDelimiter . $uid);
|
---|
| 99 |
|
---|
| 100 | if (count($get_quota) == 0)
|
---|
| 101 | {
|
---|
| 102 | $quota['mailquota'] = '-1';
|
---|
| 103 | $quota['mailquota_used'] = '-1';
|
---|
| 104 | }
|
---|
| 105 | else
|
---|
| 106 | {
|
---|
| 107 | $quota['mailquota'] = round (($get_quota['limit'] / 1024), 2);
|
---|
| 108 | $quota['mailquota_used'] = round (($get_quota['usage'] / 1024), 2);
|
---|
| 109 | }
|
---|
| 110 | return $quota;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | function change_user_quota($uid, $quota)
|
---|
| 114 | {
|
---|
| 115 | $result['status'] = true;
|
---|
| 116 |
|
---|
| 117 | if (!imap_set_quota($this->imap,"user" . $this->imapDelimiter . $uid, ($quota*1024)) )
|
---|
| 118 | {
|
---|
| 119 | $result['status'] = false;
|
---|
| 120 | $result['msg'] = $this->functions->lang('it was not possible to change users mailbox quota') . ".\n";
|
---|
| 121 | $result['msg'] .= $this->functions->lang('Server returns') . ': ' . imap_last_error();
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | return $result;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | function delete_user($uid)
|
---|
| 128 | {
|
---|
| 129 | $result['status'] = true;
|
---|
| 130 |
|
---|
| 131 | //Seta acl imap para poder deletar o user.
|
---|
| 132 | // Esta sem tratamento de erro, pois o retorno da funcao deve ter um bug.
|
---|
| 133 | imap_setacl($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, 'c');
|
---|
| 134 |
|
---|
| 135 | if (!imap_deletemailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid))
|
---|
| 136 | {
|
---|
| 137 | $result['status'] = false;
|
---|
| 138 | $result['msg'] = $this->functions->lang('it was not possible to delete users mailbox') . ".\n";
|
---|
| 139 | $result['msg'] .= $this->functions->lang('Server returns') . ': ' . imap_last_error();
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | return $result;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | function rename_mailbox($old_mailbox, $new_mailbox)
|
---|
| 146 | {
|
---|
| 147 | $result['status'] = true;
|
---|
| 148 |
|
---|
| 149 | if (!$quota = @imap_get_quotaroot($this->imap, 'user' . $this->imapDelimiter . $old_mailbox))
|
---|
| 150 | {
|
---|
| 151 | $result['status'] = false;
|
---|
| 152 | $result['msg'] = $this->functions->lang("Error getting user quota. Process aborted.\n") . $this->functions->lang('Server returns') . ': ' . imap_last_error();
|
---|
| 153 | return $result;
|
---|
| 154 | }
|
---|
| 155 | $limit = $quota['STORAGE']['limit'];
|
---|
| 156 | $usage = $quota['STORAGE']['usage'];
|
---|
| 157 |
|
---|
| 158 | if ($usage >= $limit)
|
---|
| 159 | {
|
---|
| 160 | if (! @imap_set_quota($this->imap, 'user' . $this->imapDelimiter . $old_mailbox, (int)($usage+10240)) )
|
---|
| 161 | {
|
---|
| 162 | $result['status'] = false;
|
---|
| 163 | $result['msg'] = $this->functions->lang("Error increasing user quota. Process aborted.\n") . $this->functions->lang('Server returns') . ': ' . imap_last_error();
|
---|
| 164 | return $result;
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | if (! @imap_renamemailbox($this->imap,
|
---|
| 170 | '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $old_mailbox,
|
---|
| 171 | '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $new_mailbox) )
|
---|
| 172 | {
|
---|
| 173 | $result['status'] = false;
|
---|
| 174 | $result['msg'] = $this->functions->lang('Server returns') . ': ' . imap_last_error();
|
---|
| 175 |
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 |
|
---|
| 179 | if ($usage >= $limit)
|
---|
| 180 | {
|
---|
| 181 | if (! @imap_set_quota($this->imap, 'user' . $this->imapDelimiter . $new_mailbox, (int)($limit)) )
|
---|
| 182 | {
|
---|
| 183 | $result['status'] = false;
|
---|
| 184 | $result['msg'] .= $this->functions->lang("Error returning user quota.\n") . $this->functions->lang('Server returns') . ': ' . imap_last_error();
|
---|
| 185 |
|
---|
| 186 | @imap_renamemailbox($this->imap,
|
---|
| 187 | '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $new_mailbox,
|
---|
| 188 | '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $old_mailbox);
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | return $result;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | function empty_inbox($params)
|
---|
| 196 | {
|
---|
| 197 | // Verifica o acesso do gerente
|
---|
| 198 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_user_inbox'))
|
---|
| 199 | {
|
---|
| 200 | $result['status'] = false;
|
---|
| 201 | $result['msg'] = $this->functions->lang('You do not have access to clean an user inbox');
|
---|
| 202 | return $result;
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes')
|
---|
| 206 | {
|
---|
| 207 | $imap_options = '/tls/novalidate-cert';
|
---|
| 208 | }
|
---|
| 209 | else
|
---|
| 210 | {
|
---|
| 211 | $imap_options = '/notls/novalidate-cert';
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 |
|
---|
| 215 | $result['status'] = true;
|
---|
| 216 | $uid = $params['uid'];
|
---|
| 217 |
|
---|
| 218 | $return_setacl = imap_setacl($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, 'lrswipcda');
|
---|
| 219 |
|
---|
| 220 | if ($return_setacl)
|
---|
| 221 | {
|
---|
| 222 | $mbox_stream = imap_open('{'.$this->imap_server.':'.$this->imap_port.$imap_options .'}user'. $this->imapDelimiter . $uid, $this->imap_admin, $this->imap_passwd);
|
---|
| 223 |
|
---|
| 224 | $check = imap_mailboxmsginfo($mbox_stream);
|
---|
| 225 | $inbox_size = (string)(round ((($check->Size)/(1024*1024)), 2));
|
---|
| 226 |
|
---|
| 227 | $return_imap_delete = imap_delete($mbox_stream,'1:*');
|
---|
| 228 | imap_close($mbox_stream, CL_EXPUNGE);
|
---|
| 229 |
|
---|
| 230 | imap_setacl ($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, '');
|
---|
| 231 |
|
---|
| 232 | if ($return_imap_delete)
|
---|
| 233 | {
|
---|
| 234 | $result['inbox_size'] = $inbox_size;
|
---|
| 235 |
|
---|
| 236 | $get_user_quota = @imap_get_quotaroot($this->imap,"user" . $this->imapDelimiter . $uid);
|
---|
| 237 | $result['mailquota_used'] = (string)(round(($get_user_quota['usage']/1024), 2));
|
---|
| 238 | }
|
---|
| 239 | else
|
---|
| 240 | {
|
---|
| 241 | $result['status'] = false;
|
---|
| 242 | $result['msg'] = $this->functions->lang('It was not possible clean the users inbox') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 | else
|
---|
| 246 | {
|
---|
| 247 | $result['status'] = false;
|
---|
| 248 | $result['msg'] = $this->functions->lang('It was not possible to modify the users acl') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
|
---|
| 249 | }
|
---|
| 250 | return $result;
|
---|
| 251 | }
|
---|
| 252 | }
|
---|