source: sandbox/webservice/api/rest/mail/RenameFolderResource.php @ 7489

Revision 7489, 1.3 KB checked in by alexandrecorreia, 11 years ago (diff)

Ticket #2507 - Emparelhando os codigos do servidor de produção com o sandbox.

  • Property svn:executable set to *
RevLine 
[6155]1<?php
2
3class RenameFolderResource extends MailAdapter {
4        public function post($request){
5                // to Receive POST Params (use $this->params)
6                parent::post($request);
7
8                if($this-> isLoggedIn())
9                {
[7489]10                        $old_id  = mb_convert_encoding($this->getParam('folderID'), "UTF-8", "ISO-8859-1");
[7469]11                        $new_name = mb_convert_encoding($this->getParam('folderName'), "UTF-8", "ISO-8859-1");
[6155]12
[7489]13                        if(!$this->getImap()->folder_exists(mb_convert_encoding($old_id, "UTF7-IMAP", "UTF-8")))
[6165]14                                Errors::runException("MAIL_INVALID_OLD_FOLDER");
[7489]15 
[6155]16                        $default_folders = array_keys($this->defaultFolders);
17                        if(in_array($old_id, $default_folders))
[6165]18                                Errors::runException("MAIL_INVALID_OLD_FOLDER");
[6155]19
20                        if(empty($new_name) || preg_match('/[\/\\\!\@\#\$\%\&\*\(\)]/', $new_name))
[6165]21                                Errors::runException("MAIL_INVALID_NEW_FOLDER_NAME");
[6155]22
23                        $old_id_arr = explode($this->getImap()->imap_delimiter, $old_id);
24
25                        $new_id     = implode($this->getImap()->imap_delimiter, array_slice($old_id_arr, 0, count($old_id_arr) - 1)) . $this->getImap()->imap_delimiter . $new_name;
26
27                        $params['current'] = $old_id;
28                        $params['rename']  = $new_id;
29
30                        $result = $this->getImap()->ren_mailbox($params);
31                        if($result != 'Ok')
[6165]32                                Errors::runException("MAIL_FOLDER_NOT_RENAMED");
[6155]33                }
34
35                $this->setResult(array('folderID' => $new_id));
36
37                //to Send Response (JSON RPC format)
38                return $this->getResponse();
39        }
40
41}
Note: See TracBrowser for help on using the repository browser.