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

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

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

  • Property svn:executable set to *
Line 
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                {
10                        $old_id  = mb_convert_encoding($this->getParam('folderID'), "UTF-8", "ISO-8859-1");
11                        $new_name = mb_convert_encoding($this->getParam('folderName'), "UTF-8", "ISO-8859-1");
12
13                        if(!$this->getImap()->folder_exists(mb_convert_encoding($old_id, "UTF7-IMAP", "UTF-8")))
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.