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