[7306] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class FoldersResource 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 | $imap_folders = $this->getImap()->get_folders_list(); |
---|
| 11 | } |
---|
| 12 | if(!$imap_folders){ |
---|
| 13 | return $this->getResponse(); |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | $all_folders = array(); |
---|
| 17 | $user_folders = array(); |
---|
| 18 | $shared_folders = array(); |
---|
| 19 | |
---|
| 20 | foreach ($imap_folders as $i => $imap_folder) { |
---|
| 21 | if(is_int($i)) { |
---|
| 22 | $folder = array(); |
---|
| 23 | $folder['folderName'] = mb_convert_encoding($imap_folder['folder_name'], "UTF8", "ISO_8859-1"); |
---|
| 24 | if(strtoupper($folder['folderName']) == 'INBOX') { |
---|
| 25 | $folder['folderName'] = $this->getImap()->functions->getLang("Inbox"); |
---|
| 26 | } |
---|
| 27 | $folder['folderParentID'] = mb_convert_encoding($imap_folder['folder_parent'],'UTF8','ISO-8859-1'); |
---|
| 28 | $folder['folderHasChildren'] = $imap_folder['folder_hasChildren']; |
---|
| 29 | $folder['qtdUnreadMessages'] = $imap_folder['folder_unseen']; |
---|
| 30 | $folder['qtdMessages'] = $this->getImap()->get_num_msgs(array("folder" => $imap_folder['folder_id'])); |
---|
| 31 | $folder['folderID'] = mb_convert_encoding($imap_folder['folder_id'],'UTF8','ISO-8859-1'); |
---|
| 32 | |
---|
| 33 | if(substr($folder['folderID'], 0, 4) == 'user'){ |
---|
| 34 | $folder['folderType'] = "6"; |
---|
| 35 | $shared_folders[] = $folder; |
---|
| 36 | }else if(array_key_exists($folder['folderID'], $this->defaultFolders) !== false) { |
---|
| 37 | $folder_type = $this->defaultFolders[$folder['folderID']]; |
---|
| 38 | $folder['folderType'] = $folder_type; |
---|
| 39 | $default_folders[] = $folder; |
---|
| 40 | } |
---|
| 41 | else{ |
---|
| 42 | $folder['folderType'] = "5"; |
---|
| 43 | $user_folders[] = $folder; |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | $all_folders = array_merge($default_folders, $user_folders, $shared_folders); |
---|
| 49 | $quota_folders = $this->getImap()->get_quota_folders(); |
---|
| 50 | $search = $this->getParam('search') ? mb_convert_encoding($this->getParam('search'),"ISO_8859-1", "UTF8") : null; |
---|
| 51 | foreach($all_folders as $i => $folder){ |
---|
| 52 | $folder_name = mb_convert_encoding($folder['folderName'],"ISO_8859-1", "UTF8"); |
---|
| 53 | $folder_id = mb_convert_encoding($folder['folderID'],"ISO_8859-1", "UTF8"); |
---|
| 54 | if($folder_id == 'INBOX') { |
---|
| 55 | $j = $this->getImap()->functions->getLang("Inbox"); |
---|
| 56 | }else { |
---|
| 57 | $j = str_replace("INBOX".$this->getImap()->imap_delimiter,"",$folder_id); |
---|
| 58 | } |
---|
| 59 | $all_folders[$i]['diskSizeUsed'] = $quota_folders[$j]['quota_used']; |
---|
| 60 | $all_folders[$i]['diskSizePercent'] = $quota_folders[$j]['quota_percent']/100; |
---|
| 61 | if($search != null && stristr($folder_name, $search) == null){ |
---|
| 62 | unset($all_folders[$i]); |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | $result = array ( |
---|
| 67 | 'folders' => array_values($all_folders), |
---|
| 68 | 'diskSizeUsed' => $quota_folders['quota_root']['quota_used']*1024, |
---|
| 69 | 'diskSizeLimit' => $quota_folders['quota_root']['quota_limit']*1024, |
---|
| 70 | 'diskSizePercent' => $quota_folders['quota_root']['quota_percent']/100 |
---|
| 71 | ); |
---|
| 72 | |
---|
| 73 | $this->setResult($result); |
---|
| 74 | |
---|
| 75 | //to Send Response (JSON RPC format) |
---|
| 76 | return $this->getResponse(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | } |
---|