- Timestamp:
- 06/13/12 09:30:36 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.3/expressoMail1_2/inc/class.imap_functions.inc.php
r6340 r6474 360 360 //reconstrói o email 361 361 $email = implode("", file($params['FILES'][0]['tmp_name'])); 362 $email = preg_replace('/(?<!\r)\n/', "\r\n", $email);363 362 //coloca o email na pasta selecionada 364 363 $status = @imap_append($this->mbox, $folder, $email); … … 1092 1091 $msg->encoding[ $msg_number ][ $values ] = 'quoted-printable'; 1093 1092 } 1094 /* 1093 1095 1094 $body = $this->decodeBody( 1096 1095 imap_fetchbody( 1097 1096 $this->mbox, 1098 1097 $msg_number, … … 1102 1101 $msg->encoding[ $msg_number ][ $values ], 1103 1102 $msg->charset[ $msg_number ][ $values ] 1104 ); 1105 */ 1106 $body = $this->decodeBody( 1107 imap_fetchbody( 1108 $this->mbox, 1109 $msg_number, 1110 $attachment['part_in_msg'] . ".1", 1111 FT_UID 1112 ), 1113 $msg->encoding[ $msg_number ][ $values ], 1114 $msg->charset[ $msg_number ][ $values ] 1115 ); 1116 1103 ); 1104 1117 1105 if ( strtolower( $msg->structure[$msg_number]->parts[1]->parts[0]->subtype ) == 'plain' ) 1118 1106 { … … 1574 1562 $this->db = new db_functions(); 1575 1563 1576 // TODO: testar se existe um certificado no banco e verificar qual ï¿œo mais atual.1564 // TODO: testar se existe um certificado no banco e verificar qual é o mais atual. 1577 1565 if(!$certificado->dados['EXPIRADO'] && !$certificado->dados['REVOGADO'] && count($certificado->erros_ssl) < 1) 1578 1566 $this->db->insert_certificate(strtolower($certificado->dados['EMAIL']), $certificado->cert_assinante, $certificado->dados['SERIALNUMBER'], $certificado->dados['AUTHORITYKEYIDENTIFIER']); … … 1856 1844 $i = 0; 1857 1845 while (list($key, $val) = each($folders_list)) { 1858 $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); 1859 1860 //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); 1861 $tmp_folder_id = explode("}", $val->name ); 1862 1863 $tmp_folder_id[1] = mb_convert_encoding( $tmp_folder_id[1], "ISO-8859-1", "UTF7-IMAP" ); 1864 1865 if( $tmp_folder_id[1]=='INBOX'.$this->imap_delimiter.'decifradas') 1846 $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); 1847 1848 //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); 1849 $tmp_folder_id = explode("}", $val->name ); 1850 1851 $folderUser = trim( strpos( $tmp_folder_id[1], $this->imap_delimiter , 5 ) ); 1852 1853 $folderUser = trim( substr( $tmp_folder_id[1], 0, $folderUser ) ); 1854 1855 $Permission = true; 1856 1857 if( $folderUser != "INBOX" && $folderUser != "" ) 1866 1858 { 1867 continue;1859 $Permission = imap_getacl( $mbox_stream, $folderUser ); 1868 1860 } 1869 $result[$i]['folder_unseen'] = $status->unseen; 1870 $folder_id = $tmp_folder_id[1]; 1871 $result[$i]['folder_id'] = $folder_id; 1872 1873 $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); 1874 $result[$i]['folder_name'] = array_pop($tmp_folder_parent); 1875 $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; 1876 1877 if ($uid2cn && substr($folder_id,0,4) == 'user') { 1878 //$this->ldap = new ldap_functions(); 1879 if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])) { 1880 $result[$i]['folder_name'] = $cn; 1881 } 1882 } 1883 1884 $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); 1885 $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; 1886 1887 if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) 1888 $result[$i]['folder_hasChildren'] = 1; 1889 else 1890 $result[$i]['folder_hasChildren'] = 0; 1891 1892 switch ($tmp_folder_id[1]) { 1893 case $inbox: 1894 case $sent: 1895 case $drafts: 1896 case $spam: 1897 case $trash: 1898 $resultDefault[]=$result[$i]; 1899 break; 1900 default: 1901 $resultMine[]=$result[$i]; 1861 1862 if( $Permission ) 1863 { 1864 $tmp_folder_id[1] = mb_convert_encoding( $tmp_folder_id[1], "ISO-8859-1", "UTF7-IMAP" ); 1865 1866 if( $tmp_folder_id[1]=='INBOX'.$this->imap_delimiter.'decifradas') 1867 { 1868 continue; 1869 } 1870 $result[$i]['folder_unseen'] = $status->unseen; 1871 $folder_id = $tmp_folder_id[1]; 1872 $result[$i]['folder_id'] = $folder_id; 1873 1874 $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); 1875 $result[$i]['folder_name'] = array_pop($tmp_folder_parent); 1876 $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; 1877 1878 if ($uid2cn && substr($folder_id,0,4) == 'user') { 1879 //$this->ldap = new ldap_functions(); 1880 if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])) { 1881 $result[$i]['folder_name'] = $cn; 1882 } 1883 } 1884 1885 $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); 1886 $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; 1887 1888 if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) 1889 $result[$i]['folder_hasChildren'] = 1; 1890 else 1891 $result[$i]['folder_hasChildren'] = 0; 1892 1893 switch ($tmp_folder_id[1]) { 1894 case $inbox: 1895 case $sent: 1896 case $drafts: 1897 case $spam: 1898 case $trash: 1899 $resultDefault[]=$result[$i]; 1900 break; 1901 default: 1902 $resultMine[]=$result[$i]; 1903 } 1904 1902 1905 } 1903 1906 $i++; … … 3241 3244 else 3242 3245 $folder_id = "INBOX"; 3243 3246 3247 $folderQuotas = $this->get_folders_with_quota(); 3248 3244 3249 if(!$this->mbox || !is_resource($this->mbox)) 3245 3250 $this->mbox = $this->open_mbox(); … … 3269 3274 $quotaPercent = (($quotaPercent)* 100 + .5 )* .01; 3270 3275 } 3276 3271 3277 return array( 3272 3278 'quota_percent' => floor($quotaPercent), 3273 3279 'quota_used' => $quota_used, 3274 'quota_limit' => $quota_limit 3280 'quota_limit' => $quota_limit, 3281 'quota_folder' => $folderQuotas 3275 3282 ); 3283 3276 3284 } 3277 3285 else 3278 3286 return array(); 3279 3287 } 3288 3289 function get_quotaroot($params){ 3290 if(!$this->mbox || !is_resource($this->mbox)) 3291 $this->mbox = $this->open_mbox(); 3292 3293 $quota = imap_get_quotaroot($this->mbox, $params['folder']); 3294 if($this->mbox && is_resource($this->mbox)) 3295 imap_close($this->mbox); 3296 3297 if (!$quota){ 3298 return array( 3299 'quota_percent' => 0, 3300 'quota_used' => 0, 3301 'quota_limit' => 0, 3302 'quota_root' => '' 3303 ); 3304 } 3305 3306 // Additional Imap Class for not-implemented functions into PHP-IMAP extension. 3307 include_once("class.imapfp.inc.php"); 3308 $imapfp = new imapfp(); 3309 3310 if(!$imapfp->open($this->imap_server,$this->imap_port)) 3311 return $imapfp->get_error(); 3312 if (!$imapfp->login($this->username,$this->password)) 3313 return $imapfp->get_error(); 3314 3315 if ($imapfp->put_line($imapfp->tag." GETQUOTAROOT \"".$params['folder']."\"")) { 3316 $response=$imapfp->get_server_responce(); 3317 3318 if(substr($response,strpos($response,"$imapfp->tag ")+strlen($imapfp->tag)+1,2)!="OK") { 3319 $imapfp->error= "Error : $response !<br>"; 3320 return $imapfp->get_error(); 3321 } 3322 } 3323 else 3324 { 3325 $imapfp->error= "Error : Could not send User request. <br>"; 3326 return $imapfp->get_error(); 3327 } 3328 $response_array = split("\r\n", $response); 3329 array_pop($response_array); 3330 array_pop($response_array); 3331 array_shift($response_array); 3332 3333 $response_array[0]=substr($response_array[0],strpos($response_array[0],"QUOTAROOT")); 3334 $quota['quota_root']=substr(str_replace("\"","",$response_array[0]),/*strlen("QUOTAROOT ... ")=*/11+strlen($params['folder'])); 3335 $imapfp->close(); 3336 3337 if(count($quota) && $quota['limit']) { 3338 $quota_limit = $quota['limit']; 3339 $quota_used = $quota['usage']; 3340 $quota_root = $quota['quota_root']; 3341 if($quota_used >= $quota_limit) 3342 { 3343 $quotaPercent = 100; 3344 } 3345 else 3346 { 3347 $quotaPercent = ($quota_used / $quota_limit)*100; 3348 $quotaPercent = (($quotaPercent)* 100 + .5 )* .01; 3349 } 3350 return array( 3351 'quota_percent' => floor($quotaPercent), 3352 'quota_used' => $quota_used, 3353 'quota_limit' => $quota_limit, 3354 'quota_root' => $quota_root 3355 ); 3356 } 3357 else 3358 return array(); 3359 } 3280 3360 3281 3361 function send_notification($params){ … … 4056 4136 imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}".$folder)); 4057 4137 } 4058 4059 // string date ( string $format [, int $timestamp = time() ] )4060 // bool imap_append ( resource $imap_stream , string $mailbox , string $message [, string $options = NULL [, string $internal_date = NULL ]] )4061 // 'd-M-Y H:i:s O'4062 4063 $return = array();4064 4138 if($timestamp){ 4065 4139 $tempDir = $_SESSION['phpgw_info']['server']['temp_dir']; … … 4073 4147 $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $source, "\\Seen"); 4074 4148 } 4075 4076 if (!empty($return['command']))4077 {4078 list ($result, $msg) = explode(':',$return['command']);4079 if (strtoupper($result) === 'NO')4080 {4081 $return['error'] = $msg;4082 return $return;4083 }4084 }4085 4086 4149 $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 4087 4150 … … 4121 4184 if (version_compare(PHP_VERSION, '5.2.0', '>=')){ 4122 4185 if(!$source = base64_decode($source,true)) 4123 return "error ".$source."Espaï¿ œos ".$i;4186 return "error ".$source."Espaï¿?os ".$i; 4124 4187 4125 4188 } 4126 4189 else { 4127 4190 if(!$source = base64_decode($source)) 4128 return "error ".$source."Espaï¿ œos ".$i;4191 return "error ".$source."Espaï¿?os ".$i; 4129 4192 } 4130 4193 … … 4212 4275 { 4213 4276 $error[] = $ids[$index]; 4214 4277 } 4215 4278 else 4216 4279 { 4217 4280 $archived[] = $ids[$index]; 4218 4281 } 4219 4282 } 4220 4283 } … … 4223 4286 { 4224 4287 $return['error'] = $error; 4225 4288 } 4226 4289 if (!empty($archived)) 4227 4290 { 4228 4291 $return['archived'] = $archived; 4229 4292 } 4230 4293 4231 4294 return $return; 4232 4295 } … … 4257 4320 return $imapfp->get_error(); 4258 4321 4259 $data = array(); 4260 $quota_root = $this->get_quota(array('folder_id' => "INBOX")); 4261 $data["quota_root"] = $quota_root; 4322 $data = array(); 4323 $quota_root = $this->get_quota(array('folder_id' => "INBOX")); 4324 $data["quota_root"] = $quota_root; 4262 4325 4263 4326 foreach ($response_array as $idx=>$line) { … … 4266 4329 list($folder,$size) = explode(";",$line2); 4267 4330 $quota_used = str_replace(")","",$size); 4268 $quotaPercent = (($quota_used / 1024) / $data["quota_root"]["quota_limit"])*100; 4331 $quota=$this->get_quotaroot(array('folder' => $folder)); 4332 $hasquota=($quota['quota_root']!=""); 4333 $isroot=(strpos($quota['quota_root'],$folder)!==false); 4334 $quotaPercent = ($hasquota?(($quota_used / 1024) / $quota['quota_limit'])*100:0); 4269 4335 $folder = mb_convert_encoding($folder, "ISO_8859-1", "UTF7-IMAP"); 4270 4336 if(!preg_match('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i',$folder)){ … … 4274 4340 $folder = preg_replace('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i','', $folder); 4275 4341 4276 $data[$folder] = array("quota_percent" => sprintf("%.1f",round($quotaPercent,1)), "quota_used" => $quota_used);4342 $data[$folder] = array("quota_percent" => ($hasquota?sprintf("%.1f",round($quotaPercent,1)):''), "quota_used" => $quota_used, "quota_limit" => ($isroot && $folder!=$this->functions->getLang("Inbox")?$quota['quota_limit']:'')); 4277 4343 } 4278 4344 $imapfp->close(); 4279 4345 return $data; 4280 } 4346 } 4347 function get_folders_with_quota(){ 4348 4349 // Additional Imap Class for not-implemented functions into PHP-IMAP extension. 4350 include_once("class.imapfp.inc.php"); 4351 $imapfp = new imapfp(); 4352 4353 if(!$imapfp->open($this->imap_server,$this->imap_port)) 4354 return $imapfp->get_error(); 4355 if (!$imapfp->login( $this->username,$this->password )) 4356 return $imapfp->get_error(); 4357 4358 $response_array = $imapfp->get_mailboxes_size(); 4359 if ($imapfp->error) 4360 return $imapfp->get_error(); 4361 4362 $data = array(); 4363 4364 foreach ($response_array as $idx=>$line) { 4365 $line2 = str_replace('"', "", $line); 4366 $line2 = str_replace(" /vendor/cmu/cyrus-imapd/size (value.shared ",";",str_replace("* ANNOTATION ","",$line2)); 4367 list($folder,$size) = explode(";",$line2); 4368 $quota_used = str_replace(")","",$size); 4369 $quota=$this->get_quotaroot(array('folder' => $folder)); 4370 $hasquota=($quota['quota_limit']!=""); 4371 $isroot=(strpos($quota['quota_root'],$folder)!==false); 4372 if($isroot){ 4373 $quotaPercent = ($hasquota?(($quota_used / 1024) / $quota['quota_limit'])*100:0); 4374 $folder = mb_convert_encoding($folder, "ISO_8859-1", "UTF7-IMAP"); 4375 if(preg_match('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i',$folder)){ 4376 $folder = preg_replace('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i','', $folder); 4377 $data[$folder] = array("quota_percent" => ($hasquota?sprintf("%.1f",round($quotaPercent,1)):''), "quota_used" => $quota_used, "quota_limit" => ($isroot && $folder!=$this->functions->getLang("Inbox")?$quota['quota_limit']:'')); 4378 return $data; 4379 } 4380 4381 } 4382 } 4383 $imapfp->close(); 4384 return false; 4385 } 4386 4387 4281 4388 } 4282 4389 ?>
Note: See TracChangeset
for help on using the changeset viewer.