[2] | 1 | <?php |
---|
[1040] | 2 | |
---|
[2] | 3 | include_once("class.functions.inc.php"); |
---|
| 4 | include_once("class.ldap_functions.inc.php"); |
---|
[91] | 5 | include_once("class.exporteml.inc.php"); |
---|
| 6 | |
---|
[2] | 7 | class imap_functions |
---|
| 8 | { |
---|
| 9 | var $public_functions = array |
---|
[1472] | 10 | ( |
---|
[2] | 11 | 'get_range_msgs' => True, |
---|
| 12 | 'get_info_msg' => True, |
---|
[689] | 13 | 'get_info_msgs' => True, |
---|
[615] | 14 | 'get_folders_list' => True, |
---|
[1518] | 15 | 'import_msgs' => True, |
---|
| 16 | 'msgs_to_archive' => True |
---|
[2] | 17 | ); |
---|
| 18 | |
---|
| 19 | var $ldap; |
---|
| 20 | var $mbox; |
---|
| 21 | var $imap_port; |
---|
| 22 | var $has_cid; |
---|
| 23 | var $imap_options = ''; |
---|
| 24 | var $functions; |
---|
[3071] | 25 | var $prefs; |
---|
[650] | 26 | var $foldersLimit; |
---|
[1912] | 27 | var $imap_sentfolder; |
---|
[2] | 28 | |
---|
| 29 | function imap_functions (){ |
---|
[3226] | 30 | $this->foldersLimit = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['imap_max_folders'] ? $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['imap_max_folders'] : 20000; //Limit of folders (mailboxes) user can see |
---|
[2] | 31 | $this->username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 32 | $this->password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
| 33 | $this->imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 34 | $this->imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
| 35 | $this->imap_delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter']; |
---|
[1472] | 36 | $this->functions = new functions(); |
---|
[1912] | 37 | $this->imap_sentfolder = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] : str_replace("*","", $this->functions->getLang("Sent")); |
---|
[2] | 38 | $this->has_cid = false; |
---|
[3071] | 39 | $this->prefs = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']; |
---|
[1472] | 40 | |
---|
[3071] | 41 | |
---|
[2] | 42 | if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') |
---|
| 43 | { |
---|
| 44 | $this->imap_options = '/tls/novalidate-cert'; |
---|
| 45 | } |
---|
| 46 | else |
---|
| 47 | { |
---|
| 48 | $this->imap_options = '/notls/novalidate-cert'; |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | // BEGIN of functions. |
---|
[3391] | 52 | function open_mbox($folder = False,$force_die=true) |
---|
[2] | 53 | { |
---|
[4587] | 54 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); |
---|
[828] | 55 | if (is_resource($this->mbox)) |
---|
[3394] | 56 | { |
---|
| 57 | if ($force_die) |
---|
| 58 | { |
---|
| 59 | @imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); |
---|
| 60 | } |
---|
| 61 | else |
---|
| 62 | { |
---|
| 63 | @imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | else |
---|
| 67 | { |
---|
| 68 | if($force_die) |
---|
| 69 | { |
---|
| 70 | $this->mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); |
---|
| 71 | } |
---|
| 72 | else |
---|
| 73 | { |
---|
| 74 | $this->mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | } |
---|
| 78 | return $this->mbox; |
---|
[2] | 79 | } |
---|
| 80 | |
---|
[504] | 81 | function parse_error($error){ |
---|
| 82 | // This error is returned from Imap. |
---|
| 83 | if(strstr($error,'Connection refused')) { |
---|
| 84 | return str_replace("%1", $this->functions->getLang("Mail"), $this->functions->getLang("Connection failed with %1 Server. Try later.")); |
---|
| 85 | } |
---|
| 86 | // This error is returned from Postfix. |
---|
| 87 | elseif(strstr($error,'message file too big')) { |
---|
[1264] | 88 | return str_replace("%1",$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size'],$this->functions->getLang('The size of this message has exceeded the limit (%1B).')); |
---|
[504] | 89 | } |
---|
[628] | 90 | elseif(strstr($error,'virus')) { |
---|
| 91 | return str_replace("%1", $this->functions->getLang("Mail"), $this->functions->getLang("Your message was rejected by antivirus. Perhaps your attachment has been infected.")); |
---|
| 92 | } |
---|
[504] | 93 | // This condition verifies if SESSION is expired. |
---|
[1472] | 94 | elseif(!count($_SESSION)) |
---|
[504] | 95 | return "nosession"; |
---|
| 96 | |
---|
| 97 | return $error; |
---|
| 98 | } |
---|
[1472] | 99 | |
---|
[4038] | 100 | function get_range_msgs2($params) |
---|
[4150] | 101 | { |
---|
| 102 | // Free others requests |
---|
| 103 | session_write_close(); |
---|
| 104 | $folder = $params['folder']; |
---|
| 105 | $msg_range_begin = $params['msg_range_begin']; |
---|
| 106 | $msg_range_end = $params['msg_range_end']; |
---|
| 107 | $sort_box_type = $params['sort_box_type']; |
---|
| 108 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 109 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
[1472] | 110 | |
---|
[4150] | 111 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 112 | $this->mbox = $this->open_mbox($folder); |
---|
[4048] | 113 | |
---|
[4150] | 114 | $return = array(); |
---|
[4165] | 115 | |
---|
| 116 | $return['folder'] = $folder; |
---|
| 117 | |
---|
[4150] | 118 | //Para enviar o offset entre o timezone definido pelo usuário e GMT |
---|
| 119 | $return['offsetToGMT'] = $this->functions->CalculateDateOffset(); |
---|
[4048] | 120 | |
---|
[4150] | 121 | if(!$search_box_type || $search_box_type=="UNSEEN" || $search_box_type=="SEEN") { |
---|
[4587] | 122 | $msgs_info = imap_status($this->mbox,"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".mb_convert_encoding( $folder, "UTF7-IMAP", "ISO-8859-1" ) ,SA_ALL); |
---|
[4022] | 123 | |
---|
[4150] | 124 | |
---|
| 125 | $return['tot_unseen'] = $search_box_type == "SEEN" ? 0 : $msgs_info->unseen; |
---|
| 126 | |
---|
| 127 | $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); |
---|
| 128 | |
---|
| 129 | $num_msgs = ($search_box_type=="UNSEEN") ? $msgs_info->unseen : (($search_box_type=="SEEN") ? ($msgs_info->messages - $msgs_info->unseen) : $msgs_info->messages); |
---|
| 130 | |
---|
[3392] | 131 | $i = 0; |
---|
[4150] | 132 | if(is_array($sort_array_msg)){ |
---|
| 133 | foreach($sort_array_msg as $msg_number => $value) |
---|
| 134 | { |
---|
| 135 | $temp = $this->get_info_head_msg($msg_number); |
---|
[4164] | 136 | $temp['msg_sample'] = $this->get_msg_sample($msg_number,$folder); |
---|
[4150] | 137 | if(!$temp) |
---|
| 138 | return false; |
---|
[3392] | 139 | |
---|
[4150] | 140 | $return[$i] = $temp; |
---|
| 141 | $i++; |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | $return['num_msgs'] = $num_msgs; |
---|
| 145 | } |
---|
| 146 | else { |
---|
| 147 | $num_msgs = imap_num_msg($this->mbox); |
---|
| 148 | $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$num_msgs); |
---|
[828] | 149 | |
---|
[4150] | 150 | |
---|
| 151 | $return['tot_unseen'] = 0; |
---|
| 152 | $i = 0; |
---|
| 153 | |
---|
| 154 | if(is_array($sort_array_msg)){ |
---|
| 155 | foreach($sort_array_msg as $msg_number => $value) |
---|
| 156 | { |
---|
| 157 | $temp = $this->get_info_head_msg($msg_number); |
---|
| 158 | if(!$temp) |
---|
| 159 | return false; |
---|
| 160 | |
---|
| 161 | if($temp['Unseen'] == 'U' || $temp['Recent'] == 'N'){ |
---|
| 162 | $return['tot_unseen']++; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | if($i <= ($msg_range_end-$msg_range_begin)) |
---|
| 166 | $return[$i] = $temp; |
---|
| 167 | $i++; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | $return['num_msgs'] = count($sort_array_msg)+($msg_range_begin-1); |
---|
| 171 | |
---|
| 172 | } |
---|
| 173 | return $return; |
---|
| 174 | } |
---|
| 175 | |
---|
[4038] | 176 | function get_info_head_msg($msg_number) |
---|
| 177 | { |
---|
[689] | 178 | $head_array = array(); |
---|
| 179 | include_once("class.imap_attachment.inc.php"); |
---|
[828] | 180 | |
---|
[3271] | 181 | $imap_attachment = new imap_attachment(); |
---|
| 182 | //if ($this->prefs['use_important_flag'] ) |
---|
| 183 | //{ |
---|
[4022] | 184 | /*Como eu preciso do atributo Importance para saber se o email é |
---|
| 185 | * importante ou não, uso abaixo a função imap_fetchheader e busco |
---|
| 186 | * o atributo importance nela. Isso faz com que eu acesse o cabeçalho |
---|
[3071] | 187 | * duas vezes e de duas formas diferentes, mas em contrapartida, eu |
---|
[4022] | 188 | * não preciso reimplementar o método utilizando o fetchheader. |
---|
| 189 | * Como as mensagens são renderizadas em um número pequeno por vez, |
---|
| 190 | * não parece ter perda considerável de performance. |
---|
[3071] | 191 | */ |
---|
[830] | 192 | |
---|
[3071] | 193 | $tempHeader = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); |
---|
| 194 | $flag = preg_match('/importance *: *(.*)\r/i', $tempHeader, $importance); |
---|
[3271] | 195 | //} |
---|
[4022] | 196 | // Reimplementado código para identificação dos e-mails assinados e cifrados |
---|
| 197 | // no método getMessageType(). Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
[3271] | 198 | $head_array['ContentType'] = $this->getMessageType($msg_number, $tempHeader); |
---|
| 199 | $head_array['Importance'] = $flag==0?"Normal":$importance[1]; |
---|
[1174] | 200 | |
---|
[689] | 201 | $header = $this->get_header($msg_number); |
---|
[828] | 202 | if (!is_object($header)) |
---|
| 203 | return false; |
---|
[689] | 204 | $head_array['Recent'] = $header->Recent; |
---|
| 205 | $head_array['Unseen'] = $header->Unseen; |
---|
| 206 | if($header->Answered =='A' && $header->Draft == 'X'){ |
---|
| 207 | $head_array['Forwarded'] = 'F'; |
---|
[2] | 208 | } |
---|
[689] | 209 | else { |
---|
| 210 | $head_array['Answered'] = $header->Answered; |
---|
[828] | 211 | $head_array['Draft'] = $header->Draft; |
---|
[46] | 212 | } |
---|
[689] | 213 | $head_array['Deleted'] = $header->Deleted; |
---|
| 214 | $head_array['Flagged'] = $header->Flagged; |
---|
| 215 | $head_array['msg_number'] = $msg_number; |
---|
[3057] | 216 | $head_array['udate'] = $header->udate; |
---|
[3923] | 217 | $head_array['offsetToGMT'] = $this->functions->CalculateDateOffset(); |
---|
[828] | 218 | |
---|
[3923] | 219 | $msgTimestamp = $header->udate + $head_array['offsetToGMT']; |
---|
| 220 | $head_array['timestamp'] = $msgTimestamp; |
---|
| 221 | |
---|
[3499] | 222 | $date_msg = gmdate("d/m/Y",$msgTimestamp); |
---|
| 223 | // if (date("d/m/Y") == $date_msg) |
---|
| 224 | // $return['udate'] = $header->udate; |
---|
| 225 | // else |
---|
| 226 | |
---|
| 227 | if (date("d/m/Y") == $date_msg) //no dia |
---|
| 228 | { |
---|
| 229 | $head_array['smalldate'] = gmdate("H:i",$msgTimestamp); |
---|
| 230 | } |
---|
| 231 | else |
---|
| 232 | { |
---|
| 233 | $head_array['smalldate'] = gmdate("d/m/Y",$msgTimestamp); |
---|
| 234 | } |
---|
| 235 | |
---|
[689] | 236 | $from = $header->from; |
---|
| 237 | $head_array['from'] = array(); |
---|
[1740] | 238 | $head_array['from']['name'] = ( isset( $from[0]->personal ) ) ? $this->decode_string($from[0]->personal) : NULL; |
---|
[689] | 239 | $head_array['from']['email'] = $this->decode_string($from[0]->mailbox) . "@" . $from[0]->host; |
---|
| 240 | if(!$head_array['from']['name']) |
---|
| 241 | $head_array['from']['name'] = $head_array['from']['email']; |
---|
| 242 | $to = $header->to; |
---|
| 243 | $head_array['to'] = array(); |
---|
[4022] | 244 | if($to[1] && $to[1]->host == ".SYNTAX-ERROR.") { //E-mails que não possuem o campo "para", vêm com o recipiente preenchido, porém com um recipiente a mais alegando erro de sintaxe. |
---|
[3831] | 245 | $head_array['to']['name'] = $head_array['to']['email'] = NULL; |
---|
| 246 | } |
---|
| 247 | else { |
---|
| 248 | $tmp = ( isset( $to[0]->personal ) ) ? imap_mime_header_decode($to[0]->personal) : NULL; |
---|
| 249 | $head_array['to']['name'] = ( isset( $tmp[0]->text ) ) ? $this->decode_string($this->decode_string($tmp[0]->text)) : NULL; |
---|
| 250 | $head_array['to']['email'] = ( isset( $to[0]->mailbox ) ) ? ( $this->decode_string($to[0]->mailbox) . "@" . ( ( isset( $to[0]->host ) ) ? $to[0]->host : '' ) ) : NULL; |
---|
| 251 | if(!$head_array['to']['name']) |
---|
| 252 | $head_array['to']['name'] = $head_array['to']['email']; |
---|
| 253 | } |
---|
[3777] | 254 | $cc = $header->cc; |
---|
[3831] | 255 | $cco = $header->bcc; |
---|
[3777] | 256 | if ( ($cc) && (!$head_array['to']['name']) ){ |
---|
| 257 | $head_array['to']['name'] = ( isset( $cc[0]->personal ) ) ? $this->decode_string($cc[0]->personal) : NULL; |
---|
| 258 | $head_array['to']['email'] = $this->decode_string($cc[0]->mailbox) . "@" . $cc[0]->host; |
---|
| 259 | if(!$head_array['to']['name']) |
---|
| 260 | $head_array['to']['name'] = $head_array['from']['email']; |
---|
| 261 | } |
---|
[3831] | 262 | else if ( ($cco) && (!$head_array['to']['name']) ){ |
---|
| 263 | $head_array['to']['name'] = ( isset( $cco[0]->personal ) ) ? $this->decode_string($cco[0]->personal) : NULL; |
---|
| 264 | $head_array['to']['email'] = $this->decode_string($cco[0]->mailbox) . "@" . $cco[0]->host; |
---|
| 265 | if(!$head_array['to']['name']) |
---|
| 266 | $head_array['to']['name'] = $head_array['from']['email']; |
---|
| 267 | } |
---|
[1751] | 268 | $head_array['subject'] = ( isset( $header->fetchsubject ) ) ? $this->decode_string($header->fetchsubject) : ''; |
---|
[828] | 269 | |
---|
[689] | 270 | $head_array['Size'] = $header->Size; |
---|
[828] | 271 | |
---|
[689] | 272 | $head_array['attachment'] = array(); |
---|
| 273 | $head_array['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); |
---|
[828] | 274 | |
---|
[689] | 275 | return $head_array; |
---|
[2] | 276 | } |
---|
[828] | 277 | |
---|
[2] | 278 | function decode_string($string) |
---|
[1472] | 279 | { |
---|
| 280 | |
---|
[2] | 281 | if ((strpos(strtolower($string), '=?iso-8859-1') !== false) || (strpos(strtolower($string), '=?windows-1252') !== false)) |
---|
| 282 | { |
---|
[1740] | 283 | $return = ''; |
---|
[2] | 284 | $tmp = imap_mime_header_decode($string); |
---|
| 285 | foreach ($tmp as $tmp1) |
---|
| 286 | $return .= $this->htmlspecialchars_encode($tmp1->text); |
---|
[1472] | 287 | |
---|
[3560] | 288 | $return = str_replace("\t", "", $return); |
---|
[2] | 289 | return $return; |
---|
| 290 | } |
---|
| 291 | else if (strpos(strtolower($string), '=?utf-8') !== false) |
---|
| 292 | { |
---|
[1401] | 293 | $elements = imap_mime_header_decode($string); |
---|
| 294 | |
---|
| 295 | for($i = 0;$i < count($elements);$i++) |
---|
| 296 | { |
---|
[1384] | 297 | $charset = strtolower($elements[$i]->charset); |
---|
[1401] | 298 | $text = $elements[$i]->text; |
---|
| 299 | |
---|
| 300 | if(!strcasecmp($charset, "utf-8") || !strcasecmp($charset, "utf-7")) |
---|
| 301 | { |
---|
[1384] | 302 | $decoded .= $this->functions->utf8_to_ncr($text); |
---|
| 303 | } |
---|
| 304 | else |
---|
[1401] | 305 | { |
---|
| 306 | if( strcasecmp($charset,"default") ) |
---|
| 307 | $decoded .= $this->htmlspecialchars_encode(iconv($charset, "iso-8859-1", $text)); |
---|
| 308 | else |
---|
| 309 | $decoded .= $this->htmlspecialchars_encode($text); |
---|
| 310 | } |
---|
[1384] | 311 | } |
---|
[2] | 312 | return $decoded; |
---|
| 313 | } |
---|
| 314 | else |
---|
| 315 | return $this->htmlspecialchars_encode($string); |
---|
| 316 | } |
---|
[615] | 317 | /** |
---|
[4022] | 318 | * Função que importa arquivos .eml exportados pelo expresso para a caixa do usuário. Testado apenas |
---|
| 319 | * com .emls gerados pelo expresso, e o arquivo pode ser um zip contendo vários emls ou um .eml. |
---|
[615] | 320 | */ |
---|
[660] | 321 | function import_msgs($params) { |
---|
[1000] | 322 | if(!$this->mbox) |
---|
[660] | 323 | $this->mbox = $this->open_mbox(); |
---|
[1472] | 324 | |
---|
[1365] | 325 | if( preg_match('/local_/',$params["folder"]) ) |
---|
[1000] | 326 | { |
---|
[1366] | 327 | // PLEASE, BE CAREFULL!!! YOU SHOULD USE EMAIL CONFIGURATION VALUES (EMAILADMIN MODULE) |
---|
[1367] | 328 | $tmp_box = mb_convert_encoding('INBOX'.$this->imap_delimiter.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'].$this->imap_delimiter.'tmpMoveToLocal', "UTF7-IMAP", "UTF-8"); |
---|
[1000] | 329 | if ( ! imap_createmailbox( $this -> mbox,"{".$this -> imap_server."}$tmp_box" ) ) |
---|
| 330 | return $this->functions->getLang( 'Import to Local : fail...' ); |
---|
| 331 | imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$tmp_box); |
---|
| 332 | $params["folder"] = $tmp_box; |
---|
| 333 | } |
---|
[615] | 334 | $errors = array(); |
---|
| 335 | $invalid_format = false; |
---|
[1472] | 336 | $filename = $params['FILES'][0]['name']; |
---|
[4587] | 337 | $params["folder"] = mb_convert_encoding($params["folder"], "UTF7-IMAP","ISO-8859-1"); |
---|
[660] | 338 | $quota = imap_get_quotaroot($this->mbox, $params["folder"]); |
---|
| 339 | if((($quota['limit'] - $quota['usage'])*1024) <= $params['FILES'][0]['size']){ |
---|
| 340 | return array( 'error' => $this->functions->getLang("fail in import:"). |
---|
[1000] | 341 | " ".$this->functions->getLang("Over quota")); |
---|
[660] | 342 | } |
---|
[615] | 343 | if(substr($filename,strlen($filename)-4)==".zip") { |
---|
[660] | 344 | $zip = zip_open($params['FILES'][0]['tmp_name']); |
---|
[615] | 345 | |
---|
| 346 | if ($zip) { |
---|
| 347 | while ($zip_entry = zip_read($zip)) { |
---|
[1000] | 348 | |
---|
[615] | 349 | if (zip_entry_open($zip, $zip_entry, "r")) { |
---|
| 350 | $email = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); |
---|
| 351 | $status = @imap_append($this->mbox, |
---|
[660] | 352 | "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], |
---|
[615] | 353 | $email |
---|
| 354 | ); |
---|
| 355 | if(!$status) |
---|
| 356 | array_push($errors,zip_entry_name($zip_entry)); |
---|
| 357 | zip_entry_close($zip_entry); |
---|
| 358 | } |
---|
| 359 | } |
---|
[660] | 360 | zip_close($zip); |
---|
[615] | 361 | } |
---|
[1000] | 362 | |
---|
| 363 | if ( isset( $tmp_box ) && ! sizeof( $errors ) ) |
---|
| 364 | { |
---|
| 365 | |
---|
| 366 | $mc = imap_check($this->mbox); |
---|
| 367 | |
---|
| 368 | $result = imap_fetch_overview( $this -> mbox, "1:{$mc -> Nmsgs}", 0 ); |
---|
| 369 | |
---|
| 370 | $ids = array( ); |
---|
| 371 | foreach ($result as $overview) |
---|
| 372 | $ids[ ] = $overview -> uid; |
---|
| 373 | |
---|
| 374 | return implode( ',', $ids ); |
---|
[830] | 375 | } |
---|
[1000] | 376 | } |
---|
[615] | 377 | else if(substr($filename,strlen($filename)-4)==".eml") { |
---|
[660] | 378 | $email = implode("",file($params['FILES'][0]['tmp_name'])); |
---|
[615] | 379 | $status = @imap_append($this->mbox, |
---|
[660] | 380 | "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], |
---|
[615] | 381 | $email |
---|
| 382 | ); |
---|
[660] | 383 | if(!$status){ |
---|
[615] | 384 | array_push($errors,zip_entry_name($zip_entry)); |
---|
[660] | 385 | zip_entry_close($zip_entry); |
---|
| 386 | } |
---|
[615] | 387 | } |
---|
[1000] | 388 | else |
---|
[615] | 389 | { |
---|
[1000] | 390 | if ( isset( $tmp_box ) ) |
---|
| 391 | imap_deletemailbox( $this->mbox,"{".$this -> imap_server."}$tmp_box" ); |
---|
| 392 | |
---|
[660] | 393 | return array("error" => $this->functions->getLang("wrong file format")); |
---|
[615] | 394 | $invalid_format = true; |
---|
| 395 | } |
---|
[1000] | 396 | |
---|
[615] | 397 | if(!$invalid_format) { |
---|
| 398 | if(count($errors)>0) { |
---|
[660] | 399 | $message = $this->functions->getLang("fail in import:")."\n"; |
---|
[615] | 400 | foreach($errors as $arquivo) { |
---|
| 401 | $message.=$arquivo."\n"; |
---|
| 402 | } |
---|
[660] | 403 | return array("error" => $message); |
---|
[615] | 404 | } |
---|
| 405 | else |
---|
[3843] | 406 | return $this->functions->getLang("The import was executed successfully."); |
---|
[615] | 407 | } |
---|
[1000] | 408 | } |
---|
| 409 | /* |
---|
[4022] | 410 | Remove os anexos de uma mensagem. A estratégia para isso é criar uma mensagem nova sem os anexos, mantendo apenas |
---|
| 411 | a primeira parte do e-mail, que é o texto, sem anexos. |
---|
| 412 | O método considera que o email é multpart. |
---|
[613] | 413 | */ |
---|
| 414 | function remove_attachments($params) { |
---|
| 415 | include_once("class.message_components.inc.php"); |
---|
| 416 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 417 | $this->mbox = $this->open_mbox($params["folder"]); |
---|
| 418 | $return["status"] = true; |
---|
| 419 | $header = ""; |
---|
[1472] | 420 | |
---|
[613] | 421 | $headertemp = explode("\n",imap_fetchheader($this->mbox, imap_msgno($this->mbox, $params["msg_num"]))); |
---|
[4022] | 422 | foreach($headertemp as $head) {//Se eu colocar todo o header do email dá pau no append, então procuro apenas o que interessa. |
---|
[613] | 423 | $head1 = explode(":",$head); |
---|
[1472] | 424 | if ( (strtoupper($head1[0]) == "TO") || |
---|
[3566] | 425 | (strtoupper($head1[0]) == "FROM") || |
---|
| 426 | (strtoupper($head1[0]) == "SUBJECT") || |
---|
| 427 | (strtoupper($head1[0]) == "DATE") ) |
---|
| 428 | $header .= $head."\r\n"; |
---|
[613] | 429 | } |
---|
[1472] | 430 | |
---|
[613] | 431 | $msg = &new message_components($this->mbox); |
---|
[4022] | 432 | $msg->fetch_structure($params["msg_num"]);/* O fetchbody tava trazendo o email com problemas na acentuação. |
---|
| 433 | Então uso essa classe para verificar a codificação e o charset, |
---|
| 434 | para que o método decodeBody do expresso possa trazer tudo certinho*/ |
---|
[1472] | 435 | |
---|
[3566] | 436 | $all_body_type = strtolower($msg->file_type[$params["msg_num"]][0]); |
---|
| 437 | $all_body_encoding = $msg->encoding[$params["msg_num"]][0]; |
---|
| 438 | $all_body_charset = $msg->charset[$params["msg_num"]][0]; |
---|
| 439 | |
---|
| 440 | if($all_body_type=='multipart/alternative') { |
---|
| 441 | if(strtolower($msg->file_type[$params["msg_num"]][2]=='text/html') && |
---|
| 442 | $msg->pid[$params["msg_num"]][2] == '1.2') { |
---|
| 443 | $body_part_to_show = '1.2'; |
---|
| 444 | $all_body_type = strtolower($msg->file_type[$params["msg_num"]][2]); |
---|
| 445 | $all_body_encoding = $msg->encoding[$params["msg_num"]][2]; |
---|
| 446 | $all_body_charset = $msg->charset[$params["msg_num"]][2]; |
---|
| 447 | } |
---|
| 448 | else { |
---|
| 449 | $body_part_to_show = '1.1'; |
---|
| 450 | $all_body_type = strtolower($msg->file_type[$params["msg_num"]][1]); |
---|
| 451 | $all_body_encoding = $msg->encoding[$params["msg_num"]][1]; |
---|
| 452 | $all_body_charset = $msg->charset[$params["msg_num"]][1]; |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | else |
---|
| 456 | $body_part_to_show = '1'; |
---|
| 457 | |
---|
[1319] | 458 | $status = imap_append($this->mbox, |
---|
[613] | 459 | "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], |
---|
| 460 | $header. |
---|
[3566] | 461 | "Content-Type: ".$all_body_type."; charset = \"".$all_body_charset."\"". |
---|
[613] | 462 | "\r\n". |
---|
[3566] | 463 | "Content-Transfer-Encoding: ".$all_body_encoding. |
---|
| 464 | "\r\n". |
---|
| 465 | "\r\n". |
---|
[613] | 466 | str_replace("\n","\r\n",$this->decodeBody( |
---|
[3566] | 467 | imap_fetchbody($this->mbox,imap_msgno($this->mbox, $params["msg_num"]),$body_part_to_show), |
---|
| 468 | $all_body_encoding, $all_body_charset |
---|
[1472] | 469 | ) |
---|
[4022] | 470 | ), "\\Seen"); //Append do novo email, só com header e conteúdo sem anexos. |
---|
[1472] | 471 | |
---|
[1319] | 472 | if(!$status) |
---|
| 473 | { |
---|
[613] | 474 | $return["status"] = false; |
---|
| 475 | $return["msg"] = lang("error appending mail on delete attachments"); |
---|
| 476 | } |
---|
[1319] | 477 | else |
---|
| 478 | { |
---|
| 479 | $status = imap_status($this->mbox, "{".$this->imap_server.":".$this->imap_port."}".$params['folder'], SA_UIDNEXT); |
---|
[1472] | 480 | $return['msg_no'] = $status->uidnext - 1; |
---|
[1319] | 481 | imap_delete($this->mbox, imap_msgno($this->mbox, $params["msg_num"])); |
---|
| 482 | imap_expunge($this->mbox); |
---|
| 483 | } |
---|
[1472] | 484 | |
---|
[613] | 485 | return $return; |
---|
[1472] | 486 | |
---|
[613] | 487 | } |
---|
[1518] | 488 | |
---|
| 489 | function msgs_to_archive($params) { |
---|
| 490 | |
---|
| 491 | $folder = $params['folder']; |
---|
[1931] | 492 | $all_ids = $this-> get_msgs($folder, 'SORTARRIVAL', false, 0,-1,-1); |
---|
[613] | 493 | |
---|
[1518] | 494 | $messages_not_to_copy = explode(",",$params['mails']); |
---|
| 495 | $ids = array(); |
---|
| 496 | |
---|
[1931] | 497 | $cont = 0; |
---|
| 498 | |
---|
[1518] | 499 | foreach($all_ids as $each_id=>$value) { |
---|
[1931] | 500 | if(!in_array($each_id,$messages_not_to_copy)) { |
---|
[1518] | 501 | array_push($ids,$each_id); |
---|
[1931] | 502 | $cont++; |
---|
| 503 | } |
---|
| 504 | if($cont>=100) |
---|
| 505 | break; |
---|
[1518] | 506 | } |
---|
| 507 | |
---|
| 508 | if (empty($ids)) |
---|
| 509 | return array(); |
---|
| 510 | |
---|
| 511 | $params = array("folder"=>$folder,"msgs_number"=>implode(",",$ids)); |
---|
| 512 | |
---|
| 513 | |
---|
| 514 | return $this->get_info_msgs($params); |
---|
| 515 | |
---|
| 516 | |
---|
| 517 | } |
---|
| 518 | |
---|
[689] | 519 | /** |
---|
[1472] | 520 | * |
---|
| 521 | * @return |
---|
[689] | 522 | * @param $params Object |
---|
| 523 | */ |
---|
| 524 | function get_info_msgs($params) { |
---|
| 525 | include_once("class.exporteml.inc.php"); |
---|
| 526 | $return = array(); |
---|
| 527 | $new_params = array(); |
---|
| 528 | $attach_params = array(); |
---|
| 529 | $new_params["msg_folder"]=$params["folder"]; |
---|
| 530 | $attach_params["folder"] = $params["folder"]; |
---|
| 531 | $msgs = explode(",",$params["msgs_number"]); |
---|
| 532 | $exporteml = new ExportEml(); |
---|
[1382] | 533 | $unseen_msgs = array(); |
---|
[689] | 534 | foreach($msgs as $msg_number) { |
---|
| 535 | $new_params["msg_number"] = $msg_number; |
---|
| 536 | //ini_set("display_errors","1"); |
---|
| 537 | $msg_info = $this->get_info_msg($new_params); |
---|
| 538 | |
---|
[4022] | 539 | $this->mbox = $this->open_mbox($params['folder']); //Não sei porque, mas se não abrir de novo a caixa dá erro. |
---|
[689] | 540 | $msg_info['header'] = $this->get_info_head_msg($msg_number); |
---|
| 541 | |
---|
| 542 | $attach_params["num_msg"] = $msg_number; |
---|
| 543 | $msg_info['array_attach'] = $exporteml->get_attachments_in_array($attach_params); |
---|
| 544 | $msg_info['url_export_file'] = $exporteml->export_to_archive($msg_number,$params["folder"]); |
---|
| 545 | imap_close($this->mbox); |
---|
| 546 | $this->mbox=false; |
---|
| 547 | array_push($return,serialize($msg_info)); |
---|
[1472] | 548 | |
---|
[1388] | 549 | if($msg_info['Unseen'] == "U" || $msg_info['Recent'] == "N"){ |
---|
[1472] | 550 | array_push($unseen_msgs,$msg_number); |
---|
| 551 | } |
---|
| 552 | } |
---|
[1382] | 553 | if($unseen_msgs){ |
---|
| 554 | $msgs_list = implode(",",$unseen_msgs); |
---|
| 555 | $array_msgs = array('folder' => $new_params["msg_folder"], "msgs_to_set" => $msgs_list, "flag" => "unseen"); |
---|
[1472] | 556 | $this->set_messages_flag($array_msgs); |
---|
[689] | 557 | } |
---|
[1472] | 558 | |
---|
[689] | 559 | return $return; |
---|
| 560 | } |
---|
| 561 | |
---|
[2] | 562 | function get_info_msg($params) |
---|
| 563 | { |
---|
[51] | 564 | $return = array(); |
---|
[2] | 565 | $msg_number = $params['msg_number']; |
---|
[3427] | 566 | if(@preg_match('(.+)(_[a-zA-Z0-9]+)',$msg_number,$matches)) { //Verifies if it comes from a tab diferent of the main one. |
---|
[1969] | 567 | $msg_number = $matches[1]; |
---|
| 568 | $plus_id = $matches[2]; |
---|
| 569 | } |
---|
| 570 | else { |
---|
| 571 | $plus_id = ''; |
---|
| 572 | } |
---|
[1724] | 573 | $msg_folder = urldecode($params['msg_folder']); |
---|
[1472] | 574 | |
---|
[411] | 575 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[1472] | 576 | $this->mbox = $this->open_mbox($msg_folder); |
---|
[535] | 577 | $header = $this->get_header($msg_number); |
---|
[205] | 578 | if (!$header) { |
---|
[1472] | 579 | $return['status_get_msg_info'] = "false"; |
---|
[205] | 580 | return $return; |
---|
| 581 | } |
---|
[1472] | 582 | |
---|
[828] | 583 | $header_ = imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
| 584 | |
---|
[51] | 585 | $return_get_body = $this->get_body_msg($msg_number, $msg_folder); |
---|
[1707] | 586 | |
---|
| 587 | $body = $return_get_body['body']; |
---|
[1808] | 588 | |
---|
[1035] | 589 | if($return_get_body['body']=='isCripted'){ |
---|
| 590 | $exporteml = new ExportEml(); |
---|
| 591 | $return['source']=$exporteml->export_msg_data($msg_number,$msg_folder); |
---|
| 592 | $return['body'] = ""; |
---|
| 593 | $return['attachments'] = ""; |
---|
| 594 | $return['thumbs'] = ""; |
---|
| 595 | $return['signature'] = ""; |
---|
| 596 | //return $return; |
---|
| 597 | }else{ |
---|
[3576] | 598 | $return['body'] = $body; |
---|
| 599 | $return['attachments'] = $return_get_body['attachments']; |
---|
| 600 | $return['thumbs'] = $return_get_body['thumbs']; |
---|
| 601 | $return['signature'] = $return_get_body['signature']; |
---|
[1707] | 602 | } |
---|
[3798] | 603 | |
---|
| 604 | $flag = preg_match('/importance *: *(.*)\r/i', $header_, $importance); |
---|
| 605 | $return['Importance'] = ($flag == 0) ? "Normal" : $importance[1]; |
---|
[1707] | 606 | |
---|
[3018] | 607 | $pattern = '/^[ \t]*Disposition-Notification-To:[ ]*<?[[:alnum:]\._-]+@[[:alnum:]_-]+[\.[:alnum:]]+>?/sm'; |
---|
[828] | 608 | if (preg_match($pattern, $header_, $fields)) |
---|
| 609 | { |
---|
[3018] | 610 | if(preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$fields[0], $matches)){ |
---|
| 611 | $return['DispositionNotificationTo'] = "<".$matches[0].">"; |
---|
| 612 | } |
---|
[2] | 613 | } |
---|
[828] | 614 | |
---|
[2] | 615 | $return['Recent'] = $header->Recent; |
---|
| 616 | $return['Unseen'] = $header->Unseen; |
---|
[1472] | 617 | $return['Deleted'] = $header->Deleted; |
---|
[2] | 618 | $return['Flagged'] = $header->Flagged; |
---|
| 619 | |
---|
| 620 | if($header->Answered =='A' && $header->Draft == 'X'){ |
---|
| 621 | $return['Forwarded'] = 'F'; |
---|
| 622 | } |
---|
[1472] | 623 | |
---|
[2] | 624 | else { |
---|
| 625 | $return['Answered'] = $header->Answered; |
---|
[1472] | 626 | $return['Draft'] = $header->Draft; |
---|
[2] | 627 | } |
---|
| 628 | |
---|
[1969] | 629 | $return['msg_number'] = $msg_number.$plus_id; |
---|
[2] | 630 | $return['msg_folder'] = $msg_folder; |
---|
[1472] | 631 | |
---|
[3798] | 632 | $offset = $this->functions->CalculateDateOffset(); |
---|
| 633 | $msgTimestamp = $header->udate + $offset; |
---|
[3493] | 634 | |
---|
| 635 | $date_msg = gmdate("d/m/Y",$msgTimestamp); |
---|
[3499] | 636 | // if (date("d/m/Y") == $date_msg) |
---|
| 637 | // $return['udate'] = $header->udate; |
---|
| 638 | // else |
---|
| 639 | $return['udate'] = $header->udate; |
---|
[1472] | 640 | |
---|
| 641 | $return['msg_day'] = $date_msg; |
---|
[3493] | 642 | $return['msg_hour'] = gmdate("H:i",$msgTimestamp); |
---|
[1472] | 643 | |
---|
[2] | 644 | if (date("d/m/Y") == $date_msg) //no dia |
---|
| 645 | { |
---|
[3493] | 646 | $return['fulldate'] = gmdate("d/m/Y H:i",$msgTimestamp); |
---|
| 647 | $return['smalldate'] = gmdate("H:i",$msgTimestamp); |
---|
[605] | 648 | |
---|
[4428] | 649 | $timestamp_now = strtotime("now") + $offset; |
---|
[3493] | 650 | $timestamp_msg_time = $msgTimestamp; |
---|
| 651 | // $timestamp_now and $timestamp_msg_time are GMT. |
---|
[535] | 652 | // The variable $timestamp_diff is calculated without MailDate TZ. |
---|
[3493] | 653 | $timestamp_diff = $timestamp_now - $timestamp_msg_time; |
---|
[4428] | 654 | |
---|
[2] | 655 | if (gmdate("H",$timestamp_diff) > 0) |
---|
| 656 | { |
---|
[197] | 657 | $return['fulldate'] .= " (" . gmdate("H:i", $timestamp_diff) . ' ' . $this->functions->getLang('hours ago') . ')'; |
---|
[2] | 658 | } |
---|
| 659 | else |
---|
| 660 | { |
---|
| 661 | if (gmdate("i",$timestamp_diff) == 0){ |
---|
[197] | 662 | $return['fulldate'] .= ' ('. $this->functions->getLang('now').')'; |
---|
[2] | 663 | } |
---|
| 664 | elseif (gmdate("i",$timestamp_diff) == 1){ |
---|
[197] | 665 | $return['fulldate'] .= ' (1 '. $this->functions->getLang('minute ago').')'; |
---|
[2] | 666 | } |
---|
| 667 | else{ |
---|
[197] | 668 | $return['fulldate'] .= " (" . gmdate("i",$timestamp_diff) .' '. $this->functions->getLang('minutes ago') . ')'; |
---|
[2] | 669 | } |
---|
| 670 | } |
---|
| 671 | } |
---|
| 672 | else{ |
---|
[3493] | 673 | $return['fulldate'] = gmdate("d/m/Y H:i",$msgTimestamp); |
---|
| 674 | $return['smalldate'] = gmdate("d/m/Y",$msgTimestamp); |
---|
[2] | 675 | } |
---|
[1472] | 676 | |
---|
[2] | 677 | $from = $header->from; |
---|
| 678 | $return['from'] = array(); |
---|
[1384] | 679 | $return['from']['name'] = $this->decode_string($from[0]->personal); |
---|
[2] | 680 | $return['from']['email'] = $this->decode_string($from[0]->mailbox . "@" . $from[0]->host); |
---|
| 681 | if ($return['from']['name']) |
---|
| 682 | { |
---|
| 683 | if (substr($return['from']['name'], 0, 1) == '"') |
---|
| 684 | $return['from']['full'] = $return['from']['name'] . ' ' . '<' . $return['from']['email'] . '>'; |
---|
| 685 | else |
---|
| 686 | $return['from']['full'] = '"' . $return['from']['name'] . '" ' . '<' . $return['from']['email'] . '>'; |
---|
| 687 | } |
---|
| 688 | else |
---|
| 689 | $return['from']['full'] = $return['from']['email']; |
---|
[1472] | 690 | |
---|
[2] | 691 | // Sender attribute |
---|
| 692 | $sender = $header->sender; |
---|
[1472] | 693 | $return['sender'] = array(); |
---|
[1384] | 694 | $return['sender']['name'] = $this->decode_string($sender[0]->personal); |
---|
[2] | 695 | $return['sender']['email'] = $this->decode_string($sender[0]->mailbox . "@" . $sender[0]->host); |
---|
| 696 | if ($return['sender']['name']) |
---|
| 697 | { |
---|
| 698 | if (substr($return['sender']['name'], 0, 1) == '"') |
---|
| 699 | $return['sender']['full'] = $return['sender']['name'] . ' ' . '<' . $return['sender']['email'] . '>'; |
---|
| 700 | else |
---|
| 701 | $return['sender']['full'] = '"' . $return['sender']['name'] . '" ' . '<' . $return['sender']['email'] . '>'; |
---|
| 702 | } |
---|
| 703 | else |
---|
| 704 | $return['sender']['full'] = $return['sender']['email']; |
---|
| 705 | |
---|
| 706 | if($return['from']['full'] == $return['sender']['full']) |
---|
| 707 | $return['sender'] = null; |
---|
| 708 | $to = $header->to; |
---|
| 709 | $return['toaddress2'] = ""; |
---|
| 710 | if (!empty($to)) |
---|
| 711 | { |
---|
| 712 | foreach ($to as $tmp) |
---|
| 713 | { |
---|
| 714 | if (!empty($tmp->personal)) |
---|
| 715 | { |
---|
| 716 | $personal_tmp = imap_mime_header_decode($tmp->personal); |
---|
| 717 | $return['toaddress2'] .= '"' . $personal_tmp[0]->text . '"'; |
---|
| 718 | $return['toaddress2'] .= " "; |
---|
| 719 | $return['toaddress2'] .= "<"; |
---|
[320] | 720 | if ($tmp->host != 'unspecified-domain') |
---|
| 721 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
| 722 | else |
---|
| 723 | $return['toaddress2'] .= $tmp->mailbox; |
---|
[2] | 724 | $return['toaddress2'] .= ">"; |
---|
| 725 | $return['toaddress2'] .= ", "; |
---|
| 726 | } |
---|
| 727 | else |
---|
| 728 | { |
---|
[320] | 729 | if ($tmp->host != 'unspecified-domain') |
---|
| 730 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
| 731 | else |
---|
| 732 | $return['toaddress2'] .= $tmp->mailbox; |
---|
[2] | 733 | $return['toaddress2'] .= ", "; |
---|
| 734 | } |
---|
| 735 | } |
---|
| 736 | $return['toaddress2'] = $this->del_last_two_caracters($return['toaddress2']); |
---|
| 737 | } |
---|
[1472] | 738 | |
---|
[2] | 739 | $cc = $header->cc; |
---|
| 740 | $return['cc'] = ""; |
---|
| 741 | if (!empty($cc)) |
---|
| 742 | { |
---|
| 743 | foreach ($cc as $tmp_cc) |
---|
| 744 | { |
---|
| 745 | if (!empty($tmp_cc->personal)) |
---|
| 746 | { |
---|
| 747 | $personal_tmp_cc = imap_mime_header_decode($tmp_cc->personal); |
---|
| 748 | $return['cc'] .= '"' . $personal_tmp_cc[0]->text . '"'; |
---|
| 749 | $return['cc'] .= " "; |
---|
| 750 | $return['cc'] .= "<"; |
---|
| 751 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
| 752 | $return['cc'] .= ">"; |
---|
| 753 | $return['cc'] .= ", "; |
---|
| 754 | } |
---|
| 755 | else |
---|
| 756 | { |
---|
| 757 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
| 758 | $return['cc'] .= ", "; |
---|
| 759 | } |
---|
| 760 | } |
---|
| 761 | $return['cc'] = $this->del_last_two_caracters($return['cc']); |
---|
| 762 | } |
---|
| 763 | else |
---|
| 764 | { |
---|
| 765 | $return['cc'] = ""; |
---|
[1472] | 766 | } |
---|
[449] | 767 | |
---|
| 768 | ## |
---|
| 769 | # @AUTHOR Rodrigo Souza dos Santos |
---|
| 770 | # @DATE 2008/09/12 |
---|
| 771 | # @BRIEF Adding the BCC field. |
---|
| 772 | ## |
---|
| 773 | $bcc = $header->bcc; |
---|
| 774 | $return['bcc'] = ""; |
---|
| 775 | if (!empty($bcc)) |
---|
| 776 | { |
---|
| 777 | foreach ($bcc as $tmp_bcc) |
---|
| 778 | { |
---|
| 779 | if (!empty($tmp_bcc->personal)) |
---|
| 780 | { |
---|
| 781 | $personal_tmp_bcc = imap_mime_header_decode($tmp_bcc->personal); |
---|
| 782 | $return['bcc'] .= '"' . $personal_tmp_bcc[0]->text . '"'; |
---|
| 783 | $return['bcc'] .= " "; |
---|
| 784 | $return['bcc'] .= "<"; |
---|
| 785 | $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
| 786 | $return['bcc'] .= ">"; |
---|
| 787 | $return['bcc'] .= ", "; |
---|
| 788 | } |
---|
| 789 | else |
---|
| 790 | { |
---|
| 791 | $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
| 792 | $return['bcc'] .= ", "; |
---|
| 793 | } |
---|
| 794 | } |
---|
| 795 | $return['bcc'] = $this->del_last_two_caracters($return['bcc']); |
---|
[426] | 796 | } |
---|
[449] | 797 | else |
---|
| 798 | { |
---|
| 799 | $return['bcc'] = ""; |
---|
[1472] | 800 | } |
---|
[426] | 801 | |
---|
[2] | 802 | $reply_to = $header->reply_to; |
---|
| 803 | $return['reply_to'] = ""; |
---|
| 804 | if (is_object($reply_to[0])) |
---|
| 805 | { |
---|
| 806 | if ($return['from']['email'] != ($reply_to[0]->mailbox."@".$reply_to[0]->host)) |
---|
| 807 | { |
---|
| 808 | if (!empty($reply_to[0]->personal)) |
---|
| 809 | { |
---|
| 810 | $personal_reply_to = imap_mime_header_decode($tmp_reply_to->personal); |
---|
[41] | 811 | if(!empty($personal_reply_to[0]->text)) { |
---|
| 812 | $return['reply_to'] .= '"' . $personal_reply_to[0]->text . '"'; |
---|
| 813 | $return['reply_to'] .= " "; |
---|
| 814 | $return['reply_to'] .= "<"; |
---|
| 815 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 816 | $return['reply_to'] .= ">"; |
---|
| 817 | } |
---|
| 818 | else { |
---|
| 819 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 820 | } |
---|
[2] | 821 | } |
---|
| 822 | else |
---|
| 823 | { |
---|
| 824 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 825 | } |
---|
| 826 | } |
---|
| 827 | } |
---|
| 828 | $return['reply_to'] = $this->decode_string($return['reply_to']); |
---|
| 829 | $return['subject'] = $this->decode_string($header->fetchsubject); |
---|
| 830 | $return['Size'] = $header->Size; |
---|
[828] | 831 | $return['reply_toaddress'] = $header->reply_toaddress; |
---|
| 832 | |
---|
[689] | 833 | //All this is to help in local messages |
---|
[3399] | 834 | //$return['timestamp'] = $header->udate; |
---|
[3499] | 835 | $return['timestamp'] = $header->udate; |
---|
[689] | 836 | $return['login'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];//$GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 837 | $return['reply_toaddress'] = $header->reply_toaddress; |
---|
[3394] | 838 | |
---|
| 839 | if($return_get_body['body']=='isSigned'){ |
---|
| 840 | imap_close($this->mbox); |
---|
| 841 | $new_mail = $this->show_decript($return_get_body,$dec = 1); |
---|
| 842 | //$new_mail['signature'] = $return_get_body['signature']; |
---|
| 843 | $return['body'] = $new_mail['body']; |
---|
| 844 | $return['attachments'] = $new_mail['attachments']; |
---|
| 845 | $return['thumbs'] = $new_mail['thumbs']; |
---|
| 846 | $return['folder'] = $return['msg_folder']; |
---|
| 847 | $return['original_ID'] = $return['msg_number']; |
---|
| 848 | $return['msg_folder'] = 'INBOX'.$this->imap_delimiter.'decifradas'; |
---|
| 849 | $return['msg_number'] = $new_mail['msg_no']; |
---|
| 850 | //$return['signature'] = $return_get_body['signature']; |
---|
| 851 | } |
---|
[2] | 852 | return $return; |
---|
| 853 | } |
---|
[1472] | 854 | |
---|
[1940] | 855 | function get_msg_sample($msg_number) |
---|
[1752] | 856 | { |
---|
| 857 | |
---|
[4140] | 858 | $return = ""; |
---|
| 859 | if( (!isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] != "1")) && |
---|
| 860 | (!isset($this->prefs['preview_msg_tip'] ) || ($this->prefs['preview_msg_tip'] != "1")) ) |
---|
[3049] | 861 | { |
---|
| 862 | $return['body'] = ""; |
---|
| 863 | return $return; |
---|
| 864 | } |
---|
[1752] | 865 | |
---|
| 866 | include_once("class.message_components.inc.php"); |
---|
| 867 | $msg = &new message_components($this->mbox); |
---|
[3049] | 868 | $msg->fetch_structure($msg_number); |
---|
[1752] | 869 | |
---|
| 870 | if(!$msg->structure[$msg_number]->parts) |
---|
| 871 | { |
---|
| 872 | $content = ''; |
---|
| 873 | if (strtolower($msg->structure[$msg_number]->subtype) == "plain" || strtolower($msg->structure[$msg_number]->subtype) == "html") |
---|
| 874 | { |
---|
| 875 | $content = $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID|FT_PEEK), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]); |
---|
| 876 | } |
---|
| 877 | } |
---|
| 878 | else |
---|
| 879 | { |
---|
| 880 | foreach($msg->pid[$msg_number] as $values => $msg_part) |
---|
| 881 | { |
---|
| 882 | |
---|
| 883 | $file_type = strtolower($msg->file_type[$msg_number][$values]); |
---|
| 884 | if($file_type == "text/plain" || $file_type == "text/html") { |
---|
| 885 | $content = $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID|FT_PEEK), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); |
---|
| 886 | break; |
---|
| 887 | } |
---|
| 888 | } |
---|
| 889 | } |
---|
| 890 | $content = $this->replace_special_characters($content); |
---|
| 891 | $tags_replace = array("<br>","<br/>","<br />"); |
---|
| 892 | $content = str_replace($tags_replace," ", $content); |
---|
| 893 | $content = strip_tags($content); |
---|
| 894 | $content = str_replace(array("{","}"," "), " ", $content); |
---|
| 895 | $content = trim($content); |
---|
[3249] | 896 | $content = html_entity_decode(substr($content,0,300)); |
---|
[1752] | 897 | $content != "" ? $return['body'] = " - " . $content: $return['body'] = ""; |
---|
| 898 | return $return; |
---|
| 899 | } |
---|
| 900 | |
---|
[2] | 901 | function get_body_msg($msg_number, $msg_folder) |
---|
| 902 | { |
---|
| 903 | include_once("class.message_components.inc.php"); |
---|
[51] | 904 | $msg = &new message_components($this->mbox); |
---|
[2] | 905 | $msg->fetch_structure($msg_number); |
---|
[51] | 906 | $return = array(); |
---|
[1472] | 907 | $return['attachments'] = $this-> download_attachment($msg,$msg_number); |
---|
[51] | 908 | if(!$this->has_cid) |
---|
[91] | 909 | { |
---|
[178] | 910 | $return['thumbs'] = $this->get_thumbs($msg,$msg_number,urlencode($msg_folder)); |
---|
[91] | 911 | $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); |
---|
[1472] | 912 | } |
---|
| 913 | |
---|
[2] | 914 | if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece |
---|
| 915 | { |
---|
[3394] | 916 | if((strtolower($msg->structure[$msg_number]->subtype) == 'x-pkcs7-mime') && (count($return['signature']) == 0 ) ){ |
---|
[3018] | 917 | $return['body']='isCripted'; |
---|
| 918 | return $return; |
---|
| 919 | } |
---|
[1035] | 920 | |
---|
[2] | 921 | $attachment = array(); //No attachments |
---|
[1035] | 922 | |
---|
[3394] | 923 | if (strtolower($msg->structure[$msg_number]->subtype) == "x-pkcs7-mime") |
---|
| 924 | { |
---|
| 925 | $return['body']='isSigned'; |
---|
| 926 | $headers = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); |
---|
| 927 | $header_body_array = explode('MIME-Version: 1.0', $headers); |
---|
| 928 | $show_pkcs7 = $header_body_array[0] . 'MIME-Version: 1.0' . chr(0x0D) .chr(0x0A). $return['signature'][0]; |
---|
| 929 | $return['source']=$show_pkcs7; |
---|
| 930 | array_shift($return['signature']); |
---|
| 931 | $return['signature']; |
---|
| 932 | //$return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); |
---|
| 933 | imap_close($this->mbox); |
---|
| 934 | return $return; |
---|
[1035] | 935 | } |
---|
| 936 | |
---|
[3018] | 937 | $content = ''; |
---|
| 938 | // If simple message is subtype 'html' or 'plain', then get content body. |
---|
| 939 | if(strtolower($msg->structure[$msg_number]->subtype) == "html" || |
---|
| 940 | strtolower( $msg -> structure[ $msg_number ] -> subtype ) == 'plain'){ |
---|
| 941 | |
---|
| 942 | $content = $this->decodeBody( |
---|
| 943 | imap_body( $this -> mbox, $msg_number, FT_UID ), |
---|
| 944 | $msg -> encoding[ $msg_number ][ 0 ], |
---|
| 945 | $msg -> charset[ $msg_number ][ 0 ] |
---|
| 946 | ); |
---|
| 947 | |
---|
| 948 | if ( strtolower( $msg -> structure[ $msg_number ] -> subtype ) == 'plain' ) |
---|
| 949 | { |
---|
| 950 | $content = str_replace( array( '<', '>' ), array( ' #$<$# ', ' #$>$# ' ), $content ); |
---|
| 951 | $content = htmlentities( $content ); |
---|
| 952 | $content = $this -> replace_links( $content ); |
---|
| 953 | $content = str_replace( array( ' #$<$# ', ' #$>$# ' ), array( '<', '>' ), $content ); |
---|
[3130] | 954 | $content = '<pre>' . $content . '</pre>'; |
---|
[3912] | 955 | $content = str_replace("\x00", '', $content); |
---|
| 956 | $return[ 'body' ] = $content; |
---|
[3018] | 957 | |
---|
| 958 | return $return; |
---|
| 959 | } |
---|
| 960 | } |
---|
[2] | 961 | } |
---|
[1472] | 962 | else |
---|
[2] | 963 | { //Complicated message, multiple parts |
---|
| 964 | $html_body = ''; |
---|
| 965 | $content = ''; |
---|
| 966 | $has_multipart = true; |
---|
[3922] | 967 | $is_alternative = false; |
---|
[2] | 968 | $this->has_cid = false; |
---|
[3922] | 969 | $alternative_content; |
---|
[3394] | 970 | array_shift($return['signature']); |
---|
[2] | 971 | if (strtolower($msg->structure[$msg_number]->subtype) == "related") |
---|
| 972 | $this->has_cid = true; |
---|
[1472] | 973 | |
---|
[469] | 974 | if (strtolower($msg->structure[$msg_number]->subtype) == "alternative") { |
---|
[3922] | 975 | $is_alternative = true; |
---|
[469] | 976 | $show_only_html = false; |
---|
| 977 | foreach($msg->pid[$msg_number] as $values => $msg_part) { |
---|
[432] | 978 | $file_type = strtolower($msg->file_type[$msg_number][$values]); |
---|
| 979 | if($file_type == "text/html") |
---|
[1472] | 980 | $show_only_html = true; |
---|
[432] | 981 | } |
---|
[469] | 982 | } |
---|
[2] | 983 | else |
---|
| 984 | $show_only_html = false; |
---|
| 985 | |
---|
| 986 | foreach($msg->pid[$msg_number] as $values => $msg_part) |
---|
| 987 | { |
---|
[1472] | 988 | |
---|
[2] | 989 | $file_type = strtolower($msg->file_type[$msg_number][$values]); |
---|
[3018] | 990 | if($file_type == "message/rfc822" || $file_type == "multipart/alternative") |
---|
| 991 | { |
---|
| 992 | // Show only 'text/html' part, when message/rfc822 format contains 'text/plain' alternative part. |
---|
| 993 | if(array_key_exists($values+1, $msg->file_type[$msg_number]) && |
---|
| 994 | strtolower($msg->file_type[$msg_number][$values+1]) == 'text/plain' && |
---|
| 995 | array_key_exists($values+2, $msg->file_type[$msg_number]) && |
---|
| 996 | strtolower($msg->file_type[$msg_number][$values+2]) == 'text/html') { |
---|
| 997 | $has_multipart = false; |
---|
| 998 | } |
---|
| 999 | } |
---|
[1472] | 1000 | |
---|
| 1001 | if(($file_type == "text/plain" |
---|
[2] | 1002 | || $file_type == "text/html") |
---|
[3018] | 1003 | && $file_type != 'attachment') |
---|
[2] | 1004 | { |
---|
[3414] | 1005 | |
---|
| 1006 | |
---|
| 1007 | if($this->prefs['max_msg_size'] == "1") |
---|
| 1008 | $max_size = 1048576; |
---|
| 1009 | else |
---|
| 1010 | $max_size = 102400; |
---|
| 1011 | |
---|
[2] | 1012 | if($file_type == "text/plain" && !$show_only_html && $has_multipart) |
---|
| 1013 | { |
---|
| 1014 | // if TXT file size > 100kb, then it will not expand. |
---|
[3414] | 1015 | if(!($file_type == "text/plain" && $msg->fsize[$msg_number][$values] > $max_size)) { |
---|
[3018] | 1016 | $content .= htmlentities($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); |
---|
[3414] | 1017 | $content = '<pre>' . $content . '</pre>'; |
---|
[2] | 1018 | } |
---|
| 1019 | } |
---|
| 1020 | // if HTML attachment file size > 300kb, then it will not expand. |
---|
[3414] | 1021 | else if($file_type == "text/html" && $msg->fsize[$msg_number][$values] < $max_size*3) |
---|
[2] | 1022 | { |
---|
[3922] | 1023 | if ($is_alternative) |
---|
| 1024 | { |
---|
| 1025 | $alternative_content = $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); |
---|
| 1026 | } |
---|
| 1027 | else |
---|
| 1028 | { |
---|
| 1029 | $content .= $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); |
---|
| 1030 | $show_only_html = true; |
---|
| 1031 | } |
---|
[2] | 1032 | } |
---|
| 1033 | } |
---|
[3018] | 1034 | else if($file_type == "message/delivery-status" || $file_type == "message/feedback-report"){ |
---|
[2] | 1035 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[3039] | 1036 | $content .= $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); |
---|
[3130] | 1037 | $content = '<pre>' . $content . '</pre>'; |
---|
[2] | 1038 | } |
---|
[65] | 1039 | else if($file_type == "message/rfc822" || $file_type == "text/rfc822-headers"){ |
---|
[1472] | 1040 | |
---|
[2] | 1041 | include_once("class.imap_attachment.inc.php"); |
---|
| 1042 | $att = new imap_attachment(); |
---|
[51] | 1043 | $attachments = $att -> get_attachment_info($this->mbox,$msg_number); |
---|
[3018] | 1044 | if($attachments['number_attachments'] > 0) { |
---|
| 1045 | foreach($attachments ['attachment'] as $index => $attachment) |
---|
| 1046 | { |
---|
| 1047 | if ( in_array( strtolower( $attachment[ 'type' ] ), array( 'delivery-status', 'rfc822', 'rfc822-headers', 'plain' ) ) ) |
---|
| 1048 | { |
---|
| 1049 | $obj = imap_rfc822_parse_headers( imap_fetchbody( $this -> mbox, $msg_number, $msg_part, FT_UID ), $msg -> encoding[ $msg_number ][ $values ] ); |
---|
[1897] | 1050 | |
---|
[3018] | 1051 | $content .= '<hr align="left" width="95%" style="border:1px solid #DCDCDC">'; |
---|
| 1052 | $content .= '<br><table style="margin:2px;border:1px solid black;background:#EAEAEA">'; |
---|
[1897] | 1053 | |
---|
[3018] | 1054 | $content .= '<tr><td><b>' . $this->functions->getLang("Subject") |
---|
| 1055 | . ':</b></td><td>' .$this->decode_string($obj->subject) . '</td></tr>'; |
---|
[1897] | 1056 | |
---|
[3018] | 1057 | $content .= '<tr><td><b>' . $this -> functions -> getLang( 'From' ) . ':</b></td><td>' |
---|
| 1058 | . $this -> replace_links( $this -> decode_string( $obj -> from[ 0 ] -> mailbox . '@' . $obj -> from[ 0 ] -> host) ) |
---|
| 1059 | . '</td></tr>'; |
---|
[1897] | 1060 | |
---|
[3018] | 1061 | $content .= '<tr><td><b>' . $this->functions->getLang("Date") . ':</b></td><td>' . $obj->date . '</td></tr>'; |
---|
[1897] | 1062 | |
---|
[3018] | 1063 | $content .= '<tr><td><b>' . $this -> functions -> getLang( 'TO' ) . ':</b></td><td>' |
---|
| 1064 | . $this -> replace_links( $this -> decode_string( $obj -> to[ 0 ] -> mailbox . '@' . $obj -> to[ 0 ] -> host ) ) |
---|
| 1065 | . '</td></tr>'; |
---|
[1897] | 1066 | |
---|
[3018] | 1067 | if ( $obj->cc ) |
---|
| 1068 | $content .= '<tr><td><b>' . $this -> functions -> getLang( 'CC' ) . ':</b></td><td>' |
---|
| 1069 | . $this -> replace_links( $this -> decode_string( $obj -> cc[ 0 ] -> mailbox . '@' . $obj -> cc[ 0 ] -> host ) ) |
---|
| 1070 | . '</td></tr>'; |
---|
[1897] | 1071 | |
---|
[3018] | 1072 | $content .= '</table><br>'; |
---|
[1897] | 1073 | |
---|
[3018] | 1074 | |
---|
| 1075 | $id = ( ( strtolower( $attachment[ 'type' ] ) == 'delivery-status' ) ? false : true ); |
---|
| 1076 | if ( strtolower( $msg->structure[$msg_number]->parts[1]->parts[0]->subtype ) == 'plain' ) |
---|
| 1077 | { |
---|
| 1078 | $id = !$id; |
---|
| 1079 | if ( $msg->structure[$msg_number]->parts[1]->parts[0]->encoding == 4 ) |
---|
| 1080 | $msg->encoding[ $msg_number ][ $values ] = 'quoted-printable'; |
---|
| 1081 | } |
---|
| 1082 | |
---|
| 1083 | $body = $this->decodeBody( |
---|
| 1084 | imap_fetchbody( |
---|
| 1085 | $this->mbox, |
---|
| 1086 | $msg_number, |
---|
| 1087 | ( $attachment['part_in_msg'] + ( ( int ) $id ) ) . ".1", |
---|
| 1088 | FT_UID |
---|
| 1089 | ), |
---|
| 1090 | $msg->encoding[ $msg_number ][ $values ], |
---|
| 1091 | $msg->charset[ $msg_number ][ $values ] |
---|
| 1092 | ); |
---|
| 1093 | |
---|
| 1094 | if ( strtolower( $msg->structure[$msg_number]->parts[1]->parts[0]->subtype ) == 'plain' ) |
---|
| 1095 | { |
---|
| 1096 | $body = str_replace( array( '<', '>' ), array( ' #$<$# ', ' #$>$# ' ), $body ); |
---|
| 1097 | $body = htmlentities( $body ); |
---|
| 1098 | $body = $this -> replace_links( $body ); |
---|
| 1099 | $body = str_replace( array( ' #$<$# ', ' #$>$# ' ), array( '<', '>' ), $body ); |
---|
[3130] | 1100 | $body = '<pre>' . $body . '</pre>'; |
---|
[3018] | 1101 | } |
---|
| 1102 | |
---|
| 1103 | $content .= $body; |
---|
| 1104 | break; |
---|
[2] | 1105 | } |
---|
| 1106 | } |
---|
| 1107 | } |
---|
| 1108 | } |
---|
| 1109 | } |
---|
[3922] | 1110 | if ($is_alternative && !empty($alternative_content)) |
---|
| 1111 | { |
---|
| 1112 | $content .= $alternative_content; |
---|
| 1113 | } |
---|
[2] | 1114 | if($file_type == "text/plain" && ($show_only_html && $msg_part == 1) || (!$show_only_html && $msg_part == 3)){ |
---|
| 1115 | if(strtolower($msg->structure[$msg_number]->subtype) == "mixed" && $msg_part == 1) |
---|
[51] | 1116 | $content .= nl2br(imap_base64(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID))); |
---|
[25] | 1117 | else if(!strtolower($msg->structure[$msg_number]->subtype) == "mixed") |
---|
[1472] | 1118 | $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID)); |
---|
[2] | 1119 | } |
---|
[1472] | 1120 | } |
---|
[2] | 1121 | // Force message with flag Seen (imap_fetchbody not works correctly) |
---|
[1472] | 1122 | $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); |
---|
[2] | 1123 | $this->set_messages_flag($params); |
---|
[205] | 1124 | $content = $this->process_embedded_images($msg,$msg_number,$content, $msg_folder); |
---|
[2] | 1125 | $content = $this->replace_special_characters($content); |
---|
[51] | 1126 | $return['body'] = $content; |
---|
| 1127 | return $return; |
---|
[2] | 1128 | } |
---|
[1472] | 1129 | |
---|
[2] | 1130 | function htmlfilter($body) |
---|
| 1131 | { |
---|
| 1132 | require_once('htmlfilter.inc'); |
---|
[1472] | 1133 | |
---|
[2] | 1134 | $tag_list = Array( |
---|
| 1135 | false, |
---|
| 1136 | 'blink', |
---|
| 1137 | 'object', |
---|
| 1138 | 'meta', |
---|
| 1139 | 'html', |
---|
| 1140 | 'link', |
---|
| 1141 | 'frame', |
---|
| 1142 | 'iframe', |
---|
| 1143 | 'layer', |
---|
| 1144 | 'ilayer', |
---|
| 1145 | 'plaintext' |
---|
| 1146 | ); |
---|
| 1147 | |
---|
| 1148 | /** |
---|
| 1149 | * A very exclusive set: |
---|
| 1150 | */ |
---|
| 1151 | // $tag_list = Array(true, "b", "a", "i", "img", "strong", "em", "p"); |
---|
| 1152 | $rm_tags_with_content = Array( |
---|
| 1153 | 'script', |
---|
| 1154 | 'style', |
---|
| 1155 | 'applet', |
---|
| 1156 | 'embed', |
---|
| 1157 | 'head', |
---|
| 1158 | 'frameset', |
---|
| 1159 | 'xml', |
---|
| 1160 | 'xmp' |
---|
| 1161 | ); |
---|
| 1162 | |
---|
| 1163 | $self_closing_tags = Array( |
---|
| 1164 | 'img', |
---|
| 1165 | 'br', |
---|
| 1166 | 'hr', |
---|
| 1167 | 'input' |
---|
| 1168 | ); |
---|
| 1169 | |
---|
| 1170 | $force_tag_closing = true; |
---|
| 1171 | |
---|
| 1172 | $rm_attnames = Array( |
---|
| 1173 | '/.*/' => |
---|
| 1174 | Array( |
---|
| 1175 | '/target/i', |
---|
| 1176 | //'/^on.*/i', -> onClick, dos compromissos da agenda. |
---|
| 1177 | '/^dynsrc/i', |
---|
| 1178 | '/^datasrc/i', |
---|
| 1179 | '/^data.*/i', |
---|
| 1180 | '/^lowsrc/i' |
---|
| 1181 | ) |
---|
| 1182 | ); |
---|
| 1183 | |
---|
| 1184 | /** |
---|
| 1185 | * Yeah-yeah, so this looks horrible. Check out htmlfilter.inc for |
---|
| 1186 | * some idea of what's going on here. :) |
---|
| 1187 | */ |
---|
| 1188 | |
---|
| 1189 | $bad_attvals = Array( |
---|
| 1190 | '/.*/' => |
---|
| 1191 | Array( |
---|
| 1192 | '/.*/' => |
---|
| 1193 | Array( |
---|
| 1194 | Array( |
---|
| 1195 | '/^([\'\"])\s*\S+\s*script\s*:*(.*)([\'\"])/si', |
---|
| 1196 | //'/^([\'\"])\s*https*\s*:(.*)([\'\"])/si', -> doclinks notes |
---|
| 1197 | '/^([\'\"])\s*mocha\s*:*(.*)([\'\"])/si', |
---|
| 1198 | '/^([\'\"])\s*about\s*:(.*)([\'\"])/si' |
---|
| 1199 | ), |
---|
| 1200 | Array( |
---|
| 1201 | '\\1oddjob:\\2\\1', |
---|
| 1202 | //'\\1uucp:\\2\\1', -> doclinks notes |
---|
| 1203 | '\\1amaretto:\\2\\1', |
---|
| 1204 | '\\1round:\\2\\1' |
---|
| 1205 | ) |
---|
[1472] | 1206 | ), |
---|
| 1207 | |
---|
[2] | 1208 | '/^style/i' => |
---|
| 1209 | Array( |
---|
| 1210 | Array( |
---|
| 1211 | '/expression/i', |
---|
| 1212 | '/behaviou*r/i', |
---|
| 1213 | '/binding/i', |
---|
| 1214 | '/include-source/i', |
---|
| 1215 | '/url\s*\(\s*([\'\"]*)\s*https*:.*([\'\"]*)\s*\)/si', |
---|
| 1216 | '/url\s*\(\s*([\'\"]*)\s*\S+\s*script:.*([\'\"]*)\s*\)/si' |
---|
| 1217 | ), |
---|
| 1218 | Array( |
---|
| 1219 | 'idiocy', |
---|
| 1220 | 'idiocy', |
---|
| 1221 | 'idiocy', |
---|
| 1222 | 'idiocy', |
---|
| 1223 | 'url(\\1http://securityfocus.com/\\1)', |
---|
| 1224 | 'url(\\1http://securityfocus.com/\\1)' |
---|
| 1225 | ) |
---|
| 1226 | ) |
---|
| 1227 | ) |
---|
| 1228 | ); |
---|
| 1229 | |
---|
| 1230 | $add_attr_to_tag = Array( |
---|
| 1231 | '/^a$/i' => Array('target' => '"_new"') |
---|
| 1232 | ); |
---|
[1472] | 1233 | |
---|
| 1234 | |
---|
[2] | 1235 | $trusted_body = sanitize($body, |
---|
| 1236 | $tag_list, |
---|
| 1237 | $rm_tags_with_content, |
---|
| 1238 | $self_closing_tags, |
---|
| 1239 | $force_tag_closing, |
---|
| 1240 | $rm_attnames, |
---|
| 1241 | $bad_attvals, |
---|
| 1242 | $add_attr_to_tag |
---|
| 1243 | ); |
---|
[1472] | 1244 | |
---|
[2] | 1245 | return $trusted_body; |
---|
| 1246 | } |
---|
[1472] | 1247 | |
---|
[2] | 1248 | function decodeBody($body, $encoding, $charset=null) |
---|
| 1249 | { |
---|
| 1250 | /** |
---|
| 1251 | * replace e-mail by anchor. |
---|
| 1252 | */ |
---|
| 1253 | // HTML Filter |
---|
[13] | 1254 | //$body = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=# onclick=\"javascript:new_message('new_by_message', '\\2@\\3')\">\\2@\\3</a>", $body); |
---|
[828] | 1255 | //$body = str_replace("\r\n", "\n", $body); |
---|
[2] | 1256 | if ($encoding == 'quoted-printable') |
---|
[828] | 1257 | { |
---|
| 1258 | /* |
---|
[1472] | 1259 | |
---|
[2] | 1260 | for($i=0;$i<256;$i++) { |
---|
| 1261 | $c1=dechex($i); |
---|
| 1262 | if(strlen($c1)==1){$c1="0".$c1;} |
---|
| 1263 | $c1="=".$c1; |
---|
| 1264 | $myqprinta[]=$c1; |
---|
| 1265 | $myqprintb[]=chr($i); |
---|
[1472] | 1266 | } |
---|
[828] | 1267 | */ |
---|
[2] | 1268 | $body = str_replace($myqprinta,$myqprintb,($body)); |
---|
| 1269 | $body = quoted_printable_decode($body); |
---|
[1472] | 1270 | while (ereg("=\n", $body)) |
---|
[2] | 1271 | { |
---|
| 1272 | $body = ereg_replace ("=\n", '', $body); |
---|
| 1273 | } |
---|
| 1274 | } |
---|
[1472] | 1275 | else if ($encoding == 'base64') |
---|
[2] | 1276 | { |
---|
| 1277 | $body = base64_decode($body); |
---|
| 1278 | } |
---|
[1792] | 1279 | |
---|
[2] | 1280 | // All other encodings are returned raw. |
---|
| 1281 | if (strtolower($charset) == "utf-8") |
---|
| 1282 | return utf8_decode($body); |
---|
| 1283 | else |
---|
| 1284 | return $body; |
---|
| 1285 | } |
---|
[1472] | 1286 | |
---|
[205] | 1287 | function process_embedded_images($msg, $msgno, $body, $msg_folder) |
---|
[2] | 1288 | { |
---|
| 1289 | if (count($msg->inline_id[$msgno]) > 0) |
---|
| 1290 | { |
---|
| 1291 | foreach ($msg->inline_id[$msgno] as $index => $cid) |
---|
| 1292 | { |
---|
| 1293 | $cid = eregi_replace("<", "", $cid); |
---|
| 1294 | $cid = eregi_replace(">", "", $cid); |
---|
| 1295 | $msg_part = $msg->pid[$msgno][$index]; |
---|
| 1296 | //$body = eregi_replace("alt=\"\"", "", $body); |
---|
| 1297 | $body = eregi_replace("<br/>", "", $body); |
---|
| 1298 | $body = str_replace("src=\"cid:".$cid."\"", " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=$msg_part\" ", $body); |
---|
| 1299 | $body = str_replace("src='cid:".$cid."'", " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=$msg_part\" ", $body); |
---|
| 1300 | $body = str_replace("src=cid:".$cid, " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=$msg_part\" ", $body); |
---|
| 1301 | } |
---|
| 1302 | } |
---|
[1472] | 1303 | |
---|
[2] | 1304 | return $body; |
---|
| 1305 | } |
---|
[1472] | 1306 | |
---|
[2] | 1307 | function replace_special_characters($body) |
---|
| 1308 | { |
---|
| 1309 | // Suspected TAGS! |
---|
[1472] | 1310 | /*$tag_list = Array( |
---|
[2] | 1311 | 'blink','object','meta', |
---|
| 1312 | 'html','link','frame', |
---|
| 1313 | 'iframe','layer','ilayer', |
---|
| 1314 | 'plaintext','script','style','img', |
---|
| 1315 | 'applet','embed','head', |
---|
| 1316 | 'frameset','xml','xmp'); |
---|
| 1317 | */ |
---|
| 1318 | |
---|
[1472] | 1319 | // Layout problem: Change html elements |
---|
| 1320 | // with absolute position to relate position, CASE INSENSITIVE. |
---|
[3912] | 1321 | $body = str_replace("\x00", '', $body); |
---|
| 1322 | $body = @mb_eregi_replace("POSITION: ABSOLUTE;","",$body); |
---|
[6] | 1323 | |
---|
[2] | 1324 | $tag_list = Array('head','blink','object','frame', |
---|
| 1325 | 'iframe','layer','ilayer','plaintext','script', |
---|
[63] | 1326 | 'applet','embed','frameset','xml','xmp','style'); |
---|
[2] | 1327 | |
---|
[1472] | 1328 | $blocked_tags = array(); |
---|
[2] | 1329 | foreach($tag_list as $index => $tag) { |
---|
[1233] | 1330 | $new_body = @mb_eregi_replace("<$tag", "<!--$tag", $body); |
---|
[2] | 1331 | if($body != $new_body) { |
---|
| 1332 | $blocked_tags[] = $tag; |
---|
| 1333 | } |
---|
[1233] | 1334 | $body = @mb_eregi_replace("</$tag>", "</$tag-->", $new_body); |
---|
[2] | 1335 | } |
---|
[650] | 1336 | // Malicious Code Remove |
---|
[1923] | 1337 | $dirtyCodePattern = "/(<([\w]+[\w0-9]*)(.*)on(mouse(move|over|down|up)|load|blur|change|error|click|dblclick|focus|key(down|up|press)|select)([\n\ ]*)=([\n\ ]*)[\"'][^>\"']*[\"']([^>]*)>)(.*)(<\/\\2>)?/misU"; |
---|
[650] | 1338 | preg_match_all($dirtyCodePattern,$body,$rest,PREG_PATTERN_ORDER); |
---|
| 1339 | foreach($rest[0] as $i => $val) |
---|
[1270] | 1340 | if (!(preg_match("/javascript:window\.open\(\"([^'\"]*)\/index\.php\?menuaction=calendar\.uicalendar\.set_action\&cal_id=([^;'\"]+);?['\"]/i",$rest[1][$i]) && strtoupper($rest[4][$i]) == "CLICK" )) //Calendar events |
---|
[3250] | 1341 | $body = str_replace($rest[1][$i],"<".$rest[2][$i].$rest[3][$i].$rest[7][$i].">",$body); |
---|
[2] | 1342 | |
---|
[3250] | 1343 | $body = $this-> replace_links($body); |
---|
| 1344 | |
---|
[4022] | 1345 | //Remoção de tags <span></span> para correção de erro no firefox |
---|
[3250] | 1346 | $body = mb_eregi_replace("<span><span>","",$body); |
---|
| 1347 | $body = mb_eregi_replace("</span></span>","",$body); |
---|
[4022] | 1348 | //Correção para compatibilização com Outlook, ao visualizar a mensagem |
---|
[3250] | 1349 | $body = mb_ereg_replace('<!--\[','<!-- [',$body); |
---|
[3294] | 1350 | $body = mb_ereg_replace('<!\[endif\]-->', '<![endif]-->', $body); |
---|
| 1351 | $body = str_replace("\x00", '', $body); |
---|
[3912] | 1352 | |
---|
[3250] | 1353 | return "<span>".$body; |
---|
[2] | 1354 | } |
---|
| 1355 | |
---|
[1897] | 1356 | function replace_links( $body ) |
---|
| 1357 | { |
---|
[3018] | 1358 | // Domains and IPs addresses found in the text and which is not a link yet should be replaced by one. |
---|
| 1359 | // See more informations in www.iana.org |
---|
| 1360 | $octets = array( |
---|
| 1361 | 'first' => '(2[0-3][0-9]|1[0-9]{2}|[1-9][0-9]?)', |
---|
| 1362 | 'middle' => '(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})', |
---|
| 1363 | 'last' => '(25[0-4]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)' |
---|
| 1364 | ); |
---|
[1897] | 1365 | |
---|
[3018] | 1366 | $ip = "\b{$octets[ 'first' ]}\.({$octets[ 'middle' ]}\.){2}{$octets[ 'last' ]}\b"; |
---|
[1472] | 1367 | |
---|
[3018] | 1368 | $top_level_domains = '(\.(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|as|asia|at|au|aw|ax|az|' |
---|
| 1369 | . 'ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bl|bm|bn|bo|br|bs|bt|bv|bw|by|bz|' |
---|
| 1370 | . 'ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cx|cy|cz|' |
---|
| 1371 | . 'de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|' |
---|
| 1372 | . 'ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|' |
---|
| 1373 | . 'hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|' |
---|
| 1374 | . 'ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|' |
---|
| 1375 | . 'ma|mc|md|me|mf|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|' |
---|
| 1376 | . 'mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|' |
---|
| 1377 | . 'pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|' |
---|
| 1378 | . 'sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|' |
---|
| 1379 | . 'tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|' |
---|
| 1380 | . 'ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))+\b'; |
---|
[1707] | 1381 | |
---|
[3018] | 1382 | $path = '(?>\/[\w\d\/\.\'\(\)\-\+~?!&#@$%|:;,*=_]+)?'; |
---|
| 1383 | $port = '(?>:\d{2,5})?'; |
---|
| 1384 | $domain = '(?>[\w\d_\-]+)'; |
---|
| 1385 | $subdomain = "(?>{$domain}\.)*"; |
---|
| 1386 | $protocol = '(?>(http|ftp)(s)?:\/\/)?'; |
---|
| 1387 | $url = "(?>{$protocol}((?>{$subdomain}{$domain}{$top_level_domains}|{$ip}){$port}{$path}))"; |
---|
[1707] | 1388 | |
---|
[3018] | 1389 | $pattern = "/(<\w[^>]+|[\/\"'@=])?{$url}/"; |
---|
| 1390 | ini_set( 'pcre.backtrack_limit', 300000 ); |
---|
| 1391 | |
---|
| 1392 | /* |
---|
| 1393 | // PHP 5.3 |
---|
| 1394 | $replace = function( $matches ) |
---|
| 1395 | { |
---|
| 1396 | if ( $matches[ 1 ] ) |
---|
| 1397 | return $matches[ 0 ]; |
---|
| 1398 | |
---|
| 1399 | $url = ( $matches[ 2 ] ) ? $matches[ 2 ] : 'http'; |
---|
| 1400 | $url .= "{$matches[ 3 ]}://{$matches[ 4 ]}"; |
---|
| 1401 | return "<a href=\"{$url}\" target=\"_blank\">{$matches[ 4 ]}</a>"; |
---|
| 1402 | }; |
---|
| 1403 | $body = preg_replace_callback( $pattern, $replace, $body ); |
---|
| 1404 | */ |
---|
| 1405 | |
---|
[4022] | 1406 | // PHP 5.2.x - Remover assim que possível |
---|
[3018] | 1407 | $body = preg_replace_callback( $pattern, |
---|
| 1408 | create_function( |
---|
| 1409 | '$matches', |
---|
| 1410 | 'if ( $matches[ 1 ] ) return $matches[ 0 ];' |
---|
| 1411 | . '$url = ( $matches[ 2 ] ) ? $matches[ 2 ] : "http";' |
---|
| 1412 | . '$url .= "{$matches[ 3 ]}://{$matches[ 4 ]}";' |
---|
| 1413 | . 'return "<a href=\"{$url}\" target=\"_blank\">{$matches[ 4 ]}</a>";' |
---|
| 1414 | ), $body |
---|
| 1415 | ); |
---|
| 1416 | ini_set( 'pcre.backtrack_limit', 100000 ); |
---|
[1897] | 1417 | // E-mail address in the text should create a new e-mail on ExpressoMail |
---|
[3018] | 1418 | $pattern = '/( |<|<|>)([A-Za-z0-9\.~?\/_=#\-]*@[A-Za-z0-9\.~?\/_=#\-]*)( |>|>|<)/im'; |
---|
| 1419 | $replacement = '$1<a href="mailto:$2">$2</a>$3'; |
---|
[1897] | 1420 | $body = preg_replace( $pattern, $replacement, $body ); |
---|
[1707] | 1421 | |
---|
| 1422 | return $body; |
---|
[2] | 1423 | } |
---|
| 1424 | |
---|
[91] | 1425 | function get_signature($msg, $msg_number, $msg_folder) |
---|
[1035] | 1426 | { |
---|
[3352] | 1427 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
| 1428 | include_once("class.db_functions.inc.php"); |
---|
| 1429 | foreach ($msg->file_type[$msg_number] as $index => $file_type) |
---|
| 1430 | { |
---|
| 1431 | $sign = array(); |
---|
| 1432 | $temp = $this->get_info_head_msg($msg_number); |
---|
| 1433 | if($temp['ContentType'] =='normal') return $sign; |
---|
| 1434 | $file_type = strtolower($file_type); |
---|
| 1435 | if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') |
---|
[91] | 1436 | { |
---|
[3394] | 1437 | if ($temp['ContentType'] == 'signature') |
---|
[3352] | 1438 | { |
---|
[3394] | 1439 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 1440 | $this->mbox = $this->open_mbox($msg_folder); |
---|
[1035] | 1441 | |
---|
[3352] | 1442 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); |
---|
[1035] | 1443 | |
---|
[3352] | 1444 | $imap_msg = @imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
| 1445 | $imap_msg .= @imap_body($this->mbox, $msg_number, FT_UID); |
---|
[1035] | 1446 | |
---|
[3352] | 1447 | $certificado = new certificadoB(); |
---|
| 1448 | $validade = $certificado->verificar($imap_msg); |
---|
[3394] | 1449 | $sign[] = $certificado->msg_sem_assinatura; |
---|
[3352] | 1450 | if ($certificado->apresentado) |
---|
| 1451 | { |
---|
| 1452 | $from = $header->from; |
---|
| 1453 | foreach ($from as $id => $object) |
---|
| 1454 | { |
---|
| 1455 | $fromname = $object->personal; |
---|
| 1456 | $fromaddress = $object->mailbox . "@" . $object->host; |
---|
| 1457 | } |
---|
| 1458 | foreach ($certificado->erros_ssl as $item) |
---|
| 1459 | { |
---|
| 1460 | $sign[] = $item . "#@#"; |
---|
| 1461 | } |
---|
[1035] | 1462 | |
---|
[3352] | 1463 | if (count($certificado->erros_ssl) < 1) |
---|
| 1464 | { |
---|
| 1465 | $check_msg = 'Message untouched'; |
---|
| 1466 | if(strtoupper($fromaddress) == strtoupper($certificado->dados['EMAIL'])) |
---|
| 1467 | { |
---|
| 1468 | $check_msg .= ' and authentic###'; |
---|
| 1469 | } |
---|
| 1470 | else |
---|
| 1471 | { |
---|
| 1472 | $check_msg .= ' with signer different from sender#@#'; |
---|
| 1473 | } |
---|
| 1474 | $sign[] = $check_msg; |
---|
| 1475 | } |
---|
| 1476 | |
---|
| 1477 | $sign[] = 'Message signed by: ###' . $certificado->dados['NOME']; |
---|
| 1478 | $sign[] = 'Certificate email: ###' . $certificado->dados['EMAIL']; |
---|
| 1479 | $sign[] = 'Mail from: ###' . $fromaddress; |
---|
| 1480 | $sign[] = 'Certificate Authority: ###' . $certificado->dados['EMISSOR']; |
---|
| 1481 | $sign[] = 'Validity of certificate: ###' . gmdate('r',openssl_to_timestamp($certificado->dados['FIM_VALIDADE'])); |
---|
| 1482 | $sign[] = 'Message date: ###' . $header->Date; |
---|
[1035] | 1483 | |
---|
[3352] | 1484 | $cert = openssl_x509_parse($certificado->cert_assinante); |
---|
[1035] | 1485 | |
---|
[3352] | 1486 | $sign_alert = array(); |
---|
| 1487 | $sign_alert[] = 'Certificate Owner###:\n'; |
---|
| 1488 | $sign_alert[] = 'Common Name (CN)### ' . $cert[subject]['CN'] . '\n'; |
---|
| 1489 | $X = substr($certificado->dados['NASCIMENTO'] ,0,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,2,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,4,4); |
---|
| 1490 | $sign_alert[]= 'Organization (O)### ' . $cert[subject]['O'] . '\n'; |
---|
| 1491 | $sign_alert[]= 'Organizational Unit (OU)### ' . $cert[subject]['OU'][0] . '\n'; |
---|
| 1492 | //$sign_alert[] = 'Serial Number### ' . $cert['serialNumber'] . '\n'; |
---|
| 1493 | $sign_alert[] = 'Personal Data###:' . '\n'; |
---|
| 1494 | $sign_alert[] = 'Birthday### ' . $X . '\n'; |
---|
| 1495 | $sign_alert[]= 'Fiscal Id### ' . $certificado->dados['CPF'] . '\n'; |
---|
| 1496 | $sign_alert[]= 'Identification### ' . $certificado->dados['RG'] . '\n\n'; |
---|
| 1497 | $sign_alert[]= 'Certificate Issuer###:\n'; |
---|
| 1498 | $sign_alert[]= 'Common Name (CN)### ' . $cert[issuer]['CN'] . '\n'; |
---|
| 1499 | $sign_alert[]= 'Organization (O)### ' . $cert[issuer]['O'] . '\n'; |
---|
| 1500 | $sign_alert[]= 'Organizational Unit (OU)### ' . $cert[issuer]['OU'][0] . '\n\n'; |
---|
| 1501 | $sign_alert[]= 'Validity###:\n'; |
---|
| 1502 | $H = data_hora($cert[validFrom]); |
---|
| 1503 | $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); |
---|
| 1504 | $sign_alert[]= 'Valid From### ' . $X . '\n'; |
---|
| 1505 | $H = data_hora($cert[validTo]); |
---|
| 1506 | $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); |
---|
| 1507 | $sign_alert[]= 'Valid Until### ' . $X; |
---|
| 1508 | $sign[] = $sign_alert; |
---|
| 1509 | |
---|
| 1510 | $this->db = new db_functions(); |
---|
| 1511 | |
---|
[4022] | 1512 | // TODO: testar se existe um certificado no banco e verificar qual ᅵ o mais atual. |
---|
[3352] | 1513 | if(!$certificado->dados['EXPIRADO'] && !$certificado->dados['REVOGADO'] && count($certificado->erros_ssl) < 1) |
---|
| 1514 | $this->db->insert_certificate(strtolower($certificado->dados['EMAIL']), $certificado->cert_assinante, $certificado->dados['SERIALNUMBER'], $certificado->dados['AUTHORITYKEYIDENTIFIER']); |
---|
[91] | 1515 | } |
---|
[3352] | 1516 | else |
---|
| 1517 | { |
---|
| 1518 | $sign[] = "<span style=color:red>" . $this->functions->getLang('Invalid signature') . "</span>"; |
---|
| 1519 | foreach($certificado->erros_ssl as $item) |
---|
| 1520 | $sign[] = "<span style=color:red>" . $this->functions->getLang($item) . "</span>"; |
---|
| 1521 | } |
---|
| 1522 | } |
---|
[91] | 1523 | } |
---|
[3352] | 1524 | } |
---|
| 1525 | return $sign; |
---|
[91] | 1526 | } |
---|
| 1527 | |
---|
[51] | 1528 | function get_thumbs($msg, $msg_number, $msg_folder) |
---|
[2] | 1529 | { |
---|
| 1530 | $thumbs_array = array(); |
---|
| 1531 | $i = 0; |
---|
| 1532 | foreach ($msg->file_type[$msg_number] as $index => $file_type) |
---|
| 1533 | { |
---|
| 1534 | $file_type = strtolower($file_type); |
---|
| 1535 | if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') { |
---|
| 1536 | if (($file_type == 'image/jpeg') || ($file_type == 'image/pjpeg') || ($file_type == 'image/gif') || ($file_type == 'image/png')) { |
---|
| 1537 | $img = "<IMG id='".$msg_folder.";;".$msg_number.";;".$i.";;".$msg->pid[$msg_number][$index].";;".$msg->encoding[$msg_number][$index]."' style='border:2px solid #fde7bc;padding:5px' title='".$this->functions->getLang("Click here do view (+)")."'src=./inc/show_thumbs.php?file_type=".$file_type."&msg_num=".$msg_number."&msg_folder=".$msg_folder."&msg_part=".$msg->pid[$msg_number][$index].">"; |
---|
[1005] | 1538 | $href = "<a onMouseDown='save_image(event,this,\"".$file_type."\")' href='#".$msg_folder.";;".$msg_number.";;".$i.";;".$msg->pid[$msg_number][$index].";;".$msg->encoding[$msg_number][$index]."' onClick=\"window.open('./inc/show_img.php?msg_num=".$msg_number."&msg_folder=".$msg_folder."&msg_part=".$msg->pid[$msg_number][$index]."','mywindow','width=700,height=600,scrollbars=yes');\">". $img ."</a>"; |
---|
[2] | 1539 | $thumbs_array[] = $href; |
---|
| 1540 | } |
---|
| 1541 | $i++; |
---|
| 1542 | } |
---|
| 1543 | } |
---|
| 1544 | return $thumbs_array; |
---|
| 1545 | } |
---|
[1472] | 1546 | |
---|
[2] | 1547 | /*function delete_msg($params) |
---|
| 1548 | { |
---|
| 1549 | $folder = $params['folder']; |
---|
| 1550 | $msgs_to_delete = explode(",",$params['msgs_to_delete']); |
---|
[1472] | 1551 | |
---|
[2] | 1552 | $mbox_stream = $this->open_mbox($folder); |
---|
[1472] | 1553 | |
---|
[2] | 1554 | foreach ($msgs_to_delete as $msg_number){ |
---|
| 1555 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
| 1556 | } |
---|
| 1557 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
| 1558 | return $params['msgs_to_delete']; |
---|
| 1559 | }*/ |
---|
| 1560 | |
---|
| 1561 | // Novo |
---|
| 1562 | function delete_msgs($params) |
---|
| 1563 | { |
---|
[1472] | 1564 | |
---|
[2] | 1565 | $folder = $params['folder']; |
---|
[51] | 1566 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); |
---|
[2] | 1567 | $msgs_number = explode(",",$params['msgs_number']); |
---|
| 1568 | $border_ID = $params['border_ID']; |
---|
[1472] | 1569 | |
---|
[2] | 1570 | $return = array(); |
---|
[1472] | 1571 | |
---|
[449] | 1572 | if ($params['get_previous_msg']){ |
---|
[2] | 1573 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
[449] | 1574 | // Fix problem in unserialize function JS. |
---|
| 1575 | $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); |
---|
| 1576 | } |
---|
[2] | 1577 | |
---|
[1472] | 1578 | //$mbox_stream = $this->open_mbox($folder); |
---|
[504] | 1579 | $mbox_stream = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); |
---|
[1472] | 1580 | |
---|
[2] | 1581 | foreach ($msgs_number as $msg_number) |
---|
| 1582 | { |
---|
| 1583 | if (imap_delete($mbox_stream, $msg_number, FT_UID)); |
---|
| 1584 | $return['msgs_number'][] = $msg_number; |
---|
| 1585 | } |
---|
[1472] | 1586 | |
---|
[2] | 1587 | $return['folder'] = $folder; |
---|
| 1588 | $return['border_ID'] = $border_ID; |
---|
[1472] | 1589 | |
---|
[51] | 1590 | if($mbox_stream) |
---|
| 1591 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 1592 | return $return; |
---|
| 1593 | } |
---|
| 1594 | |
---|
[1472] | 1595 | |
---|
[2] | 1596 | function refresh($params) |
---|
| 1597 | { |
---|
[3265] | 1598 | |
---|
[2] | 1599 | $folder = $params['folder']; |
---|
| 1600 | $msg_range_begin = $params['msg_range_begin']; |
---|
| 1601 | $msg_range_end = $params['msg_range_end']; |
---|
| 1602 | $msgs_existent = $params['msgs_existent']; |
---|
[1472] | 1603 | $sort_box_type = $params['sort_box_type']; |
---|
[2] | 1604 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 1605 | $msgs_in_the_server = array(); |
---|
[53] | 1606 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
[828] | 1607 | $msgs_in_the_server = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); |
---|
| 1608 | $msgs_in_the_server = array_keys($msgs_in_the_server); |
---|
| 1609 | if(!count($msgs_in_the_server)) |
---|
[51] | 1610 | return array(); |
---|
[1472] | 1611 | |
---|
[828] | 1612 | $num_msgs = (count($msgs_in_the_server) - imap_num_recent($this->mbox)); |
---|
[1472] | 1613 | $msgs_in_the_client = explode(",", $msgs_existent); |
---|
[51] | 1614 | |
---|
[2] | 1615 | $msg_to_insert = array_diff($msgs_in_the_server, $msgs_in_the_client); |
---|
[271] | 1616 | $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); |
---|
[1472] | 1617 | |
---|
[2] | 1618 | $msgs_to_exec = array(); |
---|
[3265] | 1619 | foreach($msg_to_insert as $msg_number) |
---|
| 1620 | $msgs_to_exec[] = $msg_number; |
---|
| 1621 | sort($msgs_to_exec); |
---|
[1472] | 1622 | |
---|
[2] | 1623 | $return = array(); |
---|
[4583] | 1624 | $return['new_msgs'] = imap_num_recent($this->mbox); |
---|
[2] | 1625 | $i = 0; |
---|
[3265] | 1626 | foreach($msgs_to_exec as $msg_number) |
---|
[2] | 1627 | { |
---|
[4022] | 1628 | /*A função imap_headerinfo não traz o cabeçalho completo, e sim alguns |
---|
| 1629 | * atributos do cabeçalho. Como eu preciso do atributo Importance |
---|
| 1630 | * para saber se o email é importante ou não, uso abaixo a função |
---|
[614] | 1631 | * imap_fetchheader e busco o atributo importance nela para passar |
---|
[4022] | 1632 | * para as funções ajax. Isso faz com que eu acesse o cabeçalho |
---|
[614] | 1633 | * duas vezes e de duas formas diferentes, mas em contrapartida, eu |
---|
[4022] | 1634 | * não preciso reimplementar o método utilizando o fetchheader. |
---|
[614] | 1635 | */ |
---|
[3955] | 1636 | |
---|
| 1637 | $tempHeader = @imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); |
---|
[1035] | 1638 | $flag = preg_match('/importance *: *(.*)\r/i', $tempHeader, $importance); |
---|
[689] | 1639 | $return[$i]['Importance'] = $flag==0?"Normal":$importance[1]; |
---|
[1472] | 1640 | |
---|
[1752] | 1641 | $msg_sample = $this->get_msg_sample($msg_number); |
---|
| 1642 | $return[$i]['msg_sample'] = $msg_sample; |
---|
| 1643 | |
---|
[535] | 1644 | $header = $this->get_header($msg_number); |
---|
[2] | 1645 | if (!is_object($header)) |
---|
[828] | 1646 | continue; |
---|
| 1647 | |
---|
[2] | 1648 | $return[$i]['msg_number'] = $msg_number; |
---|
[3955] | 1649 | |
---|
| 1650 | //get the next msg number to append this msg in the view in a correct place |
---|
| 1651 | $msg_key_position = array_search($msg_number, $msgs_in_the_server); |
---|
| 1652 | |
---|
| 1653 | if($msg_key_position !== false && array_key_exists($msg_key_position + 1) !== false) |
---|
| 1654 | $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position + 1]; |
---|
[1472] | 1655 | |
---|
[2] | 1656 | $return[$i]['msg_folder'] = $folder; |
---|
[3955] | 1657 | // Atribui o tipo (normal, signature ou cipher) ao campo Content-Type |
---|
[3265] | 1658 | $return[$i]['ContentType'] = $this->getMessageType($msg_number, $tempHeader); |
---|
[2] | 1659 | $return[$i]['Recent'] = $header->Recent; |
---|
| 1660 | $return[$i]['Unseen'] = $header->Unseen; |
---|
| 1661 | $return[$i]['Answered'] = $header->Answered; |
---|
| 1662 | $return[$i]['Deleted'] = $header->Deleted; |
---|
| 1663 | $return[$i]['Draft'] = $header->Draft; |
---|
| 1664 | $return[$i]['Flagged'] = $header->Flagged; |
---|
| 1665 | |
---|
[3106] | 1666 | $return[$i]['udate'] = $header->udate; |
---|
| 1667 | |
---|
[2] | 1668 | $from = $header->from; |
---|
| 1669 | $return[$i]['from'] = array(); |
---|
| 1670 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 1671 | $return[$i]['from']['name'] = $tmp[0]->text; |
---|
| 1672 | $return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
[1472] | 1673 | //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; |
---|
[2] | 1674 | if(!$return[$i]['from']['name']) |
---|
| 1675 | $return[$i]['from']['name'] = $return[$i]['from']['email']; |
---|
[1472] | 1676 | |
---|
[2] | 1677 | /*$toaddress = imap_mime_header_decode($header->toaddress); |
---|
| 1678 | $return[$i]['toaddress'] = ''; |
---|
| 1679 | foreach ($toaddress as $tmp) |
---|
| 1680 | $return[$i]['toaddress'] .= $tmp->text;*/ |
---|
| 1681 | $to = $header->to; |
---|
| 1682 | $return[$i]['to'] = array(); |
---|
| 1683 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
| 1684 | $return[$i]['to']['name'] = $tmp[0]->text; |
---|
| 1685 | $return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
| 1686 | $return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; |
---|
[3777] | 1687 | $cc = $header->cc; |
---|
| 1688 | if ( ($cc) && (!$return[$i]['to']['name']) ){ |
---|
| 1689 | $return[$i]['to']['name'] = $cc[0]->personal; |
---|
| 1690 | $return[$i]['to']['email'] = $cc[0]->mailbox . "@" . $cc[0]->host; |
---|
| 1691 | } |
---|
[2] | 1692 | $return[$i]['subject'] = $this->decode_string($header->fetchsubject); |
---|
| 1693 | |
---|
| 1694 | $return[$i]['Size'] = $header->Size; |
---|
| 1695 | $return[$i]['reply_toaddress'] = $header->reply_toaddress; |
---|
[1472] | 1696 | |
---|
[2] | 1697 | $return[$i]['attachment'] = array(); |
---|
[3265] | 1698 | if (!isset($imap_attachment)) |
---|
| 1699 | { |
---|
| 1700 | include_once("class.imap_attachment.inc.php"); |
---|
| 1701 | $imap_attachment = new imap_attachment(); |
---|
| 1702 | } |
---|
[51] | 1703 | $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); |
---|
[2] | 1704 | $i++; |
---|
| 1705 | } |
---|
[3265] | 1706 | $return['quota'] = $this->get_quota(array('folder_id' => $folder)); |
---|
| 1707 | $return['sort_box_type'] = $params['sort_box_type']; |
---|
[3427] | 1708 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 1709 | { |
---|
| 1710 | $this->open_mbox($folder); |
---|
| 1711 | } |
---|
[4583] | 1712 | |
---|
[271] | 1713 | $return['msgs_to_delete'] = $msg_to_delete; |
---|
[3493] | 1714 | $return['offsetToGMT'] = $this->functions->CalculateDateOffset(); |
---|
[411] | 1715 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 1716 | imap_close($this->mbox); |
---|
[828] | 1717 | |
---|
[2] | 1718 | return $return; |
---|
| 1719 | } |
---|
| 1720 | |
---|
[1035] | 1721 | /** |
---|
[4022] | 1722 | * Método que faz a verificação do Content-Type do e-mail e verifica se é um e-mail normal, |
---|
[1035] | 1723 | * assinado ou cifrado. |
---|
[4022] | 1724 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
| 1725 | * @param $headers Uma String contendo os Headers do e-mail retornados pela função imap_imap_fetchheader |
---|
| 1726 | * @param $msg_number O número da mesagem |
---|
[1035] | 1727 | * @return Retorna o tipo da mensagem (normal, signature, cipher). |
---|
| 1728 | */ |
---|
| 1729 | function getMessageType($msg_number, $headers = false){ |
---|
[3394] | 1730 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
[1035] | 1731 | $contentType = "normal"; |
---|
| 1732 | if (!$headers){ |
---|
| 1733 | $headers = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); |
---|
| 1734 | } |
---|
[3394] | 1735 | |
---|
| 1736 | if (preg_match("/pkcs7-signature/i", $headers) == 1){ |
---|
[1035] | 1737 | $contentType = "signature"; |
---|
[3394] | 1738 | } else if (preg_match("/pkcs7-mime/i", $headers) == 1){ |
---|
| 1739 | $contentType = testa_p7m( imap_body($this->mbox, imap_msgno($this->mbox, $msg_number)) ); |
---|
[1035] | 1740 | } |
---|
| 1741 | |
---|
| 1742 | return $contentType; |
---|
| 1743 | } |
---|
| 1744 | |
---|
[1375] | 1745 | /** |
---|
| 1746 | * Metodo que retorna todas as pastas do usuario logado. |
---|
| 1747 | * @param $params array opcional para repassar os argumentos ao metodo. |
---|
[4022] | 1748 | * Se usar $params['noSharedFolders'] = true, ira retornar todas as pastas do usuário logado, |
---|
[1375] | 1749 | * excluindo as compartilhadas para ele. |
---|
[4022] | 1750 | * Se usar $params['folderType'] = "default" irá retornar somente as pastas defaults |
---|
| 1751 | * Se usar $params['folderType'] = "personal" irá retornar somente as pastas pessoais |
---|
| 1752 | * Se usar $params['folderType'] = null irá retornar todas as pastas |
---|
[1472] | 1753 | * @return Retorna um array contendo as seguintes informacoes de cada pasta: folder_unseen, |
---|
[1375] | 1754 | * folder_id, folder_name, folder_parent e folder_hasChildren. |
---|
[1472] | 1755 | */ |
---|
[449] | 1756 | function get_folders_list($params = null) |
---|
[2] | 1757 | { |
---|
[1472] | 1758 | $mbox_stream = $this->open_mbox(); |
---|
[1953] | 1759 | if($params && $params['onload'] && $_SESSION['phpgw_info']['expressomail']['server']['certificado']){ |
---|
| 1760 | $this->delete_mailbox(array("del_past" => "INBOX/decifradas")); |
---|
| 1761 | } |
---|
[650] | 1762 | |
---|
[4581] | 1763 | $inbox = 'INBOX'; |
---|
| 1764 | $trash = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; |
---|
[3018] | 1765 | $drafts = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']; |
---|
[4581] | 1766 | $spam = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']; |
---|
| 1767 | $sent = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']; |
---|
[3018] | 1768 | $uid2cn = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn']; |
---|
| 1769 | // Free others requests |
---|
| 1770 | session_write_close(); |
---|
[1816] | 1771 | |
---|
[3018] | 1772 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
[3790] | 1773 | |
---|
[3192] | 1774 | if ( $params && $params['noSharedFolders'] ) |
---|
[3790] | 1775 | $folders_list = array_merge(imap_getmailboxes($mbox_stream, $serverString, 'INBOX' ), imap_getmailboxes($mbox_stream, $serverString, 'INBOX/*' ) ); |
---|
| 1776 | else |
---|
| 1777 | $folders_list = imap_getmailboxes($mbox_stream, $serverString, '*' ); |
---|
[3761] | 1778 | |
---|
[3018] | 1779 | $folders_list = array_slice($folders_list,0,$this->foldersLimit); |
---|
| 1780 | |
---|
| 1781 | $tmp = array(); |
---|
| 1782 | $resultMine = array(); |
---|
| 1783 | $resultDefault = array(); |
---|
| 1784 | |
---|
[4581] | 1785 | if ( is_array($folders_list) ) |
---|
| 1786 | { |
---|
[3761] | 1787 | reset($folders_list); |
---|
| 1788 | $this->ldap = new ldap_functions(); |
---|
[1472] | 1789 | |
---|
[2] | 1790 | $i = 0; |
---|
[1035] | 1791 | |
---|
[4581] | 1792 | while (list($key, $val) = each($folders_list)) |
---|
| 1793 | { |
---|
| 1794 | $status = imap_status( $mbox_stream, $val->name, SA_UNSEEN ); |
---|
| 1795 | |
---|
| 1796 | $tmp_folder_id = explode("}", $val->name ); |
---|
[3761] | 1797 | |
---|
[4581] | 1798 | $folderUser = trim( strpos( $tmp_folder_id[1], $this->imap_delimiter , 5 ) ); |
---|
[1472] | 1799 | |
---|
[4581] | 1800 | $folderUser = trim( substr( $tmp_folder_id[1], 0, $folderUser ) ); |
---|
[1472] | 1801 | |
---|
[4581] | 1802 | $Permission = true; |
---|
| 1803 | |
---|
| 1804 | if( $folderUser != "INBOX" && $folderUser != "" ) |
---|
| 1805 | { |
---|
| 1806 | $Permission = imap_getacl( $mbox_stream, $folderUser ); |
---|
| 1807 | } |
---|
| 1808 | |
---|
| 1809 | if( $Permission ) |
---|
| 1810 | { |
---|
[4587] | 1811 | $tmp_folder_id[1] = mb_convert_encoding( $tmp_folder_id[1], "ISO-8859-1", "UTF7-IMAP" ); |
---|
[1472] | 1812 | |
---|
[4581] | 1813 | if( $tmp_folder_id[1]=='INBOX'.$this->imap_delimiter.'decifradas') |
---|
| 1814 | { |
---|
| 1815 | //error_log('passou', 3,'/tmp/imap_get_list.log'); |
---|
| 1816 | //imap_deletemailbox($mbox_stream,imap_utf7_encode("{".$this->imap_server."}".'INBOX/decifradas')); |
---|
| 1817 | continue; |
---|
| 1818 | } |
---|
| 1819 | |
---|
| 1820 | $result[$i]['folder_unseen'] = $status->unseen; |
---|
| 1821 | $folder_id = $tmp_folder_id[1]; |
---|
| 1822 | $result[$i]['folder_id'] = $folder_id; |
---|
[2] | 1823 | |
---|
[4581] | 1824 | $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); |
---|
| 1825 | $result[$i]['folder_name'] = array_pop($tmp_folder_parent); |
---|
| 1826 | $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; |
---|
[1816] | 1827 | |
---|
[4581] | 1828 | if ($uid2cn && substr($folder_id,0,4) == 'user') |
---|
| 1829 | { |
---|
| 1830 | //$this->ldap = new ldap_functions(); |
---|
| 1831 | if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])) |
---|
| 1832 | { |
---|
| 1833 | $result[$i]['folder_name'] = $cn; |
---|
| 1834 | } |
---|
| 1835 | } |
---|
| 1836 | |
---|
| 1837 | $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); |
---|
| 1838 | $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; |
---|
| 1839 | |
---|
| 1840 | if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) |
---|
| 1841 | $result[$i]['folder_hasChildren'] = 1; |
---|
| 1842 | else |
---|
| 1843 | $result[$i]['folder_hasChildren'] = 0; |
---|
| 1844 | |
---|
| 1845 | switch ($tmp_folder_id[1]) |
---|
| 1846 | { |
---|
| 1847 | case $inbox: |
---|
| 1848 | case $sent: |
---|
| 1849 | case $drafts: |
---|
| 1850 | case $spam: |
---|
| 1851 | case $trash: |
---|
| 1852 | $resultDefault[]=$result[$i]; |
---|
| 1853 | break; |
---|
| 1854 | default: |
---|
| 1855 | $resultMine[]=$result[$i]; |
---|
| 1856 | } |
---|
| 1857 | } |
---|
| 1858 | |
---|
| 1859 | $i++; |
---|
| 1860 | } |
---|
[2] | 1861 | } |
---|
[1472] | 1862 | |
---|
[3564] | 1863 | if ( $params && !$params['noQuotaInfo'] ) { |
---|
| 1864 | //Get quota info of current folder |
---|
| 1865 | $current_folder = "INBOX"; |
---|
| 1866 | if($params && $params['folder']) |
---|
| 1867 | $current_folder = $params['folder']; |
---|
[3790] | 1868 | |
---|
[3564] | 1869 | $arr_quota_info = $this->get_quota(array('folder_id' => $current_folder)); |
---|
| 1870 | } else { |
---|
| 1871 | $arr_quota_info = array(); |
---|
| 1872 | } |
---|
[3790] | 1873 | |
---|
[1816] | 1874 | // Sorting resultMine |
---|
| 1875 | foreach ($resultMine as $folder_info) |
---|
[2] | 1876 | { |
---|
| 1877 | $array_tmp[] = $folder_info['folder_id']; |
---|
| 1878 | } |
---|
[1472] | 1879 | |
---|
[2] | 1880 | natcasesort($array_tmp); |
---|
[3575] | 1881 | |
---|
[3790] | 1882 | $result2 = array(); |
---|
[1472] | 1883 | |
---|
[2] | 1884 | foreach ($array_tmp as $key => $folder_id) |
---|
| 1885 | { |
---|
[1816] | 1886 | $result2[] = $resultMine[$key]; |
---|
[2] | 1887 | } |
---|
[1816] | 1888 | |
---|
| 1889 | // Sorting resultDefault |
---|
| 1890 | foreach ($resultDefault as $key => $folder_id) |
---|
| 1891 | { |
---|
| 1892 | switch ($resultDefault[$key]['folder_id']) { |
---|
[1824] | 1893 | case $inbox: |
---|
[1816] | 1894 | $resultDefault2[0] = $resultDefault[$key]; |
---|
| 1895 | break; |
---|
[1824] | 1896 | case $sent: |
---|
[1816] | 1897 | $resultDefault2[1] = $resultDefault[$key]; |
---|
| 1898 | break; |
---|
[1824] | 1899 | case $drafts: |
---|
[1816] | 1900 | $resultDefault2[2] = $resultDefault[$key]; |
---|
| 1901 | break; |
---|
[1824] | 1902 | case $spam: |
---|
[1816] | 1903 | $resultDefault2[3] = $resultDefault[$key]; |
---|
| 1904 | break; |
---|
[1824] | 1905 | case $trash: |
---|
[1816] | 1906 | $resultDefault2[4] = $resultDefault[$key]; |
---|
| 1907 | break; |
---|
| 1908 | } |
---|
| 1909 | } |
---|
[3553] | 1910 | |
---|
| 1911 | if ( $params && $params['folderType'] && $params['folderType'] == 'default' ) |
---|
[3790] | 1912 | return array_merge($resultDefault2, $arr_quota_info); |
---|
[1816] | 1913 | |
---|
[3553] | 1914 | if ( $params && $params['folderType'] && $params['folderType'] == 'personal' ) |
---|
[3790] | 1915 | return array_merge($result2, $arr_quota_info); |
---|
| 1916 | |
---|
[3553] | 1917 | // Merge default folders and personal |
---|
[3790] | 1918 | $result2 = array_merge($resultDefault2, $result2); |
---|
[1816] | 1919 | |
---|
[3553] | 1920 | return array_merge($result2, $arr_quota_info); |
---|
[2] | 1921 | } |
---|
[1472] | 1922 | |
---|
[2] | 1923 | function create_mailbox($arr) |
---|
| 1924 | { |
---|
| 1925 | $namebox = $arr['newp']; |
---|
| 1926 | $mbox_stream = $this->open_mbox(); |
---|
| 1927 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[51] | 1928 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); |
---|
[1472] | 1929 | |
---|
[2] | 1930 | $result = "Ok"; |
---|
[51] | 1931 | if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
[2] | 1932 | { |
---|
| 1933 | $result = implode("<br />\n", imap_errors()); |
---|
[1472] | 1934 | } |
---|
| 1935 | |
---|
[51] | 1936 | if($mbox_stream) |
---|
| 1937 | imap_close($mbox_stream); |
---|
[1472] | 1938 | |
---|
[2] | 1939 | return $result; |
---|
[1472] | 1940 | |
---|
[2] | 1941 | } |
---|
[1472] | 1942 | |
---|
[2] | 1943 | function create_extra_mailbox($arr) |
---|
| 1944 | { |
---|
| 1945 | $nameboxs = explode(";",$arr['nw_folders']); |
---|
| 1946 | $result = ""; |
---|
| 1947 | $mbox_stream = $this->open_mbox(); |
---|
| 1948 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[1472] | 1949 | foreach($nameboxs as $key=>$tmp){ |
---|
[2] | 1950 | if($tmp != ""){ |
---|
| 1951 | if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ |
---|
| 1952 | $result = implode("<br />\n", imap_errors()); |
---|
[51] | 1953 | if($mbox_stream) |
---|
[1472] | 1954 | imap_close($mbox_stream); |
---|
[2] | 1955 | return $result; |
---|
| 1956 | } |
---|
| 1957 | } |
---|
| 1958 | } |
---|
[51] | 1959 | if($mbox_stream) |
---|
| 1960 | imap_close($mbox_stream); |
---|
[2] | 1961 | return true; |
---|
| 1962 | } |
---|
[1472] | 1963 | |
---|
[2] | 1964 | function delete_mailbox($arr) |
---|
| 1965 | { |
---|
| 1966 | $namebox = $arr['del_past']; |
---|
| 1967 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[1953] | 1968 | $mbox_stream = $this->mbox ? $this->mbox : $this->open_mbox(); |
---|
[2] | 1969 | //$del_folder = imap_deletemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox"); |
---|
[1472] | 1970 | |
---|
[2] | 1971 | $result = "Ok"; |
---|
| 1972 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
| 1973 | if(!imap_deletemailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
| 1974 | { |
---|
| 1975 | $result = implode("<br />\n", imap_errors()); |
---|
| 1976 | } |
---|
[1953] | 1977 | /* |
---|
[51] | 1978 | if($mbox_stream) |
---|
| 1979 | imap_close($mbox_stream); |
---|
[1953] | 1980 | */ |
---|
[2] | 1981 | return $result; |
---|
| 1982 | } |
---|
[1472] | 1983 | |
---|
[2] | 1984 | function ren_mailbox($arr) |
---|
| 1985 | { |
---|
| 1986 | $namebox = $arr['current']; |
---|
| 1987 | $new_box = $arr['rename']; |
---|
| 1988 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 1989 | $mbox_stream = $this->open_mbox(); |
---|
| 1990 | //$ren_folder = imap_renamemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox","{".$imap_server."}INBOX.$new_box"); |
---|
[1472] | 1991 | |
---|
[2] | 1992 | $result = "Ok"; |
---|
| 1993 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
[51] | 1994 | $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); |
---|
[1472] | 1995 | |
---|
[2] | 1996 | if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) |
---|
| 1997 | { |
---|
[1472] | 1998 | $result = imap_errors(); |
---|
[2] | 1999 | } |
---|
[51] | 2000 | if($mbox_stream) |
---|
| 2001 | imap_close($mbox_stream); |
---|
[2] | 2002 | return $result; |
---|
[1472] | 2003 | |
---|
[2] | 2004 | } |
---|
[1472] | 2005 | |
---|
[2] | 2006 | function get_num_msgs($params) |
---|
| 2007 | { |
---|
| 2008 | $folder = $params['folder']; |
---|
[411] | 2009 | if(!$this->mbox || !is_resource($this->mbox)) { |
---|
[2] | 2010 | $this->mbox = $this->open_mbox($folder); |
---|
[411] | 2011 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[2] | 2012 | return imap_last_error(); |
---|
[1472] | 2013 | } |
---|
[2] | 2014 | $num_msgs = imap_num_msg($this->mbox); |
---|
[432] | 2015 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 2016 | imap_close($this->mbox); |
---|
[1472] | 2017 | |
---|
[2] | 2018 | return $num_msgs; |
---|
| 2019 | } |
---|
[1472] | 2020 | |
---|
[1912] | 2021 | function folder_exists($folder){ |
---|
| 2022 | $mbox = $this->open_mbox(); |
---|
| 2023 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 2024 | $list = imap_getmailboxes($mbox,$serverString, $folder); |
---|
| 2025 | $return = is_array($list); |
---|
| 2026 | imap_close($mbox); |
---|
| 2027 | return $return; |
---|
| 2028 | } |
---|
| 2029 | |
---|
[2] | 2030 | function send_mail($params) |
---|
| 2031 | { |
---|
| 2032 | include_once("class.phpmailer.php"); |
---|
| 2033 | $mail = new PHPMailer(); |
---|
| 2034 | include_once("class.db_functions.inc.php"); |
---|
| 2035 | $db = new db_functions(); |
---|
| 2036 | $fromaddress = $params['input_from'] ? explode(';',$params['input_from']) : ""; |
---|
[449] | 2037 | ## |
---|
| 2038 | # @AUTHOR Rodrigo Souza dos Santos |
---|
[3369] | 2039 | # @DATE 2008/09/17$fileName |
---|
[449] | 2040 | # @BRIEF Checks if the user has permission to send an email with the email address used. |
---|
| 2041 | ## |
---|
| 2042 | if ( is_array($fromaddress) && ($fromaddress[1] != $_SESSION['phpgw_info']['expressomail']['user']['email']) ) |
---|
| 2043 | { |
---|
| 2044 | $deny = true; |
---|
| 2045 | foreach( $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] as $key => $val ) |
---|
| 2046 | if ( array_key_exists('mail', $val) && $val['mail'][0] == $fromaddress[1] ) |
---|
| 2047 | $deny = false and end($_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes']); |
---|
| 2048 | |
---|
| 2049 | if ( $deny ) |
---|
| 2050 | return "The server denied your request to send a mail, you cannot use this mail address."; |
---|
| 2051 | } |
---|
[828] | 2052 | |
---|
[2] | 2053 | $toaddress = implode(',',$db->getAddrs(explode(',',$params['input_to']))); |
---|
| 2054 | $ccaddress = implode(',',$db->getAddrs(explode(',',$params['input_cc']))); |
---|
| 2055 | $ccoaddress = implode(',',$db->getAddrs(explode(',',$params['input_cco']))); |
---|
[3527] | 2056 | $replytoaddress = $params['input_replyto']; |
---|
[2] | 2057 | $subject = $params['input_subject']; |
---|
[271] | 2058 | $msg_uid = $params['msg_id']; |
---|
[2] | 2059 | $return_receipt = $params['input_return_receipt']; |
---|
[614] | 2060 | $is_important = $params['input_important_message']; |
---|
[1035] | 2061 | $encrypt = $params['input_return_cripto']; |
---|
| 2062 | $signed = $params['input_return_digital']; |
---|
| 2063 | |
---|
| 2064 | if($params['smime']) |
---|
| 2065 | { |
---|
| 2066 | $body = $params['smime']; |
---|
| 2067 | $mail->SMIME = true; |
---|
| 2068 | // A MSG assinada deve ser testada neste ponto. |
---|
| 2069 | // Testar o certificado e a integridade da msg.... |
---|
[3271] | 2070 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
[1035] | 2071 | $erros_acumulados = ''; |
---|
| 2072 | $certificado = new certificadoB(); |
---|
| 2073 | $validade = $certificado->verificar($body); |
---|
| 2074 | if(!$validade) |
---|
| 2075 | { |
---|
| 2076 | foreach($certificado->erros_ssl as $linha_erro) |
---|
| 2077 | { |
---|
| 2078 | $erros_acumulados .= $linha_erro; |
---|
| 2079 | } |
---|
| 2080 | } |
---|
| 2081 | else |
---|
| 2082 | { |
---|
| 2083 | // Testa o CERTIFICADO: se o CPF he o do usuario logado, se pode assinar msgs e se nao esta expirado... |
---|
| 2084 | if ($certificado->apresentado) |
---|
| 2085 | { |
---|
| 2086 | if($certificado->dados['EXPIRADO']) $erros_acumulados .='Certificado expirado.'; |
---|
| 2087 | if($certificado->dados['CPF'] != $this->username) $erros_acumulados .=' CPF no certificado diferente do logado no expresso.'; |
---|
| 2088 | if(!($certificado->dados['KEYUSAGE']['digitalSignature'] && $certificado->dados['EXTKEYUSAGE']['emailProtection'])) $erros_acumulados .=' Certificado nao permite assinar mensagens.'; |
---|
| 2089 | } |
---|
| 2090 | else |
---|
| 2091 | { |
---|
| 2092 | $$erros_acumulados .= 'Nao foi possivel usar o certificado para assinar a msg'; |
---|
| 2093 | } |
---|
| 2094 | } |
---|
| 2095 | if(!$erros_acumulados =='') |
---|
| 2096 | { |
---|
| 2097 | return $erros_acumulados; |
---|
| 2098 | } |
---|
| 2099 | } |
---|
| 2100 | else |
---|
| 2101 | { |
---|
| 2102 | $body = $params['body']; |
---|
[4022] | 2103 | //Compatibilização com Outlook, ao encaminhar a mensagem |
---|
[3250] | 2104 | $body = mb_ereg_replace('<!--\[','<!-- [',$body); |
---|
[1035] | 2105 | } |
---|
[1247] | 2106 | //echo "<script language=\"javascript\">javascript:alert('".$body."');</script>"; |
---|
[3900] | 2107 | $attachments = $_FILES; |
---|
[2] | 2108 | $forwarding_attachments = $params['forwarding_attachments']; |
---|
[689] | 2109 | $local_attachments = $params['local_attachments']; |
---|
[3369] | 2110 | |
---|
[1912] | 2111 | //Test if must be saved in shared folder and change if necessary |
---|
| 2112 | if( $fromaddress[2] == 'y' ){ |
---|
| 2113 | //build shared folder path |
---|
| 2114 | $newfolder = "user".$this->imap_delimiter.$fromaddress[3].$this->imap_delimiter.$this->imap_sentfolder; |
---|
| 2115 | if( $this->folder_exists($newfolder) ) $folder = $newfolder; |
---|
| 2116 | else $folder = $params['folder']; |
---|
| 2117 | } else { |
---|
| 2118 | $folder = $params['folder']; |
---|
| 2119 | } |
---|
| 2120 | |
---|
[4587] | 2121 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); |
---|
[1472] | 2122 | $folder_name = $params['folder_name']; |
---|
[6] | 2123 | // Fix problem with cyrus delimiter changes. |
---|
[1472] | 2124 | // Dots in names: enabled/disabled. |
---|
[6] | 2125 | $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); |
---|
| 2126 | $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); |
---|
| 2127 | // End Fix. |
---|
[1472] | 2128 | if ($folder != 'null'){ |
---|
[2] | 2129 | $mail->SaveMessageInFolder = $folder; |
---|
| 2130 | } |
---|
| 2131 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2132 | $mail->SMTPDebug = false; |
---|
[1035] | 2133 | |
---|
| 2134 | if($signed && !$params['smime']) |
---|
| 2135 | { |
---|
| 2136 | $mail->Mailer = "smime"; |
---|
| 2137 | $mail->SignedBody = true; |
---|
| 2138 | } |
---|
| 2139 | else |
---|
| 2140 | $mail->IsSMTP(); |
---|
[1472] | 2141 | |
---|
[2] | 2142 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
| 2143 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
| 2144 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 2145 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
| 2146 | if($fromaddress){ |
---|
| 2147 | $mail->Sender = $mail->From; |
---|
| 2148 | $mail->SenderName = $mail->FromName; |
---|
| 2149 | $mail->FromName = $fromaddress[0]; |
---|
| 2150 | $mail->From = $fromaddress[1]; |
---|
| 2151 | } |
---|
[1472] | 2152 | |
---|
[2] | 2153 | $this->add_recipients("to", $toaddress, &$mail); |
---|
| 2154 | $this->add_recipients("cc", $ccaddress, &$mail); |
---|
| 2155 | $this->add_recipients("cco", $ccoaddress, &$mail); |
---|
[3527] | 2156 | $mail->AddReplyTo($replytoaddress); |
---|
[2] | 2157 | $mail->Subject = $subject; |
---|
[4202] | 2158 | $mail->IsHTML( ( array_key_exists( 'type', $params ) && in_array( strtolower( $params[ 'type' ] ), array( 'html', 'plain' ) ) ) ? strtolower( $params[ 'type' ] ) != 'plain' : true ); |
---|
[1035] | 2159 | $mail->Body = $body; |
---|
[271] | 2160 | |
---|
[1035] | 2161 | if (($encrypt && $signed && $params['smime']) || ($encrypt && !$signed)) // a msg deve ser enviada cifrada... |
---|
| 2162 | { |
---|
| 2163 | $email = $this->add_recipients_cert($toaddress . ',' . $ccaddress. ',' .$ccoaddress); |
---|
| 2164 | $email = explode(",",$email); |
---|
| 2165 | // Deve ser testado se foram obtidos os certificados de todos os destinatarios. |
---|
| 2166 | // Deve ser verificado um numero limite de destinatarios. |
---|
| 2167 | // Deve ser verificado se os certificados sao validos. |
---|
| 2168 | // Se uma das verificacoes falhar, nao enviar o e-mail e avisar o usuario. |
---|
| 2169 | // O array $mail->Certs_crypt soh deve ser preenchido se os certificados passarem nas verificacoes. |
---|
| 2170 | $numero_maximo = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['num_max_certs_to_cipher']; // Este valor dever ser configurado pelo administrador do site .... |
---|
| 2171 | $erros_acumulados = ""; |
---|
| 2172 | $aux_mails = array(); |
---|
| 2173 | $mail_list = array(); |
---|
| 2174 | if(count($email) > $numero_maximo) |
---|
| 2175 | { |
---|
| 2176 | $erros_acumulados .= "Excedido o numero maximo (" . $numero_maximo . ") de destinatarios para uma msg cifrada...." . chr(0x0A); |
---|
| 2177 | return $erros_acumulados; |
---|
| 2178 | } |
---|
| 2179 | // adiciona o email do remetente. eh para cifrar a msg para ele tambem. Assim vai poder visualizar a msg na pasta enviados.. |
---|
| 2180 | $email[] = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 2181 | foreach($email as $item) |
---|
| 2182 | { |
---|
| 2183 | $certificate = $db->get_certificate(strtolower($item)); |
---|
| 2184 | if(!$certificate) |
---|
| 2185 | { |
---|
| 2186 | $erros_acumulados .= "Chamada com parametro invalido. e-Mail nao pode ser vazio." . chr(0x0A); |
---|
| 2187 | return $erros_acumulados; |
---|
| 2188 | } |
---|
| 2189 | |
---|
| 2190 | if (array_key_exists("dberr1", $certificate)) |
---|
| 2191 | { |
---|
| 2192 | |
---|
| 2193 | $erros_acumulados .= "Ocorreu um erro quando pesquisava certificados dos destinatarios para cifrar a msg." . chr(0x0A); |
---|
| 2194 | return $erros_acumulados; |
---|
| 2195 | } |
---|
| 2196 | if (array_key_exists("dberr2", $certificate)) |
---|
| 2197 | { |
---|
| 2198 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado nao localizado.' . chr(0x0A); |
---|
| 2199 | //continue; |
---|
| 2200 | } |
---|
| 2201 | /* Retirado este teste para evitar mensagem de erro duplicada. |
---|
| 2202 | if (!array_key_exists("certs", $certificate)) |
---|
| 2203 | { |
---|
| 2204 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado nao localizado.' . chr(0x0A); |
---|
| 2205 | continue; |
---|
| 2206 | } |
---|
| 2207 | */ |
---|
[3271] | 2208 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
[1035] | 2209 | |
---|
| 2210 | foreach ($certificate['certs'] as $registro) |
---|
| 2211 | { |
---|
| 2212 | $c1 = new certificadoB(); |
---|
| 2213 | $c1->certificado($registro['chave_publica']); |
---|
| 2214 | if ($c1->apresentado) |
---|
| 2215 | { |
---|
| 2216 | $c2 = new Verifica_Certificado($c1->dados,$registro['chave_publica']); |
---|
| 2217 | if (!$c1->dados['EXPIRADO'] && !$c2->revogado && $c2->status) |
---|
| 2218 | { |
---|
| 2219 | $aux_mails[] = $registro['chave_publica']; |
---|
| 2220 | $mail_list[] = strtolower($item); |
---|
| 2221 | } |
---|
| 2222 | else |
---|
| 2223 | { |
---|
| 2224 | if ($c1->dados['EXPIRADO'] || $c2->revogado) |
---|
| 2225 | { |
---|
| 2226 | $db->update_certificate($c1->dados['SERIALNUMBER'],$c1->dados['EMAIL'],$c1->dados['AUTHORITYKEYIDENTIFIER'], |
---|
| 2227 | $c1->dados['EXPIRADO'],$c2->revogado); |
---|
| 2228 | } |
---|
| 2229 | |
---|
| 2230 | $erros_acumulados .= $item . ': ' . $c2->msgerro . chr(0x0A); |
---|
| 2231 | foreach($c2->erros_ssl as $linha) |
---|
| 2232 | { |
---|
| 2233 | $erros_acumulados .= $linha . chr(0x0A); |
---|
| 2234 | } |
---|
| 2235 | $erros_acumulados .= 'Emissor: ' . $c1->dados['EMISSOR'] . chr(0x0A); |
---|
| 2236 | $erros_acumulados .= $c1->dados['CRLDISTRIBUTIONPOINTS'] . chr(0x0A); |
---|
| 2237 | } |
---|
| 2238 | } |
---|
| 2239 | else |
---|
| 2240 | { |
---|
| 2241 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado invalido.' . chr(0x0A); |
---|
| 2242 | } |
---|
| 2243 | } |
---|
| 2244 | if(!(in_array(strtolower($item),$mail_list)) && !empty($erros_acumulados)) |
---|
| 2245 | { |
---|
| 2246 | return $erros_acumulados; |
---|
| 2247 | } |
---|
| 2248 | } |
---|
| 2249 | |
---|
| 2250 | $mail->Certs_crypt = $aux_mails; |
---|
| 2251 | } |
---|
[3018] | 2252 | // Build CID images |
---|
| 2253 | $this->buildEmbeddedImages($mail,$msg_uid,$forwarding_attachments); |
---|
[1035] | 2254 | |
---|
[2] | 2255 | // Build Uploading Attachments!!! |
---|
[3387] | 2256 | if (count($attachments)>0) //Caso seja forward normal... |
---|
[2] | 2257 | { |
---|
| 2258 | $total_uploaded_size = 0; |
---|
[1264] | 2259 | $upload_max_filesize = str_replace("M","",$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) * 1024 * 1024; |
---|
[2] | 2260 | foreach ($attachments as $attach) |
---|
| 2261 | { |
---|
[3900] | 2262 | if($attach['error'] == UPLOAD_ERR_INI_SIZE) |
---|
| 2263 | return $this->parse_error("message file too big"); |
---|
[3387] | 2264 | if($attach['name']=='Unknown') |
---|
| 2265 | continue; |
---|
[2] | 2266 | $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); // optional name |
---|
| 2267 | $total_uploaded_size = $total_uploaded_size + $attach['size']; |
---|
| 2268 | } |
---|
[3387] | 2269 | if( $total_uploaded_size > $upload_max_filesize){ |
---|
[1472] | 2270 | return $this->parse_error("message file too big"); |
---|
[3387] | 2271 | } |
---|
[828] | 2272 | } |
---|
[3387] | 2273 | if(count($local_attachments)>0) { //Caso seja forward de mensagens locais |
---|
[828] | 2274 | |
---|
[689] | 2275 | $total_uploaded_size = 0; |
---|
[1472] | 2276 | $upload_max_filesize = str_replace("M","",ini_get('upload_max_filesize')) * 1024 * 1024; |
---|
[689] | 2277 | foreach($local_attachments as $local_attachment) { |
---|
| 2278 | $file_description = unserialize(rawurldecode($local_attachment)); |
---|
| 2279 | $tmp = array_values($file_description); |
---|
[1472] | 2280 | foreach($file_description as $i => $descriptor){ |
---|
[689] | 2281 | $tmp[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 2282 | } |
---|
| 2283 | $mail->AddAttachment($_FILES[$tmp[1]]['tmp_name'], $tmp[2], "base64", $this->get_file_type($tmp[2])); // optional name |
---|
| 2284 | $total_uploaded_size = $total_uploaded_size + $_FILES[$tmp[1]]['size']; |
---|
| 2285 | } |
---|
| 2286 | if( $total_uploaded_size > $upload_max_filesize) |
---|
[828] | 2287 | return 'false'; |
---|
[689] | 2288 | } |
---|
[2] | 2289 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[271] | 2290 | // Build Forwarding Attachments!!! |
---|
[2] | 2291 | if (count($forwarding_attachments) > 0) |
---|
| 2292 | { |
---|
| 2293 | // Bug fixed for array_search function |
---|
[3018] | 2294 | $name_cid_files = array(); |
---|
[2] | 2295 | if(count($name_cid_files) > 0) { |
---|
| 2296 | $name_cid_files[count($name_cid_files)] = $name_cid_files[0]; |
---|
| 2297 | $name_cid_files[0] = null; |
---|
[1472] | 2298 | } |
---|
| 2299 | |
---|
[2] | 2300 | foreach($forwarding_attachments as $forwarding_attachment) |
---|
| 2301 | { |
---|
[271] | 2302 | $file_description = unserialize(rawurldecode($forwarding_attachment)); |
---|
| 2303 | $tmp = array_values($file_description); |
---|
[1472] | 2304 | foreach($file_description as $i => $descriptor){ |
---|
[271] | 2305 | $tmp[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 2306 | } |
---|
[1472] | 2307 | $file_description = $tmp; |
---|
[271] | 2308 | $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); |
---|
| 2309 | $fileName = $file_description[2]; |
---|
| 2310 | if(!array_search(trim($fileName),$name_cid_files)) { |
---|
[3369] | 2311 | $mail->AddStringAttachment($fileContent,html_entity_decode(rawurldecode($fileName)), $file_description[4], $this->get_file_type($file_description[2])); |
---|
[63] | 2312 | } |
---|
[2] | 2313 | } |
---|
| 2314 | } |
---|
[37] | 2315 | |
---|
[2] | 2316 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[614] | 2317 | // Important message |
---|
| 2318 | if($is_important) |
---|
| 2319 | $mail->isImportant(); |
---|
| 2320 | |
---|
| 2321 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[2] | 2322 | // Disposition-Notification-To |
---|
| 2323 | if ($return_receipt) |
---|
| 2324 | $mail->ConfirmReadingTo = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 2325 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[504] | 2326 | |
---|
[117] | 2327 | $sent = $mail->Send(); |
---|
[1472] | 2328 | |
---|
[117] | 2329 | if(!$sent) |
---|
[2] | 2330 | { |
---|
[504] | 2331 | return $this->parse_error($mail->ErrorInfo); |
---|
[2] | 2332 | } |
---|
| 2333 | else |
---|
| 2334 | { |
---|
[1035] | 2335 | if ($signed && !$params['smime']) |
---|
| 2336 | { |
---|
| 2337 | return $sent; |
---|
| 2338 | } |
---|
[1472] | 2339 | if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") |
---|
[117] | 2340 | { |
---|
| 2341 | $userid = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 2342 | $userip = $_SESSION['phpgw_info']['expressomail']['user']['session_ip']; |
---|
| 2343 | $now = date("d/m/y H:i:s"); |
---|
| 2344 | $addrs = $toaddress.$ccaddress.$ccoaddress; |
---|
[1472] | 2345 | $sent = trim($sent); |
---|
[117] | 2346 | error_log("$now - $userip - $sent [$subject] - $userid => $addrs\r\n", 3, "/home/expressolivre/mail_senders.log"); |
---|
| 2347 | } |
---|
[1472] | 2348 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['number_of_contacts'] && |
---|
[485] | 2349 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts']) { |
---|
[469] | 2350 | $contacts = new dynamic_contacts(); |
---|
[485] | 2351 | $new_contacts = $contacts->add_dynamic_contacts($toaddress.",".$ccaddress.",".$ccoaddress); |
---|
| 2352 | return array("success" => true, "new_contacts" => $new_contacts); |
---|
[413] | 2353 | } |
---|
[485] | 2354 | return array("success" => true); |
---|
[2] | 2355 | } |
---|
| 2356 | } |
---|
[3018] | 2357 | function buildEmbeddedImages(&$mail,$msg_uid,&$forwarding_attachments) |
---|
| 2358 | { |
---|
| 2359 | // Build CID for embedded Images!!! |
---|
| 2360 | $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; |
---|
| 2361 | $cid_imgs = ''; |
---|
| 2362 | preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); |
---|
| 2363 | $cid_array = array(); |
---|
| 2364 | foreach($cid_imgs[6] as $j => $val){ |
---|
| 2365 | if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) |
---|
| 2366 | { |
---|
| 2367 | $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); |
---|
| 2368 | } |
---|
| 2369 | $cid = $cid_array[$cid_imgs[4][$j].$val]; |
---|
| 2370 | $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); |
---|
[2] | 2371 | |
---|
[3018] | 2372 | if ($msg_uid != $cid_imgs[4][$j]) // The image is not in the same mail? |
---|
| 2373 | { |
---|
| 2374 | $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); |
---|
| 2375 | //prototype: get_forwarding_attachment ( folder, msg number, part, encoding) |
---|
| 2376 | $fileName = "image_".($j).".jpg"; |
---|
| 2377 | $fileCode = "base64"; |
---|
| 2378 | $fileType = "image/jpg"; |
---|
| 2379 | $file_attached[0] = $cid_imgs[2][$j]; |
---|
| 2380 | $file_attached[1] = $cid_imgs[4][$j]; |
---|
| 2381 | $file_attached[2] = $fileName; |
---|
| 2382 | $file_attached[3] = $cid_imgs[6][$j]; |
---|
| 2383 | $file_attached[4] = 'base64'; |
---|
| 2384 | $file_attached[5] = strlen($fileContent); //Size of file |
---|
| 2385 | $return_forward[] = $file_attached; |
---|
| 2386 | |
---|
| 2387 | $attachment_ = unserialize(rawurldecode($forwarding_attachments[$cid_imgs[6][$j]-2])); |
---|
| 2388 | if ($file_attached[3] == $attachment_[3]) |
---|
| 2389 | unset($forwarding_attachments[$cid_imgs[6][$j]-2]); |
---|
| 2390 | } |
---|
| 2391 | else |
---|
| 2392 | { |
---|
| 2393 | $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; |
---|
| 2394 | $file_description = unserialize(rawurldecode($attach_img)); |
---|
| 2395 | if (is_array($file_description)) |
---|
| 2396 | foreach($file_description as $i => $descriptor){ |
---|
| 2397 | $file_description[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 2398 | } |
---|
| 2399 | $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64'); |
---|
| 2400 | $fileName = $file_description[2]; |
---|
| 2401 | $fileCode = $file_description[4]; |
---|
| 2402 | $fileType = $this->get_file_type($file_description[2]); |
---|
| 2403 | unset($forwarding_attachments[$cid_imgs[6][$j]-2]); |
---|
| 2404 | if (!empty($file_description)) |
---|
| 2405 | { |
---|
| 2406 | $file_description[5] = strlen($fileContent); //Size of file |
---|
| 2407 | $return_forward[] = $file_description; |
---|
| 2408 | } |
---|
| 2409 | } |
---|
| 2410 | $tempDir = ini_get("session.save_path"); |
---|
| 2411 | $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat"; |
---|
| 2412 | $f = fopen($tempDir.'/'.$file,"w"); |
---|
| 2413 | fputs($f,$fileContent); |
---|
| 2414 | fclose($f); |
---|
| 2415 | if ($fileContent) |
---|
| 2416 | $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); |
---|
| 2417 | //else |
---|
| 2418 | // return "Error loading image attachment content"; |
---|
| 2419 | |
---|
| 2420 | } |
---|
| 2421 | return $return_forward; |
---|
| 2422 | } |
---|
| 2423 | function add_recipients_cert($full_address) |
---|
[1035] | 2424 | { |
---|
| 2425 | $result = ""; |
---|
| 2426 | $parse_address = imap_rfc822_parse_adrlist($full_address, ""); |
---|
| 2427 | foreach ($parse_address as $val) |
---|
| 2428 | { |
---|
| 2429 | //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; |
---|
| 2430 | if ($val->mailbox == "INVALID_ADDRESS") |
---|
| 2431 | continue; |
---|
| 2432 | if ($val->mailbox == "UNEXPECTED_DATA_AFTER_ADDRESS") |
---|
| 2433 | continue; |
---|
| 2434 | if (empty($val->personal)) |
---|
| 2435 | $result .= $val->mailbox."@".$val->host . ","; |
---|
| 2436 | else |
---|
| 2437 | $result .= $val->mailbox."@".$val->host . ","; |
---|
| 2438 | } |
---|
| 2439 | |
---|
| 2440 | return substr($result,0,-1); |
---|
| 2441 | } |
---|
| 2442 | |
---|
[2] | 2443 | function add_recipients($recipient_type, $full_address, $mail) |
---|
| 2444 | { |
---|
[3932] | 2445 | //remove a comma if is given two unexpected commas |
---|
| 2446 | $full_address = preg_replace("/, ?,/",",",$full_address); |
---|
[1472] | 2447 | $parse_address = imap_rfc822_parse_adrlist($full_address, ""); |
---|
| 2448 | foreach ($parse_address as $val) |
---|
[2] | 2449 | { |
---|
| 2450 | //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; |
---|
| 2451 | if ($val->mailbox == "INVALID_ADDRESS") |
---|
| 2452 | continue; |
---|
[1472] | 2453 | |
---|
[2] | 2454 | if (empty($val->personal)) |
---|
| 2455 | { |
---|
| 2456 | switch($recipient_type) |
---|
| 2457 | { |
---|
| 2458 | case "to": |
---|
| 2459 | $mail->AddAddress($val->mailbox."@".$val->host); |
---|
| 2460 | break; |
---|
| 2461 | case "cc": |
---|
| 2462 | $mail->AddCC($val->mailbox."@".$val->host); |
---|
| 2463 | break; |
---|
| 2464 | case "cco": |
---|
| 2465 | $mail->AddBCC($val->mailbox."@".$val->host); |
---|
| 2466 | break; |
---|
| 2467 | } |
---|
| 2468 | } |
---|
| 2469 | else |
---|
| 2470 | { |
---|
| 2471 | switch($recipient_type) |
---|
| 2472 | { |
---|
| 2473 | case "to": |
---|
| 2474 | $mail->AddAddress($val->mailbox."@".$val->host, $val->personal); |
---|
| 2475 | break; |
---|
| 2476 | case "cc": |
---|
| 2477 | $mail->AddCC($val->mailbox."@".$val->host, $val->personal); |
---|
| 2478 | break; |
---|
| 2479 | case "cco": |
---|
| 2480 | $mail->AddBCC($val->mailbox."@".$val->host, $val->personal); |
---|
| 2481 | break; |
---|
| 2482 | } |
---|
| 2483 | } |
---|
| 2484 | } |
---|
| 2485 | return true; |
---|
| 2486 | } |
---|
[1472] | 2487 | |
---|
[2] | 2488 | function get_forwarding_attachment($msg_folder, $msg_number, $msg_part, $encoding) |
---|
| 2489 | { |
---|
[828] | 2490 | $mbox_stream = $this->open_mbox(utf8_decode(urldecode($msg_folder))); |
---|
[1472] | 2491 | $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); |
---|
[2] | 2492 | if($encoding == 'base64') |
---|
[449] | 2493 | # The function imap_base64 adds a new line |
---|
| 2494 | # at ASCII text, with CRLF line terminators. |
---|
| 2495 | # So is being exchanged for base64_decode. |
---|
| 2496 | # |
---|
| 2497 | #$fileContent = imap_base64($fileContent); |
---|
| 2498 | $fileContent = base64_decode($fileContent); |
---|
[2] | 2499 | else if($encoding == 'quoted-printable') |
---|
[1472] | 2500 | $fileContent = quoted_printable_decode($fileContent); |
---|
[2] | 2501 | return $fileContent; |
---|
| 2502 | } |
---|
[1472] | 2503 | |
---|
[2] | 2504 | function del_last_caracter($string) |
---|
| 2505 | { |
---|
| 2506 | $string = substr($string,0,(strlen($string) - 1)); |
---|
[1472] | 2507 | return $string; |
---|
[2] | 2508 | } |
---|
[1472] | 2509 | |
---|
[2] | 2510 | function del_last_two_caracters($string) |
---|
| 2511 | { |
---|
| 2512 | $string = substr($string,0,(strlen($string) - 2)); |
---|
[1472] | 2513 | return $string; |
---|
[2] | 2514 | } |
---|
[1472] | 2515 | |
---|
[828] | 2516 | function messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd) |
---|
[659] | 2517 | { |
---|
[1625] | 2518 | if ($sort_box_type != "SORTFROM" && $search_box_type!= "FLAGGED"){ |
---|
[970] | 2519 | $imapsort = imap_sort($this->mbox,constant($sort_box_type),$sort_box_reverse,SE_UID,$search_box_type); |
---|
| 2520 | foreach($imapsort as $iuid) |
---|
| 2521 | $sort[$iuid] = ""; |
---|
[1518] | 2522 | |
---|
| 2523 | if ($offsetBegin == -1 && $offsetEnd ==-1 ) |
---|
| 2524 | $slice_array = false; |
---|
| 2525 | else |
---|
| 2526 | $slice_array = true; |
---|
[970] | 2527 | } |
---|
| 2528 | else |
---|
[659] | 2529 | { |
---|
[970] | 2530 | $sort = array(); |
---|
| 2531 | if ($offsetBegin > $offsetEnd) {$temp=$offsetEnd; $offsetEnd=$offsetBegin; $offsetBegin=$temp;} |
---|
| 2532 | $num_msgs = imap_num_msg($this->mbox); |
---|
| 2533 | if ($offsetEnd > $num_msgs) {$offsetEnd = $num_msgs;} |
---|
[975] | 2534 | $slice_array = true; |
---|
| 2535 | |
---|
[983] | 2536 | for ($i=$num_msgs; $i>0; $i--) |
---|
[828] | 2537 | { |
---|
[983] | 2538 | if ($sort_box_type == "SORTARRIVAL" && $sort_box_reverse && count($sort) >= $offsetEnd) |
---|
| 2539 | break; |
---|
[970] | 2540 | $iuid = @imap_uid($this->mbox,$i); |
---|
| 2541 | $header = $this->get_header($iuid); |
---|
| 2542 | // List UNSEEN messages. |
---|
| 2543 | if($search_box_type == "UNSEEN" && (!trim($header->Recent) && !trim($header->Unseen))){ |
---|
| 2544 | continue; |
---|
| 2545 | } |
---|
| 2546 | // List SEEN messages. |
---|
| 2547 | elseif($search_box_type == "SEEN" && (trim($header->Recent) || trim($header->Unseen))){ |
---|
| 2548 | continue; |
---|
| 2549 | } |
---|
| 2550 | // List ANSWERED messages. |
---|
| 2551 | elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ |
---|
| 2552 | continue; |
---|
| 2553 | } |
---|
| 2554 | // List FLAGGED messages. |
---|
| 2555 | elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ |
---|
| 2556 | continue; |
---|
| 2557 | } |
---|
| 2558 | |
---|
| 2559 | if($sort_box_type=='SORTFROM') { |
---|
| 2560 | if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) |
---|
| 2561 | $from = $header->to; |
---|
| 2562 | else |
---|
| 2563 | $from = $header->from; |
---|
| 2564 | |
---|
| 2565 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 2566 | |
---|
| 2567 | if ($tmp[0]->text != "") |
---|
| 2568 | $sort[$iuid] = $tmp[0]->text; |
---|
| 2569 | else |
---|
| 2570 | $sort[$iuid] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
| 2571 | } |
---|
| 2572 | else if($sort_box_type=='SORTSUBJECT') { |
---|
| 2573 | $sort[$iuid] = $header->subject; |
---|
| 2574 | } |
---|
| 2575 | else if($sort_box_type=='SORTSIZE') { |
---|
| 2576 | $sort[$iuid] = $header->Size; |
---|
| 2577 | } |
---|
| 2578 | else { |
---|
| 2579 | $sort[$iuid] = $header->udate; |
---|
| 2580 | } |
---|
| 2581 | |
---|
[659] | 2582 | } |
---|
[970] | 2583 | natcasesort($sort); |
---|
[828] | 2584 | |
---|
[970] | 2585 | if ($sort_box_reverse) |
---|
| 2586 | $sort = array_reverse($sort,true); |
---|
[659] | 2587 | } |
---|
[828] | 2588 | |
---|
[972] | 2589 | if(!is_array($sort)) |
---|
| 2590 | $sort = array(); |
---|
[1472] | 2591 | |
---|
[1808] | 2592 | |
---|
[972] | 2593 | if ($slice_array) |
---|
[828] | 2594 | $sort = array_slice($sort,$offsetBegin-1,$offsetEnd-($offsetBegin-1),true); |
---|
[970] | 2595 | |
---|
[1472] | 2596 | |
---|
[828] | 2597 | return $sort; |
---|
| 2598 | |
---|
[659] | 2599 | } |
---|
[970] | 2600 | |
---|
| 2601 | |
---|
[1472] | 2602 | function move_search_messages($params){ |
---|
| 2603 | $params['selected_messages'] = urldecode($params['selected_messages']); |
---|
[163] | 2604 | $params['new_folder'] = urldecode($params['new_folder']); |
---|
| 2605 | $params['new_folder_name'] = urldecode($params['new_folder_name']); |
---|
| 2606 | $sel_msgs = explode(",", $params['selected_messages']); |
---|
[1472] | 2607 | @reset($sel_msgs); |
---|
[163] | 2608 | $sorted_msgs = array(); |
---|
| 2609 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 2610 | $sel_msg = explode(";", $sel_msg); |
---|
| 2611 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 2612 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
[1472] | 2613 | } |
---|
[163] | 2614 | else { |
---|
| 2615 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 2616 | } |
---|
| 2617 | } |
---|
| 2618 | @ksort($sorted_msgs); |
---|
[1472] | 2619 | $last_return = false; |
---|
| 2620 | foreach($sorted_msgs as $folder => $msgs_number) { |
---|
[163] | 2621 | $params['msgs_number'] = $msgs_number; |
---|
[1472] | 2622 | $params['folder'] = $folder; |
---|
[163] | 2623 | if($params['new_folder'] && $folder != $params['new_folder']){ |
---|
[1472] | 2624 | $last_return = $this -> move_messages($params); |
---|
[163] | 2625 | } |
---|
| 2626 | elseif(!$params['new_folder'] || $params['delete'] ){ |
---|
| 2627 | $last_return = $this -> delete_msgs($params); |
---|
| 2628 | $last_return['deleted'] = true; |
---|
| 2629 | } |
---|
| 2630 | } |
---|
| 2631 | return $last_return; |
---|
| 2632 | } |
---|
[1472] | 2633 | |
---|
[2] | 2634 | function move_messages($params) |
---|
| 2635 | { |
---|
[1472] | 2636 | $folder = $params['folder']; |
---|
| 2637 | $mbox_stream = $this->open_mbox($folder); |
---|
[51] | 2638 | $newmailbox = ($params['new_folder']); |
---|
[4587] | 2639 | $newmailbox = mb_convert_encoding($newmailbox, "UTF7-IMAP","ISO-8859-1"); |
---|
[2] | 2640 | $new_folder_name = $params['new_folder_name']; |
---|
| 2641 | $msgs_number = $params['msgs_number']; |
---|
| 2642 | $return = array('msgs_number' => $msgs_number, |
---|
| 2643 | 'folder' => $folder, |
---|
| 2644 | 'new_folder_name' => $new_folder_name, |
---|
[325] | 2645 | 'border_ID' => $params['border_ID'], |
---|
| 2646 | 'status' => true); //Status foi adicionado para validar as permissoes ACL |
---|
[1472] | 2647 | |
---|
[325] | 2648 | //Este bloco tem a finalidade de averiguar as permissoes para pastas compartilhadas |
---|
| 2649 | if (substr($folder,0,4) == 'user'){ |
---|
| 2650 | $acl = $this->getacltouser($folder); |
---|
| 2651 | /* |
---|
| 2652 | * l - lookup (mailbox is visible to LIST/LSUB commands) |
---|
| 2653 | * r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL, SEARCH, COPY from mailbox) |
---|
| 2654 | * s - keep seen/unseen information across sessions (STORE SEEN flag) |
---|
| 2655 | * w - write (STORE flags other than SEEN and DELETED) |
---|
| 2656 | * i - insert (perform APPEND, COPY into mailbox) |
---|
| 2657 | * p - post (send mail to submission address for mailbox, not enforced by IMAP4 itself) |
---|
| 2658 | * c - create (CREATE new sub-mailboxes in any implementation-defined hierarchy) |
---|
| 2659 | * d - delete (STORE DELETED flag, perform EXPUNGE) |
---|
| 2660 | * a - administer (perform SETACL) |
---|
| 2661 | */ |
---|
| 2662 | if (strpos($acl, "d") === false){ |
---|
| 2663 | $return['status'] = false; |
---|
| 2664 | return $return; |
---|
| 2665 | } |
---|
| 2666 | } |
---|
[432] | 2667 | //Este bloco tem a finalidade de transformar o CPF das pastas compartilhadas em common name |
---|
[1747] | 2668 | if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn']){ |
---|
| 2669 | if (substr($new_folder_name,0,4) == 'user'){ |
---|
| 2670 | $this->ldap = new ldap_functions(); |
---|
| 2671 | $tmp_folder_name = explode($this->imap_delimiter, $new_folder_name); |
---|
| 2672 | $return['new_folder_name'] = array_pop($tmp_folder_name); |
---|
| 2673 | if( $cn = $this->ldap->uid2cn($return['new_folder_name'])) |
---|
| 2674 | { |
---|
| 2675 | $return['new_folder_name'] = $cn; |
---|
| 2676 | } |
---|
| 2677 | } |
---|
[432] | 2678 | } |
---|
[1472] | 2679 | |
---|
| 2680 | // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior. |
---|
[51] | 2681 | if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) |
---|
[449] | 2682 | { |
---|
[2] | 2683 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
[449] | 2684 | // Fix problem in unserialize function JS. |
---|
| 2685 | $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); |
---|
| 2686 | } |
---|
[1472] | 2687 | |
---|
| 2688 | $mbox_stream = $this->open_mbox($folder); |
---|
[2] | 2689 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
| 2690 | imap_expunge($mbox_stream); |
---|
[51] | 2691 | if($mbox_stream) |
---|
| 2692 | imap_close($mbox_stream); |
---|
[2] | 2693 | return $return; |
---|
| 2694 | }else { |
---|
[1472] | 2695 | if(strstr(imap_last_error(),'Over quota')) { |
---|
[2] | 2696 | $accountID = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminUsername']; |
---|
[1472] | 2697 | $pass = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; |
---|
| 2698 | $userID = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
[2] | 2699 | $server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[504] | 2700 | $mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}INBOX", $accountID, $pass) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); |
---|
[2] | 2701 | if(!$mbox) |
---|
| 2702 | return imap_last_error(); |
---|
[1472] | 2703 | $quota = imap_get_quotaroot($mbox_stream, "INBOX"); |
---|
[2] | 2704 | if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { |
---|
[51] | 2705 | if($mbox_stream) |
---|
| 2706 | imap_close($mbox_stream); |
---|
[1472] | 2707 | if($mbox) |
---|
[51] | 2708 | imap_close($mbox); |
---|
[1472] | 2709 | return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; |
---|
[2] | 2710 | } |
---|
| 2711 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
| 2712 | imap_expunge($mbox_stream); |
---|
[51] | 2713 | if($mbox_stream) |
---|
| 2714 | imap_close($mbox_stream); |
---|
[2] | 2715 | // return to original quota limit. |
---|
| 2716 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
[51] | 2717 | if($mbox) |
---|
| 2718 | imap_close($mbox); |
---|
[1472] | 2719 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
[2] | 2720 | } |
---|
[1472] | 2721 | return $return; |
---|
[2] | 2722 | } |
---|
| 2723 | else { |
---|
[51] | 2724 | if($mbox_stream) |
---|
| 2725 | imap_close($mbox_stream); |
---|
[2] | 2726 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
[51] | 2727 | if($mbox) |
---|
| 2728 | imap_close($mbox); |
---|
[1472] | 2729 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
[2] | 2730 | } |
---|
[1472] | 2731 | return imap_last_error(); |
---|
[2] | 2732 | } |
---|
[1472] | 2733 | |
---|
[2] | 2734 | } |
---|
| 2735 | else { |
---|
[51] | 2736 | if($mbox_stream) |
---|
| 2737 | imap_close($mbox_stream); |
---|
| 2738 | return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; |
---|
[2] | 2739 | } |
---|
[1472] | 2740 | } |
---|
[2] | 2741 | } |
---|
[1472] | 2742 | |
---|
[2] | 2743 | function save_msg($params) |
---|
| 2744 | { |
---|
[1472] | 2745 | |
---|
[271] | 2746 | include_once("class.phpmailer.php"); |
---|
| 2747 | $mail = new PHPMailer(); |
---|
| 2748 | include_once("class.db_functions.inc.php"); |
---|
| 2749 | $toaddress = $params['input_to']; |
---|
| 2750 | $ccaddress = $params['input_cc']; |
---|
[3798] | 2751 | $ccoaddress = $params['input_cco']; |
---|
| 2752 | $return_receipt = $params['input_return_receipt']; |
---|
| 2753 | $is_important = $params['input_important_message']; |
---|
[271] | 2754 | $subject = $params['input_subject']; |
---|
[320] | 2755 | $msg_uid = $params['msg_id']; |
---|
[2] | 2756 | $body = $params['body']; |
---|
| 2757 | $body = str_replace("%nbsp;"," ",$params['body']); |
---|
[155] | 2758 | $body = preg_replace("/\n/"," ",$body); |
---|
[51] | 2759 | $body = preg_replace("/\r/","",$body); |
---|
[271] | 2760 | $forwarding_attachments = $params['forwarding_attachments']; |
---|
| 2761 | $attachments = $params['FILES']; |
---|
| 2762 | $return_files = $params['FILES']; |
---|
[1472] | 2763 | |
---|
[271] | 2764 | $folder = $params['folder']; |
---|
[4587] | 2765 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); |
---|
[271] | 2766 | // Fix problem with cyrus delimiter changes. |
---|
[1472] | 2767 | // Dots in names: enabled/disabled. |
---|
[271] | 2768 | $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); |
---|
| 2769 | $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); |
---|
| 2770 | // End Fix. |
---|
[3798] | 2771 | if(strtoupper($folder) == 'INBOX/DRAFTS') $mail->SaveMessageAsDraft = $folder; |
---|
| 2772 | |
---|
[271] | 2773 | $mail->SaveMessageInFolder = $folder; |
---|
| 2774 | $mail->SMTPDebug = false; |
---|
[1472] | 2775 | |
---|
[271] | 2776 | $mail->IsSMTP(); |
---|
| 2777 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
| 2778 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
| 2779 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 2780 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
[1472] | 2781 | |
---|
[271] | 2782 | $mail->Sender = $mail->From; |
---|
| 2783 | $mail->SenderName = $mail->FromName; |
---|
| 2784 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
| 2785 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
[1472] | 2786 | |
---|
[271] | 2787 | $this->add_recipients("to", $toaddress, &$mail); |
---|
| 2788 | $this->add_recipients("cc", $ccaddress, &$mail); |
---|
[3798] | 2789 | $this->add_recipients("cco", $ccoaddress, &$mail); |
---|
[3527] | 2790 | $mail->AddReplyTo($replytoaddress); |
---|
[271] | 2791 | $mail->Subject = $subject; |
---|
| 2792 | $mail->IsHTML(true); |
---|
| 2793 | $mail->Body = $body; |
---|
[3798] | 2794 | |
---|
| 2795 | // Important message |
---|
| 2796 | if($is_important) |
---|
| 2797 | $mail->isImportant(); |
---|
[1472] | 2798 | |
---|
[3798] | 2799 | // Disposition-Notification-To |
---|
| 2800 | if ($return_receipt) |
---|
| 2801 | $mail->ConfirmReadingTo = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 2802 | |
---|
[3018] | 2803 | $return_forward = $this->buildEmbeddedImages($mail,$msg_uid,$forwarding_attachments); |
---|
[1472] | 2804 | |
---|
| 2805 | // Build Forwarding Attachments!!! |
---|
[271] | 2806 | if (count($forwarding_attachments) > 0) |
---|
| 2807 | { |
---|
| 2808 | foreach($forwarding_attachments as $forwarding_attachment) |
---|
| 2809 | { |
---|
| 2810 | $file_description = unserialize(rawurldecode($forwarding_attachment)); |
---|
| 2811 | $tmp = array_values($file_description); |
---|
[1472] | 2812 | foreach($file_description as $i => $descriptor){ |
---|
[271] | 2813 | $tmp[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 2814 | } |
---|
| 2815 | $file_description = $tmp; |
---|
[1472] | 2816 | |
---|
[271] | 2817 | $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); |
---|
| 2818 | $fileName = $file_description[2]; |
---|
[1472] | 2819 | |
---|
[271] | 2820 | $file_description[5] = strlen($fileContent); //Size of file |
---|
| 2821 | $return_forward[] = $file_description; |
---|
[1472] | 2822 | |
---|
[271] | 2823 | $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); |
---|
| 2824 | } |
---|
| 2825 | } |
---|
[1472] | 2826 | |
---|
[271] | 2827 | if ((count($return_forward) > 0) && (count($return_files) > 0)) |
---|
| 2828 | $return_files = array_merge_recursive($return_forward,$return_files); |
---|
| 2829 | else |
---|
| 2830 | if (count($return_files) < 1) |
---|
| 2831 | $return_files = $return_forward; |
---|
[1472] | 2832 | |
---|
[271] | 2833 | // Build Uploading Attachments!!! |
---|
[1005] | 2834 | $sizeof_attachments = count($attachments); |
---|
| 2835 | if ($sizeof_attachments) |
---|
| 2836 | foreach ($attachments as $numb => $attach){ |
---|
| 2837 | if ($numb == ($sizeof_attachments-1) && $params['insertImg'] == 'true'){ // Auto-resize image |
---|
| 2838 | list($width, $height,$image_type) = getimagesize($attach['tmp_name']); |
---|
| 2839 | switch ($image_type) |
---|
| 2840 | { |
---|
[1380] | 2841 | // Do not corrupt animated gif |
---|
| 2842 | //case 1: $image_big = imagecreatefromgif($attach['tmp_name']);break; |
---|
[1005] | 2843 | case 2: $image_big = imagecreatefromjpeg($attach['tmp_name']); break; |
---|
| 2844 | case 3: $image_big = imagecreatefrompng($attach['tmp_name']); break; |
---|
| 2845 | case 6: |
---|
[1247] | 2846 | require_once("gd_functions.php"); |
---|
[1005] | 2847 | $image_big = imagecreatefrombmp($attach['tmp_name']); break; |
---|
| 2848 | default: |
---|
| 2849 | $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); |
---|
| 2850 | break; |
---|
| 2851 | } |
---|
| 2852 | header('Content-type: image/jpeg'); |
---|
| 2853 | $max_resolution = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['image_size']; |
---|
| 2854 | $max_resolution = ($max_resolution==""?'65536':$max_resolution); |
---|
| 2855 | if ($width < $max_resolution && $height < $max_resolution){ |
---|
| 2856 | $new_width = $width; |
---|
| 2857 | $new_height = $height; |
---|
| 2858 | } |
---|
| 2859 | else if ($width > $max_resolution){ |
---|
| 2860 | $new_width = $max_resolution; |
---|
| 2861 | $new_height = $height*($new_width/$width); |
---|
| 2862 | } |
---|
| 2863 | else { |
---|
| 2864 | $new_height = $max_resolution; |
---|
| 2865 | $new_width = $width*($new_height/$height); |
---|
| 2866 | } |
---|
| 2867 | $image_new = imagecreatetruecolor($new_width, $new_height); |
---|
| 2868 | imagecopyresampled($image_new, $image_big, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
---|
| 2869 | $tmpDir = ini_get("session.save_path"); |
---|
[1472] | 2870 | $_file = "/cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".dat"; |
---|
[1005] | 2871 | imagejpeg($image_new,$tmpDir.$_file, 85); |
---|
| 2872 | $mail->AddAttachment($tmpDir.$_file, $attach['name'], "base64", $this->get_file_type($tmpDir.$_file)); |
---|
| 2873 | } |
---|
| 2874 | else |
---|
| 2875 | $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); |
---|
| 2876 | // optional name |
---|
| 2877 | } |
---|
[1472] | 2878 | |
---|
| 2879 | |
---|
| 2880 | |
---|
| 2881 | |
---|
[271] | 2882 | if(!empty($mail->AltBody)) |
---|
| 2883 | $mail->ContentType = "multipart/alternative"; |
---|
| 2884 | |
---|
[828] | 2885 | $mail->error_count = 0; // reset errors |
---|
| 2886 | $mail->SetMessageType(); |
---|
| 2887 | $header = $mail->CreateHeader(); |
---|
[1472] | 2888 | $body = $mail->CreateBody(); |
---|
[828] | 2889 | |
---|
[1472] | 2890 | $mbox_stream = $this->open_mbox($folder); |
---|
[271] | 2891 | $new_header = str_replace("\n", "\r\n", $header); |
---|
| 2892 | $new_body = str_replace("\n", "\r\n", $body); |
---|
[830] | 2893 | $return['append'] = imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, $new_header . $new_body, "\\Seen \\Draft"); |
---|
[271] | 2894 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); |
---|
| 2895 | $return['msg_no'] = $status->uidnext - 1; |
---|
| 2896 | $return['folder_id'] = $folder; |
---|
[828] | 2897 | |
---|
[51] | 2898 | if($mbox_stream) |
---|
| 2899 | imap_close($mbox_stream); |
---|
[1472] | 2900 | if (is_array($return_files)) |
---|
[828] | 2901 | foreach ($return_files as $index => $_attachment) { |
---|
| 2902 | if (array_key_exists("name",$_attachment)){ |
---|
[271] | 2903 | unset($return_files[$index]); |
---|
| 2904 | $return_files[$index] = $_attachment['name']."_SIZE_".$return_files[$index][1] = $_attachment['size']; |
---|
| 2905 | } |
---|
| 2906 | else |
---|
| 2907 | { |
---|
| 2908 | unset($return_files[$index]); |
---|
| 2909 | $return_files[$index] = $_attachment[2]."_SIZE_". $return_files[$index][1] = $_attachment[5]; |
---|
| 2910 | } |
---|
| 2911 | } |
---|
[1472] | 2912 | |
---|
[271] | 2913 | $return['files'] = serialize($return_files); |
---|
[673] | 2914 | $return["subject"] = $subject; |
---|
[1472] | 2915 | |
---|
[3571] | 2916 | if (!$return['append']) { |
---|
[2] | 2917 | $return['append'] = imap_last_error(); |
---|
[3571] | 2918 | $return['has_error'] = true; |
---|
| 2919 | } |
---|
[1472] | 2920 | |
---|
[2] | 2921 | return $return; |
---|
| 2922 | } |
---|
[1472] | 2923 | |
---|
[2] | 2924 | function set_messages_flag($params) |
---|
| 2925 | { |
---|
| 2926 | $folder = $params['folder']; |
---|
| 2927 | $msgs_to_set = $params['msgs_to_set']; |
---|
| 2928 | $flag = $params['flag']; |
---|
| 2929 | $return = array(); |
---|
| 2930 | $return["msgs_to_set"] = $msgs_to_set; |
---|
| 2931 | $return["flag"] = $flag; |
---|
[1472] | 2932 | |
---|
[411] | 2933 | if(!$this->mbox && !is_resource($this->mbox)) |
---|
[51] | 2934 | $this->mbox = $this->open_mbox($folder); |
---|
[1472] | 2935 | |
---|
[2] | 2936 | if ($flag == "unseen") |
---|
[51] | 2937 | $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); |
---|
[2] | 2938 | elseif ($flag == "seen") |
---|
[51] | 2939 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); |
---|
[2] | 2940 | elseif ($flag == "answered"){ |
---|
[51] | 2941 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered", ST_UID); |
---|
| 2942 | imap_clearflag_full($this->mbox, $msgs_to_set, "\\Draft", ST_UID); |
---|
[2] | 2943 | } |
---|
| 2944 | elseif ($flag == "forwarded") |
---|
[51] | 2945 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered \\Draft", ST_UID); |
---|
[2] | 2946 | elseif ($flag == "flagged") |
---|
[51] | 2947 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); |
---|
[614] | 2948 | elseif ($flag == "unflagged") { |
---|
| 2949 | $flag_importance = false; |
---|
| 2950 | $msgs_number = explode(",",$msgs_to_set); |
---|
[659] | 2951 | $unflagged_msgs = ""; |
---|
[614] | 2952 | foreach($msgs_number as $msg_number) { |
---|
| 2953 | preg_match('/importance *: *(.*)\r/i', |
---|
| 2954 | imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) |
---|
[1472] | 2955 | ,$importance); |
---|
[673] | 2956 | if(strtolower($importance[1])=="high" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { |
---|
[614] | 2957 | $flag_importance=true; |
---|
| 2958 | } |
---|
[659] | 2959 | else { |
---|
| 2960 | $unflagged_msgs.=$msg_number.","; |
---|
[1472] | 2961 | } |
---|
[614] | 2962 | } |
---|
| 2963 | |
---|
[659] | 2964 | if($unflagged_msgs!="") { |
---|
| 2965 | imap_clearflag_full($this->mbox,substr($unflagged_msgs,0,strlen($unflagged_msgs)-1), "\\Flagged", ST_UID); |
---|
| 2966 | $return["msgs_unflageds"] = substr($unflagged_msgs,0,strlen($unflagged_msgs)-1); |
---|
| 2967 | } |
---|
| 2968 | else { |
---|
| 2969 | $return["msgs_unflageds"] = false; |
---|
| 2970 | } |
---|
| 2971 | |
---|
[673] | 2972 | if($flag_importance && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { |
---|
[614] | 2973 | $return["status"] = false; |
---|
| 2974 | $return["msg"] = $this->functions->getLang("At least one of selected message cant be marked as normal"); |
---|
| 2975 | } |
---|
[659] | 2976 | else { |
---|
| 2977 | $return["status"] = true; |
---|
| 2978 | } |
---|
[614] | 2979 | } |
---|
[1472] | 2980 | |
---|
[411] | 2981 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 2982 | imap_close($this->mbox); |
---|
[2] | 2983 | return $return; |
---|
| 2984 | } |
---|
[1472] | 2985 | |
---|
[2] | 2986 | function get_file_type($file_name) |
---|
| 2987 | { |
---|
| 2988 | $file_name = strtolower($file_name); |
---|
| 2989 | $strFileType = strrev(substr(strrev($file_name),0,4)); |
---|
[1472] | 2990 | if ($strFileType == ".asf") |
---|
[2] | 2991 | return "video/x-ms-asf"; |
---|
| 2992 | if ($strFileType == ".avi") |
---|
| 2993 | return "video/avi"; |
---|
| 2994 | if ($strFileType == ".doc") |
---|
| 2995 | return "application/msword"; |
---|
| 2996 | if ($strFileType == ".zip") |
---|
| 2997 | return "application/zip"; |
---|
| 2998 | if ($strFileType == ".xls") |
---|
| 2999 | return "application/vnd.ms-excel"; |
---|
| 3000 | if ($strFileType == ".gif") |
---|
| 3001 | return "image/gif"; |
---|
| 3002 | if ($strFileType == ".jpg" || $strFileType == "jpeg") |
---|
| 3003 | return "image/jpeg"; |
---|
| 3004 | if ($strFileType == ".png") |
---|
| 3005 | return "image/png"; |
---|
| 3006 | if ($strFileType == ".wav") |
---|
| 3007 | return "audio/wav"; |
---|
| 3008 | if ($strFileType == ".mp3") |
---|
| 3009 | return "audio/mpeg3"; |
---|
| 3010 | if ($strFileType == ".mpg" || $strFileType == "mpeg") |
---|
| 3011 | return "video/mpeg"; |
---|
| 3012 | if ($strFileType == ".rtf") |
---|
| 3013 | return "application/rtf"; |
---|
| 3014 | if ($strFileType == ".htm" || $strFileType == "html") |
---|
| 3015 | return "text/html"; |
---|
[1472] | 3016 | if ($strFileType == ".xml") |
---|
[2] | 3017 | return "text/xml"; |
---|
[1472] | 3018 | if ($strFileType == ".xsl") |
---|
[2] | 3019 | return "text/xsl"; |
---|
[1472] | 3020 | if ($strFileType == ".css") |
---|
[2] | 3021 | return "text/css"; |
---|
[1472] | 3022 | if ($strFileType == ".php") |
---|
[2] | 3023 | return "text/php"; |
---|
[1472] | 3024 | if ($strFileType == ".asp") |
---|
[2] | 3025 | return "text/asp"; |
---|
| 3026 | if ($strFileType == ".pdf") |
---|
| 3027 | return "application/pdf"; |
---|
| 3028 | if ($strFileType == ".txt") |
---|
| 3029 | return "text/plain"; |
---|
| 3030 | if ($strFileType == ".wmv") |
---|
| 3031 | return "video/x-ms-wmv"; |
---|
| 3032 | if ($strFileType == ".sxc") |
---|
| 3033 | return "application/vnd.sun.xml.calc"; |
---|
| 3034 | if ($strFileType == ".stc") |
---|
| 3035 | return "application/vnd.sun.xml.calc.template"; |
---|
| 3036 | if ($strFileType == ".sxd") |
---|
| 3037 | return "application/vnd.sun.xml.draw"; |
---|
| 3038 | if ($strFileType == ".std") |
---|
| 3039 | return "application/vnd.sun.xml.draw.template"; |
---|
| 3040 | if ($strFileType == ".sxi") |
---|
| 3041 | return "application/vnd.sun.xml.impress"; |
---|
| 3042 | if ($strFileType == ".sti") |
---|
| 3043 | return "application/vnd.sun.xml.impress.template"; |
---|
| 3044 | if ($strFileType == ".sxm") |
---|
| 3045 | return "application/vnd.sun.xml.math"; |
---|
| 3046 | if ($strFileType == ".sxw") |
---|
| 3047 | return "application/vnd.sun.xml.writer"; |
---|
| 3048 | if ($strFileType == ".sxq") |
---|
| 3049 | return "application/vnd.sun.xml.writer.global"; |
---|
| 3050 | if ($strFileType == ".stw") |
---|
| 3051 | return "application/vnd.sun.xml.writer.template"; |
---|
[1472] | 3052 | |
---|
| 3053 | |
---|
| 3054 | return "application/octet-stream"; |
---|
[2] | 3055 | } |
---|
[1472] | 3056 | |
---|
[2] | 3057 | function htmlspecialchars_encode($str) |
---|
| 3058 | { |
---|
[449] | 3059 | return str_replace( array('&', '"','\'','<','>','{','}'), array('&','"',''','<','>','{','}'), $str); |
---|
[2] | 3060 | } |
---|
| 3061 | function htmlspecialchars_decode($str) |
---|
| 3062 | { |
---|
[449] | 3063 | return str_replace( array('&','"',''','<','>','{','}'), array('&', '"','\'','<','>','{','}'), $str); |
---|
[2] | 3064 | } |
---|
[1472] | 3065 | |
---|
[828] | 3066 | function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$offsetBegin = 0,$offsetEnd = 0) |
---|
| 3067 | { |
---|
| 3068 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[51] | 3069 | $this->mbox = $this->open_mbox($folder); |
---|
[432] | 3070 | |
---|
[828] | 3071 | return $this->messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd); |
---|
| 3072 | } |
---|
[1472] | 3073 | |
---|
[53] | 3074 | function get_info_next_msg($params) |
---|
| 3075 | { |
---|
| 3076 | $msg_number = $params['msg_number']; |
---|
| 3077 | $folder = $params['msg_folder']; |
---|
| 3078 | $sort_box_type = $params['sort_box_type']; |
---|
| 3079 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 3080 | $reuse_border = $params['reuse_border']; |
---|
| 3081 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
[1472] | 3082 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
| 3083 | |
---|
[320] | 3084 | $success = false; |
---|
| 3085 | if (is_array($sort_array_msg)) |
---|
[2] | 3086 | { |
---|
[320] | 3087 | foreach ($sort_array_msg as $i => $value){ |
---|
| 3088 | if ($value == $msg_number) |
---|
| 3089 | { |
---|
| 3090 | $success = true; |
---|
| 3091 | break; |
---|
| 3092 | } |
---|
| 3093 | } |
---|
[2] | 3094 | } |
---|
| 3095 | |
---|
[320] | 3096 | if (! $success || $i >= sizeof($sort_array_msg)-1) |
---|
[2] | 3097 | { |
---|
| 3098 | $params['status'] = 'false'; |
---|
| 3099 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
| 3100 | return $params; |
---|
| 3101 | } |
---|
[1472] | 3102 | |
---|
[2] | 3103 | $params = array(); |
---|
| 3104 | $params['msg_number'] = $sort_array_msg[($i+1)]; |
---|
| 3105 | $params['msg_folder'] = $folder; |
---|
[1472] | 3106 | |
---|
| 3107 | $return = $this->get_info_msg($params); |
---|
[2] | 3108 | $return["reuse_border"] = $reuse_border; |
---|
| 3109 | return $return; |
---|
| 3110 | } |
---|
| 3111 | |
---|
| 3112 | function get_info_previous_msg($params) |
---|
| 3113 | { |
---|
| 3114 | $msg_number = $params['msgs_number']; |
---|
| 3115 | $folder = $params['folder']; |
---|
| 3116 | $sort_box_type = $params['sort_box_type']; |
---|
| 3117 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 3118 | $reuse_border = $params['reuse_border']; |
---|
[53] | 3119 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
| 3120 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
[1472] | 3121 | |
---|
[320] | 3122 | $success = false; |
---|
| 3123 | if (is_array($sort_array_msg)) |
---|
[2] | 3124 | { |
---|
[320] | 3125 | foreach ($sort_array_msg as $i => $value){ |
---|
| 3126 | if ($value == $msg_number) |
---|
| 3127 | { |
---|
| 3128 | $success = true; |
---|
| 3129 | break; |
---|
| 3130 | } |
---|
| 3131 | } |
---|
[2] | 3132 | } |
---|
[320] | 3133 | if (! $success || $i == 0) |
---|
| 3134 | { |
---|
[2] | 3135 | $params['status'] = 'false'; |
---|
| 3136 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
| 3137 | return $params; |
---|
| 3138 | } |
---|
[1472] | 3139 | |
---|
[2] | 3140 | $params = array(); |
---|
| 3141 | $params['msg_number'] = $sort_array_msg[($i-1)]; |
---|
| 3142 | $params['msg_folder'] = $folder; |
---|
[1472] | 3143 | |
---|
[2] | 3144 | $return = $this->get_info_msg($params); |
---|
| 3145 | $return["reuse_border"] = $reuse_border; |
---|
| 3146 | return $return; |
---|
| 3147 | } |
---|
[1472] | 3148 | |
---|
[2] | 3149 | // This function updates the values: quota, paging and new messages menu. |
---|
| 3150 | function get_menu_values($params){ |
---|
| 3151 | $return_array = array(); |
---|
| 3152 | $return_array = $this->get_quota($params); |
---|
[1472] | 3153 | |
---|
[2] | 3154 | $mbox_stream = $this->open_mbox($params['folder']); |
---|
[1472] | 3155 | $return_array['num_msgs'] = imap_num_msg($mbox_stream); |
---|
[51] | 3156 | if($mbox_stream) |
---|
| 3157 | imap_close($mbox_stream); |
---|
[1472] | 3158 | |
---|
| 3159 | return $return_array; |
---|
[2] | 3160 | } |
---|
[1472] | 3161 | |
---|
[325] | 3162 | function get_quota($params){ |
---|
[449] | 3163 | // folder_id = user/{uid} for shared folders |
---|
| 3164 | if(substr($params['folder_id'],0,5) != 'INBOX' && preg_match('/user\\'.$this->imap_delimiter.'/i', $params['folder_id'])){ |
---|
| 3165 | $array_folder = explode($this->imap_delimiter,$params['folder_id']); |
---|
[1472] | 3166 | $folder_id = "user".$this->imap_delimiter.$array_folder[1]; |
---|
[449] | 3167 | } |
---|
| 3168 | // folder_id = INBOX for inbox folders |
---|
| 3169 | else |
---|
| 3170 | $folder_id = "INBOX"; |
---|
[1472] | 3171 | |
---|
[1035] | 3172 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[51] | 3173 | $this->mbox = $this->open_mbox(); |
---|
[345] | 3174 | |
---|
[325] | 3175 | $quota = imap_get_quotaroot($this->mbox, $folder_id); |
---|
[411] | 3176 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 3177 | imap_close($this->mbox); |
---|
[1472] | 3178 | |
---|
[2] | 3179 | if (!$quota){ |
---|
| 3180 | return array( |
---|
| 3181 | 'quota_percent' => 0, |
---|
| 3182 | 'quota_used' => 0, |
---|
| 3183 | 'quota_limit' => 0 |
---|
| 3184 | ); |
---|
| 3185 | } |
---|
[1472] | 3186 | |
---|
[2] | 3187 | if(count($quota) && $quota['limit']) { |
---|
[3064] | 3188 | $quota_limit = $quota['limit']; |
---|
| 3189 | $quota_used = $quota['usage']; |
---|
[2] | 3190 | if($quota_used >= $quota_limit) |
---|
[650] | 3191 | { |
---|
| 3192 | $quotaPercent = 100; |
---|
| 3193 | } |
---|
| 3194 | else |
---|
| 3195 | { |
---|
[2] | 3196 | $quotaPercent = ($quota_used / $quota_limit)*100; |
---|
| 3197 | $quotaPercent = (($quotaPercent)* 100 + .5 )* .01; |
---|
[650] | 3198 | } |
---|
[2] | 3199 | return array( |
---|
| 3200 | 'quota_percent' => floor($quotaPercent), |
---|
[3064] | 3201 | 'quota_used' => $quota_used, |
---|
| 3202 | 'quota_limit' => $quota_limit |
---|
[2] | 3203 | ); |
---|
| 3204 | } |
---|
[1472] | 3205 | else |
---|
[2] | 3206 | return array(); |
---|
| 3207 | } |
---|
[1472] | 3208 | |
---|
[2] | 3209 | function send_notification($params){ |
---|
[3231] | 3210 | include("../header.inc.php"); |
---|
[2] | 3211 | require_once("class.phpmailer.php"); |
---|
| 3212 | $mail = new PHPMailer(); |
---|
[1472] | 3213 | |
---|
[2] | 3214 | $toaddress = $params['notificationto']; |
---|
[1472] | 3215 | |
---|
[3231] | 3216 | $subject = lang("Read receipt: %1",$params['subject']); |
---|
| 3217 | $body = lang("Your message: %1",$params['subject']) . '<br>'; |
---|
[4568] | 3218 | $body .= lang("Received in: %1",date("d/m/Y H:i",$params['date'])) . '<br>'; |
---|
[3231] | 3219 | $body .= lang("Has been read by: %1 < %2 > at %3", $_SESSION['phpgw_info']['expressomail']['user']['fullname'], $_SESSION['phpgw_info']['expressomail']['user']['email'], date("d/m/Y H:i")); |
---|
[2] | 3220 | $mail->SMTPDebug = false; |
---|
| 3221 | $mail->IsSMTP(); |
---|
| 3222 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
| 3223 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
| 3224 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 3225 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
| 3226 | $mail->AddAddress($toaddress); |
---|
| 3227 | $mail->Subject = $this->htmlspecialchars_decode($subject); |
---|
| 3228 | |
---|
| 3229 | $mail->IsHTML(true); |
---|
| 3230 | $mail->Body = $body; |
---|
[1472] | 3231 | |
---|
[2] | 3232 | if(!$mail->Send()){ |
---|
| 3233 | return $mail->ErrorInfo; |
---|
| 3234 | } |
---|
| 3235 | else |
---|
| 3236 | return true; |
---|
| 3237 | } |
---|
[1472] | 3238 | |
---|
[1965] | 3239 | function empty_folder($params) |
---|
[2] | 3240 | { |
---|
[1965] | 3241 | $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server'][$params['clean_folder']]; |
---|
[2] | 3242 | $mbox_stream = $this->open_mbox($folder); |
---|
| 3243 | $return = imap_delete($mbox_stream,'1:*'); |
---|
[51] | 3244 | if($mbox_stream) |
---|
| 3245 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 3246 | return $return; |
---|
| 3247 | } |
---|
[1472] | 3248 | |
---|
[2] | 3249 | function search($params) |
---|
| 3250 | { |
---|
[673] | 3251 | include("class.imap_attachment.inc.php"); |
---|
[1472] | 3252 | $imap_attachment = new imap_attachment(); |
---|
[2] | 3253 | $criteria = $params['criteria']; |
---|
| 3254 | $return = array(); |
---|
| 3255 | $folders = $this->get_folders_list(); |
---|
[1472] | 3256 | |
---|
[2] | 3257 | $j = 0; |
---|
| 3258 | foreach($folders as $folder) |
---|
| 3259 | { |
---|
| 3260 | $mbox_stream = $this->open_mbox($folder); |
---|
| 3261 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
[1472] | 3262 | |
---|
[2] | 3263 | if ($messages == '') |
---|
| 3264 | continue; |
---|
[1472] | 3265 | |
---|
[2] | 3266 | $i = 0; |
---|
| 3267 | $return[$j] = array(); |
---|
| 3268 | $return[$j]['folder_name'] = $folder['name']; |
---|
[1472] | 3269 | |
---|
[2] | 3270 | foreach($messages as $msg_number) |
---|
| 3271 | { |
---|
[535] | 3272 | $header = $this->get_header($msg_number); |
---|
[2] | 3273 | if (!is_object($header)) |
---|
| 3274 | return false; |
---|
[1472] | 3275 | |
---|
[2] | 3276 | $return[$j][$i]['msg_folder'] = $folder['name']; |
---|
| 3277 | $return[$j][$i]['msg_number'] = $msg_number; |
---|
| 3278 | $return[$j][$i]['Recent'] = $header->Recent; |
---|
| 3279 | $return[$j][$i]['Unseen'] = $header->Unseen; |
---|
| 3280 | $return[$j][$i]['Answered'] = $header->Answered; |
---|
| 3281 | $return[$j][$i]['Deleted'] = $header->Deleted; |
---|
| 3282 | $return[$j][$i]['Draft'] = $header->Draft; |
---|
| 3283 | $return[$j][$i]['Flagged'] = $header->Flagged; |
---|
[1472] | 3284 | |
---|
[535] | 3285 | $date_msg = gmdate("d/m/Y",$header->udate); |
---|
| 3286 | if (gmdate("d/m/Y") == $date_msg) |
---|
| 3287 | $return[$j][$i]['udate'] = gmdate("H:i",$header->udate); |
---|
[2] | 3288 | else |
---|
| 3289 | $return[$j][$i]['udate'] = $date_msg; |
---|
[1472] | 3290 | |
---|
[2] | 3291 | $fromaddress = imap_mime_header_decode($header->fromaddress); |
---|
| 3292 | $return[$j][$i]['fromaddress'] = ''; |
---|
| 3293 | foreach ($fromaddress as $tmp) |
---|
| 3294 | $return[$j][$i]['fromaddress'] .= $this->replace_maior_menor($tmp->text); |
---|
[1472] | 3295 | |
---|
[2] | 3296 | $from = $header->from; |
---|
| 3297 | $return[$j][$i]['from'] = array(); |
---|
| 3298 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 3299 | $return[$j][$i]['from']['name'] = $tmp[0]->text; |
---|
| 3300 | $return[$j][$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
[1472] | 3301 | $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; |
---|
[2] | 3302 | |
---|
| 3303 | $to = $header->to; |
---|
| 3304 | $return[$j][$i]['to'] = array(); |
---|
| 3305 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
| 3306 | $return[$j][$i]['to']['name'] = $tmp[0]->text; |
---|
| 3307 | $return[$j][$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
[1472] | 3308 | $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; |
---|
[2] | 3309 | |
---|
| 3310 | $subject = imap_mime_header_decode($header->fetchsubject); |
---|
| 3311 | $return[$j][$i]['subject'] = ''; |
---|
| 3312 | foreach ($subject as $tmp) |
---|
| 3313 | $return[$j][$i]['subject'] .= $tmp->text; |
---|
| 3314 | |
---|
| 3315 | $return[$j][$i]['Size'] = $header->Size; |
---|
| 3316 | $return[$j][$i]['reply_toaddress'] = $header->reply_toaddress; |
---|
[1472] | 3317 | |
---|
[2] | 3318 | $return[$j][$i]['attachment'] = array(); |
---|
| 3319 | $return[$j][$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($mbox_stream, $msg_number); |
---|
[1472] | 3320 | |
---|
[2] | 3321 | $i++; |
---|
| 3322 | } |
---|
| 3323 | $j++; |
---|
[51] | 3324 | if($mbox_stream) |
---|
| 3325 | imap_close($mbox_stream); |
---|
[2] | 3326 | } |
---|
[1472] | 3327 | |
---|
[2] | 3328 | return $return; |
---|
| 3329 | } |
---|
[3923] | 3330 | |
---|
| 3331 | |
---|
[1709] | 3332 | function mobile_search($params) |
---|
| 3333 | { |
---|
| 3334 | include("class.imap_attachment.inc.php"); |
---|
| 3335 | $imap_attachment = new imap_attachment(); |
---|
| 3336 | $criterias = array ("TO","SUBJECT","FROM","CC"); |
---|
| 3337 | $return = array(); |
---|
[3589] | 3338 | if(!isset($params['folder'])) { |
---|
| 3339 | $folder_params = array("noSharedFolders"=>1); |
---|
| 3340 | if(isset($params['folderType'])) |
---|
| 3341 | $folder_params['folderType'] = $params['folderType']; |
---|
| 3342 | $folders = $this->get_folders_list($folder_params); |
---|
| 3343 | } |
---|
| 3344 | else |
---|
| 3345 | $folders = array(0=>array('folder_id'=>$params['folder'])); |
---|
[1709] | 3346 | $num_msgs = 0; |
---|
[3923] | 3347 | $max_msgs = $params['max_msgs'] + 1; //get one more because mobile paginate |
---|
| 3348 | $return["msgs"] = array(); |
---|
| 3349 | |
---|
| 3350 | //get max_msgs of each folder order by date and later order all messages together and retur only max_msgs msgs |
---|
[1709] | 3351 | foreach($folders as $id =>$folder) |
---|
| 3352 | { |
---|
| 3353 | if(strpos($folder['folder_id'],'user')===false && is_array($folder)) { |
---|
| 3354 | foreach($criterias as $criteria_fixed) |
---|
[3923] | 3355 | { |
---|
| 3356 | $_filter = $criteria_fixed . ' "'.$params['filter'].'"'; |
---|
| 3357 | |
---|
[3573] | 3358 | $mbox_stream = $this->open_mbox($folder['folder_id']); |
---|
[3923] | 3359 | |
---|
| 3360 | $messages = imap_sort($mbox_stream,SORTARRIVAL,1,SE_UID,$_filter); |
---|
[1709] | 3361 | |
---|
| 3362 | if ($messages == ''){ |
---|
| 3363 | if($mbox_stream) |
---|
| 3364 | imap_close($mbox_stream); |
---|
| 3365 | continue; |
---|
| 3366 | } |
---|
[3923] | 3367 | |
---|
[1709] | 3368 | foreach($messages as $msg_number) |
---|
[3923] | 3369 | { |
---|
[1709] | 3370 | $temp = $this->get_info_head_msg($msg_number); |
---|
| 3371 | if(!$temp) |
---|
| 3372 | return false; |
---|
[3573] | 3373 | $temp['msg_folder'] = $folder['folder_id']; |
---|
[3923] | 3374 | $return["msgs"][$num_msgs] = $temp; |
---|
[1709] | 3375 | $num_msgs++; |
---|
| 3376 | } |
---|
[3923] | 3377 | |
---|
[1709] | 3378 | if($mbox_stream) |
---|
| 3379 | imap_close($mbox_stream); |
---|
| 3380 | } |
---|
[3923] | 3381 | } |
---|
[1709] | 3382 | } |
---|
[3923] | 3383 | |
---|
| 3384 | if(!function_exists("cmp_date")) { |
---|
| 3385 | function cmp_date($obj1, $obj2){ |
---|
| 3386 | if($obj1['timestamp'] == $obj2['timestamp']) return 0; |
---|
| 3387 | return ($obj1['timestamp'] < $obj2['timestamp']) ? 1 : -1; |
---|
| 3388 | } |
---|
| 3389 | } |
---|
| 3390 | usort($return["msgs"], "cmp_date"); |
---|
| 3391 | $return["has_more_msg"] = (sizeof($return["msgs"]) > $max_msgs); |
---|
| 3392 | $return["msgs"] = array_slice($return["msgs"], 0, $max_msgs); |
---|
[4524] | 3393 | $return["msgs"]['num_msgs'] = $num_msgs; |
---|
[3923] | 3394 | |
---|
[1709] | 3395 | return $return; |
---|
| 3396 | } |
---|
[1472] | 3397 | |
---|
[2] | 3398 | function delete_and_show_previous_message($params) |
---|
| 3399 | { |
---|
| 3400 | $return = $this->get_info_previous_msg($params); |
---|
[1472] | 3401 | |
---|
[2] | 3402 | $params_tmp1 = array(); |
---|
| 3403 | $params_tmp1['msgs_to_delete'] = $params['msg_number']; |
---|
| 3404 | $params_tmp1['folder'] = $params['msg_folder']; |
---|
| 3405 | $return_tmp1 = $this->delete_msg($params_tmp1); |
---|
[1472] | 3406 | |
---|
[2] | 3407 | $return['msg_number_deleted'] = $return_tmp1; |
---|
[1472] | 3408 | |
---|
[2] | 3409 | return $return; |
---|
| 3410 | } |
---|
[1472] | 3411 | |
---|
| 3412 | |
---|
[2] | 3413 | function automatic_trash_cleanness($params) |
---|
| 3414 | { |
---|
| 3415 | $before_date = date("m/d/Y", strtotime("-".$params['before_date']." day")); |
---|
| 3416 | $criteria = 'BEFORE "'.$before_date.'"'; |
---|
[325] | 3417 | $mbox_stream = $this->open_mbox('INBOX'.$this->imap_delimiter.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']); |
---|
[3018] | 3418 | // Free others requests |
---|
| 3419 | session_write_close(); |
---|
[2] | 3420 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
| 3421 | if (is_array($messages)){ |
---|
| 3422 | foreach ($messages as $msg_number){ |
---|
| 3423 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
| 3424 | } |
---|
| 3425 | } |
---|
[51] | 3426 | if($mbox_stream) |
---|
| 3427 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 3428 | return $messages; |
---|
| 3429 | } |
---|
| 3430 | // Fix the search problem with special characters!!!! |
---|
| 3431 | function remove_accents($string) { |
---|
[1472] | 3432 | return strtr($string, |
---|
[4022] | 3433 | "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ", |
---|
[2] | 3434 | "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); |
---|
| 3435 | } |
---|
| 3436 | |
---|
[1622] | 3437 | function make_search_date($date){ |
---|
| 3438 | |
---|
| 3439 | //TODO: Adaptar a data de acordo com o locale do sistema. |
---|
| 3440 | list($day,$month,$year) = explode("/", $date); |
---|
[4431] | 3441 | $before?$day=(int)$day+1:$day=(int)$day; |
---|
| 3442 | $timestamp = mktime(0,0,0,(int)$month,$day,(int)$year); |
---|
| 3443 | $search_date = date('d-M-Y',$timestamp); |
---|
[1622] | 3444 | return $search_date; |
---|
| 3445 | |
---|
| 3446 | } |
---|
| 3447 | |
---|
[3843] | 3448 | function search_msg( $params = false ) |
---|
| 3449 | { |
---|
| 3450 | $mbox_stream = ""; |
---|
| 3451 | |
---|
| 3452 | if(strpos($params['condition'],"#")===false) |
---|
| 3453 | { //local messages |
---|
| 3454 | $search=false; |
---|
| 3455 | } |
---|
| 3456 | else |
---|
| 3457 | { |
---|
| 3458 | $search = explode(",",$params['condition']); |
---|
| 3459 | } |
---|
| 3460 | |
---|
| 3461 | $params['page'] = $params['page'] * 1; |
---|
[689] | 3462 | |
---|
[3843] | 3463 | if( is_array($search) ) |
---|
| 3464 | { |
---|
| 3465 | $search = array_unique($search); // Remove duplicated folders |
---|
| 3466 | $search_criteria = ''; |
---|
| 3467 | $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; |
---|
| 3468 | foreach($search as $tmp) |
---|
| 3469 | { |
---|
| 3470 | $tmp1 = explode("##",$tmp); |
---|
| 3471 | $sum = 0; |
---|
| 3472 | $name_box = $tmp1[0]; |
---|
| 3473 | unset($filter); |
---|
| 3474 | foreach($tmp1 as $index => $criteria) |
---|
| 3475 | { |
---|
| 3476 | if ($index != 0 && strlen($criteria) != 0) |
---|
| 3477 | { |
---|
| 3478 | $filter_array = explode("<=>",html_entity_decode(rawurldecode($criteria))); |
---|
| 3479 | $filter .= " ".$filter_array[0]; |
---|
| 3480 | if (strlen($filter_array[1]) != 0) |
---|
| 3481 | { |
---|
| 3482 | if ( trim($filter_array[0]) != 'BEFORE' && |
---|
| 3483 | trim($filter_array[0]) != 'SINCE' && |
---|
| 3484 | trim($filter_array[0]) != 'ON') |
---|
| 3485 | { |
---|
| 3486 | $filter .= '"'.$filter_array[1].'"'; |
---|
[4431] | 3487 | }else if(trim($filter_array[0]) == 'BEFORE' ){ |
---|
| 3488 | $filter .= '"'.$this->make_search_date($filter_array[1],true).'"'; |
---|
| 3489 | }else{ |
---|
[3843] | 3490 | $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; |
---|
| 3491 | } |
---|
| 3492 | } |
---|
| 3493 | } |
---|
| 3494 | } |
---|
| 3495 | |
---|
[4587] | 3496 | $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO-8859-1" ); |
---|
[3843] | 3497 | $filter = $this->remove_accents($filter); |
---|
[1472] | 3498 | |
---|
[3843] | 3499 | //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name |
---|
| 3500 | if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user') |
---|
| 3501 | { |
---|
| 3502 | $folder_name = explode($this->imap_delimiter,$name_box); |
---|
| 3503 | $this->ldap = new ldap_functions(); |
---|
| 3504 | |
---|
| 3505 | if ($cn = $this->ldap->uid2cn($folder_name[1])) |
---|
| 3506 | { |
---|
| 3507 | $folder_name[1] = $cn; |
---|
| 3508 | } |
---|
| 3509 | $folder_name = implode($this->imap_delimiter,$folder_name); |
---|
[3391] | 3510 | } |
---|
[3843] | 3511 | else |
---|
[4587] | 3512 | $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO-8859-1" ); |
---|
[3843] | 3513 | |
---|
| 3514 | if(!is_resource($mbox_stream)) |
---|
| 3515 | $mbox_stream = $this->open_mbox($name_box); |
---|
| 3516 | else |
---|
| 3517 | imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); |
---|
| 3518 | |
---|
| 3519 | if (preg_match("/^.?\bALL\b/", $filter)) |
---|
| 3520 | { |
---|
| 3521 | // Quick Search, note: this ALL isn't the same ALL from imap_search |
---|
| 3522 | $all_criterias = array ("TO","SUBJECT","FROM","CC"); |
---|
| 3523 | |
---|
| 3524 | foreach($all_criterias as $criteria_fixed) |
---|
| 3525 | { |
---|
| 3526 | $_filter = $criteria_fixed . substr($filter,4); |
---|
| 3527 | |
---|
| 3528 | $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); |
---|
| 3529 | |
---|
| 3530 | if(is_array($search_criteria)) |
---|
| 3531 | { |
---|
| 3532 | foreach($search_criteria as $new_search) |
---|
| 3533 | { |
---|
| 3534 | $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); |
---|
[4587] | 3535 | $elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); |
---|
[3843] | 3536 | $elem['uid'] = $new_search; |
---|
[4437] | 3537 | /* compare dates in ordering */ |
---|
| 3538 | $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); |
---|
[3843] | 3539 | $retorno[] = $elem; |
---|
| 3540 | } |
---|
| 3541 | } |
---|
| 3542 | } |
---|
[4067] | 3543 | } |
---|
| 3544 | else { |
---|
| 3545 | $search_criteria = imap_search($mbox_stream, $filter, SE_UID); |
---|
| 3546 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) |
---|
[3843] | 3547 | { |
---|
[4067] | 3548 | if((!strpos($filter,"FLAGGED") === false) || (!strpos($filter,"UNFLAGGED") === false)) |
---|
| 3549 | { |
---|
| 3550 | $num_msgs = imap_num_msg($mbox_stream); |
---|
| 3551 | $flagged_msgs = array(); |
---|
| 3552 | for ($i=$num_msgs; $i>0; $i--) |
---|
| 3553 | { |
---|
| 3554 | $iuid = @imap_uid($this->mbox,$i); |
---|
| 3555 | $header = $this->get_header($iuid); |
---|
| 3556 | if(trim($header->Flagged)) |
---|
| 3557 | { |
---|
| 3558 | $flagged_msgs[$i] = $iuid; |
---|
| 3559 | } |
---|
| 3560 | } |
---|
| 3561 | if((count($flagged_msgs) >0) && (strpos($filter,"UNFLAGGED") === false)) |
---|
| 3562 | { |
---|
| 3563 | $arry_diff = is_array($search_criteria) ? array_diff($flagged_msgs,$search_criteria):$flagged_msgs; |
---|
| 3564 | foreach($arry_diff as $msg) |
---|
| 3565 | { |
---|
| 3566 | $search_criteria[] = $msg; |
---|
| 3567 | } |
---|
| 3568 | } |
---|
| 3569 | else if((count($flagged_msgs) >0) && (is_array($search_criteria)) && (!strpos($filter,"UNFLAGGED") === false)) |
---|
| 3570 | { |
---|
| 3571 | $search_criteria = array_diff($search_criteria,$flagged_msgs); |
---|
| 3572 | } |
---|
| 3573 | } |
---|
| 3574 | } |
---|
| 3575 | if( is_array( $search_criteria) ) |
---|
| 3576 | { |
---|
[3843] | 3577 | foreach($search_criteria as $new_search) |
---|
| 3578 | { |
---|
| 3579 | $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); |
---|
[4587] | 3580 | $elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); |
---|
[3843] | 3581 | $elem['uid'] = $new_search; |
---|
[4437] | 3582 | /* compare dates in ordering */ |
---|
| 3583 | $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); |
---|
[3843] | 3584 | $retorno[] = $elem; |
---|
| 3585 | } |
---|
| 3586 | } |
---|
[4067] | 3587 | } |
---|
[3843] | 3588 | } |
---|
| 3589 | } |
---|
| 3590 | |
---|
| 3591 | if($mbox_stream) |
---|
| 3592 | { |
---|
| 3593 | imap_close($mbox_stream); |
---|
[3803] | 3594 | } |
---|
[3843] | 3595 | |
---|
[3803] | 3596 | $num_msgs = count($retorno); |
---|
[3223] | 3597 | |
---|
[3803] | 3598 | /* Comparison functions, descendent is ascendent with parms inverted */ |
---|
[4437] | 3599 | function SORTDATE($a, $b){ return ($a['udatecomp'] < $b['udatecomp']); } |
---|
[3803] | 3600 | function SORTDATE_REVERSE($b, $a) { return SORTDATE($a,$b); } |
---|
[3391] | 3601 | |
---|
[3803] | 3602 | function SORTWHO($a, $b) { return (strtoupper($a['from']) > strtoupper($b['from'])); } |
---|
| 3603 | function SORTWHO_REVERSE($b, $a) { return SORTWHO($a,$b); } |
---|
| 3604 | |
---|
| 3605 | function SORTSUBJECT($a, $b) { return (strtoupper($a['subject']) > strtoupper($b['subject'])); } |
---|
| 3606 | function SORTSUBJECT_REVERSE($b, $a) { return SORTSUBJECT($a,$b); } |
---|
| 3607 | |
---|
| 3608 | function SORTBOX($a, $b) { return ($a['boxname'] > $b['boxname']); } |
---|
| 3609 | function SORTBOX_REVERSE($b, $a) { return SORTBOX($a,$b); } |
---|
| 3610 | |
---|
| 3611 | function SORTSIZE($a, $b) { return ($a['size'] > $b['size']); } |
---|
| 3612 | function SORTSIZE_REVERSE($b, $a) { return SORTSIZE($a,$b); } |
---|
| 3613 | |
---|
[3843] | 3614 | usort( $retorno, $params['sort_type']); |
---|
| 3615 | $pageret = array_slice( $retorno, $params['page'] * $this->prefs['max_email_per_page'], $this->prefs['max_email_per_page']); |
---|
| 3616 | |
---|
| 3617 | $arrayRetorno['num_msgs'] = $num_msgs; |
---|
| 3618 | $arrayRetorno['data'] = $pageret; |
---|
[4146] | 3619 | $arrayRetorno['currentTab'] = $params['current_tab']; |
---|
[3803] | 3620 | |
---|
[3843] | 3621 | if ($pageret) |
---|
| 3622 | { |
---|
| 3623 | return $arrayRetorno; |
---|
| 3624 | } |
---|
| 3625 | else |
---|
| 3626 | { |
---|
| 3627 | return 'none'; |
---|
| 3628 | } |
---|
[2] | 3629 | } |
---|
[1472] | 3630 | |
---|
[3803] | 3631 | function get_msg_detail($uid_msg,$name_box, $mbox_stream ) |
---|
[271] | 3632 | { |
---|
[828] | 3633 | $header = $this->get_header($uid_msg); |
---|
[3803] | 3634 | require_once("class.imap_attachment.inc.php"); |
---|
[828] | 3635 | $imap_attachment = new imap_attachment(); |
---|
| 3636 | $attachments = $imap_attachment->get_attachment_headerinfo($mbox_stream, $uid_msg); |
---|
| 3637 | $attachments = $attachments['number_attachments'] > 0?"T".$attachments['number_attachments']:""; |
---|
| 3638 | $flag = $header->Unseen |
---|
| 3639 | .$header->Recent |
---|
| 3640 | .$header->Flagged |
---|
| 3641 | .$header->Draft |
---|
| 3642 | .$header->Answered |
---|
| 3643 | .$header->Deleted |
---|
| 3644 | .$attachments; |
---|
| 3645 | |
---|
| 3646 | |
---|
[163] | 3647 | $subject = $this->decode_string($header->fetchsubject); |
---|
| 3648 | $from = $header->from[0]->mailbox; |
---|
[2] | 3649 | if($header->from[0]->personal != "") |
---|
| 3650 | $from = $header->from[0]->personal; |
---|
[3843] | 3651 | $ret_msg['from'] = $this->decode_string($from); |
---|
| 3652 | $ret_msg['subject'] = $subject; |
---|
| 3653 | $ret_msg['udate'] = gmdate("d/m/Y",$header->udate + $this->functions->CalculateDateOffset()); |
---|
| 3654 | $ret_msg['size'] = $header->Size; |
---|
| 3655 | $ret_msg['flag'] = $flag; |
---|
[1472] | 3656 | return $ret_msg; |
---|
| 3657 | } |
---|
[3391] | 3658 | |
---|
| 3659 | |
---|
| 3660 | function size_msg($size){ |
---|
| 3661 | $var = floor($size/1024); |
---|
| 3662 | if($var >= 1){ |
---|
| 3663 | return $var." kb"; |
---|
| 3664 | }else{ |
---|
| 3665 | return $size ." b"; |
---|
| 3666 | } |
---|
| 3667 | } |
---|
| 3668 | |
---|
[2] | 3669 | function ob_array($the_object) |
---|
| 3670 | { |
---|
| 3671 | $the_array=array(); |
---|
| 3672 | if(!is_scalar($the_object)) |
---|
| 3673 | { |
---|
| 3674 | foreach($the_object as $id => $object) |
---|
| 3675 | { |
---|
| 3676 | if(is_scalar($object)) |
---|
| 3677 | { |
---|
| 3678 | $the_array[$id]=$object; |
---|
| 3679 | } |
---|
| 3680 | else |
---|
| 3681 | { |
---|
| 3682 | $the_array[$id]=$this->ob_array($object); |
---|
| 3683 | } |
---|
| 3684 | } |
---|
| 3685 | return $the_array; |
---|
| 3686 | } |
---|
| 3687 | else |
---|
| 3688 | { |
---|
| 3689 | return $the_object; |
---|
| 3690 | } |
---|
| 3691 | } |
---|
[1472] | 3692 | |
---|
[2] | 3693 | function getacl() |
---|
| 3694 | { |
---|
| 3695 | $this->ldap = new ldap_functions(); |
---|
[1472] | 3696 | |
---|
[2] | 3697 | $return = array(); |
---|
[1472] | 3698 | $mbox_stream = $this->open_mbox(); |
---|
[2] | 3699 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
[1472] | 3700 | |
---|
[2] | 3701 | $i = 0; |
---|
| 3702 | foreach ($mbox_acl as $user => $acl) |
---|
| 3703 | { |
---|
| 3704 | if ($user != $this->username) |
---|
| 3705 | { |
---|
| 3706 | $return[$i]['uid'] = $user; |
---|
| 3707 | $return[$i]['cn'] = $this->ldap->uid2cn($user); |
---|
| 3708 | } |
---|
| 3709 | $i++; |
---|
| 3710 | } |
---|
| 3711 | return $return; |
---|
| 3712 | } |
---|
[1472] | 3713 | |
---|
[2] | 3714 | function setacl($params) |
---|
| 3715 | { |
---|
| 3716 | $old_users = $this->getacl(); |
---|
| 3717 | if (!count($old_users)) |
---|
| 3718 | $old_users = array(); |
---|
[1472] | 3719 | |
---|
[2] | 3720 | $tmp_array = array(); |
---|
| 3721 | foreach ($old_users as $index => $user_info) |
---|
| 3722 | { |
---|
| 3723 | $tmp_array[$index] = $user_info['uid']; |
---|
| 3724 | } |
---|
| 3725 | $old_users = $tmp_array; |
---|
[1472] | 3726 | |
---|
[2] | 3727 | $users = unserialize($params['users']); |
---|
| 3728 | if (!count($users)) |
---|
| 3729 | $users = array(); |
---|
[1472] | 3730 | |
---|
[2] | 3731 | //$add_share = array_diff($users, $old_users); |
---|
| 3732 | $remove_share = array_diff($old_users, $users); |
---|
| 3733 | |
---|
| 3734 | $mbox_stream = $this->open_mbox(); |
---|
| 3735 | |
---|
| 3736 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 3737 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
| 3738 | |
---|
| 3739 | /*if (count($add_share)) |
---|
| 3740 | { |
---|
| 3741 | foreach ($add_share as $index=>$uid) |
---|
| 3742 | { |
---|
| 3743 | if (is_array($mailboxes_list)) |
---|
| 3744 | { |
---|
| 3745 | foreach ($mailboxes_list as $key => $val) |
---|
| 3746 | { |
---|
| 3747 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
| 3748 | imap_setacl ($mbox_stream, $folder, "$uid", "lrswipcda"); |
---|
| 3749 | } |
---|
| 3750 | } |
---|
| 3751 | } |
---|
| 3752 | }*/ |
---|
[1472] | 3753 | |
---|
[4575] | 3754 | if (count($remove_share)) |
---|
| 3755 | { |
---|
| 3756 | foreach ($remove_share as $index=>$uid) |
---|
| 3757 | { |
---|
| 3758 | if (is_array($mailboxes_list)) |
---|
| 3759 | { |
---|
| 3760 | foreach ($mailboxes_list as $key => $val) |
---|
| 3761 | { |
---|
[4587] | 3762 | $folder = str_replace($serverString, "", $val->name); |
---|
[4575] | 3763 | imap_setacl ($mbox_stream, $folder, "$uid", ""); |
---|
| 3764 | } |
---|
| 3765 | } |
---|
| 3766 | } |
---|
| 3767 | } |
---|
[1472] | 3768 | |
---|
[2] | 3769 | return true; |
---|
| 3770 | } |
---|
[1472] | 3771 | |
---|
[2] | 3772 | function getaclfromuser($params) |
---|
| 3773 | { |
---|
| 3774 | $useracl = $params['user']; |
---|
[1472] | 3775 | |
---|
[2] | 3776 | $return = array(); |
---|
| 3777 | $return[$useracl] = 'false'; |
---|
[1472] | 3778 | $mbox_stream = $this->open_mbox(); |
---|
[2] | 3779 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
[1472] | 3780 | |
---|
[2] | 3781 | foreach ($mbox_acl as $user => $acl) |
---|
| 3782 | { |
---|
| 3783 | if (($user != $this->username) && ($user == $useracl)) |
---|
| 3784 | { |
---|
| 3785 | $return[$user] = $acl; |
---|
| 3786 | } |
---|
| 3787 | } |
---|
| 3788 | return $return; |
---|
| 3789 | } |
---|
| 3790 | |
---|
| 3791 | function getacltouser($user) |
---|
| 3792 | { |
---|
| 3793 | $return = array(); |
---|
| 3794 | $mbox_stream = $this->open_mbox(); |
---|
[325] | 3795 | //Alterado, antes era 'imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); |
---|
| 3796 | //Afim de tratar as pastas compartilhadas, verificandos as permissoes de operacao sobre as mesmas |
---|
| 3797 | //No caso de se tratar da caixa do proprio usuario logado, utiliza a sintaxe abaixo |
---|
| 3798 | if(substr($user,0,4) != 'user') |
---|
[449] | 3799 | $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); |
---|
[325] | 3800 | else |
---|
| 3801 | $mbox_acl = imap_getacl($mbox_stream, $user); |
---|
[2] | 3802 | return $mbox_acl[$this->username]; |
---|
| 3803 | } |
---|
| 3804 | |
---|
[1472] | 3805 | |
---|
[2] | 3806 | function setaclfromuser($params) |
---|
| 3807 | { |
---|
| 3808 | $user = $params['user']; |
---|
| 3809 | $acl = $params['acl']; |
---|
[1472] | 3810 | |
---|
[2] | 3811 | $mbox_stream = $this->open_mbox(); |
---|
| 3812 | |
---|
| 3813 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 3814 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
| 3815 | |
---|
| 3816 | if (is_array($mailboxes_list)) |
---|
| 3817 | { |
---|
| 3818 | foreach ($mailboxes_list as $key => $val) |
---|
| 3819 | { |
---|
[449] | 3820 | $folder = str_replace($serverString, "", imap_utf7_encode($val->name)); |
---|
| 3821 | $folder = str_replace("&-", "&", $folder); |
---|
[2] | 3822 | if (!imap_setacl ($mbox_stream, $folder, $user, $acl)) |
---|
| 3823 | { |
---|
[449] | 3824 | $return = imap_last_error(); |
---|
[2] | 3825 | } |
---|
| 3826 | } |
---|
| 3827 | } |
---|
[449] | 3828 | if (isset($return)) |
---|
| 3829 | return $return; |
---|
| 3830 | else |
---|
| 3831 | return true; |
---|
[2] | 3832 | } |
---|
[1472] | 3833 | |
---|
[51] | 3834 | function download_attachment($msg,$msgno) |
---|
| 3835 | { |
---|
[1472] | 3836 | $array_parts_attachments = array(); |
---|
[3289] | 3837 | //$array_parts_attachments['names'] = ''; |
---|
[689] | 3838 | include_once("class.imap_attachment.inc.php"); |
---|
[1472] | 3839 | $imap_attachment = new imap_attachment(); |
---|
| 3840 | |
---|
[51] | 3841 | if (count($msg->fname[$msgno]) > 0) |
---|
| 3842 | { |
---|
| 3843 | $i = 0; |
---|
| 3844 | foreach ($msg->fname[$msgno] as $index=>$fname) |
---|
| 3845 | { |
---|
| 3846 | $array_parts_attachments[$i]['pid'] = $msg->pid[$msgno][$index]; |
---|
[1397] | 3847 | $array_parts_attachments[$i]['name'] = $imap_attachment->flat_mime_decode($this->decode_string($fname)); |
---|
[51] | 3848 | $array_parts_attachments[$i]['name'] = $array_parts_attachments[$i]['name'] ? $array_parts_attachments[$i]['name'] : "attachment.bin"; |
---|
| 3849 | $array_parts_attachments[$i]['encoding'] = $msg->encoding[$msgno][$index]; |
---|
[3289] | 3850 | //$array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', '; |
---|
[51] | 3851 | $array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index]; |
---|
| 3852 | $i++; |
---|
| 3853 | } |
---|
| 3854 | } |
---|
[3289] | 3855 | //$array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); |
---|
[51] | 3856 | return $array_parts_attachments; |
---|
[1472] | 3857 | } |
---|
[69] | 3858 | |
---|
| 3859 | function spam($params) |
---|
| 3860 | { |
---|
| 3861 | $is_spam = $params['spam']; |
---|
| 3862 | $folder = $params['folder']; |
---|
| 3863 | $mbox_stream = $this->open_mbox($folder); |
---|
| 3864 | $msgs_number = explode(',',$params['msgs_number']); |
---|
| 3865 | |
---|
| 3866 | foreach($msgs_number as $msg_number) { |
---|
[877] | 3867 | $imap_msg_number = imap_msgno($mbox_stream, $msg_number); |
---|
| 3868 | $header = imap_fetchheader($mbox_stream, $imap_msg_number); |
---|
| 3869 | $body = imap_body($mbox_stream, $imap_msg_number); |
---|
[69] | 3870 | $msg = $header . $body; |
---|
| 3871 | $email = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
[449] | 3872 | $username = $this->username; |
---|
[69] | 3873 | strtok($email, '@'); |
---|
| 3874 | $domain = strtok('@'); |
---|
| 3875 | |
---|
[449] | 3876 | //Encontrar a assinatura do dspam no cabecalho |
---|
| 3877 | $v = explode("\r\n", $header); |
---|
| 3878 | foreach ($v as $linha){ |
---|
[877] | 3879 | if (eregi("^Message-ID", $linha)) { |
---|
| 3880 | $args = explode(" ", $linha); |
---|
| 3881 | $msg_id = "'$args[1]'"; |
---|
| 3882 | } elseif (eregi("^X-DSPAM-Signature", $linha)) { |
---|
[449] | 3883 | $args = explode(" ",$linha); |
---|
| 3884 | $signature = $args[1]; |
---|
| 3885 | } |
---|
| 3886 | } |
---|
| 3887 | |
---|
[877] | 3888 | // Seleciona qual comando a ser executado |
---|
[449] | 3889 | switch($is_spam){ |
---|
| 3890 | case 'true': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam']; break; |
---|
| 3891 | case 'false': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham']; break; |
---|
| 3892 | } |
---|
[877] | 3893 | |
---|
| 3894 | $tags = array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##', '##MSGID##'); |
---|
| 3895 | $cmd = str_replace($tags, array($email, $username, $domain, $signature, $msg_id), $cmd); |
---|
[78] | 3896 | system($cmd); |
---|
[69] | 3897 | } |
---|
| 3898 | imap_close($mbox_stream); |
---|
| 3899 | return false; |
---|
| 3900 | } |
---|
[535] | 3901 | function get_header($msg_number){ |
---|
[3493] | 3902 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); |
---|
[535] | 3903 | if (!is_object($header)) |
---|
| 3904 | return false; |
---|
[1472] | 3905 | |
---|
[673] | 3906 | if($header->Flagged != "F" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { |
---|
[659] | 3907 | $flag = preg_match('/importance *: *(.*)\r/i', |
---|
| 3908 | imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) |
---|
[1472] | 3909 | ,$importance); |
---|
[659] | 3910 | $header->Flagged = $flag==0?false:strtolower($importance[1])=="high"?"F":false; |
---|
| 3911 | } |
---|
[1472] | 3912 | |
---|
[535] | 3913 | return $header; |
---|
| 3914 | } |
---|
[1000] | 3915 | |
---|
| 3916 | //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Insere emails no imap a partir do fonte do mesmo. Se o argumento timestamp for passado ele utiliza do script python |
---|
[4022] | 3917 | ///expressoMail1_2/imap.py para inserir uma msg com o horário correto pois isso não é porssível com a função imap_append do php. |
---|
[1000] | 3918 | |
---|
[3911] | 3919 | function insert_email($source,$folder,$timestamp,$flags){ |
---|
[1000] | 3920 | $username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 3921 | $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
| 3922 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 3923 | $imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
| 3924 | $imap_options = '/notls/novalidate-cert'; |
---|
| 3925 | $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); |
---|
| 3926 | if(imap_last_error()) |
---|
| 3927 | { |
---|
| 3928 | imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}".$folder)); |
---|
[3872] | 3929 | } |
---|
[1000] | 3930 | if($timestamp){ |
---|
| 3931 | $tempDir = ini_get("session.save_path"); |
---|
[1247] | 3932 | $file = $tempDir."imap_".$_SESSION[ 'phpgw_session' ][ 'session_id' ]; |
---|
[1000] | 3933 | $f = fopen($file,"w"); |
---|
| 3934 | fputs($f,base64_encode($source)); |
---|
| 3935 | fclose($f); |
---|
[1586] | 3936 | $command = "python ".$_SERVER['DOCUMENT_ROOT']."/expressoMail1_2/imap.py ".escapeshellarg($imap_server)." ".escapeshellarg($imap_port)." ".escapeshellarg($username)." ".escapeshellarg($password)." ".escapeshellarg($timestamp)." ".escapeshellarg($folder)." ".escapeshellarg($file); |
---|
[1012] | 3937 | $return['command']=exec(escapeshellcmd($command)); |
---|
[1000] | 3938 | }else{ |
---|
| 3939 | $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $source, "\\Seen"); |
---|
| 3940 | } |
---|
| 3941 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); |
---|
[3872] | 3942 | |
---|
[1000] | 3943 | $return['msg_no'] = $status->uidnext - 1; |
---|
[3911] | 3944 | $return['error'] = imap_last_error(); |
---|
| 3945 | if(!$return['error'] && $flags != '' ){ |
---|
[3872] | 3946 | |
---|
[3911] | 3947 | $flags_array=explode(':',$flags); |
---|
| 3948 | //"Answered","Draft","Flagged","Unseen" |
---|
| 3949 | $flags_fixed = ""; |
---|
| 3950 | if($flags_array[0] == 'A') |
---|
| 3951 | $flags_fixed.="\\Answered "; |
---|
| 3952 | if($flags_array[1] == 'X') |
---|
| 3953 | $flags_fixed.="\\Draft "; |
---|
| 3954 | if($flags_array[2] == 'F') |
---|
| 3955 | $flags_fixed.="\\Flagged "; |
---|
| 3956 | if($flags_array[3] != 'U') |
---|
| 3957 | $flags_fixed.="\\Seen "; |
---|
| 3958 | |
---|
| 3959 | imap_setflag_full($mbox_stream, $return['msg_no'], $flags_fixed, ST_UID); |
---|
| 3960 | } |
---|
[1000] | 3961 | if($mbox_stream) |
---|
[3911] | 3962 | imap_close($mbox_stream); |
---|
[1000] | 3963 | return $return; |
---|
| 3964 | } |
---|
| 3965 | |
---|
[3803] | 3966 | function show_decript($params){ |
---|
[1035] | 3967 | $source = $params['source']; |
---|
| 3968 | //error_log("source: $source\nversao: " . PHP_VERSION, 3, '/tmp/teste.log'); |
---|
[3803] | 3969 | $source = str_replace(" ", "+", $source,$i); |
---|
[1472] | 3970 | |
---|
[3803] | 3971 | if (version_compare(PHP_VERSION, '5.2.0', '>=')){ |
---|
| 3972 | if(!$source = base64_decode($source,true)) |
---|
[4022] | 3973 | return "error ".$source."Espaços ".$i; |
---|
[1035] | 3974 | |
---|
| 3975 | } |
---|
[3803] | 3976 | else { |
---|
| 3977 | if(!$source = base64_decode($source)) |
---|
[4022] | 3978 | return "error ".$source."Espaços ".$i; |
---|
[3803] | 3979 | } |
---|
| 3980 | |
---|
[1035] | 3981 | $insert = $this->insert_email($source,'INBOX'.$this->imap_delimiter.'decifradas'); |
---|
| 3982 | |
---|
| 3983 | $get['msg_number'] = $insert['msg_no']; |
---|
| 3984 | $get['msg_folder'] = 'INBOX'.$this->imap_delimiter.'decifradas'; |
---|
| 3985 | $return = $this->get_info_msg($get); |
---|
| 3986 | $get['msg_number'] = $params['ID']; |
---|
| 3987 | $get['msg_folder'] = $params['folder']; |
---|
| 3988 | $tmp = $this->get_info_msg($get); |
---|
| 3989 | if(!$tmp['status_get_msg_info']) |
---|
| 3990 | { |
---|
| 3991 | $return['msg_day']=$tmp['msg_day']; |
---|
| 3992 | $return['msg_hour']=$tmp['msg_hour']; |
---|
| 3993 | $return['fulldate']=$tmp['fulldate']; |
---|
| 3994 | $return['smalldate']=$tmp['smalldate']; |
---|
| 3995 | } |
---|
| 3996 | else |
---|
| 3997 | { |
---|
| 3998 | $return['msg_day']=''; |
---|
| 3999 | $return['msg_hour']=''; |
---|
| 4000 | $return['fulldate']=''; |
---|
| 4001 | $return['smalldate']=''; |
---|
| 4002 | } |
---|
| 4003 | $return['msg_no'] =$insert['msg_no']; |
---|
| 4004 | $return['error'] = $insert['error']; |
---|
| 4005 | $return['folder'] = $params['folder']; |
---|
| 4006 | //$return['acls'] = $insert['acls']; |
---|
| 4007 | $return['original_ID'] = $params['ID']; |
---|
| 4008 | |
---|
| 4009 | return $return; |
---|
| 4010 | |
---|
| 4011 | } |
---|
[1472] | 4012 | |
---|
[1000] | 4013 | //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Trata fontes de emails enviados via POST para o servidor por um xmlhttprequest, as partes codificados com |
---|
[4022] | 4014 | //Base64 os "+" são substituidos por " " no envio e essa função arruma esse efeito. |
---|
[1000] | 4015 | |
---|
| 4016 | function treat_base64_from_post($source){ |
---|
| 4017 | $offset = 0; |
---|
| 4018 | do |
---|
| 4019 | { |
---|
| 4020 | if($inicio = strpos($source, 'Content-Transfer-Encoding: base64', $offset)) |
---|
| 4021 | { |
---|
| 4022 | $inicio = strpos($source, "\n\r", $inicio); |
---|
| 4023 | $fim = strpos($source, '--', $inicio); |
---|
| 4024 | if(!$fim) |
---|
| 4025 | $fim = strpos($source,"\n\r", $inicio); |
---|
| 4026 | $length = $fim-$inicio; |
---|
| 4027 | $parte = substr( $source,$inicio,$length-1); |
---|
| 4028 | $parte = str_replace(" ", "+", $parte); |
---|
| 4029 | $source = substr_replace($source, $parte, $inicio, $length-1); |
---|
| 4030 | } |
---|
| 4031 | if($offset > $inicio) |
---|
| 4032 | $offset=FALSE; |
---|
| 4033 | else |
---|
| 4034 | $offset = $inicio; |
---|
| 4035 | } |
---|
| 4036 | while($offset); |
---|
| 4037 | return $source; |
---|
| 4038 | } |
---|
| 4039 | |
---|
[4022] | 4040 | //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Recebe os fontes dos emails a serem desarquivados, separa e envia cada um para função insert_mail. |
---|
[1000] | 4041 | |
---|
| 4042 | function unarchive_mail($params) |
---|
| 4043 | { |
---|
| 4044 | $dest_folder = $params['folder']; |
---|
| 4045 | $sources = explode("#@#@#@",$params['source']); |
---|
| 4046 | $timestamps = explode("#@#@#@",$params['timestamp']); |
---|
[3911] | 4047 | $flags = explode("#@#@#@",$params['flags']); |
---|
[3872] | 4048 | |
---|
[3843] | 4049 | foreach($sources as $index=>$src) |
---|
| 4050 | { |
---|
| 4051 | if($src!="") |
---|
| 4052 | { |
---|
[3911] | 4053 | $source = $this->treat_base64_from_post($src); |
---|
| 4054 | $insert = $this->insert_email($source,$dest_folder,$timestamps[$index],$flags[$index]); |
---|
| 4055 | } |
---|
| 4056 | } |
---|
[3843] | 4057 | |
---|
[1000] | 4058 | return $insert; |
---|
| 4059 | } |
---|
| 4060 | |
---|
| 4061 | function download_all_local_attachments($params) |
---|
| 4062 | { |
---|
| 4063 | $source = $params['source']; |
---|
| 4064 | $source = $this->treat_base64_from_post($source); |
---|
| 4065 | $insert = $this->insert_email($source,'INBOX'.$this->imap_delimiter.'decifradas'); |
---|
| 4066 | $exporteml = new ExportEml(); |
---|
| 4067 | $params['num_msg']=$insert['msg_no']; |
---|
| 4068 | $params['folder']='INBOX'.$this->imap_delimiter.'decifradas'; |
---|
| 4069 | return $exporteml->download_all_attachments($params); |
---|
| 4070 | } |
---|
[3157] | 4071 | function get_quota_folders(){ |
---|
| 4072 | |
---|
| 4073 | // Additional Imap Class for not-implemented functions into PHP-IMAP extension. |
---|
| 4074 | include_once("class.imapfp.inc.php"); |
---|
| 4075 | $imapfp = new imapfp(); |
---|
| 4076 | |
---|
| 4077 | if(!$imapfp->open($this->imap_server,$this->imap_port)) |
---|
| 4078 | return $imapfp->get_error(); |
---|
| 4079 | if (!$imapfp->login( $this->username,$this->password )) |
---|
| 4080 | return $imapfp->get_error(); |
---|
| 4081 | |
---|
| 4082 | $response_array = $imapfp->get_mailboxes_size(); |
---|
| 4083 | if ($imapfp->error) |
---|
| 4084 | return $imapfp->get_error(); |
---|
| 4085 | |
---|
| 4086 | $data = array(); |
---|
| 4087 | $quota_root = $this->get_quota(array('folder_id' => "INBOX")); |
---|
| 4088 | $data["quota_root"] = $quota_root; |
---|
| 4089 | |
---|
| 4090 | foreach ($response_array as $idx=>$line) { |
---|
| 4091 | $line2 = str_replace('"', "", $line); |
---|
| 4092 | $line2 = str_replace(" /vendor/cmu/cyrus-imapd/size (value.shared ",";",str_replace("* ANNOTATION ","",$line2)); |
---|
| 4093 | list($folder,$size) = explode(";",$line2); |
---|
[3854] | 4094 | $quota_used = str_replace(")","",$size); |
---|
| 4095 | $quotaPercent = (($quota_used / 1024) / $data["quota_root"]["quota_limit"])*100; |
---|
[4587] | 4096 | $folder = mb_convert_encoding($folder, "ISO-8859-1", "UTF7-IMAP"); |
---|
[3157] | 4097 | if(!preg_match('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i',$folder)){ |
---|
| 4098 | $folder = $this->functions->getLang("Inbox"); |
---|
| 4099 | } |
---|
| 4100 | else |
---|
| 4101 | $folder = preg_replace('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i','', $folder); |
---|
| 4102 | |
---|
| 4103 | $data[$folder] = array("quota_percent" => sprintf("%.1f",round($quotaPercent,1)), "quota_used" => $quota_used); |
---|
| 4104 | } |
---|
| 4105 | $imapfp->close(); |
---|
| 4106 | return $data; |
---|
| 4107 | } |
---|
[2] | 4108 | } |
---|
[278] | 4109 | ?> |
---|