Revision 7306,
1.2 KB
checked in by alexandrecorreia, 12 years ago
(diff) |
Ticket #3093 - Integração da API REST.
|
-
Property svn:executable set to
*
|
Rev | Line | |
---|
[7306] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class 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 | { |
---|
| 10 | $old_id = $this->getParam('folderID'); |
---|
| 11 | $new_name = $this->getParam('folderName'); |
---|
| 12 | |
---|
| 13 | if(!$this->getImap()->folder_exists($old_id)) |
---|
| 14 | Errors::runException("MAIL_INVALID_OLD_FOLDER"); |
---|
| 15 | |
---|
| 16 | $default_folders = array_keys($this->defaultFolders); |
---|
| 17 | if(in_array($old_id, $default_folders)) |
---|
| 18 | Errors::runException("MAIL_INVALID_OLD_FOLDER"); |
---|
| 19 | |
---|
| 20 | if(empty($new_name) || preg_match('/[\/\\\!\@\#\$\%\&\*\(\)]/', $new_name)) |
---|
| 21 | Errors::runException("MAIL_INVALID_NEW_FOLDER_NAME"); |
---|
| 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') |
---|
| 32 | Errors::runException("MAIL_FOLDER_NOT_RENAMED"); |
---|
| 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.