[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; |
---|
[5134] | 29 | var $rawMessage; |
---|
[2] | 30 | |
---|
| 31 | function imap_functions (){ |
---|
[5134] | 32 | $this->init(); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | function init(){ |
---|
[3226] | 36 | $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] | 37 | $this->username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 38 | $this->password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
| 39 | $this->imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 40 | $this->imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
| 41 | $this->imap_delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter']; |
---|
[1472] | 42 | $this->functions = new functions(); |
---|
[1912] | 43 | $this->imap_sentfolder = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] : str_replace("*","", $this->functions->getLang("Sent")); |
---|
[2] | 44 | $this->has_cid = false; |
---|
[3071] | 45 | $this->prefs = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']; |
---|
[1472] | 46 | |
---|
[3071] | 47 | |
---|
[2] | 48 | if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') |
---|
| 49 | { |
---|
| 50 | $this->imap_options = '/tls/novalidate-cert'; |
---|
| 51 | } |
---|
| 52 | else |
---|
| 53 | { |
---|
| 54 | $this->imap_options = '/notls/novalidate-cert'; |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | // BEGIN of functions. |
---|
[3391] | 58 | function open_mbox($folder = False,$force_die=true) |
---|
[2] | 59 | { |
---|
[5134] | 60 | $folder = mb_convert_encoding($folder, "UTF7-IMAP", mb_detect_encoding($folder.'x', 'UTF-8, ISO-8859-1, UTF7-IMAP')); |
---|
[828] | 61 | if (is_resource($this->mbox)) |
---|
[3394] | 62 | { |
---|
| 63 | if ($force_die) |
---|
| 64 | { |
---|
| 65 | @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())))); |
---|
| 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
| 69 | @imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder); |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | else |
---|
| 73 | { |
---|
| 74 | if($force_die) |
---|
| 75 | { |
---|
| 76 | $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())))); |
---|
| 77 | } |
---|
| 78 | else |
---|
| 79 | { |
---|
| 80 | $this->mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | } |
---|
| 84 | return $this->mbox; |
---|
[2] | 85 | } |
---|
| 86 | |
---|
[5134] | 87 | function parse_error($error, $field = ''){ |
---|
[504] | 88 | // This error is returned from Imap. |
---|
| 89 | if(strstr($error,'Connection refused')) { |
---|
| 90 | return str_replace("%1", $this->functions->getLang("Mail"), $this->functions->getLang("Connection failed with %1 Server. Try later.")); |
---|
| 91 | } |
---|
[5134] | 92 | else if(strstr($error,'virus')) { |
---|
[628] | 93 | return str_replace("%1", $this->functions->getLang("Mail"), $this->functions->getLang("Your message was rejected by antivirus. Perhaps your attachment has been infected.")); |
---|
| 94 | } |
---|
[5134] | 95 | else if(strstr($error,'Failed to add recipient:')) { |
---|
| 96 | preg_match_all('/:\s([\s\.";@!a-z0-9]+)\s\[SMTP:/', $error, $res); |
---|
| 97 | return str_replace("%1", $res['1']['0'], $this->functions->getLang("SMTP Error: The following recipient addresses failed: %1")); |
---|
| 98 | } |
---|
| 99 | else if(strstr($error,'Recipient address rejected')) { |
---|
| 100 | return str_replace("%1", $this->functions->getLang("Mail"), $this->functions->getLang("Invalid recipients in the message").'.'); |
---|
| 101 | } |
---|
| 102 | else if(strstr($error,'Invalid Mail:')) { |
---|
| 103 | return str_replace("%1", $field, $this->functions->getLang("The recipients addresses failed %1")); |
---|
| 104 | } |
---|
| 105 | else if(strstr($error,'Message file too big')) { |
---|
| 106 | return ($this->functions->getLang("Message file too big.")); |
---|
| 107 | } |
---|
[504] | 108 | // This condition verifies if SESSION is expired. |
---|
[4795] | 109 | elseif(!count($_SESSION)) |
---|
[504] | 110 | return "nosession"; |
---|
| 111 | |
---|
| 112 | return $error; |
---|
| 113 | } |
---|
[1472] | 114 | |
---|
[2] | 115 | function get_range_msgs2($params) |
---|
[4025] | 116 | { |
---|
[4044] | 117 | // Free others requests |
---|
| 118 | session_write_close(); |
---|
[4162] | 119 | $folder = $params['folder']; |
---|
| 120 | $msg_range_begin = $params['msg_range_begin']; |
---|
| 121 | $msg_range_end = $params['msg_range_end']; |
---|
[5134] | 122 | $sort_box_type = isset($params['sort_box_type']) ? $params['sort_box_type'] : ''; |
---|
| 123 | $sort_box_reverse = isset($params['sort_box_reverse']) ? $params['sort_box_reverse'] : ''; |
---|
| 124 | $search_box_type = (isset($params['search_box_type']) && $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" )? $params['search_box_type'] : false; |
---|
[1472] | 125 | |
---|
[4044] | 126 | if( !$this->mbox || !is_resource( $this->mbox ) ) |
---|
[3392] | 127 | $this->mbox = $this->open_mbox($folder); |
---|
| 128 | |
---|
[4044] | 129 | $return = array(); |
---|
[4050] | 130 | |
---|
[4169] | 131 | $return['folder'] = $folder; |
---|
| 132 | |
---|
[4044] | 133 | //Para enviar o offset entre o timezone definido pelo usuário e GMT |
---|
| 134 | $return['offsetToGMT'] = $this->functions->CalculateDateOffset(); |
---|
[3392] | 135 | |
---|
[4162] | 136 | if(!$search_box_type || $search_box_type=="UNSEEN" || $search_box_type=="SEEN") { |
---|
| 137 | $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] | 138 | |
---|
| 139 | |
---|
[4162] | 140 | $return['tot_unseen'] = $search_box_type == "SEEN" ? 0 : $msgs_info->unseen; |
---|
[828] | 141 | |
---|
[4162] | 142 | $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); |
---|
[3392] | 143 | |
---|
[4162] | 144 | $num_msgs = ($search_box_type=="UNSEEN") ? $msgs_info->unseen : (($search_box_type=="SEEN") ? ($msgs_info->messages - $msgs_info->unseen) : $msgs_info->messages); |
---|
| 145 | |
---|
[4025] | 146 | $i = 0; |
---|
[4162] | 147 | if(is_array($sort_array_msg)){ |
---|
| 148 | foreach($sort_array_msg as $msg_number => $value) |
---|
| 149 | { |
---|
| 150 | $temp = $this->get_info_head_msg($msg_number); |
---|
[5134] | 151 | $temp['msg_sample'] = $this->get_msg_sample($msg_number,$folder); |
---|
[4162] | 152 | if(!$temp) |
---|
| 153 | return false; |
---|
[4025] | 154 | |
---|
[4162] | 155 | $return[$i] = $temp; |
---|
| 156 | $i++; |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | $return['num_msgs'] = $num_msgs; |
---|
| 160 | } |
---|
| 161 | else { |
---|
| 162 | $num_msgs = imap_num_msg($this->mbox); |
---|
| 163 | $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$num_msgs); |
---|
[828] | 164 | |
---|
[4044] | 165 | |
---|
[4162] | 166 | $return['tot_unseen'] = 0; |
---|
| 167 | $i = 0; |
---|
[4044] | 168 | |
---|
[4162] | 169 | if(is_array($sort_array_msg)){ |
---|
| 170 | |
---|
| 171 | foreach($sort_array_msg as $msg_number => $value) |
---|
| 172 | { |
---|
| 173 | $temp = $this->get_info_head_msg($msg_number); |
---|
| 174 | if(!$temp) |
---|
| 175 | return false; |
---|
| 176 | |
---|
| 177 | if($temp['Unseen'] == 'U' || $temp['Recent'] == 'N'){ |
---|
| 178 | $return['tot_unseen']++; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | if($i <= ($msg_range_end-$msg_range_begin)) |
---|
| 182 | $return[$i] = $temp; |
---|
| 183 | $i++; |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | $return['num_msgs'] = count($sort_array_msg)+($msg_range_begin-1); |
---|
| 187 | } |
---|
| 188 | return $return; |
---|
[4044] | 189 | } |
---|
| 190 | |
---|
| 191 | function get_info_head_msg($msg_number) |
---|
| 192 | { |
---|
[689] | 193 | $head_array = array(); |
---|
| 194 | include_once("class.imap_attachment.inc.php"); |
---|
[828] | 195 | |
---|
[3271] | 196 | $imap_attachment = new imap_attachment(); |
---|
| 197 | //if ($this->prefs['use_important_flag'] ) |
---|
| 198 | //{ |
---|
[3071] | 199 | /*Como eu preciso do atributo Importance para saber se o email é |
---|
| 200 | * importante ou não, uso abaixo a função imap_fetchheader e busco |
---|
| 201 | * o atributo importance nela. Isso faz com que eu acesse o cabeçalho |
---|
| 202 | * duas vezes e de duas formas diferentes, mas em contrapartida, eu |
---|
| 203 | * não preciso reimplementar o método utilizando o fetchheader. |
---|
| 204 | * Como as mensagens são renderizadas em um número pequeno por vez, |
---|
| 205 | * não parece ter perda considerável de performance. |
---|
| 206 | */ |
---|
[830] | 207 | |
---|
[3071] | 208 | $tempHeader = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); |
---|
| 209 | $flag = preg_match('/importance *: *(.*)\r/i', $tempHeader, $importance); |
---|
[3271] | 210 | //} |
---|
| 211 | // Reimplementado código para identificação dos e-mails assinados e cifrados |
---|
| 212 | // no método getMessageType(). Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
| 213 | $head_array['ContentType'] = $this->getMessageType($msg_number, $tempHeader); |
---|
| 214 | $head_array['Importance'] = $flag==0?"Normal":$importance[1]; |
---|
[1174] | 215 | |
---|
[689] | 216 | $header = $this->get_header($msg_number); |
---|
[828] | 217 | if (!is_object($header)) |
---|
| 218 | return false; |
---|
[689] | 219 | $head_array['Recent'] = $header->Recent; |
---|
| 220 | $head_array['Unseen'] = $header->Unseen; |
---|
| 221 | if($header->Answered =='A' && $header->Draft == 'X'){ |
---|
| 222 | $head_array['Forwarded'] = 'F'; |
---|
[2] | 223 | } |
---|
[689] | 224 | else { |
---|
| 225 | $head_array['Answered'] = $header->Answered; |
---|
[828] | 226 | $head_array['Draft'] = $header->Draft; |
---|
[46] | 227 | } |
---|
[689] | 228 | $head_array['Deleted'] = $header->Deleted; |
---|
| 229 | $head_array['Flagged'] = $header->Flagged; |
---|
| 230 | $head_array['msg_number'] = $msg_number; |
---|
[3057] | 231 | $head_array['udate'] = $header->udate; |
---|
[3923] | 232 | $head_array['offsetToGMT'] = $this->functions->CalculateDateOffset(); |
---|
[828] | 233 | |
---|
[3923] | 234 | $msgTimestamp = $header->udate + $head_array['offsetToGMT']; |
---|
| 235 | $head_array['timestamp'] = $msgTimestamp; |
---|
| 236 | |
---|
[3499] | 237 | $date_msg = gmdate("d/m/Y",$msgTimestamp); |
---|
| 238 | // if (date("d/m/Y") == $date_msg) |
---|
| 239 | // $return['udate'] = $header->udate; |
---|
| 240 | // else |
---|
| 241 | |
---|
| 242 | if (date("d/m/Y") == $date_msg) //no dia |
---|
| 243 | { |
---|
| 244 | $head_array['smalldate'] = gmdate("H:i",$msgTimestamp); |
---|
| 245 | } |
---|
| 246 | else |
---|
| 247 | { |
---|
| 248 | $head_array['smalldate'] = gmdate("d/m/Y",$msgTimestamp); |
---|
| 249 | } |
---|
| 250 | |
---|
[5134] | 251 | if(isset($header->from)) |
---|
[689] | 252 | $from = $header->from; |
---|
| 253 | $head_array['from'] = array(); |
---|
[1740] | 254 | $head_array['from']['name'] = ( isset( $from[0]->personal ) ) ? $this->decode_string($from[0]->personal) : NULL; |
---|
[5134] | 255 | if(isset($from)) |
---|
[689] | 256 | $head_array['from']['email'] = $this->decode_string($from[0]->mailbox) . "@" . $from[0]->host; |
---|
[5134] | 257 | else |
---|
| 258 | $head_array['from']['email'] = $this->decode_string($from[0]->mailbox) . "@"; |
---|
| 259 | if(!$head_array['from']['name'] || trim($head_array['from']['name']) === '' ) |
---|
[689] | 260 | $head_array['from']['name'] = $head_array['from']['email']; |
---|
[5134] | 261 | if(isset($header->to)) |
---|
[689] | 262 | $to = $header->to; |
---|
| 263 | $head_array['to'] = array(); |
---|
[5134] | 264 | if(isset($to[1]) && $to[1]->host == ".SYNTAX-ERROR.") { //E-mails que não possuem o campo "para", vêm com o recipiente preenchido, porém com um recipiente a mais alegando erro de sintaxe. |
---|
[3831] | 265 | $head_array['to']['name'] = $head_array['to']['email'] = NULL; |
---|
| 266 | } |
---|
| 267 | else { |
---|
| 268 | $tmp = ( isset( $to[0]->personal ) ) ? imap_mime_header_decode($to[0]->personal) : NULL; |
---|
| 269 | $head_array['to']['name'] = ( isset( $tmp[0]->text ) ) ? $this->decode_string($this->decode_string($tmp[0]->text)) : NULL; |
---|
| 270 | $head_array['to']['email'] = ( isset( $to[0]->mailbox ) ) ? ( $this->decode_string($to[0]->mailbox) . "@" . ( ( isset( $to[0]->host ) ) ? $to[0]->host : '' ) ) : NULL; |
---|
| 271 | if(!$head_array['to']['name']) |
---|
| 272 | $head_array['to']['name'] = $head_array['to']['email']; |
---|
| 273 | } |
---|
[5134] | 274 | $cc = null; |
---|
| 275 | $cco = null; |
---|
| 276 | if(isset($header->cc)){ |
---|
[3777] | 277 | $cc = $header->cc; |
---|
[5134] | 278 | } |
---|
| 279 | if(isset($header->bcc)){ |
---|
[3831] | 280 | $cco = $header->bcc; |
---|
[5134] | 281 | } |
---|
[3777] | 282 | if ( ($cc) && (!$head_array['to']['name']) ){ |
---|
| 283 | $head_array['to']['name'] = ( isset( $cc[0]->personal ) ) ? $this->decode_string($cc[0]->personal) : NULL; |
---|
| 284 | $head_array['to']['email'] = $this->decode_string($cc[0]->mailbox) . "@" . $cc[0]->host; |
---|
[5134] | 285 | if(!$head_array['to']['name']){ |
---|
| 286 | $head_array['to']['name'] = $head_array['from']['name']; |
---|
| 287 | //$head_array['to']['email'] = $head_array['from']['email']; |
---|
| 288 | } |
---|
[3777] | 289 | } |
---|
[3831] | 290 | else if ( ($cco) && (!$head_array['to']['name']) ){ |
---|
| 291 | $head_array['to']['name'] = ( isset( $cco[0]->personal ) ) ? $this->decode_string($cco[0]->personal) : NULL; |
---|
| 292 | $head_array['to']['email'] = $this->decode_string($cco[0]->mailbox) . "@" . $cco[0]->host; |
---|
| 293 | if(!$head_array['to']['name']) |
---|
[5134] | 294 | $head_array['to']['name'] = $head_array['from']['name']; |
---|
[3831] | 295 | } |
---|
[1751] | 296 | $head_array['subject'] = ( isset( $header->fetchsubject ) ) ? $this->decode_string($header->fetchsubject) : ''; |
---|
[5134] | 297 | if($head_array['subject'] == "" || $head_array['subject'] == '' || $head_array['subject'] == null ){ |
---|
| 298 | $head_array['subject'] = $this->functions->getLang("(no subject) "); |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | if($head_array['to']['name'] == 'undisclosed-recipients@' || $head_array['to']['name'] == '@'){ |
---|
| 302 | $head_array['to']['name'] = $head_array['from']['name']; |
---|
| 303 | $head_array['to']['email'] = $head_array['from']['email']; |
---|
| 304 | } |
---|
[828] | 305 | |
---|
[689] | 306 | $head_array['Size'] = $header->Size; |
---|
[828] | 307 | |
---|
[689] | 308 | $head_array['attachment'] = array(); |
---|
| 309 | $head_array['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); |
---|
[828] | 310 | |
---|
[689] | 311 | return $head_array; |
---|
[2] | 312 | } |
---|
[828] | 313 | |
---|
[4416] | 314 | /** |
---|
[5079] | 315 | * |
---|
[4416] | 316 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
[5134] | 317 | * @param string $string String a ser decodificada |
---|
| 318 | * @return string |
---|
[4416] | 319 | * @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 |
---|
| 320 | * @todo Executar testes suficientes para validar a funçao iconv_mime_decode em substituição à este método decode_string |
---|
| 321 | */ |
---|
[2] | 322 | function decode_string($string) |
---|
[4795] | 323 | { |
---|
[5134] | 324 | $return = ''; |
---|
| 325 | $decoded = ''; |
---|
[4795] | 326 | if ((strpos(strtolower($string), '=?iso-8859-1') !== false) || (strpos(strtolower($string), '=?windows-1252') !== false)) |
---|
| 327 | { |
---|
| 328 | $tmp = imap_mime_header_decode($string); |
---|
| 329 | foreach ($tmp as $tmp1) |
---|
[4416] | 330 | { |
---|
[4795] | 331 | $return .= $this->htmlspecialchars_encode($tmp1->text); |
---|
[4416] | 332 | } |
---|
[4795] | 333 | |
---|
[4416] | 334 | return str_replace("\t", "", $return); |
---|
[4795] | 335 | } |
---|
| 336 | else if (strpos(strtolower($string), '=?utf-8') !== false) |
---|
| 337 | { |
---|
| 338 | $elements = imap_mime_header_decode($string); |
---|
[1472] | 339 | |
---|
[4795] | 340 | for($i = 0;$i < count($elements);$i++) |
---|
| 341 | { |
---|
| 342 | $charset = strtolower($elements[$i]->charset); |
---|
| 343 | $text = $elements[$i]->text; |
---|
| 344 | if(!strcasecmp($charset, "utf-8") || !strcasecmp($charset, "utf-7")) |
---|
| 345 | $decoded .= $this->functions->utf8_to_ncr($text); |
---|
| 346 | else |
---|
| 347 | { |
---|
| 348 | if( strcasecmp($charset,"default") ) |
---|
| 349 | $decoded .= $this->htmlspecialchars_encode(iconv($charset, "iso-8859-1", $text)); |
---|
| 350 | else |
---|
| 351 | $decoded .= $this->htmlspecialchars_encode($text); |
---|
| 352 | } |
---|
| 353 | } |
---|
[1401] | 354 | |
---|
[4416] | 355 | return str_replace("\t", "", $decoded); |
---|
[4795] | 356 | } |
---|
[4773] | 357 | else if(strpos(strtolower($string), '=?us-ascii') !== false) |
---|
| 358 | { |
---|
| 359 | $retun = ''; |
---|
| 360 | $tmp = imap_mime_header_decode($string); |
---|
| 361 | foreach ($tmp as $tmp1) |
---|
| 362 | $return .= $this->htmlspecialchars_encode(quoted_printable_decode($tmp1->text)); |
---|
| 363 | |
---|
| 364 | return str_replace("\t", "", $return); |
---|
| 365 | |
---|
| 366 | } |
---|
[5134] | 367 | else if( strpos( $string , '=?' ) !== false ) |
---|
| 368 | return $this->htmlspecialchars_encode(iconv_mime_decode( $string )); |
---|
[4773] | 369 | |
---|
[1401] | 370 | |
---|
[4795] | 371 | return $this->htmlspecialchars_encode($string); |
---|
| 372 | } |
---|
[5079] | 373 | |
---|
| 374 | |
---|
[615] | 375 | /** |
---|
| 376 | * Função que importa arquivos .eml exportados pelo expresso para a caixa do usuário. Testado apenas |
---|
| 377 | * com .emls gerados pelo expresso, e o arquivo pode ser um zip contendo vários emls ou um .eml. |
---|
| 378 | */ |
---|
[660] | 379 | function import_msgs($params) { |
---|
[1000] | 380 | if(!$this->mbox) |
---|
[660] | 381 | $this->mbox = $this->open_mbox(); |
---|
[1472] | 382 | |
---|
[1365] | 383 | if( preg_match('/local_/',$params["folder"]) ) |
---|
[1000] | 384 | { |
---|
[1366] | 385 | // PLEASE, BE CAREFULL!!! YOU SHOULD USE EMAIL CONFIGURATION VALUES (EMAILADMIN MODULE) |
---|
[1367] | 386 | $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] | 387 | if ( ! imap_createmailbox( $this -> mbox,"{".$this -> imap_server."}$tmp_box" ) ) |
---|
| 388 | return $this->functions->getLang( 'Import to Local : fail...' ); |
---|
| 389 | imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$tmp_box); |
---|
| 390 | $params["folder"] = $tmp_box; |
---|
| 391 | } |
---|
[615] | 392 | $errors = array(); |
---|
| 393 | $invalid_format = false; |
---|
[1472] | 394 | $filename = $params['FILES'][0]['name']; |
---|
[1365] | 395 | $params["folder"] = mb_convert_encoding($params["folder"], "UTF7-IMAP","ISO_8859-1"); |
---|
[660] | 396 | $quota = imap_get_quotaroot($this->mbox, $params["folder"]); |
---|
| 397 | if((($quota['limit'] - $quota['usage'])*1024) <= $params['FILES'][0]['size']){ |
---|
| 398 | return array( 'error' => $this->functions->getLang("fail in import:"). |
---|
[1000] | 399 | " ".$this->functions->getLang("Over quota")); |
---|
[660] | 400 | } |
---|
[615] | 401 | if(substr($filename,strlen($filename)-4)==".zip") { |
---|
[660] | 402 | $zip = zip_open($params['FILES'][0]['tmp_name']); |
---|
[615] | 403 | |
---|
| 404 | if ($zip) { |
---|
| 405 | while ($zip_entry = zip_read($zip)) { |
---|
[1000] | 406 | |
---|
[615] | 407 | if (zip_entry_open($zip, $zip_entry, "r")) { |
---|
| 408 | $email = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); |
---|
| 409 | $status = @imap_append($this->mbox, |
---|
[660] | 410 | "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], |
---|
[615] | 411 | $email |
---|
| 412 | ); |
---|
| 413 | if(!$status) |
---|
| 414 | array_push($errors,zip_entry_name($zip_entry)); |
---|
| 415 | zip_entry_close($zip_entry); |
---|
| 416 | } |
---|
| 417 | } |
---|
[660] | 418 | zip_close($zip); |
---|
[615] | 419 | } |
---|
[1000] | 420 | |
---|
| 421 | if ( isset( $tmp_box ) && ! sizeof( $errors ) ) |
---|
| 422 | { |
---|
| 423 | |
---|
| 424 | $mc = imap_check($this->mbox); |
---|
| 425 | |
---|
| 426 | $result = imap_fetch_overview( $this -> mbox, "1:{$mc -> Nmsgs}", 0 ); |
---|
| 427 | |
---|
| 428 | $ids = array( ); |
---|
| 429 | foreach ($result as $overview) |
---|
| 430 | $ids[ ] = $overview -> uid; |
---|
| 431 | |
---|
| 432 | return implode( ',', $ids ); |
---|
[830] | 433 | } |
---|
[1000] | 434 | } |
---|
[615] | 435 | else if(substr($filename,strlen($filename)-4)==".eml") { |
---|
[660] | 436 | $email = implode("",file($params['FILES'][0]['tmp_name'])); |
---|
[615] | 437 | $status = @imap_append($this->mbox, |
---|
[660] | 438 | "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], |
---|
[615] | 439 | $email |
---|
| 440 | ); |
---|
[5134] | 441 | if(!$status) { |
---|
| 442 | //TODO: remover zip_entry pois ele é tratado apenas ao importar mensagens zipadas |
---|
[615] | 443 | array_push($errors,zip_entry_name($zip_entry)); |
---|
[660] | 444 | zip_entry_close($zip_entry); |
---|
| 445 | } |
---|
[5134] | 446 | |
---|
| 447 | if ( isset( $tmp_box ) && ! sizeof( $errors ) ) { |
---|
| 448 | $mc = imap_check($this->mbox); |
---|
| 449 | |
---|
| 450 | $result = imap_fetch_overview( $this -> mbox, "1:{$mc -> Nmsgs}", 0 ); |
---|
| 451 | |
---|
| 452 | $ids = array( ); |
---|
| 453 | foreach ($result as $overview) |
---|
| 454 | $ids[ ] = $overview -> uid; |
---|
| 455 | |
---|
| 456 | return implode( ',', $ids ); |
---|
| 457 | } |
---|
[615] | 458 | } |
---|
[1000] | 459 | else |
---|
[615] | 460 | { |
---|
[1000] | 461 | if ( isset( $tmp_box ) ) |
---|
| 462 | imap_deletemailbox( $this->mbox,"{".$this -> imap_server."}$tmp_box" ); |
---|
| 463 | |
---|
[660] | 464 | return array("error" => $this->functions->getLang("wrong file format")); |
---|
[615] | 465 | $invalid_format = true; |
---|
| 466 | } |
---|
[1000] | 467 | |
---|
[615] | 468 | if(!$invalid_format) { |
---|
| 469 | if(count($errors)>0) { |
---|
[660] | 470 | $message = $this->functions->getLang("fail in import:")."\n"; |
---|
[615] | 471 | foreach($errors as $arquivo) { |
---|
| 472 | $message.=$arquivo."\n"; |
---|
| 473 | } |
---|
[660] | 474 | return array("error" => $message); |
---|
[615] | 475 | } |
---|
| 476 | else |
---|
[3843] | 477 | return $this->functions->getLang("The import was executed successfully."); |
---|
[615] | 478 | } |
---|
[1000] | 479 | } |
---|
| 480 | /* |
---|
[613] | 481 | Remove os anexos de uma mensagem. A estratégia para isso é criar uma mensagem nova sem os anexos, mantendo apenas |
---|
| 482 | a primeira parte do e-mail, que é o texto, sem anexos. |
---|
| 483 | O método considera que o email é multpart. |
---|
| 484 | */ |
---|
| 485 | function remove_attachments($params) { |
---|
| 486 | include_once("class.message_components.inc.php"); |
---|
| 487 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 488 | $this->mbox = $this->open_mbox($params["folder"]); |
---|
| 489 | $return["status"] = true; |
---|
| 490 | $header = ""; |
---|
[1472] | 491 | |
---|
[613] | 492 | $headertemp = explode("\n",imap_fetchheader($this->mbox, imap_msgno($this->mbox, $params["msg_num"]))); |
---|
| 493 | foreach($headertemp as $head) {//Se eu colocar todo o header do email dá pau no append, então procuro apenas o que interessa. |
---|
| 494 | $head1 = explode(":",$head); |
---|
[1472] | 495 | if ( (strtoupper($head1[0]) == "TO") || |
---|
[3566] | 496 | (strtoupper($head1[0]) == "FROM") || |
---|
| 497 | (strtoupper($head1[0]) == "SUBJECT") || |
---|
| 498 | (strtoupper($head1[0]) == "DATE") ) |
---|
| 499 | $header .= $head."\r\n"; |
---|
[613] | 500 | } |
---|
[1472] | 501 | |
---|
[5134] | 502 | $msg = new message_components($this->mbox); |
---|
[1472] | 503 | $msg->fetch_structure($params["msg_num"]);/* O fetchbody tava trazendo o email com problemas na acentuação. |
---|
| 504 | Então uso essa classe para verificar a codificação e o charset, |
---|
[613] | 505 | para que o método decodeBody do expresso possa trazer tudo certinho*/ |
---|
[1472] | 506 | |
---|
[3566] | 507 | $all_body_type = strtolower($msg->file_type[$params["msg_num"]][0]); |
---|
| 508 | $all_body_encoding = $msg->encoding[$params["msg_num"]][0]; |
---|
| 509 | $all_body_charset = $msg->charset[$params["msg_num"]][0]; |
---|
| 510 | |
---|
| 511 | if($all_body_type=='multipart/alternative') { |
---|
| 512 | if(strtolower($msg->file_type[$params["msg_num"]][2]=='text/html') && |
---|
| 513 | $msg->pid[$params["msg_num"]][2] == '1.2') { |
---|
| 514 | $body_part_to_show = '1.2'; |
---|
| 515 | $all_body_type = strtolower($msg->file_type[$params["msg_num"]][2]); |
---|
| 516 | $all_body_encoding = $msg->encoding[$params["msg_num"]][2]; |
---|
| 517 | $all_body_charset = $msg->charset[$params["msg_num"]][2]; |
---|
| 518 | } |
---|
| 519 | else { |
---|
| 520 | $body_part_to_show = '1.1'; |
---|
| 521 | $all_body_type = strtolower($msg->file_type[$params["msg_num"]][1]); |
---|
| 522 | $all_body_encoding = $msg->encoding[$params["msg_num"]][1]; |
---|
| 523 | $all_body_charset = $msg->charset[$params["msg_num"]][1]; |
---|
| 524 | } |
---|
| 525 | } |
---|
| 526 | else |
---|
| 527 | $body_part_to_show = '1'; |
---|
| 528 | |
---|
[1319] | 529 | $status = imap_append($this->mbox, |
---|
[613] | 530 | "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], |
---|
| 531 | $header. |
---|
[3566] | 532 | "Content-Type: ".$all_body_type."; charset = \"".$all_body_charset."\"". |
---|
[613] | 533 | "\r\n". |
---|
[3566] | 534 | "Content-Transfer-Encoding: ".$all_body_encoding. |
---|
| 535 | "\r\n". |
---|
| 536 | "\r\n". |
---|
[5134] | 537 | str_replace("\n","\r\n",preg_replace("/<img[^>]+\>/i", " ", $this->decodeBody( |
---|
[3566] | 538 | imap_fetchbody($this->mbox,imap_msgno($this->mbox, $params["msg_num"]),$body_part_to_show), |
---|
| 539 | $all_body_encoding, $all_body_charset |
---|
[5134] | 540 | )) |
---|
| 541 | ), "\\Seen"); //Append do novo email, só com header e conteúdo sem anexos. //Remove imagens do corpo, pois estas estão na lista de anexo e serão removidas. |
---|
[1472] | 542 | |
---|
[1319] | 543 | if(!$status) |
---|
| 544 | { |
---|
[613] | 545 | $return["status"] = false; |
---|
| 546 | $return["msg"] = lang("error appending mail on delete attachments"); |
---|
| 547 | } |
---|
[1319] | 548 | else |
---|
| 549 | { |
---|
| 550 | $status = imap_status($this->mbox, "{".$this->imap_server.":".$this->imap_port."}".$params['folder'], SA_UIDNEXT); |
---|
[1472] | 551 | $return['msg_no'] = $status->uidnext - 1; |
---|
[1319] | 552 | imap_delete($this->mbox, imap_msgno($this->mbox, $params["msg_num"])); |
---|
| 553 | imap_expunge($this->mbox); |
---|
| 554 | } |
---|
[1472] | 555 | |
---|
[613] | 556 | return $return; |
---|
[1472] | 557 | |
---|
[613] | 558 | } |
---|
[1518] | 559 | |
---|
| 560 | function msgs_to_archive($params) { |
---|
| 561 | |
---|
| 562 | $folder = $params['folder']; |
---|
[1931] | 563 | $all_ids = $this-> get_msgs($folder, 'SORTARRIVAL', false, 0,-1,-1); |
---|
[613] | 564 | |
---|
[1518] | 565 | $messages_not_to_copy = explode(",",$params['mails']); |
---|
| 566 | $ids = array(); |
---|
| 567 | |
---|
[1931] | 568 | $cont = 0; |
---|
| 569 | |
---|
[1518] | 570 | foreach($all_ids as $each_id=>$value) { |
---|
[1931] | 571 | if(!in_array($each_id,$messages_not_to_copy)) { |
---|
[1518] | 572 | array_push($ids,$each_id); |
---|
[1931] | 573 | $cont++; |
---|
| 574 | } |
---|
| 575 | if($cont>=100) |
---|
| 576 | break; |
---|
[1518] | 577 | } |
---|
| 578 | |
---|
| 579 | if (empty($ids)) |
---|
| 580 | return array(); |
---|
| 581 | |
---|
| 582 | $params = array("folder"=>$folder,"msgs_number"=>implode(",",$ids)); |
---|
| 583 | |
---|
| 584 | |
---|
| 585 | return $this->get_info_msgs($params); |
---|
| 586 | |
---|
| 587 | |
---|
| 588 | } |
---|
| 589 | |
---|
[689] | 590 | /** |
---|
[1472] | 591 | * |
---|
| 592 | * @return |
---|
[689] | 593 | * @param $params Object |
---|
| 594 | */ |
---|
| 595 | function get_info_msgs($params) { |
---|
| 596 | include_once("class.exporteml.inc.php"); |
---|
| 597 | $return = array(); |
---|
| 598 | $new_params = array(); |
---|
| 599 | $attach_params = array(); |
---|
| 600 | $new_params["msg_folder"]=$params["folder"]; |
---|
| 601 | $attach_params["folder"] = $params["folder"]; |
---|
| 602 | $msgs = explode(",",$params["msgs_number"]); |
---|
| 603 | $exporteml = new ExportEml(); |
---|
[1382] | 604 | $unseen_msgs = array(); |
---|
[689] | 605 | foreach($msgs as $msg_number) { |
---|
| 606 | $new_params["msg_number"] = $msg_number; |
---|
| 607 | //ini_set("display_errors","1"); |
---|
| 608 | $msg_info = $this->get_info_msg($new_params); |
---|
| 609 | |
---|
| 610 | $this->mbox = $this->open_mbox($params['folder']); //Não sei porque, mas se não abrir de novo a caixa dá erro. |
---|
| 611 | $msg_info['header'] = $this->get_info_head_msg($msg_number); |
---|
| 612 | |
---|
| 613 | $attach_params["num_msg"] = $msg_number; |
---|
| 614 | $msg_info['array_attach'] = $exporteml->get_attachments_in_array($attach_params); |
---|
| 615 | imap_close($this->mbox); |
---|
| 616 | $this->mbox=false; |
---|
| 617 | array_push($return,serialize($msg_info)); |
---|
[1472] | 618 | |
---|
[1388] | 619 | if($msg_info['Unseen'] == "U" || $msg_info['Recent'] == "N"){ |
---|
[1472] | 620 | array_push($unseen_msgs,$msg_number); |
---|
| 621 | } |
---|
| 622 | } |
---|
[1382] | 623 | if($unseen_msgs){ |
---|
| 624 | $msgs_list = implode(",",$unseen_msgs); |
---|
| 625 | $array_msgs = array('folder' => $new_params["msg_folder"], "msgs_to_set" => $msgs_list, "flag" => "unseen"); |
---|
[1472] | 626 | $this->set_messages_flag($array_msgs); |
---|
[689] | 627 | } |
---|
[1472] | 628 | |
---|
[689] | 629 | return $return; |
---|
| 630 | } |
---|
[4795] | 631 | |
---|
[4436] | 632 | /** |
---|
[5079] | 633 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 634 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 635 | * @param $msg_number numero da mensagem |
---|
[4436] | 636 | */ |
---|
[4416] | 637 | function getRawHeader($msg_number) |
---|
| 638 | { |
---|
| 639 | return imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
| 640 | } |
---|
| 641 | |
---|
[4436] | 642 | /** |
---|
[5079] | 643 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 644 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 645 | * @param $msg_number numero da mensagem |
---|
[4436] | 646 | */ |
---|
[4416] | 647 | function getRawBody($msg_number) |
---|
| 648 | { |
---|
| 649 | return imap_body($this->mbox, $msg_number, FT_UID); |
---|
| 650 | } |
---|
[689] | 651 | |
---|
[4436] | 652 | |
---|
| 653 | /** |
---|
[5079] | 654 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 655 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 656 | * @param $msg mensagem |
---|
[4436] | 657 | */ |
---|
[4416] | 658 | function builderMsgHeader($msg) |
---|
| 659 | { |
---|
| 660 | |
---|
| 661 | |
---|
| 662 | $fromMail = str_replace('<','', str_replace('>','',$msg->headers['from'])); |
---|
| 663 | $tosMails = str_replace('<','', str_replace('>','',$msg->headers['to'])); |
---|
| 664 | |
---|
| 665 | $tos = explode(',',$tosMails); |
---|
| 666 | $to = ''; |
---|
| 667 | foreach ($tos as $value) |
---|
| 668 | { |
---|
| 669 | $to .= '<a href="mailto:'.str_replace(' ','',$value).'">'.$value.'</a>, '; |
---|
| 670 | } |
---|
| 671 | |
---|
| 672 | $header = ' |
---|
| 673 | <table style="margin: 2px; border: 1px solid black; background: none repeat scroll 0% 0% rgb(234, 234, 234);"> |
---|
| 674 | <tbody> |
---|
| 675 | <tr><td><b>'.$this->functions->getLang('Subject').':</b></td><td>'.$msg->headers['subject'].'</td></tr> |
---|
| 676 | <tr><td><b>'.$this->functions->getLang('From').':</b></td><td><a href="mailto:'.$fromMail.'">'.$fromMail.'</a></td></tr> |
---|
| 677 | <tr><td><b>'.$this->functions->getLang('Date').':</b></td><td>'.$msg->headers['date'].'</td></tr> |
---|
| 678 | <tr><td><b>'.$this->functions->getLang('To').':</b></td><td>'.$to.'</td></tr> |
---|
| 679 | </tbody> |
---|
| 680 | </table> |
---|
| 681 | <br />' |
---|
| 682 | ; |
---|
| 683 | |
---|
| 684 | return $header; |
---|
| 685 | } |
---|
| 686 | |
---|
[5079] | 687 | /** |
---|
[5134] | 688 | * Constroe o corpo da msg direto na variavel de conteudo |
---|
| 689 | * @param Mail_mimeDecode $structure |
---|
| 690 | * @param <type> $content Ponteiro para Variavel de conteudo da msg |
---|
[5079] | 691 | */ |
---|
[4416] | 692 | function builderMsgBody($structure , &$content , $printHeader = false) |
---|
| 693 | { |
---|
| 694 | if(strtolower($structure->ctype_primary) == 'multipart' && strtolower($structure->ctype_secondary) == 'alternative') |
---|
| 695 | { |
---|
| 696 | $numParts = count($structure->parts) - 1; |
---|
| 697 | |
---|
| 698 | for($i = $numParts; $i >= 0; $i--) |
---|
| 699 | { |
---|
| 700 | $part = $structure->parts[$i]; |
---|
| 701 | |
---|
| 702 | switch (strtolower($part->ctype_primary)) |
---|
| 703 | { |
---|
| 704 | case 'text': |
---|
[5134] | 705 | $disposition = isset($part->disposition) ? strtolower($part->disposition) : ''; |
---|
[4416] | 706 | if($disposition != 'attachment') |
---|
| 707 | { |
---|
| 708 | if(strtolower($part->ctype_secondary) == 'html') |
---|
| 709 | { |
---|
| 710 | if($printHeader) |
---|
| 711 | $content .= $this->builderMsgHeader($part); |
---|
| 712 | |
---|
| 713 | $content .= $this->decodeMailPart($part->body,$part->ctype_parameters['charset']); |
---|
| 714 | } |
---|
| 715 | |
---|
| 716 | if(strtolower($part->ctype_secondary) == 'plain' ) |
---|
| 717 | { |
---|
| 718 | if($printHeader) |
---|
| 719 | $content .= $this->builderMsgHeader($part); |
---|
| 720 | |
---|
[4781] | 721 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body,$part->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 722 | } |
---|
[5134] | 723 | if(strtolower($part->ctype_secondary) == 'calendar') |
---|
| 724 | $content.= $this->builderMsgCalendar($this->decodeMailPart($part->body, $part->ctype_parameters['charset'])); |
---|
[4416] | 725 | |
---|
| 726 | } |
---|
| 727 | |
---|
| 728 | $i = -1; |
---|
| 729 | break; |
---|
| 730 | |
---|
| 731 | case 'multipart': |
---|
| 732 | |
---|
| 733 | if($printHeader) |
---|
| 734 | $content .= $this->builderMsgHeader($part); |
---|
| 735 | |
---|
| 736 | $this->builderMsgBody($part,$content); |
---|
| 737 | |
---|
| 738 | $i = -1; |
---|
| 739 | break; |
---|
| 740 | |
---|
| 741 | case 'message': |
---|
| 742 | |
---|
| 743 | if(!is_array($part->parts)) |
---|
| 744 | { |
---|
| 745 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4781] | 746 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body, $structure->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 747 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
| 748 | } |
---|
| 749 | else |
---|
| 750 | $this->builderMsgBody($part,$content,true); |
---|
| 751 | |
---|
| 752 | $i = -1; |
---|
| 753 | break; |
---|
| 754 | } |
---|
| 755 | } |
---|
| 756 | } |
---|
| 757 | else |
---|
| 758 | { |
---|
| 759 | foreach ($structure->parts as $index => $part) |
---|
| 760 | { |
---|
| 761 | switch (strtolower($part->ctype_primary)) |
---|
| 762 | { |
---|
| 763 | case 'text': |
---|
[5134] | 764 | $disposition = ''; |
---|
| 765 | if(isset($part->disposition)) |
---|
| 766 | $disposition = isset($part->disposition) ? strtolower($part->disposition) : ''; |
---|
[4416] | 767 | if($disposition != 'attachment') |
---|
| 768 | { |
---|
| 769 | if(strtolower($part->ctype_secondary) == 'html') |
---|
| 770 | { |
---|
| 771 | if($printHeader) |
---|
| 772 | $content .= $this->builderMsgHeader($part); |
---|
| 773 | |
---|
| 774 | $content .= $this->decodeMailPart($part->body,$part->ctype_parameters['charset']); |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | if(strtolower($part->ctype_secondary) == 'plain') |
---|
| 778 | { |
---|
| 779 | if($printHeader) |
---|
| 780 | $content .= $this->builderMsgHeader($part); |
---|
| 781 | |
---|
[4781] | 782 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body,$part->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 783 | } |
---|
[5134] | 784 | if(strtolower($part->ctype_secondary) == 'calendar') |
---|
| 785 | $content .= $this->builderMsgCalendar($part->body); |
---|
[4416] | 786 | |
---|
| 787 | } |
---|
| 788 | break; |
---|
| 789 | case 'multipart': |
---|
| 790 | |
---|
| 791 | if($printHeader) |
---|
| 792 | $content .= $this->builderMsgHeader($part); |
---|
| 793 | |
---|
| 794 | $this->builderMsgBody($part,$content); |
---|
| 795 | |
---|
| 796 | break; |
---|
| 797 | case 'message': |
---|
[5134] | 798 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['nested_messages_are_shown'] != '1') |
---|
| 799 | { |
---|
[4416] | 800 | if(!is_array($part->parts)) |
---|
| 801 | { |
---|
| 802 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4781] | 803 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body, $structure->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 804 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
| 805 | } |
---|
| 806 | else |
---|
| 807 | $this->builderMsgBody($part,$content,true); |
---|
| 808 | break; |
---|
| 809 | } |
---|
| 810 | } |
---|
| 811 | } |
---|
| 812 | } |
---|
[5134] | 813 | } |
---|
[4416] | 814 | |
---|
| 815 | |
---|
[4436] | 816 | /** |
---|
[5079] | 817 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 818 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 819 | * @param $msg_number numero da mensagem |
---|
[4436] | 820 | */ |
---|
| 821 | function get_msg_sample($msg_number) |
---|
[4416] | 822 | { |
---|
[5134] | 823 | $content = ''; |
---|
[4416] | 824 | |
---|
| 825 | $return = ""; |
---|
| 826 | if( (!isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] != "1")) && |
---|
| 827 | (!isset($this->prefs['preview_msg_tip'] ) || ($this->prefs['preview_msg_tip'] != "1")) ) |
---|
| 828 | { |
---|
| 829 | $return['body'] = ""; |
---|
| 830 | return $return; |
---|
| 831 | } |
---|
| 832 | |
---|
| 833 | include_once("class.message_components.inc.php"); |
---|
[5134] | 834 | $msg = new message_components($this->mbox); |
---|
[4416] | 835 | $msg->fetch_structure($msg_number); |
---|
| 836 | |
---|
[5134] | 837 | if(!isset($msg->structure[$msg_number]->parts)) |
---|
[4416] | 838 | { |
---|
| 839 | $content = ''; |
---|
| 840 | if (strtolower($msg->structure[$msg_number]->subtype) == "plain" || strtolower($msg->structure[$msg_number]->subtype) == "html") |
---|
| 841 | { |
---|
| 842 | $content = $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID|FT_PEEK), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]); |
---|
| 843 | } |
---|
| 844 | } |
---|
| 845 | else |
---|
| 846 | { |
---|
| 847 | foreach($msg->pid[$msg_number] as $values => $msg_part) |
---|
| 848 | { |
---|
| 849 | |
---|
| 850 | $file_type = strtolower($msg->file_type[$msg_number][$values]); |
---|
| 851 | if($file_type == "text/plain" || $file_type == "text/html") { |
---|
| 852 | $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]); |
---|
| 853 | break; |
---|
| 854 | } |
---|
| 855 | } |
---|
| 856 | } |
---|
[5134] | 857 | |
---|
[4416] | 858 | $tags_replace = array("<br>","<br/>","<br />"); |
---|
[5134] | 859 | $content = str_replace($tags_replace," ", nl2br($content)); |
---|
| 860 | $content = $this->html2txt($content); |
---|
[4416] | 861 | $content != "" ? $return['body'] = " - " . $content: $return['body'] = ""; |
---|
[5134] | 862 | $return['body'] = base64_encode(mb_convert_encoding(substr($return['body'], 0, 305),'ISO-8859-1')); |
---|
[4416] | 863 | return $return; |
---|
| 864 | } |
---|
[5134] | 865 | function html2txt($document){ |
---|
| 866 | $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript |
---|
| 867 | '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags |
---|
| 868 | '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly |
---|
| 869 | '@<![\s\S]*?--[ \t\n\r]*>@si' // Strip multi-line comments including CDATA |
---|
| 870 | ); |
---|
| 871 | $text = preg_replace($search, '', $document); |
---|
| 872 | return html_entity_decode($text); |
---|
| 873 | } |
---|
| 874 | |
---|
| 875 | function ope_msg_part($params) |
---|
| 876 | { |
---|
| 877 | $return = array(); |
---|
| 878 | require_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; |
---|
[4416] | 879 | |
---|
[5134] | 880 | $atObj = new attachment(); |
---|
| 881 | $atObj->setStructureFromMail($params['msg_folder'],$params['msg_number']); |
---|
| 882 | $mbox_stream = $this->open_mbox($params['save_folder']); |
---|
| 883 | $return['append'] = imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$params['save_folder'], $atObj->getAttachment($params['msg_part']), "\\Seen \\Draft"); |
---|
| 884 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$params['save_folder'], SA_UIDNEXT); |
---|
[4416] | 885 | |
---|
[5134] | 886 | $return['msg_folder'] = $params['save_folder']; |
---|
| 887 | $return['msg_number'] = $status->uidnext - 1; |
---|
| 888 | |
---|
| 889 | return $return; |
---|
| 890 | |
---|
| 891 | } |
---|
[5079] | 892 | |
---|
[2] | 893 | function get_info_msg($params) |
---|
| 894 | { |
---|
[51] | 895 | $return = array(); |
---|
[2] | 896 | $msg_number = $params['msg_number']; |
---|
[1724] | 897 | $msg_folder = urldecode($params['msg_folder']); |
---|
[4416] | 898 | |
---|
[5134] | 899 | if(preg_match('/(.+)(_[a-zA-Z0-9]+)/',$msg_number,$matches)) { //Verifies if it comes from a tab diferent of the main one. |
---|
[4795] | 900 | $msg_number = $matches[1]; |
---|
| 901 | $plus_id = $matches[2]; |
---|
| 902 | } |
---|
| 903 | else { |
---|
| 904 | $plus_id = ''; |
---|
| 905 | } |
---|
| 906 | |
---|
[411] | 907 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[4795] | 908 | $this->mbox = $this->open_mbox($msg_folder); |
---|
[4416] | 909 | |
---|
[535] | 910 | $header = $this->get_header($msg_number); |
---|
[205] | 911 | if (!$header) { |
---|
[4795] | 912 | $return['status_get_msg_info'] = "false"; |
---|
[205] | 913 | return $return; |
---|
| 914 | } |
---|
[4795] | 915 | |
---|
| 916 | $header_ = imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
[51] | 917 | $return_get_body = $this->get_body_msg($msg_number, $msg_folder); |
---|
[4416] | 918 | $body = $return_get_body['body']; |
---|
[4795] | 919 | |
---|
[1035] | 920 | if($return_get_body['body']=='isCripted'){ |
---|
| 921 | $exporteml = new ExportEml(); |
---|
| 922 | $return['source']=$exporteml->export_msg_data($msg_number,$msg_folder); |
---|
| 923 | $return['body'] = ""; |
---|
| 924 | $return['attachments'] = ""; |
---|
| 925 | $return['thumbs'] = ""; |
---|
| 926 | $return['signature'] = ""; |
---|
| 927 | //return $return; |
---|
| 928 | }else{ |
---|
[4795] | 929 | $return['body'] = $body; |
---|
| 930 | $return['attachments'] = $return_get_body['attachments']; |
---|
| 931 | $return['thumbs'] = $return_get_body['thumbs']; |
---|
[5134] | 932 | //$return['signature'] = $return_get_body['signature']; |
---|
[4795] | 933 | } |
---|
[3018] | 934 | $pattern = '/^[ \t]*Disposition-Notification-To:[ ]*<?[[:alnum:]\._-]+@[[:alnum:]_-]+[\.[:alnum:]]+>?/sm'; |
---|
[828] | 935 | if (preg_match($pattern, $header_, $fields)) |
---|
| 936 | { |
---|
[4795] | 937 | if(preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$fields[0], $matches)){ |
---|
| 938 | $return['DispositionNotificationTo'] = "<".$matches[0].">"; |
---|
| 939 | } |
---|
[2] | 940 | } |
---|
[828] | 941 | |
---|
[2] | 942 | $return['Recent'] = $header->Recent; |
---|
| 943 | $return['Unseen'] = $header->Unseen; |
---|
[4795] | 944 | $return['Deleted'] = $header->Deleted; |
---|
[2] | 945 | $return['Flagged'] = $header->Flagged; |
---|
| 946 | |
---|
| 947 | if($header->Answered =='A' && $header->Draft == 'X'){ |
---|
| 948 | $return['Forwarded'] = 'F'; |
---|
| 949 | } |
---|
[4795] | 950 | |
---|
[2] | 951 | else { |
---|
| 952 | $return['Answered'] = $header->Answered; |
---|
[4795] | 953 | $return['Draft'] = $header->Draft; |
---|
[2] | 954 | } |
---|
| 955 | |
---|
[4795] | 956 | $return['msg_number'] = $msg_number.$plus_id; |
---|
[2] | 957 | $return['msg_folder'] = $msg_folder; |
---|
[4795] | 958 | |
---|
[5134] | 959 | |
---|
| 960 | |
---|
| 961 | $msgTimesTamp = $header->udate + $this->functions->CalculateDateOffset(); //Aplica offset do usuario |
---|
| 962 | $date_msg = gmdate("d/m/Y",$msgTimesTamp); |
---|
[4795] | 963 | |
---|
[5134] | 964 | // Removido codigo pois a o método send_nofication precisa da data completa. |
---|
| 965 | // if (date("d/m/Y") == $date_msg) |
---|
| 966 | // $return['udate'] = gmdate("H:i",$header->udate); |
---|
| 967 | // else |
---|
| 968 | |
---|
| 969 | // Passa o a data completa para mensagem. |
---|
| 970 | $return['udate'] = $header->udate; |
---|
| 971 | |
---|
[4795] | 972 | $return['msg_day'] = $date_msg; |
---|
[5134] | 973 | $return['msg_hour'] = gmdate("H:i",$msgTimesTamp); |
---|
[4795] | 974 | |
---|
[2] | 975 | if (date("d/m/Y") == $date_msg) //no dia |
---|
| 976 | { |
---|
[5134] | 977 | $return['fulldate'] = gmdate("d/m/Y H:i",$msgTimesTamp); |
---|
| 978 | $return['smalldate'] = gmdate("H:i",$msgTimesTamp); |
---|
| 979 | |
---|
[605] | 980 | |
---|
[5134] | 981 | $timestamp_now = strtotime("now"); |
---|
| 982 | // removido offset nao esta sendo parametrizado |
---|
| 983 | // $timestamp_now = strtotime("now") + $offset; |
---|
| 984 | |
---|
| 985 | |
---|
| 986 | $timestamp_msg_time = $msgTimesTamp; |
---|
[4416] | 987 | // $timestamp_now is GMT and $timestamp_msg_time is MailDate TZ. |
---|
[535] | 988 | // The variable $timestamp_diff is calculated without MailDate TZ. |
---|
[4416] | 989 | $pdate = date_parse($header->MailDate); |
---|
| 990 | $timestamp_diff = $timestamp_now - $timestamp_msg_time + ($pdate['zone']*(-60)); |
---|
[4795] | 991 | |
---|
[2] | 992 | if (gmdate("H",$timestamp_diff) > 0) |
---|
| 993 | { |
---|
[197] | 994 | $return['fulldate'] .= " (" . gmdate("H:i", $timestamp_diff) . ' ' . $this->functions->getLang('hours ago') . ')'; |
---|
[2] | 995 | } |
---|
| 996 | else |
---|
| 997 | { |
---|
| 998 | if (gmdate("i",$timestamp_diff) == 0){ |
---|
[197] | 999 | $return['fulldate'] .= ' ('. $this->functions->getLang('now').')'; |
---|
[2] | 1000 | } |
---|
| 1001 | elseif (gmdate("i",$timestamp_diff) == 1){ |
---|
[197] | 1002 | $return['fulldate'] .= ' (1 '. $this->functions->getLang('minute ago').')'; |
---|
[2] | 1003 | } |
---|
| 1004 | else{ |
---|
[197] | 1005 | $return['fulldate'] .= " (" . gmdate("i",$timestamp_diff) .' '. $this->functions->getLang('minutes ago') . ')'; |
---|
[2] | 1006 | } |
---|
| 1007 | } |
---|
| 1008 | } |
---|
| 1009 | else{ |
---|
[5134] | 1010 | $return['fulldate'] = gmdate("d/m/Y H:i",$msgTimesTamp); |
---|
| 1011 | $return['smalldate'] = gmdate("d/m/Y",$msgTimesTamp); |
---|
[2] | 1012 | } |
---|
[4795] | 1013 | |
---|
[2] | 1014 | $from = $header->from; |
---|
| 1015 | $return['from'] = array(); |
---|
[5134] | 1016 | $return['from']['name'] = isset($sender[0]->personal) ? $this->decode_string($from[0]->personal) : ''; |
---|
[2] | 1017 | $return['from']['email'] = $this->decode_string($from[0]->mailbox . "@" . $from[0]->host); |
---|
| 1018 | if ($return['from']['name']) |
---|
| 1019 | { |
---|
| 1020 | if (substr($return['from']['name'], 0, 1) == '"') |
---|
| 1021 | $return['from']['full'] = $return['from']['name'] . ' ' . '<' . $return['from']['email'] . '>'; |
---|
| 1022 | else |
---|
| 1023 | $return['from']['full'] = '"' . $return['from']['name'] . '" ' . '<' . $return['from']['email'] . '>'; |
---|
| 1024 | } |
---|
| 1025 | else |
---|
| 1026 | $return['from']['full'] = $return['from']['email']; |
---|
[4795] | 1027 | |
---|
[2] | 1028 | // Sender attribute |
---|
| 1029 | $sender = $header->sender; |
---|
[4795] | 1030 | $return['sender'] = array(); |
---|
[5134] | 1031 | $return['sender']['name'] = isset($sender[0]->personal) ? $this->decode_string($sender[0]->personal): ''; |
---|
[2] | 1032 | $return['sender']['email'] = $this->decode_string($sender[0]->mailbox . "@" . $sender[0]->host); |
---|
[5134] | 1033 | |
---|
[2] | 1034 | if ($return['sender']['name']) |
---|
| 1035 | { |
---|
| 1036 | if (substr($return['sender']['name'], 0, 1) == '"') |
---|
| 1037 | $return['sender']['full'] = $return['sender']['name'] . ' ' . '<' . $return['sender']['email'] . '>'; |
---|
| 1038 | else |
---|
| 1039 | $return['sender']['full'] = '"' . $return['sender']['name'] . '" ' . '<' . $return['sender']['email'] . '>'; |
---|
| 1040 | } |
---|
| 1041 | else |
---|
| 1042 | $return['sender']['full'] = $return['sender']['email']; |
---|
| 1043 | |
---|
| 1044 | if($return['from']['full'] == $return['sender']['full']) |
---|
| 1045 | $return['sender'] = null; |
---|
| 1046 | $to = $header->to; |
---|
| 1047 | $return['toaddress2'] = ""; |
---|
| 1048 | if (!empty($to)) |
---|
| 1049 | { |
---|
| 1050 | foreach ($to as $tmp) |
---|
| 1051 | { |
---|
| 1052 | if (!empty($tmp->personal)) |
---|
| 1053 | { |
---|
| 1054 | $personal_tmp = imap_mime_header_decode($tmp->personal); |
---|
| 1055 | $return['toaddress2'] .= '"' . $personal_tmp[0]->text . '"'; |
---|
| 1056 | $return['toaddress2'] .= " "; |
---|
| 1057 | $return['toaddress2'] .= "<"; |
---|
[320] | 1058 | if ($tmp->host != 'unspecified-domain') |
---|
| 1059 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
| 1060 | else |
---|
| 1061 | $return['toaddress2'] .= $tmp->mailbox; |
---|
[2] | 1062 | $return['toaddress2'] .= ">"; |
---|
| 1063 | $return['toaddress2'] .= ", "; |
---|
| 1064 | } |
---|
| 1065 | else |
---|
| 1066 | { |
---|
[320] | 1067 | if ($tmp->host != 'unspecified-domain') |
---|
| 1068 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
| 1069 | else |
---|
| 1070 | $return['toaddress2'] .= $tmp->mailbox; |
---|
[2] | 1071 | $return['toaddress2'] .= ", "; |
---|
| 1072 | } |
---|
| 1073 | } |
---|
| 1074 | $return['toaddress2'] = $this->del_last_two_caracters($return['toaddress2']); |
---|
| 1075 | } |
---|
[4416] | 1076 | else |
---|
| 1077 | { |
---|
[4730] | 1078 | $return['toaddress2'] = ""; |
---|
[4416] | 1079 | } |
---|
[5134] | 1080 | if(isset($header->cc)) |
---|
[2] | 1081 | $cc = $header->cc; |
---|
| 1082 | $return['cc'] = ""; |
---|
| 1083 | if (!empty($cc)) |
---|
| 1084 | { |
---|
| 1085 | foreach ($cc as $tmp_cc) |
---|
| 1086 | { |
---|
| 1087 | if (!empty($tmp_cc->personal)) |
---|
| 1088 | { |
---|
| 1089 | $personal_tmp_cc = imap_mime_header_decode($tmp_cc->personal); |
---|
| 1090 | $return['cc'] .= '"' . $personal_tmp_cc[0]->text . '"'; |
---|
| 1091 | $return['cc'] .= " "; |
---|
| 1092 | $return['cc'] .= "<"; |
---|
[5134] | 1093 | if ($tmp_cc->host != 'unspecified-domain') |
---|
[2] | 1094 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[5134] | 1095 | else |
---|
| 1096 | $return['cc'] .= $tmp_cc->mailbox; |
---|
| 1097 | //$return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[2] | 1098 | $return['cc'] .= ">"; |
---|
| 1099 | $return['cc'] .= ", "; |
---|
| 1100 | } |
---|
| 1101 | else |
---|
| 1102 | { |
---|
[5134] | 1103 | if ($tmp_cc->host != 'unspecified-domain') |
---|
[2] | 1104 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[5134] | 1105 | else |
---|
| 1106 | $return['cc'] .= $tmp_cc->mailbox; |
---|
| 1107 | //$return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[2] | 1108 | $return['cc'] .= ", "; |
---|
| 1109 | } |
---|
| 1110 | } |
---|
| 1111 | $return['cc'] = $this->del_last_two_caracters($return['cc']); |
---|
| 1112 | } |
---|
| 1113 | else |
---|
| 1114 | { |
---|
| 1115 | $return['cc'] = ""; |
---|
[4795] | 1116 | } |
---|
[449] | 1117 | |
---|
| 1118 | ## |
---|
| 1119 | # @AUTHOR Rodrigo Souza dos Santos |
---|
| 1120 | # @DATE 2008/09/12 |
---|
| 1121 | # @BRIEF Adding the BCC field. |
---|
| 1122 | ## |
---|
[5134] | 1123 | if(isset($header->bcc)){ |
---|
[4795] | 1124 | $bcc = $header->bcc; |
---|
[5134] | 1125 | } |
---|
[449] | 1126 | $return['bcc'] = ""; |
---|
| 1127 | if (!empty($bcc)) |
---|
| 1128 | { |
---|
| 1129 | foreach ($bcc as $tmp_bcc) |
---|
| 1130 | { |
---|
| 1131 | if (!empty($tmp_bcc->personal)) |
---|
| 1132 | { |
---|
| 1133 | $personal_tmp_bcc = imap_mime_header_decode($tmp_bcc->personal); |
---|
| 1134 | $return['bcc'] .= '"' . $personal_tmp_bcc[0]->text . '"'; |
---|
| 1135 | $return['bcc'] .= " "; |
---|
| 1136 | $return['bcc'] .= "<"; |
---|
[5134] | 1137 | if ($tmp_bcc->host != 'unspecified-domain') |
---|
[449] | 1138 | $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
[5134] | 1139 | else |
---|
| 1140 | $return['bcc'] .= $tmp_bcc->mailbox; |
---|
[449] | 1141 | $return['bcc'] .= ">"; |
---|
| 1142 | $return['bcc'] .= ", "; |
---|
| 1143 | } |
---|
| 1144 | else |
---|
| 1145 | { |
---|
[5134] | 1146 | if ($tmp_bcc->host != 'unspecified-domain') |
---|
[449] | 1147 | $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
[5134] | 1148 | else |
---|
| 1149 | $return['bcc'] .= $tmp_bcc->mailbox; |
---|
| 1150 | //$return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
[449] | 1151 | $return['bcc'] .= ", "; |
---|
| 1152 | } |
---|
| 1153 | } |
---|
| 1154 | $return['bcc'] = $this->del_last_two_caracters($return['bcc']); |
---|
[426] | 1155 | } |
---|
[449] | 1156 | else |
---|
| 1157 | { |
---|
| 1158 | $return['bcc'] = ""; |
---|
[4795] | 1159 | } |
---|
[426] | 1160 | |
---|
[2] | 1161 | $reply_to = $header->reply_to; |
---|
| 1162 | $return['reply_to'] = ""; |
---|
| 1163 | if (is_object($reply_to[0])) |
---|
| 1164 | { |
---|
| 1165 | if ($return['from']['email'] != ($reply_to[0]->mailbox."@".$reply_to[0]->host)) |
---|
| 1166 | { |
---|
| 1167 | if (!empty($reply_to[0]->personal)) |
---|
| 1168 | { |
---|
| 1169 | $personal_reply_to = imap_mime_header_decode($tmp_reply_to->personal); |
---|
[41] | 1170 | if(!empty($personal_reply_to[0]->text)) { |
---|
| 1171 | $return['reply_to'] .= '"' . $personal_reply_to[0]->text . '"'; |
---|
| 1172 | $return['reply_to'] .= " "; |
---|
| 1173 | $return['reply_to'] .= "<"; |
---|
| 1174 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 1175 | $return['reply_to'] .= ">"; |
---|
| 1176 | } |
---|
| 1177 | else { |
---|
| 1178 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 1179 | } |
---|
[2] | 1180 | } |
---|
| 1181 | else |
---|
| 1182 | { |
---|
| 1183 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 1184 | } |
---|
| 1185 | } |
---|
| 1186 | } |
---|
| 1187 | $return['reply_to'] = $this->decode_string($return['reply_to']); |
---|
| 1188 | $return['subject'] = $this->decode_string($header->fetchsubject); |
---|
[5134] | 1189 | |
---|
| 1190 | if($return['subject'] == $this->functions->getLang("(no subject) ")){ |
---|
| 1191 | $return['subject'] = str_replace(" ","", $return['subject']); |
---|
| 1192 | } |
---|
| 1193 | if($return['subject'] == '' || $return['subject'] == null){ |
---|
| 1194 | $return['subject'] = $this->functions->getLang("(no subject) "); |
---|
| 1195 | } |
---|
[4795] | 1196 | $return['Size'] = $header->Size; |
---|
[828] | 1197 | $return['reply_toaddress'] = $header->reply_toaddress; |
---|
[4795] | 1198 | |
---|
[689] | 1199 | //All this is to help in local messages |
---|
[4795] | 1200 | $return['timestamp'] = $header->udate; |
---|
[689] | 1201 | $return['login'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];//$GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 1202 | $return['reply_toaddress'] = $header->reply_toaddress; |
---|
[4795] | 1203 | |
---|
[5134] | 1204 | if(($return['from']['email'] == '@unspecified-domain' || $return['sender']['email'] == null) && $return['msg_folder'] == 'INBOX/Drafts'){ |
---|
| 1205 | $return['from']['email'] = "Rascunho"; |
---|
| 1206 | } |
---|
| 1207 | if($return['toaddress2'] == 'undisclosed-recipients@, @'){ |
---|
| 1208 | $return['toaddress2'] = $this->functions->getLang('without destination'); |
---|
| 1209 | } |
---|
[2] | 1210 | return $return; |
---|
| 1211 | } |
---|
[1472] | 1212 | |
---|
[5079] | 1213 | |
---|
[5134] | 1214 | /* |
---|
[5079] | 1215 | * Converte textos utf8 para o padrão html. |
---|
[5134] | 1216 | * Modificado por Cristiano Corrêa Schmidt |
---|
| 1217 | * @link http://php.net/manual/en/function.utf8-decode.php |
---|
[5079] | 1218 | * @author luka8088 <luka8088@gmail.com> |
---|
| 1219 | */ |
---|
[4781] | 1220 | function utf8_to_html ($data) |
---|
[4795] | 1221 | { |
---|
[4781] | 1222 | return preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e", '$this->_utf8_to_html("\\1")', $data); |
---|
| 1223 | } |
---|
[4795] | 1224 | |
---|
[4781] | 1225 | function _utf8_to_html ($data) |
---|
[4795] | 1226 | { |
---|
[4781] | 1227 | $ret = 0; |
---|
| 1228 | foreach((str_split(strrev(chr((ord($data{0}) % 252 % 248 % 240 % 224 % 192) + 128) . substr($data, 1)))) as $k => $v) |
---|
| 1229 | $ret += (ord($v) % 128) * pow(64, $k); |
---|
[5134] | 1230 | return html_entity_decode("&#$ret;" , ENT_QUOTES); |
---|
[4795] | 1231 | } |
---|
[4781] | 1232 | //------------------------------------------------------------------------------// |
---|
[4795] | 1233 | |
---|
| 1234 | |
---|
[4416] | 1235 | /** |
---|
[5134] | 1236 | * Decodifica uma part da mensagem para iso-8859-1 |
---|
| 1237 | * @param <type> $part parte do email |
---|
| 1238 | * @param <type> $encode codificação da parte |
---|
| 1239 | * @return <type> string decodificada |
---|
[5079] | 1240 | */ |
---|
[4781] | 1241 | function decodeMailPart($part, $encode, $html = true) |
---|
[4795] | 1242 | { |
---|
[4416] | 1243 | switch (strtolower($encode)) |
---|
[4795] | 1244 | { |
---|
[4416] | 1245 | case 'iso-8859-1': |
---|
| 1246 | return $part; |
---|
| 1247 | break; |
---|
[1752] | 1248 | |
---|
[4416] | 1249 | case 'utf-8': |
---|
[5134] | 1250 | if ($html) return $this->utf8_to_html($part); |
---|
| 1251 | else return utf8_decode ($part); |
---|
[4416] | 1252 | break; |
---|
[1752] | 1253 | |
---|
[4416] | 1254 | default: |
---|
| 1255 | return mb_convert_encoding($part, 'iso-8859-1'); |
---|
[4795] | 1256 | break; |
---|
| 1257 | } |
---|
| 1258 | } |
---|
| 1259 | |
---|
[4416] | 1260 | |
---|
[2] | 1261 | function get_body_msg($msg_number, $msg_folder) |
---|
| 1262 | { |
---|
[4429] | 1263 | /* |
---|
[4416] | 1264 | * Requires of librarys |
---|
| 1265 | */ |
---|
| 1266 | require_once $_SESSION['rootPath'].'/library/mime/mimePart.php'; |
---|
| 1267 | require_once $_SESSION['rootPath'].'/library/mime/mimeDecode.php'; |
---|
| 1268 | require_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; |
---|
[5134] | 1269 | //include_once("class.message_components.inc.php"); |
---|
[4416] | 1270 | //--------------------------------------------------------------------// |
---|
[1472] | 1271 | |
---|
[4416] | 1272 | $return = array(); |
---|
[1035] | 1273 | |
---|
[5134] | 1274 | // $msg = new message_components($this->mbox); |
---|
| 1275 | // $msg->fetch_structure($msg_number); |
---|
[1035] | 1276 | |
---|
[4416] | 1277 | $content = ''; |
---|
[1035] | 1278 | |
---|
[5134] | 1279 | /* |
---|
| 1280 | * Chamada original $this->getRawHeader($msg_number)."\r\n".$this->getRawBody($msg_number); |
---|
| 1281 | * Inserido replace para corrigir um bug que acontece raramente em mensagens vindas do outlook com muitos destinatarios |
---|
| 1282 | */ |
---|
| 1283 | $rawMessageData = str_replace("\r\n\t", '', $this->getRawHeader($msg_number))."\r\n".$this->getRawBody($msg_number); |
---|
[3018] | 1284 | |
---|
[4416] | 1285 | $decoder = new Mail_mimeDecode($rawMessageData); |
---|
[3018] | 1286 | |
---|
[4416] | 1287 | $params['include_bodies'] = true; |
---|
| 1288 | $params['decode_bodies'] = true; |
---|
| 1289 | $params['decode_headers'] = true; |
---|
[5134] | 1290 | if(array_key_exists('nested_messages_are_shown', $_SESSION['phpgw_info']['user']['preferences']['expressoMail']) && ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['nested_messages_are_shown'] == '1')) |
---|
| 1291 | $params['rfc_822bodies'] = true; |
---|
[4416] | 1292 | $structure = $decoder->decode($params); |
---|
[3018] | 1293 | |
---|
[4416] | 1294 | /* |
---|
| 1295 | * Inicia Gerenciador de Anexos |
---|
| 1296 | */ |
---|
| 1297 | $attachmentManager = new attachment(); |
---|
| 1298 | $attachmentManager->setStructure($structure); |
---|
| 1299 | //----------------------------------------------// |
---|
[1472] | 1300 | |
---|
[4416] | 1301 | /* |
---|
[4429] | 1302 | * Monta informações dos anexos para o cabecalhos |
---|
[4416] | 1303 | */ |
---|
| 1304 | $attachments = $attachmentManager->getAttachmentsInfo(); |
---|
| 1305 | $return['attachments'] = $attachments; |
---|
| 1306 | //----------------------------------------------// |
---|
[2] | 1307 | |
---|
[4416] | 1308 | /* |
---|
[4429] | 1309 | * Monta informações das imagens |
---|
| 1310 | */ |
---|
[4416] | 1311 | $images = $attachmentManager->getEmbeddedImagesInfo(); |
---|
| 1312 | //----------------------------------------------// |
---|
[1472] | 1313 | |
---|
[4795] | 1314 | if(!$this->has_cid) |
---|
| 1315 | { |
---|
[4416] | 1316 | $return['thumbs'] = $this->get_thumbs($images,$msg_number,$msg_folder); |
---|
[5134] | 1317 | // $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); |
---|
[4795] | 1318 | } |
---|
[1472] | 1319 | |
---|
[4416] | 1320 | switch (strtolower($structure->ctype_primary)) |
---|
[4795] | 1321 | { |
---|
[4908] | 1322 | case 'text': |
---|
| 1323 | if(strtolower($structure->ctype_secondary) == 'x-pkcs7-mime') |
---|
| 1324 | { |
---|
[4795] | 1325 | $return['body']='isCripted'; |
---|
| 1326 | return $return; |
---|
| 1327 | } |
---|
[4416] | 1328 | $attachment = array(); |
---|
[3414] | 1329 | |
---|
[4416] | 1330 | $msg_subtype = strtolower($structure->ctype_secondary); |
---|
[5134] | 1331 | if(isset($structure->disposition)) |
---|
[4416] | 1332 | $disposition = strtolower($structure->disposition); |
---|
[5134] | 1333 | else |
---|
| 1334 | $disposition = ''; |
---|
[1472] | 1335 | |
---|
[4908] | 1336 | if(($msg_subtype == "html" || $msg_subtype == 'plain') && ($disposition != 'attachment')) |
---|
[4795] | 1337 | { |
---|
[4416] | 1338 | if(strtolower($msg_subtype) == 'plain') |
---|
[4795] | 1339 | { |
---|
[5134] | 1340 | if(isset($structure->ctype_parameters['charset'])) |
---|
[4781] | 1341 | $content = $this->decodeMailPart($structure->body, $structure->ctype_parameters['charset'],false); |
---|
[5134] | 1342 | else |
---|
| 1343 | $content = $this->decodeMailPart($structure->body, null,false); |
---|
[4795] | 1344 | $content = str_replace( array( '<', '>' ), array( ' #$<$# ', ' #$>$# ' ), $content ); |
---|
| 1345 | $content = htmlentities( $content ); |
---|
[4784] | 1346 | $this->replace_links($content); |
---|
[4795] | 1347 | $content = str_replace( array( ' #$<$# ', ' #$>$# ' ), array( '<', '>' ), $content ); |
---|
| 1348 | $content = '<pre>' . $content . '</pre>'; |
---|
| 1349 | $return[ 'body' ] = $content; |
---|
| 1350 | return $return; |
---|
| 1351 | } |
---|
[4781] | 1352 | $content = $this->decodeMailPart($structure->body, $structure->ctype_parameters['charset']); |
---|
[4795] | 1353 | } |
---|
[5134] | 1354 | if(strtolower($structure->ctype_secondary) == 'calendar') |
---|
| 1355 | $content .= $this->builderMsgCalendar($structure->body); |
---|
[1897] | 1356 | |
---|
[4416] | 1357 | break; |
---|
[1897] | 1358 | |
---|
[4429] | 1359 | case 'multipart': |
---|
[5134] | 1360 | $this->builderMsgBody($structure , $content); |
---|
[1897] | 1361 | |
---|
[4416] | 1362 | break; |
---|
[1897] | 1363 | |
---|
[4416] | 1364 | case 'message': |
---|
[5134] | 1365 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['nested_messages_are_shown'] != 1) |
---|
| 1366 | { |
---|
[4416] | 1367 | if(!is_array($structure->parts)) |
---|
[4795] | 1368 | { |
---|
[4416] | 1369 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4781] | 1370 | $content .= '<pre>'.htmlentities($this->decodeMailPart($structure->body, $structure->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 1371 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4795] | 1372 | } |
---|
| 1373 | else |
---|
[4416] | 1374 | $this->builderMsgBody($structure , $content,true); |
---|
[5134] | 1375 | } |
---|
[4429] | 1376 | break; |
---|
[3018] | 1377 | |
---|
[5134] | 1378 | case 'application': |
---|
| 1379 | if(strtolower($structure->ctype_secondary) == 'x-pkcs7-mime') |
---|
| 1380 | { |
---|
| 1381 | // $return['body']='isCripted'; |
---|
| 1382 | // return $return; |
---|
| 1383 | |
---|
| 1384 | //TODO: Descartar código após atualização do módulo de segurança da SERPRO |
---|
| 1385 | $rawMessageData2 = $this->extractSignedContents($rawMessageData); |
---|
| 1386 | if($rawMessageData2 === false){ |
---|
| 1387 | $return['body']='isCripted'; |
---|
| 1388 | return $return; |
---|
| 1389 | } |
---|
| 1390 | $decoder2 = new Mail_mimeDecode($rawMessageData2); |
---|
| 1391 | $structure2 = $decoder2->decode($params); |
---|
| 1392 | $this-> builderMsgBody($structure2 , $content); |
---|
| 1393 | |
---|
| 1394 | $attachmentManager->setStructure($structure2); |
---|
| 1395 | /* |
---|
| 1396 | * Monta informações dos anexos para o cabecarios |
---|
| 1397 | */ |
---|
| 1398 | $attachments = $attachmentManager->getAttachmentsInfo(); |
---|
| 1399 | $return['attachments'] = $attachments; |
---|
| 1400 | |
---|
| 1401 | //----------------------------------------------// |
---|
| 1402 | |
---|
| 1403 | /* |
---|
| 1404 | * Monta informações das imagens |
---|
| 1405 | */ |
---|
| 1406 | $images = $attachmentManager->getEmbeddedImagesInfo(); |
---|
| 1407 | //----------------------------------------------// |
---|
| 1408 | |
---|
| 1409 | if(!$this->has_cid){ |
---|
| 1410 | $return['thumbs'] = $this->get_thumbs($images,$msg_number,$msg_folder); |
---|
| 1411 | $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); |
---|
| 1412 | } |
---|
| 1413 | } |
---|
| 1414 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[4429] | 1415 | default: |
---|
| 1416 | if(count($attachments) > 0) |
---|
| 1417 | $content .= ''; |
---|
| 1418 | break; |
---|
[4795] | 1419 | } |
---|
[3018] | 1420 | |
---|
[1472] | 1421 | $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); |
---|
[2] | 1422 | $this->set_messages_flag($params); |
---|
[4416] | 1423 | $content = $this->process_embedded_images($images,$msg_number,$content, $msg_folder); |
---|
[4795] | 1424 | $content = $this->replace_special_characters($content); |
---|
[4416] | 1425 | $this->replace_links($content); |
---|
| 1426 | $return['body'] = &$content; |
---|
| 1427 | |
---|
[4795] | 1428 | return $return; |
---|
[2] | 1429 | } |
---|
[1472] | 1430 | |
---|
[5134] | 1431 | |
---|
| 1432 | //TODO: Descartar código após atualização do módulo de segurança da SERPRO |
---|
| 1433 | function extractSignedContents( $data ) |
---|
| 1434 | { |
---|
| 1435 | $pipes_desc = array( |
---|
| 1436 | 0 => array('pipe', 'r'), |
---|
| 1437 | 1 => array('pipe', 'w') |
---|
| 1438 | ); |
---|
| 1439 | |
---|
| 1440 | $fp = proc_open( 'openssl smime -verify -noverify -nochain', $pipes_desc, $pipes); |
---|
| 1441 | if (!is_resource($fp)) { |
---|
| 1442 | return false; |
---|
| 1443 | } |
---|
| 1444 | |
---|
| 1445 | $output = ''; |
---|
| 1446 | |
---|
| 1447 | /* $pipes[0] => writeable handle connected to child stdin |
---|
| 1448 | $pipes[1] => readable handle connected to child stdout */ |
---|
| 1449 | fwrite($pipes[0], $data); |
---|
| 1450 | fclose($pipes[0]); |
---|
| 1451 | |
---|
| 1452 | while (!feof($pipes[1])) { |
---|
| 1453 | $output .= fgets($pipes[1], 1024); |
---|
| 1454 | } |
---|
| 1455 | fclose($pipes[1]); |
---|
| 1456 | proc_close($fp); |
---|
| 1457 | |
---|
| 1458 | return $output; |
---|
| 1459 | } |
---|
| 1460 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1461 | |
---|
| 1462 | function builderMsgCalendar($calendar) |
---|
| 1463 | { |
---|
| 1464 | $icalService = ServiceLocator::getService('ical'); |
---|
| 1465 | |
---|
| 1466 | $codificao = mb_detect_encoding($calendar.'x', 'UTF-8, ISO-8859-1'); |
---|
| 1467 | if($codificao == 'UTF-8') |
---|
| 1468 | $calendar = utf8_decode($calendar); |
---|
| 1469 | |
---|
| 1470 | if($icalService->setIcal($calendar)) |
---|
| 1471 | { |
---|
| 1472 | $content = ''; |
---|
| 1473 | |
---|
| 1474 | switch ($icalService->getMethod()) { |
---|
| 1475 | |
---|
| 1476 | case 'REPLY': |
---|
| 1477 | include_once($_SESSION['rootPath'].'/header.inc.php'); |
---|
| 1478 | include_once($_SESSION['rootPath'].'/calendar/inc/class.boicalendar.inc.php'); |
---|
| 1479 | $boicalendar = new boicalendar(); |
---|
| 1480 | |
---|
| 1481 | $ical = $icalService->getComponent('vevent'); |
---|
| 1482 | $content.= '<b>'.$this->functions->getLang('Event Calendar').'</b><br /><br />'; |
---|
| 1483 | $content.= '<span style="font-size: 12" >'; |
---|
| 1484 | $notExist = false; |
---|
| 1485 | |
---|
| 1486 | foreach ($ical['attendee'] as $attendee) |
---|
| 1487 | { |
---|
| 1488 | if($attendee['params']['PARTSTAT'] == 'ACCEPTED') |
---|
| 1489 | { |
---|
| 1490 | if($boicalendar->updateExParticipantState($ical['uid']['value'],$attendee['value'],'ACCEPTED',$attendee['params']['CN'])) |
---|
| 1491 | { |
---|
| 1492 | $content.= $this->functions->getLang('User').' '; |
---|
| 1493 | if($attendee['params']['CN']) |
---|
| 1494 | $content.= '<b>'.$attendee['params']['CN'].'</b> '; |
---|
| 1495 | else |
---|
| 1496 | $content.= '<b>'.$attendee['value'].'</b> '; |
---|
| 1497 | |
---|
| 1498 | $content.= $this->functions->getLang('accepted your event'); |
---|
| 1499 | } |
---|
| 1500 | else |
---|
| 1501 | $notExist = true; |
---|
| 1502 | } |
---|
| 1503 | |
---|
| 1504 | if($attendee['params']['PARTSTAT'] == 'TENTATIVE') |
---|
| 1505 | { |
---|
| 1506 | if($boicalendar->updateExParticipantState($ical['uid']['value'],$attendee['value'],'TENTATIVE',$attendee['params']['CN'])) |
---|
| 1507 | { |
---|
| 1508 | $content.= $this->functions->getLang('User').' '; |
---|
| 1509 | if($attendee['params']['CN']) |
---|
| 1510 | $content.= '<b>'.$attendee['params']['CN'].'</b> '; |
---|
| 1511 | else |
---|
| 1512 | $content.= '<b>'.$attendee['value'].'</b> '; |
---|
| 1513 | |
---|
| 1514 | if($ical['description']['value']) |
---|
| 1515 | $content.= ' <br /> '.str_replace('\n','<br />',nl2br($ical['description']['value'])); |
---|
| 1516 | else |
---|
| 1517 | $content.= $this->functions->getLang('provisionally accepted you event'); |
---|
| 1518 | } |
---|
| 1519 | else |
---|
| 1520 | $notExist = true; |
---|
| 1521 | } |
---|
| 1522 | |
---|
| 1523 | if($attendee['params']['PARTSTAT'] == 'DECLINED') |
---|
| 1524 | { |
---|
| 1525 | if($boicalendar->updateExParticipantState($ical['uid']['value'],$attendee['value'],'DECLINED',$attendee['params']['CN'])) |
---|
| 1526 | { |
---|
| 1527 | $content.= $this->functions->getLang('User').' '; |
---|
| 1528 | if($attendee['params']['CN']) |
---|
| 1529 | $content.= '<b>'.$attendee['params']['CN'].'</b> '; |
---|
| 1530 | else |
---|
| 1531 | $content.= '<b>'.$attendee['value'].'</b> '; |
---|
| 1532 | |
---|
| 1533 | if($ical['description']['value']) |
---|
| 1534 | $content.= ' <br /> '.str_replace('\n','<br />',nl2br($ical['description']['value'])); |
---|
| 1535 | else |
---|
| 1536 | $content.= $this->functions->getLang('provisionally decline you event'); |
---|
| 1537 | } |
---|
| 1538 | else |
---|
| 1539 | $notExist = true; |
---|
| 1540 | } |
---|
| 1541 | } |
---|
| 1542 | if($notExist) |
---|
| 1543 | $content.= '<b><span style="color:red">'.$this->functions->getLang('This event does not exist on its agenda').'.</span></b>'; |
---|
| 1544 | $content.= '</span><br /><br />'; |
---|
| 1545 | |
---|
| 1546 | break; |
---|
| 1547 | |
---|
| 1548 | case 'CANCEL': |
---|
| 1549 | |
---|
| 1550 | $ical = $icalService->getComponent('vevent'); |
---|
| 1551 | $content.= '<b>'.$this->functions->getLang('Event Calendar').'</b><br /><br />'; |
---|
| 1552 | $content.= '<span style="font-size: 12" >'; |
---|
| 1553 | $content.= '<b><span style="color:red">'.$this->functions->getLang('Your event has been canceled').'</span></b>'; |
---|
| 1554 | |
---|
| 1555 | if($ical['description']['value']) |
---|
| 1556 | $content.= ' <br /> <br /> '.str_replace('\n','<br />',nl2br($ical['description']['value'])); |
---|
| 1557 | |
---|
| 1558 | $content.= '<br /><b>* '.$this->functions->getLang('To remove the event from your calendar to import the iCal file attached').'.</b>'; |
---|
| 1559 | $content.= '</span><br /><br />'; |
---|
| 1560 | break; |
---|
| 1561 | |
---|
| 1562 | case 'REQUEST': |
---|
| 1563 | |
---|
| 1564 | $ical = $icalService->getComponent('vevent'); |
---|
| 1565 | if($ical['dtstart']['value']['tz'] == 'Z') |
---|
| 1566 | { |
---|
| 1567 | $tz = $_SESSION['phpgw_info']['user']['preferences']['common']['tz_offset']; |
---|
| 1568 | $ical['dtstart']['value']['hour'] += $tz; |
---|
| 1569 | $ical['dtend']['value']['hour'] += $tz; |
---|
| 1570 | } |
---|
| 1571 | |
---|
| 1572 | $content.= '<b>'.$this->functions->getLang('Event Calendar').'</b><br />'. |
---|
| 1573 | ' <br /> <b>'.$this->functions->getLang('Title').': </b>'.$ical['summary']['value']. |
---|
| 1574 | ' <br /> <b>'.$this->functions->getLang('Location').': </b>'.$ical['location']['value']. |
---|
| 1575 | ' <br /> <b>'.$this->functions->getLang('Details').': </b>'. str_replace('\n','<br />',nl2br($ical['description']['value'])); |
---|
| 1576 | $content.= ' <br /> <b>'.$this->functions->getLang('Start') . ': </b>' . $ical['dtstart']['value']['day'] . "/" . $ical['dtstart']['value']['month'] . "/" . $ical['dtstart']['value']['year'] . " - " . $ical['dtstart']['value']['hour'] . ":" . $ical['dtstart']['value']['min'] ; |
---|
| 1577 | $content.= ' <br /> <b>'.$this->functions->getLang('End') . ': </b>' . $ical['dtend']['value']['day'] . "/" . $ical['dtend']['value']['month'] . "/" . $ical['dtend']['value']['year'] . " - " . $ical['dtend']['value']['hour'] . ":" . $ical['dtend']['value']['min'] ; |
---|
| 1578 | |
---|
| 1579 | if($ical['organizer']['params']['CN']) |
---|
| 1580 | $content.= ' <br /> <b>'.$this->functions->getLang('Organizer').': </b>'.$ical['organizer']['params']['CN'].' - <a href="MAILTO:'.$ical['organizer']['value'].'">'.$ical['organizer']['value'].'</a></li>' ; |
---|
| 1581 | else |
---|
| 1582 | $content.= ' <br /> <b>'.$this->functions->getLang('Organizer').': </b> <a href="MAILTO:'.$ical['organizer']['value'].'">'.$ical['organizer']['value'].'</a>' ; |
---|
| 1583 | |
---|
| 1584 | if($ical['attendee']) |
---|
| 1585 | { |
---|
| 1586 | $att = ' <br /> <b>'.$this->functions->getLang('Participants').': </b>'; |
---|
| 1587 | $att .= '<ul> '; |
---|
| 1588 | foreach ($ical['attendee'] as $attendee) |
---|
| 1589 | { |
---|
| 1590 | if($attendee['params']['CN']) |
---|
| 1591 | $att .= '<li>'.$attendee['params']['CN'].' - <a href="MAILTO:'.$attendee['value'].'">'.$attendee['value'].'</a></li>' ; |
---|
| 1592 | else |
---|
| 1593 | $att .= '<li><a href="MAILTO:'.$attendee['value'].'">'.$attendee['value'].'</a></li>' ; |
---|
| 1594 | } |
---|
| 1595 | $att .= '</ul> <br />' ; |
---|
| 1596 | } |
---|
| 1597 | $content.= $att; |
---|
| 1598 | |
---|
| 1599 | break; |
---|
| 1600 | default: |
---|
| 1601 | break; |
---|
| 1602 | } |
---|
| 1603 | |
---|
| 1604 | } |
---|
| 1605 | return $content; |
---|
| 1606 | } |
---|
| 1607 | |
---|
[2] | 1608 | function htmlfilter($body) |
---|
| 1609 | { |
---|
| 1610 | require_once('htmlfilter.inc'); |
---|
[1472] | 1611 | |
---|
[2] | 1612 | $tag_list = Array( |
---|
| 1613 | false, |
---|
| 1614 | 'blink', |
---|
| 1615 | 'object', |
---|
| 1616 | 'meta', |
---|
| 1617 | 'html', |
---|
| 1618 | 'link', |
---|
| 1619 | 'frame', |
---|
| 1620 | 'iframe', |
---|
| 1621 | 'layer', |
---|
| 1622 | 'ilayer', |
---|
| 1623 | 'plaintext' |
---|
| 1624 | ); |
---|
| 1625 | |
---|
| 1626 | /** |
---|
| 1627 | * A very exclusive set: |
---|
| 1628 | */ |
---|
| 1629 | // $tag_list = Array(true, "b", "a", "i", "img", "strong", "em", "p"); |
---|
| 1630 | $rm_tags_with_content = Array( |
---|
| 1631 | 'script', |
---|
| 1632 | 'style', |
---|
| 1633 | 'applet', |
---|
| 1634 | 'embed', |
---|
| 1635 | 'head', |
---|
| 1636 | 'frameset', |
---|
| 1637 | 'xml', |
---|
| 1638 | 'xmp' |
---|
| 1639 | ); |
---|
| 1640 | |
---|
| 1641 | $self_closing_tags = Array( |
---|
| 1642 | 'img', |
---|
| 1643 | 'br', |
---|
| 1644 | 'hr', |
---|
| 1645 | 'input' |
---|
| 1646 | ); |
---|
| 1647 | |
---|
| 1648 | $force_tag_closing = true; |
---|
| 1649 | |
---|
| 1650 | $rm_attnames = Array( |
---|
| 1651 | '/.*/' => |
---|
| 1652 | Array( |
---|
| 1653 | '/target/i', |
---|
| 1654 | //'/^on.*/i', -> onClick, dos compromissos da agenda. |
---|
| 1655 | '/^dynsrc/i', |
---|
| 1656 | '/^datasrc/i', |
---|
| 1657 | '/^data.*/i', |
---|
| 1658 | '/^lowsrc/i' |
---|
| 1659 | ) |
---|
| 1660 | ); |
---|
| 1661 | |
---|
| 1662 | /** |
---|
| 1663 | * Yeah-yeah, so this looks horrible. Check out htmlfilter.inc for |
---|
| 1664 | * some idea of what's going on here. :) |
---|
| 1665 | */ |
---|
| 1666 | |
---|
| 1667 | $bad_attvals = Array( |
---|
| 1668 | '/.*/' => |
---|
| 1669 | Array( |
---|
| 1670 | '/.*/' => |
---|
| 1671 | Array( |
---|
| 1672 | Array( |
---|
| 1673 | '/^([\'\"])\s*\S+\s*script\s*:*(.*)([\'\"])/si', |
---|
| 1674 | //'/^([\'\"])\s*https*\s*:(.*)([\'\"])/si', -> doclinks notes |
---|
| 1675 | '/^([\'\"])\s*mocha\s*:*(.*)([\'\"])/si', |
---|
| 1676 | '/^([\'\"])\s*about\s*:(.*)([\'\"])/si' |
---|
| 1677 | ), |
---|
| 1678 | Array( |
---|
| 1679 | '\\1oddjob:\\2\\1', |
---|
| 1680 | //'\\1uucp:\\2\\1', -> doclinks notes |
---|
| 1681 | '\\1amaretto:\\2\\1', |
---|
| 1682 | '\\1round:\\2\\1' |
---|
| 1683 | ) |
---|
[1472] | 1684 | ), |
---|
| 1685 | |
---|
[2] | 1686 | '/^style/i' => |
---|
| 1687 | Array( |
---|
| 1688 | Array( |
---|
| 1689 | '/expression/i', |
---|
| 1690 | '/behaviou*r/i', |
---|
| 1691 | '/binding/i', |
---|
| 1692 | '/include-source/i', |
---|
| 1693 | '/url\s*\(\s*([\'\"]*)\s*https*:.*([\'\"]*)\s*\)/si', |
---|
| 1694 | '/url\s*\(\s*([\'\"]*)\s*\S+\s*script:.*([\'\"]*)\s*\)/si' |
---|
| 1695 | ), |
---|
| 1696 | Array( |
---|
| 1697 | 'idiocy', |
---|
| 1698 | 'idiocy', |
---|
| 1699 | 'idiocy', |
---|
| 1700 | 'idiocy', |
---|
| 1701 | 'url(\\1http://securityfocus.com/\\1)', |
---|
| 1702 | 'url(\\1http://securityfocus.com/\\1)' |
---|
| 1703 | ) |
---|
| 1704 | ) |
---|
| 1705 | ) |
---|
| 1706 | ); |
---|
| 1707 | |
---|
| 1708 | $add_attr_to_tag = Array( |
---|
| 1709 | '/^a$/i' => Array('target' => '"_new"') |
---|
| 1710 | ); |
---|
[1472] | 1711 | |
---|
| 1712 | |
---|
[2] | 1713 | $trusted_body = sanitize($body, |
---|
| 1714 | $tag_list, |
---|
| 1715 | $rm_tags_with_content, |
---|
| 1716 | $self_closing_tags, |
---|
| 1717 | $force_tag_closing, |
---|
| 1718 | $rm_attnames, |
---|
| 1719 | $bad_attvals, |
---|
| 1720 | $add_attr_to_tag |
---|
| 1721 | ); |
---|
[1472] | 1722 | |
---|
[2] | 1723 | return $trusted_body; |
---|
| 1724 | } |
---|
[1472] | 1725 | |
---|
[2] | 1726 | function decodeBody($body, $encoding, $charset=null) |
---|
| 1727 | { |
---|
[4416] | 1728 | |
---|
[2] | 1729 | if ($encoding == 'quoted-printable') |
---|
[828] | 1730 | { |
---|
[2] | 1731 | $body = quoted_printable_decode($body); |
---|
[1792] | 1732 | |
---|
[4795] | 1733 | } |
---|
| 1734 | else if ($encoding == 'base64') |
---|
| 1735 | { |
---|
| 1736 | $body = base64_decode($body); |
---|
| 1737 | } |
---|
| 1738 | // All other encodings are returned raw. |
---|
| 1739 | if (strtolower($charset) == "utf-8") |
---|
| 1740 | return utf8_decode($body); |
---|
| 1741 | else |
---|
| 1742 | return $body; |
---|
| 1743 | } |
---|
| 1744 | |
---|
[4436] | 1745 | |
---|
| 1746 | /** |
---|
| 1747 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 1748 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 1749 | * @param $images |
---|
| 1750 | * @param $msgno |
---|
| 1751 | * @param $body |
---|
| 1752 | * @param $msg_folder |
---|
| 1753 | */ |
---|
[4416] | 1754 | function process_embedded_images($images, $msgno, $body, $msg_folder) |
---|
[2] | 1755 | { |
---|
[1472] | 1756 | |
---|
[4416] | 1757 | foreach ($images as $image) |
---|
[4795] | 1758 | { |
---|
[4416] | 1759 | $image['cid'] = eregi_replace("<", "", $image['cid']); |
---|
| 1760 | $image['cid'] = eregi_replace(">", "", $image['cid']); |
---|
[5134] | 1761 | |
---|
| 1762 | $body = str_replace("src=\"cid:".$image['cid']."\"", " src=\"./inc/get_archive.php?msgFolder=$msg_folder&msgNumber=$msgno&indexPart=".$image['pid']."\" ", $body); |
---|
| 1763 | $body = str_replace("src='cid:".$image['cid']."'", " src=\"./inc/get_archive.php?msgFolder=$msg_folder&msgNumber=$msgno&indexPart=".$image['pid']."\"", $body); |
---|
| 1764 | $body = str_replace("src=cid:".$image['cid'], " src=\"./inc/get_archive.php?msgFolder=$msg_folder&msgNumber=$msgno&indexPart=".$image['pid']."\"", $body); |
---|
[4795] | 1765 | } |
---|
| 1766 | return $body; |
---|
[2] | 1767 | } |
---|
[1472] | 1768 | |
---|
[2] | 1769 | function replace_special_characters($body) |
---|
| 1770 | { |
---|
| 1771 | // Suspected TAGS! |
---|
[4416] | 1772 | // $tag_list = Array('blink','object','meta','html','link','frame','iframe','layer','ilayer','plaintext','script','style','img','applet','embed','head','frameset','xml','xmp'); |
---|
[4795] | 1773 | |
---|
[4416] | 1774 | // remove MS Office's proprietary tag |
---|
| 1775 | //$body = mb_ereg_replace('<!\-\-\[if [^!]* mso .*\]>.*<!\[endif\]\-\->', '', $body); |
---|
| 1776 | |
---|
[4795] | 1777 | // Layout problem: Change html elements |
---|
| 1778 | // with absolute position to relate position, CASE INSENSITIVE. |
---|
| 1779 | $body = @mb_eregi_replace("POSITION: ABSOLUTE;","",$body); |
---|
[2] | 1780 | |
---|
[5134] | 1781 | //Remove Comentario Expresso |
---|
| 1782 | $findExpCom[] = '<!-- TAG <'; |
---|
| 1783 | $findExpCom[] = '> Removed by ExpressoMail -->'; |
---|
| 1784 | $body = str_replace($findExpCom, '', $body); |
---|
| 1785 | ///--------------------------------// |
---|
| 1786 | |
---|
[4416] | 1787 | // tags to be removed doe to security reasons |
---|
| 1788 | $tag_list = Array( |
---|
[5134] | 1789 | 'blink','object','frame','iframe', |
---|
[4416] | 1790 | 'layer','ilayer','plaintext','script', |
---|
| 1791 | 'applet','embed','frameset','xml','xmp' |
---|
| 1792 | ); |
---|
[4795] | 1793 | |
---|
[4416] | 1794 | foreach($tag_list as $index => $tag) { |
---|
[5134] | 1795 | $body = @mb_eregi_replace("<$tag\\b[^>]*>(.*?)</$tag>", '', $body); |
---|
[4795] | 1796 | } |
---|
[4416] | 1797 | |
---|
[5134] | 1798 | $body = @mb_eregi_replace("<meta[^>]*>", '', $body); |
---|
| 1799 | $body = @mb_eregi_replace("<base[^>]*>", '', $body); |
---|
| 1800 | |
---|
[4416] | 1801 | //try to wrap CSS code instead of remove STYLE tags |
---|
| 1802 | require_once('../library/csstidy/class.csstidy.php'); |
---|
| 1803 | $css = new csstidy(); |
---|
| 1804 | $css->set_cfg('preserve_css', false); |
---|
[6] | 1805 | |
---|
[4416] | 1806 | $regs_found = array(); |
---|
| 1807 | $tags_found = @mb_eregi("<style\b[^>]*>(.*?)</style>", $body, $regs_found); |
---|
[5134] | 1808 | $wrapper_class = 'ExpressoCssWrapper'.time(); |
---|
[4416] | 1809 | |
---|
| 1810 | foreach ($regs_found as $block_found) { |
---|
| 1811 | $n_start = strpos($block_found, '>')+1; |
---|
| 1812 | $n_length = strrpos($block_found, '<')-$n_start; |
---|
| 1813 | $bf_innerHTML = substr($block_found, $n_start, $n_length); |
---|
| 1814 | |
---|
| 1815 | $bf_innerHTML = mb_ereg_replace('<!--', '', $bf_innerHTML); |
---|
| 1816 | $bf_innerHTML = mb_ereg_replace('-->', '', $bf_innerHTML); |
---|
[2] | 1817 | |
---|
[4416] | 1818 | $css->parse($bf_innerHTML); |
---|
| 1819 | |
---|
| 1820 | $prefix = ".$wrapper_class "; |
---|
[5134] | 1821 | if( isset($css->css[41]) && count($css->css[41] > 0)) |
---|
[4416] | 1822 | foreach ($css->css[41] as $key => $value) { |
---|
[4457] | 1823 | //explode multiple selectors per block |
---|
| 1824 | $selectors = explode(',', $key); |
---|
| 1825 | |
---|
| 1826 | foreach ($selectors as $selector) { |
---|
| 1827 | if (ereg('\*', $key)) { |
---|
| 1828 | //skip selecto '*' |
---|
| 1829 | continue; |
---|
[4795] | 1830 | } |
---|
[4457] | 1831 | |
---|
| 1832 | $selector = eregi_replace('[^#\.]*body.*', '', $selector); |
---|
| 1833 | $css->css[41][$prefix.trim($selector)] = $value; |
---|
| 1834 | } |
---|
[4416] | 1835 | unset($css->css[41][$key]); |
---|
[2] | 1836 | } |
---|
[4416] | 1837 | |
---|
| 1838 | $body = str_replace($block_found, '<style>'.$css->print->plain().'</style>', $body); |
---|
[2] | 1839 | } |
---|
[4416] | 1840 | |
---|
| 1841 | |
---|
[650] | 1842 | // Malicious Code Remove |
---|
[1923] | 1843 | $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] | 1844 | preg_match_all($dirtyCodePattern,$body,$rest,PREG_PATTERN_ORDER); |
---|
[4416] | 1845 | foreach($rest[0] as $i => $val) { |
---|
[1270] | 1846 | 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] | 1847 | $body = str_replace($rest[1][$i],"<".$rest[2][$i].$rest[3][$i].$rest[7][$i].">",$body); |
---|
[4416] | 1848 | } |
---|
[4795] | 1849 | |
---|
[4777] | 1850 | /* |
---|
| 1851 | * Remove deslocamento a esquerda colocado pelo Outlook. |
---|
| 1852 | * Este delocamento faz com que algumas palavras fiquem escondidas atras da barra lateral do expresso. |
---|
| 1853 | */ |
---|
| 1854 | $body = mb_ereg_replace("(<p[^>]*)(text-indent:[^>;]*-[^>;]*;)([^>]*>)","\\1\\3",$body); |
---|
| 1855 | $body = mb_ereg_replace("(<p[^>]*)(margin-right:[^>;]*-[^>;]*;)([^>]*>)","\\1\\3",$body); |
---|
| 1856 | $body = mb_ereg_replace("(<p[^>]*)(margin-left:[^>;]*-[^>;]*;)([^>]*>)","\\1\\3",$body); |
---|
| 1857 | //--------------------------------------------------------------------------------------------// |
---|
[4795] | 1858 | |
---|
[4989] | 1859 | //Remoção de tags <span></span> para correção de erro no firefox |
---|
[5134] | 1860 | //Comentado pois estes replaces geram erros no html da msg, não se pode garantir que o os </span></span> sejam realmente os fechamentos dos <span><span>. |
---|
| 1861 | //Caso realmente haja a nescessidade de remover estes spans deve ser repensado a forma de como faze-lo. |
---|
| 1862 | // $body = mb_eregi_replace("<span><span>","",$body); |
---|
| 1863 | // $body = mb_eregi_replace("</span></span>","",$body); |
---|
[4996] | 1864 | |
---|
[5134] | 1865 | //Correção para compatibilização com Outlook, ao visualizar a mensagem |
---|
[4795] | 1866 | $body = mb_ereg_replace('<!--\[','<!-- [',$body); |
---|
[3294] | 1867 | $body = mb_ereg_replace('<!\[endif\]-->', '<![endif]-->', $body); |
---|
[4795] | 1868 | |
---|
[4416] | 1869 | return "<div class=\"$wrapper_class\"><span>".$body.'</span></div>'; |
---|
[5134] | 1870 | |
---|
[4795] | 1871 | } |
---|
[5079] | 1872 | |
---|
[4784] | 1873 | function replace_links_callback($matches) |
---|
[4800] | 1874 | { |
---|
[4784] | 1875 | if($matches[3]) |
---|
| 1876 | $pref = $matches[3]; |
---|
| 1877 | else |
---|
| 1878 | $pref = $matches[3] = 'http'; |
---|
[4795] | 1879 | |
---|
[4784] | 1880 | return '<a href="'.$pref.'://'.$matches[4].$matches[5].'" target="_blank">'.$matches[4].$matches[5].'</a>'; |
---|
| 1881 | } |
---|
[4795] | 1882 | |
---|
| 1883 | |
---|
[4436] | 1884 | /** |
---|
| 1885 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 1886 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 1887 | * @param $body corpo da mensagem |
---|
| 1888 | */ |
---|
| 1889 | function replace_links(&$body) |
---|
[4795] | 1890 | { |
---|
[4784] | 1891 | // Trata urls do tipo aaaa.bbb.empresa |
---|
| 1892 | // Usadas na intranet. |
---|
| 1893 | $pattern = '/(?<=[\s|(<br>)|\n|\r|;])(((http|https|ftp|ftps)?:\/\/((?:[\w]\.?)+(?::[\d]+)?[:\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\:\/\w.\-~&=?%;@+]*))/i'; |
---|
| 1894 | $replacement = '<a href="://$4$5" target="_blank">$4$5</a>'; |
---|
| 1895 | $body = preg_replace_callback($pattern,array( &$this, 'replace_links_callback'), $body); |
---|
[1897] | 1896 | |
---|
[4795] | 1897 | } |
---|
| 1898 | |
---|
[91] | 1899 | function get_signature($msg, $msg_number, $msg_folder) |
---|
[1035] | 1900 | { |
---|
[3352] | 1901 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
| 1902 | include_once("class.db_functions.inc.php"); |
---|
| 1903 | foreach ($msg->file_type[$msg_number] as $index => $file_type) |
---|
| 1904 | { |
---|
| 1905 | $sign = array(); |
---|
| 1906 | $temp = $this->get_info_head_msg($msg_number); |
---|
| 1907 | if($temp['ContentType'] =='normal') return $sign; |
---|
| 1908 | $file_type = strtolower($file_type); |
---|
| 1909 | if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') |
---|
[91] | 1910 | { |
---|
[3394] | 1911 | if ($temp['ContentType'] == 'signature') |
---|
[3352] | 1912 | { |
---|
[3394] | 1913 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 1914 | $this->mbox = $this->open_mbox($msg_folder); |
---|
[1035] | 1915 | |
---|
[3352] | 1916 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); |
---|
[1035] | 1917 | |
---|
[3352] | 1918 | $imap_msg = @imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
| 1919 | $imap_msg .= @imap_body($this->mbox, $msg_number, FT_UID); |
---|
[1035] | 1920 | |
---|
[3352] | 1921 | $certificado = new certificadoB(); |
---|
| 1922 | $validade = $certificado->verificar($imap_msg); |
---|
[3394] | 1923 | $sign[] = $certificado->msg_sem_assinatura; |
---|
[3352] | 1924 | if ($certificado->apresentado) |
---|
| 1925 | { |
---|
| 1926 | $from = $header->from; |
---|
| 1927 | foreach ($from as $id => $object) |
---|
| 1928 | { |
---|
| 1929 | $fromname = $object->personal; |
---|
| 1930 | $fromaddress = $object->mailbox . "@" . $object->host; |
---|
| 1931 | } |
---|
| 1932 | foreach ($certificado->erros_ssl as $item) |
---|
| 1933 | { |
---|
| 1934 | $sign[] = $item . "#@#"; |
---|
| 1935 | } |
---|
[1035] | 1936 | |
---|
[3352] | 1937 | if (count($certificado->erros_ssl) < 1) |
---|
| 1938 | { |
---|
| 1939 | $check_msg = 'Message untouched'; |
---|
| 1940 | if(strtoupper($fromaddress) == strtoupper($certificado->dados['EMAIL'])) |
---|
| 1941 | { |
---|
| 1942 | $check_msg .= ' and authentic###'; |
---|
| 1943 | } |
---|
| 1944 | else |
---|
| 1945 | { |
---|
| 1946 | $check_msg .= ' with signer different from sender#@#'; |
---|
| 1947 | } |
---|
| 1948 | $sign[] = $check_msg; |
---|
| 1949 | } |
---|
| 1950 | |
---|
| 1951 | $sign[] = 'Message signed by: ###' . $certificado->dados['NOME']; |
---|
| 1952 | $sign[] = 'Certificate email: ###' . $certificado->dados['EMAIL']; |
---|
| 1953 | $sign[] = 'Mail from: ###' . $fromaddress; |
---|
| 1954 | $sign[] = 'Certificate Authority: ###' . $certificado->dados['EMISSOR']; |
---|
| 1955 | $sign[] = 'Validity of certificate: ###' . gmdate('r',openssl_to_timestamp($certificado->dados['FIM_VALIDADE'])); |
---|
| 1956 | $sign[] = 'Message date: ###' . $header->Date; |
---|
[1035] | 1957 | |
---|
[3352] | 1958 | $cert = openssl_x509_parse($certificado->cert_assinante); |
---|
[1035] | 1959 | |
---|
[3352] | 1960 | $sign_alert = array(); |
---|
| 1961 | $sign_alert[] = 'Certificate Owner###:\n'; |
---|
| 1962 | $sign_alert[] = 'Common Name (CN)### ' . $cert[subject]['CN'] . '\n'; |
---|
| 1963 | $X = substr($certificado->dados['NASCIMENTO'] ,0,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,2,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,4,4); |
---|
| 1964 | $sign_alert[]= 'Organization (O)### ' . $cert[subject]['O'] . '\n'; |
---|
| 1965 | $sign_alert[]= 'Organizational Unit (OU)### ' . $cert[subject]['OU'][0] . '\n'; |
---|
| 1966 | //$sign_alert[] = 'Serial Number### ' . $cert['serialNumber'] . '\n'; |
---|
| 1967 | $sign_alert[] = 'Personal Data###:' . '\n'; |
---|
| 1968 | $sign_alert[] = 'Birthday### ' . $X . '\n'; |
---|
| 1969 | $sign_alert[]= 'Fiscal Id### ' . $certificado->dados['CPF'] . '\n'; |
---|
| 1970 | $sign_alert[]= 'Identification### ' . $certificado->dados['RG'] . '\n\n'; |
---|
| 1971 | $sign_alert[]= 'Certificate Issuer###:\n'; |
---|
| 1972 | $sign_alert[]= 'Common Name (CN)### ' . $cert[issuer]['CN'] . '\n'; |
---|
| 1973 | $sign_alert[]= 'Organization (O)### ' . $cert[issuer]['O'] . '\n'; |
---|
| 1974 | $sign_alert[]= 'Organizational Unit (OU)### ' . $cert[issuer]['OU'][0] . '\n\n'; |
---|
| 1975 | $sign_alert[]= 'Validity###:\n'; |
---|
| 1976 | $H = data_hora($cert[validFrom]); |
---|
| 1977 | $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); |
---|
| 1978 | $sign_alert[]= 'Valid From### ' . $X . '\n'; |
---|
| 1979 | $H = data_hora($cert[validTo]); |
---|
| 1980 | $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); |
---|
| 1981 | $sign_alert[]= 'Valid Until### ' . $X; |
---|
| 1982 | $sign[] = $sign_alert; |
---|
| 1983 | |
---|
| 1984 | $this->db = new db_functions(); |
---|
| 1985 | |
---|
| 1986 | // TODO: testar se existe um certificado no banco e verificar qual ᅵ o mais atual. |
---|
| 1987 | if(!$certificado->dados['EXPIRADO'] && !$certificado->dados['REVOGADO'] && count($certificado->erros_ssl) < 1) |
---|
| 1988 | $this->db->insert_certificate(strtolower($certificado->dados['EMAIL']), $certificado->cert_assinante, $certificado->dados['SERIALNUMBER'], $certificado->dados['AUTHORITYKEYIDENTIFIER']); |
---|
[91] | 1989 | } |
---|
[3352] | 1990 | else |
---|
| 1991 | { |
---|
| 1992 | $sign[] = "<span style=color:red>" . $this->functions->getLang('Invalid signature') . "</span>"; |
---|
| 1993 | foreach($certificado->erros_ssl as $item) |
---|
| 1994 | $sign[] = "<span style=color:red>" . $this->functions->getLang($item) . "</span>"; |
---|
| 1995 | } |
---|
| 1996 | } |
---|
[91] | 1997 | } |
---|
[3352] | 1998 | } |
---|
| 1999 | return $sign; |
---|
[91] | 2000 | } |
---|
| 2001 | |
---|
[4436] | 2002 | |
---|
| 2003 | /** |
---|
| 2004 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 2005 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 2006 | * @param $images |
---|
| 2007 | * @param $msg_number |
---|
| 2008 | * @param $msg_folder |
---|
| 2009 | */ |
---|
[4416] | 2010 | function get_thumbs($images, $msg_number, $msg_folder) |
---|
[2] | 2011 | { |
---|
[4416] | 2012 | |
---|
[5134] | 2013 | if (!count($images)) return ''; |
---|
[4416] | 2014 | |
---|
[5134] | 2015 | foreach ($images as $key => $value) { |
---|
| 2016 | $images[$key]['width'] = 160; |
---|
| 2017 | $images[$key]['height'] = 120; |
---|
| 2018 | $images[$key]['url'] = "inc/get_archive.php?msgFolder=".$msg_folder."&msgNumber=".$msg_number."&indexPart=".$image['pid']."&image=true"; |
---|
[4795] | 2019 | } |
---|
[5134] | 2020 | |
---|
| 2021 | return json_encode($images); |
---|
[2] | 2022 | } |
---|
[1472] | 2023 | |
---|
[2] | 2024 | /*function delete_msg($params) |
---|
| 2025 | { |
---|
| 2026 | $folder = $params['folder']; |
---|
| 2027 | $msgs_to_delete = explode(",",$params['msgs_to_delete']); |
---|
[1472] | 2028 | |
---|
[2] | 2029 | $mbox_stream = $this->open_mbox($folder); |
---|
[1472] | 2030 | |
---|
[2] | 2031 | foreach ($msgs_to_delete as $msg_number){ |
---|
| 2032 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
| 2033 | } |
---|
| 2034 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
| 2035 | return $params['msgs_to_delete']; |
---|
| 2036 | }*/ |
---|
| 2037 | |
---|
| 2038 | // Novo |
---|
| 2039 | function delete_msgs($params) |
---|
| 2040 | { |
---|
[4795] | 2041 | |
---|
[2] | 2042 | $folder = $params['folder']; |
---|
[51] | 2043 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); |
---|
[2] | 2044 | $msgs_number = explode(",",$params['msgs_number']); |
---|
[5134] | 2045 | if(array_key_exists('border_ID' ,$params)) |
---|
[2] | 2046 | $border_ID = $params['border_ID']; |
---|
[5134] | 2047 | else |
---|
| 2048 | $border_ID = ''; |
---|
[2] | 2049 | $return = array(); |
---|
[4795] | 2050 | |
---|
[5134] | 2051 | if (array_key_exists('get_previous_msg' , $params) && $params['get_previous_msg']){ |
---|
[2] | 2052 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
[449] | 2053 | // Fix problem in unserialize function JS. |
---|
| 2054 | $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); |
---|
| 2055 | } |
---|
[2] | 2056 | |
---|
[4795] | 2057 | //$mbox_stream = $this->open_mbox($folder); |
---|
[504] | 2058 | $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] | 2059 | |
---|
[2] | 2060 | foreach ($msgs_number as $msg_number) |
---|
| 2061 | { |
---|
| 2062 | if (imap_delete($mbox_stream, $msg_number, FT_UID)); |
---|
| 2063 | $return['msgs_number'][] = $msg_number; |
---|
| 2064 | } |
---|
[4795] | 2065 | |
---|
[2] | 2066 | $return['folder'] = $folder; |
---|
| 2067 | $return['border_ID'] = $border_ID; |
---|
[4795] | 2068 | |
---|
[51] | 2069 | if($mbox_stream) |
---|
| 2070 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 2071 | return $return; |
---|
| 2072 | } |
---|
| 2073 | |
---|
[1472] | 2074 | |
---|
[2] | 2075 | function refresh($params) |
---|
| 2076 | { |
---|
[3265] | 2077 | |
---|
[5134] | 2078 | $return = array(); |
---|
| 2079 | $return['new_msgs'] = 0; |
---|
[2] | 2080 | $folder = $params['folder']; |
---|
| 2081 | $msg_range_begin = $params['msg_range_begin']; |
---|
| 2082 | $msg_range_end = $params['msg_range_end']; |
---|
| 2083 | $msgs_existent = $params['msgs_existent']; |
---|
[1472] | 2084 | $sort_box_type = $params['sort_box_type']; |
---|
[2] | 2085 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 2086 | $msgs_in_the_server = array(); |
---|
[53] | 2087 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
[828] | 2088 | $msgs_in_the_server = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); |
---|
| 2089 | $msgs_in_the_server = array_keys($msgs_in_the_server); |
---|
[1472] | 2090 | |
---|
[828] | 2091 | $num_msgs = (count($msgs_in_the_server) - imap_num_recent($this->mbox)); |
---|
[5134] | 2092 | |
---|
[5158] | 2093 | $dif = ($params['msg_range_end'] - $params['msg_range_begin']) +1; |
---|
| 2094 | if(!count($msgs_in_the_server)){ |
---|
| 2095 | $msg_range_begin -= $dif; |
---|
| 2096 | $msg_range_end -= $dif; |
---|
| 2097 | $msgs_in_the_server = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); |
---|
| 2098 | $msgs_in_the_server = array_keys($msgs_in_the_server); |
---|
| 2099 | $num_msgs = NULL; |
---|
| 2100 | $return['msg_range_begin'] = $msg_range_begin; |
---|
| 2101 | $return['msg_range_end'] = $msg_range_end; |
---|
| 2102 | } |
---|
| 2103 | $return['new_msgs'] = imap_num_recent($this->mbox); |
---|
| 2104 | |
---|
[1472] | 2105 | $msgs_in_the_client = explode(",", $msgs_existent); |
---|
[51] | 2106 | |
---|
[2] | 2107 | $msg_to_insert = array_diff($msgs_in_the_server, $msgs_in_the_client); |
---|
[5134] | 2108 | |
---|
| 2109 | if(count($msg_to_insert) > 0 && $return['new_msgs'] == 0 && $msgs_in_the_client[0] != ""){ |
---|
| 2110 | $aux = 0; |
---|
| 2111 | while(array_key_exists($aux, $msg_to_insert)){ |
---|
| 2112 | if($msg_to_insert[$aux] > $msgs_in_the_client[0]){ |
---|
| 2113 | $return['new_msgs'] += 1; |
---|
| 2114 | } |
---|
| 2115 | $aux++; |
---|
| 2116 | } |
---|
| 2117 | }else if(count($msg_to_insert) > 0 && $msgs_in_the_server && $msgs_in_the_client[0] != "" && $return['new_msgs'] == 0){ |
---|
| 2118 | $aux = 0; |
---|
| 2119 | while(array_key_exists($aux, $msg_to_insert)){ |
---|
| 2120 | if($msg_to_insert[$aux] == $msgs_in_the_server[$aux]){ |
---|
| 2121 | $return['new_msgs'] += 1; |
---|
| 2122 | } |
---|
| 2123 | $aux++; |
---|
| 2124 | } |
---|
[5158] | 2125 | }else if($num_msgs < $msg_range_end && $return['new_msgs'] == 0 && count($msg_to_insert) > 0 && $msg_range_end == $dif){ |
---|
[5134] | 2126 | $return['tot_msgs'] = $num_msgs; |
---|
| 2127 | } |
---|
| 2128 | |
---|
[5158] | 2129 | if(!count($msgs_in_the_server)){ |
---|
| 2130 | return Array(); |
---|
| 2131 | } |
---|
| 2132 | |
---|
[271] | 2133 | $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); |
---|
[2] | 2134 | $msgs_to_exec = array(); |
---|
[3265] | 2135 | foreach($msg_to_insert as $msg_number) |
---|
| 2136 | $msgs_to_exec[] = $msg_number; |
---|
[4764] | 2137 | //sort($msgs_to_exec); |
---|
[2] | 2138 | $i = 0; |
---|
[3265] | 2139 | foreach($msgs_to_exec as $msg_number) |
---|
[2] | 2140 | { |
---|
[614] | 2141 | /*A função imap_headerinfo não traz o cabeçalho completo, e sim alguns |
---|
[1472] | 2142 | * atributos do cabeçalho. Como eu preciso do atributo Importance |
---|
[614] | 2143 | * para saber se o email é importante ou não, uso abaixo a função |
---|
| 2144 | * imap_fetchheader e busco o atributo importance nela para passar |
---|
| 2145 | * para as funções ajax. Isso faz com que eu acesse o cabeçalho |
---|
| 2146 | * duas vezes e de duas formas diferentes, mas em contrapartida, eu |
---|
| 2147 | * não preciso reimplementar o método utilizando o fetchheader. |
---|
| 2148 | */ |
---|
[3955] | 2149 | |
---|
| 2150 | $tempHeader = @imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); |
---|
[1035] | 2151 | $flag = preg_match('/importance *: *(.*)\r/i', $tempHeader, $importance); |
---|
[689] | 2152 | $return[$i]['Importance'] = $flag==0?"Normal":$importance[1]; |
---|
[1472] | 2153 | |
---|
[1752] | 2154 | $msg_sample = $this->get_msg_sample($msg_number); |
---|
| 2155 | $return[$i]['msg_sample'] = $msg_sample; |
---|
| 2156 | |
---|
[535] | 2157 | $header = $this->get_header($msg_number); |
---|
[2] | 2158 | if (!is_object($header)) |
---|
[828] | 2159 | continue; |
---|
| 2160 | |
---|
[2] | 2161 | $return[$i]['msg_number'] = $msg_number; |
---|
[3955] | 2162 | |
---|
| 2163 | //get the next msg number to append this msg in the view in a correct place |
---|
| 2164 | $msg_key_position = array_search($msg_number, $msgs_in_the_server); |
---|
| 2165 | |
---|
[4764] | 2166 | $return[$i]['msg_key_position'] = $msg_key_position; |
---|
| 2167 | if($msg_key_position !== false && array_key_exists($msg_key_position + 1,$msgs_in_the_server) !== false) |
---|
[3955] | 2168 | $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position + 1]; |
---|
[4764] | 2169 | else |
---|
| 2170 | $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position]; |
---|
[1472] | 2171 | |
---|
[2] | 2172 | $return[$i]['msg_folder'] = $folder; |
---|
[3955] | 2173 | // Atribui o tipo (normal, signature ou cipher) ao campo Content-Type |
---|
[3265] | 2174 | $return[$i]['ContentType'] = $this->getMessageType($msg_number, $tempHeader); |
---|
[2] | 2175 | $return[$i]['Recent'] = $header->Recent; |
---|
| 2176 | $return[$i]['Unseen'] = $header->Unseen; |
---|
| 2177 | $return[$i]['Answered'] = $header->Answered; |
---|
| 2178 | $return[$i]['Deleted'] = $header->Deleted; |
---|
| 2179 | $return[$i]['Draft'] = $header->Draft; |
---|
| 2180 | $return[$i]['Flagged'] = $header->Flagged; |
---|
| 2181 | |
---|
[3106] | 2182 | $return[$i]['udate'] = $header->udate; |
---|
| 2183 | |
---|
[2] | 2184 | $from = $header->from; |
---|
| 2185 | $return[$i]['from'] = array(); |
---|
| 2186 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 2187 | $return[$i]['from']['name'] = $tmp[0]->text; |
---|
| 2188 | $return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
[1472] | 2189 | //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; |
---|
[5134] | 2190 | if(!$return[$i]['from']['name'] || trim($return[$i]['from']['name']) === '') |
---|
[2] | 2191 | $return[$i]['from']['name'] = $return[$i]['from']['email']; |
---|
[1472] | 2192 | |
---|
[2] | 2193 | /*$toaddress = imap_mime_header_decode($header->toaddress); |
---|
| 2194 | $return[$i]['toaddress'] = ''; |
---|
| 2195 | foreach ($toaddress as $tmp) |
---|
| 2196 | $return[$i]['toaddress'] .= $tmp->text;*/ |
---|
| 2197 | $to = $header->to; |
---|
| 2198 | $return[$i]['to'] = array(); |
---|
[5134] | 2199 | if(isset($to[0]->personal)) |
---|
[2] | 2200 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
[5134] | 2201 | if(trim($return[$i]['to']['name']) === '') |
---|
| 2202 | $return[$i]['to']['name'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
| 2203 | else |
---|
[2] | 2204 | $return[$i]['to']['name'] = $tmp[0]->text; |
---|
| 2205 | $return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
| 2206 | $return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; |
---|
[5134] | 2207 | if(isset($header->cc)) |
---|
[3777] | 2208 | $cc = $header->cc; |
---|
[5134] | 2209 | |
---|
| 2210 | if ( isset($cc) && (!$return[$i]['to']['name'] || $return[$i]['to']['name'] == '@') ){ |
---|
[3777] | 2211 | $return[$i]['to']['name'] = $cc[0]->personal; |
---|
| 2212 | $return[$i]['to']['email'] = $cc[0]->mailbox . "@" . $cc[0]->host; |
---|
| 2213 | } |
---|
[5134] | 2214 | $return[$i]['subject'] = ( isset( $header->fetchsubject ) ) ? $this->decode_string($header->fetchsubject) : ''; |
---|
| 2215 | if($return[$i]['subject'] == "" || $return[$i]['subject'] == '' || $return[$i]['subject'] == null ){ |
---|
| 2216 | $return[$i]['subject'] = $this->functions->getLang("(no subject) "); |
---|
| 2217 | } |
---|
[2] | 2218 | $return[$i]['Size'] = $header->Size; |
---|
| 2219 | $return[$i]['reply_toaddress'] = $header->reply_toaddress; |
---|
[1472] | 2220 | |
---|
[5134] | 2221 | if($return[$i]['to']['email'] == '@' || $return[$i]['to']['email'] =='undisclosed-recipients@' || $return[$i]['to']['name'] =='undisclosed-recipients@' |
---|
| 2222 | || $return[$i]['to']['name'] == null){ |
---|
| 2223 | $return[$i]['to']['email'] = $return[$i]['from']['email']; |
---|
| 2224 | $return[$i]['to']['name'] = $return[$i]['from']['name']; |
---|
| 2225 | $return[$i]['to']['full'] = $return[$i]['reply_toaddress']; |
---|
| 2226 | } |
---|
| 2227 | |
---|
[2] | 2228 | $return[$i]['attachment'] = array(); |
---|
[3265] | 2229 | if (!isset($imap_attachment)) |
---|
| 2230 | { |
---|
| 2231 | include_once("class.imap_attachment.inc.php"); |
---|
| 2232 | $imap_attachment = new imap_attachment(); |
---|
| 2233 | } |
---|
[51] | 2234 | $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); |
---|
[2] | 2235 | $i++; |
---|
| 2236 | } |
---|
[3265] | 2237 | $return['quota'] = $this->get_quota(array('folder_id' => $folder)); |
---|
| 2238 | $return['sort_box_type'] = $params['sort_box_type']; |
---|
[3427] | 2239 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 2240 | { |
---|
| 2241 | $this->open_mbox($folder); |
---|
| 2242 | } |
---|
[4819] | 2243 | |
---|
[271] | 2244 | $return['msgs_to_delete'] = $msg_to_delete; |
---|
[3493] | 2245 | $return['offsetToGMT'] = $this->functions->CalculateDateOffset(); |
---|
[411] | 2246 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 2247 | imap_close($this->mbox); |
---|
[828] | 2248 | |
---|
[2] | 2249 | return $return; |
---|
| 2250 | } |
---|
| 2251 | |
---|
[1035] | 2252 | /** |
---|
| 2253 | * Método que faz a verificação do Content-Type do e-mail e verifica se é um e-mail normal, |
---|
| 2254 | * assinado ou cifrado. |
---|
| 2255 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
| 2256 | * @param $headers Uma String contendo os Headers do e-mail retornados pela função imap_imap_fetchheader |
---|
| 2257 | * @param $msg_number O número da mesagem |
---|
| 2258 | * @return Retorna o tipo da mensagem (normal, signature, cipher). |
---|
| 2259 | */ |
---|
| 2260 | function getMessageType($msg_number, $headers = false){ |
---|
[3394] | 2261 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
[1035] | 2262 | $contentType = "normal"; |
---|
| 2263 | if (!$headers){ |
---|
| 2264 | $headers = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); |
---|
| 2265 | } |
---|
[3394] | 2266 | |
---|
| 2267 | if (preg_match("/pkcs7-signature/i", $headers) == 1){ |
---|
[1035] | 2268 | $contentType = "signature"; |
---|
[3394] | 2269 | } else if (preg_match("/pkcs7-mime/i", $headers) == 1){ |
---|
| 2270 | $contentType = testa_p7m( imap_body($this->mbox, imap_msgno($this->mbox, $msg_number)) ); |
---|
[1035] | 2271 | } |
---|
| 2272 | |
---|
| 2273 | return $contentType; |
---|
| 2274 | } |
---|
| 2275 | |
---|
[1375] | 2276 | /** |
---|
| 2277 | * Metodo que retorna todas as pastas do usuario logado. |
---|
| 2278 | * @param $params array opcional para repassar os argumentos ao metodo. |
---|
| 2279 | * Se usar $params['noSharedFolders'] = true, ira retornar todas as pastas do usuário logado, |
---|
| 2280 | * excluindo as compartilhadas para ele. |
---|
[3553] | 2281 | * Se usar $params['folderType'] = "default" irá retornar somente as pastas defaults |
---|
| 2282 | * Se usar $params['folderType'] = "personal" irá retornar somente as pastas pessoais |
---|
| 2283 | * Se usar $params['folderType'] = null irá retornar todas as pastas |
---|
[1472] | 2284 | * @return Retorna um array contendo as seguintes informacoes de cada pasta: folder_unseen, |
---|
[1375] | 2285 | * folder_id, folder_name, folder_parent e folder_hasChildren. |
---|
[1472] | 2286 | */ |
---|
[449] | 2287 | function get_folders_list($params = null) |
---|
[2] | 2288 | { |
---|
[1472] | 2289 | $mbox_stream = $this->open_mbox(); |
---|
[5134] | 2290 | if($params && array_key_exists('onload', $params) && $params['onload'] && $_SESSION['phpgw_info']['expressomail']['server']['certificado']){ |
---|
[4726] | 2291 | $this->delete_mailbox(array("del_past" => "INBOX".$this->imap_delimiter."decifradas")); |
---|
[1953] | 2292 | } |
---|
[650] | 2293 | |
---|
[1824] | 2294 | $inbox = 'INBOX'; |
---|
[3018] | 2295 | $drafts = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']; |
---|
[5134] | 2296 | $sent = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']; |
---|
[3018] | 2297 | $spam = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']; |
---|
[5134] | 2298 | $trash = $inbox . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; |
---|
| 2299 | if(array_key_exists('uid2cn', $_SESSION['phpgw_info']['user']['preferences']['expressoMail'] )) |
---|
[3018] | 2300 | $uid2cn = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn']; |
---|
[5134] | 2301 | else |
---|
| 2302 | $uid2cn = false; |
---|
[3018] | 2303 | // Free others requests |
---|
| 2304 | session_write_close(); |
---|
[1816] | 2305 | |
---|
[3018] | 2306 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
[3790] | 2307 | |
---|
[5134] | 2308 | if ( $params && isset($params['noSharedFolders']) ) |
---|
[3790] | 2309 | $folders_list = array_merge(imap_getmailboxes($mbox_stream, $serverString, 'INBOX' ), imap_getmailboxes($mbox_stream, $serverString, 'INBOX/*' ) ); |
---|
| 2310 | else |
---|
| 2311 | $folders_list = imap_getmailboxes($mbox_stream, $serverString, '*' ); |
---|
[3761] | 2312 | |
---|
[3018] | 2313 | $folders_list = array_slice($folders_list,0,$this->foldersLimit); |
---|
| 2314 | |
---|
| 2315 | $tmp = array(); |
---|
| 2316 | $resultMine = array(); |
---|
[5134] | 2317 | $resultSharedMine = array(); |
---|
[3018] | 2318 | $resultDefault = array(); |
---|
[5134] | 2319 | $resultSharedDefault = array(); |
---|
| 2320 | $aux = ""; |
---|
| 2321 | $qtd = -1 ; |
---|
[3018] | 2322 | |
---|
[2] | 2323 | if (is_array($folders_list)) { |
---|
[3761] | 2324 | reset($folders_list); |
---|
| 2325 | $this->ldap = new ldap_functions(); |
---|
[1472] | 2326 | |
---|
[2] | 2327 | $i = 0; |
---|
[3761] | 2328 | while (list($key, $val) = each($folders_list)) { |
---|
| 2329 | $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); |
---|
[1035] | 2330 | |
---|
[3761] | 2331 | //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); |
---|
[4824] | 2332 | $tmp_folder_id = explode("}", $val->name ); |
---|
[3761] | 2333 | |
---|
[4824] | 2334 | $folderUser = trim( strpos( $tmp_folder_id[1], $this->imap_delimiter , 5 ) ); |
---|
| 2335 | |
---|
| 2336 | $folderUser = trim( substr( $tmp_folder_id[1], 0, $folderUser ) ); |
---|
| 2337 | |
---|
| 2338 | $Permission = true; |
---|
| 2339 | |
---|
| 2340 | if( $folderUser != "INBOX" && $folderUser != "" ) |
---|
| 2341 | { |
---|
[5134] | 2342 | $Permission = @imap_getacl( $mbox_stream, $folderUser ); |
---|
[4824] | 2343 | } |
---|
| 2344 | $tmp_folder_id[1] = mb_convert_encoding( $tmp_folder_id[1], "ISO-8859-1", "UTF7-IMAP" ); |
---|
| 2345 | |
---|
| 2346 | if( $tmp_folder_id[1]=='INBOX'.$this->imap_delimiter.'decifradas') |
---|
| 2347 | { |
---|
[3761] | 2348 | continue; |
---|
| 2349 | } |
---|
[5134] | 2350 | |
---|
| 2351 | if(isset($status->unseen)) |
---|
[3761] | 2352 | $result[$i]['folder_unseen'] = $status->unseen; |
---|
[5134] | 2353 | |
---|
[3761] | 2354 | $folder_id = $tmp_folder_id[1]; |
---|
[2] | 2355 | $result[$i]['folder_id'] = $folder_id; |
---|
[1472] | 2356 | |
---|
[2] | 2357 | $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); |
---|
| 2358 | $result[$i]['folder_name'] = array_pop($tmp_folder_parent); |
---|
[96] | 2359 | $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; |
---|
[3761] | 2360 | |
---|
[3018] | 2361 | if ($uid2cn && substr($folder_id,0,4) == 'user') { |
---|
[1340] | 2362 | //$this->ldap = new ldap_functions(); |
---|
[1816] | 2363 | if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])) { |
---|
[325] | 2364 | $result[$i]['folder_name'] = $cn; |
---|
| 2365 | } |
---|
| 2366 | } |
---|
[1472] | 2367 | |
---|
[2] | 2368 | $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); |
---|
| 2369 | $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; |
---|
[1472] | 2370 | |
---|
[96] | 2371 | if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) |
---|
[2] | 2372 | $result[$i]['folder_hasChildren'] = 1; |
---|
| 2373 | else |
---|
| 2374 | $result[$i]['folder_hasChildren'] = 0; |
---|
[5134] | 2375 | $user = explode($this->imap_delimiter , $tmp_folder_id[1]); |
---|
[1816] | 2376 | switch ($tmp_folder_id[1]) { |
---|
[1824] | 2377 | case $inbox: |
---|
[5134] | 2378 | case $drafts: |
---|
[1824] | 2379 | case $sent: |
---|
| 2380 | case $spam: |
---|
| 2381 | case $trash: |
---|
[3761] | 2382 | $resultDefault[]=$result[$i]; |
---|
| 2383 | break; |
---|
[5134] | 2384 | case "user". $this->imap_delimiter . $user[1]: |
---|
| 2385 | case "user". $this->imap_delimiter . $user[1] . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']: |
---|
| 2386 | case "user". $this->imap_delimiter . $user[1] . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']: |
---|
| 2387 | case "user". $this->imap_delimiter . $user[1] . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']: |
---|
| 2388 | case "user". $this->imap_delimiter . $user[1] . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']: |
---|
| 2389 | if($aux != $user[1]){ |
---|
| 2390 | $aux = $user[1]; |
---|
| 2391 | $qtd += 1; |
---|
| 2392 | } |
---|
| 2393 | if( isset($resultSharedDefault[$qtd]) && !is_array($resultSharedDefault[$qtd])) |
---|
| 2394 | $resultSharedDefault[$qtd] = array(); |
---|
| 2395 | $resultSharedDefault[$qtd][]=$result[$i]; |
---|
| 2396 | break; |
---|
[1816] | 2397 | default: |
---|
[5134] | 2398 | if($user[0] == $inbox) |
---|
[3761] | 2399 | $resultMine[]=$result[$i]; |
---|
[5134] | 2400 | else{ |
---|
| 2401 | if($aux != $user[1]){ |
---|
| 2402 | $aux = $user[1]; |
---|
| 2403 | $qtd += 1; |
---|
| 2404 | } |
---|
| 2405 | if(!is_array($resultSharedDefault[$qtd])) |
---|
| 2406 | $resultSharedMine[$qtd] = array(); |
---|
| 2407 | $resultSharedMine[$qtd][]=$result[$i]; |
---|
[1816] | 2408 | } |
---|
| 2409 | |
---|
[4824] | 2410 | } |
---|
| 2411 | $i++; |
---|
| 2412 | } |
---|
[2] | 2413 | } |
---|
[1472] | 2414 | |
---|
[5134] | 2415 | if ( $params && !array_key_exists('noQuotaInfo',$params) ) { |
---|
[3564] | 2416 | //Get quota info of current folder |
---|
| 2417 | $current_folder = "INBOX"; |
---|
[5134] | 2418 | if($params && isset($params['folder'])) |
---|
[3564] | 2419 | $current_folder = $params['folder']; |
---|
[3790] | 2420 | |
---|
[3564] | 2421 | $arr_quota_info = $this->get_quota(array('folder_id' => $current_folder)); |
---|
| 2422 | } else { |
---|
| 2423 | $arr_quota_info = array(); |
---|
| 2424 | } |
---|
[3790] | 2425 | |
---|
[1816] | 2426 | // Sorting resultMine |
---|
| 2427 | foreach ($resultMine as $folder_info) |
---|
[2] | 2428 | { |
---|
| 2429 | $array_tmp[] = $folder_info['folder_id']; |
---|
| 2430 | } |
---|
[1472] | 2431 | |
---|
[2] | 2432 | natcasesort($array_tmp); |
---|
[3575] | 2433 | |
---|
[3790] | 2434 | $result2 = array(); |
---|
[1472] | 2435 | |
---|
[2] | 2436 | foreach ($array_tmp as $key => $folder_id) |
---|
| 2437 | { |
---|
[1816] | 2438 | $result2[] = $resultMine[$key]; |
---|
[2] | 2439 | } |
---|
[1816] | 2440 | |
---|
| 2441 | // Sorting resultDefault |
---|
| 2442 | foreach ($resultDefault as $key => $folder_id) |
---|
| 2443 | { |
---|
| 2444 | switch ($resultDefault[$key]['folder_id']) { |
---|
[1824] | 2445 | case $inbox: |
---|
[1816] | 2446 | $resultDefault2[0] = $resultDefault[$key]; |
---|
| 2447 | break; |
---|
[5134] | 2448 | case $drafts: |
---|
[1816] | 2449 | $resultDefault2[1] = $resultDefault[$key]; |
---|
| 2450 | break; |
---|
[5134] | 2451 | case $sent: |
---|
[1816] | 2452 | $resultDefault2[2] = $resultDefault[$key]; |
---|
| 2453 | break; |
---|
[1824] | 2454 | case $spam: |
---|
[1816] | 2455 | $resultDefault2[3] = $resultDefault[$key]; |
---|
| 2456 | break; |
---|
[1824] | 2457 | case $trash: |
---|
[1816] | 2458 | $resultDefault2[4] = $resultDefault[$key]; |
---|
| 2459 | break; |
---|
| 2460 | } |
---|
| 2461 | } |
---|
[3553] | 2462 | |
---|
[5134] | 2463 | $shareds = array(); |
---|
| 2464 | if(!empty($resultSharedDefault)) |
---|
| 2465 | for($i = 0; $i <= $qtd; $i++){ |
---|
| 2466 | foreach ($resultSharedDefault[$i] as $key => $folder_id) |
---|
| 2467 | { |
---|
| 2468 | $user = explode($this->imap_delimiter , $resultSharedDefault[$i][$key]['folder_id']); |
---|
| 2469 | |
---|
| 2470 | switch ($resultSharedDefault[$i][$key]['folder_id']) { |
---|
| 2471 | case "user". $this->imap_delimiter . $user[1]: |
---|
| 2472 | $resultSharedDefault2[0] = $resultSharedDefault[$i][$key]; |
---|
| 2473 | break; |
---|
| 2474 | case "user". $this->imap_delimiter . $user[1]. $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']: |
---|
| 2475 | $resultSharedDefault2[1] = $resultSharedDefault[$i][$key]; |
---|
| 2476 | break; |
---|
| 2477 | case "user". $this->imap_delimiter . $user[1]. $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']: |
---|
| 2478 | $resultSharedDefault2[2] = $resultSharedDefault[$i][$key]; |
---|
| 2479 | break; |
---|
| 2480 | case "user". $this->imap_delimiter . $user[1]. $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']: |
---|
| 2481 | $resultSharedDefault2[3] = $resultSharedDefault[$i][$key]; |
---|
| 2482 | break; |
---|
| 2483 | case "user". $this->imap_delimiter . $user[1] . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']: |
---|
| 2484 | $resultSharedDefault2[4] = $resultSharedDefault[$i][$key]; |
---|
| 2485 | break; |
---|
| 2486 | } |
---|
| 2487 | } |
---|
| 2488 | if($resultDefault2 != null) |
---|
| 2489 | $shareds = array_merge($shareds, $resultSharedDefault2); |
---|
| 2490 | if(isset($resultSharedMine[$i]) && $resultSharedMine[$i] != null) |
---|
| 2491 | $shareds = array_merge($shareds, $resultSharedMine[$i]); |
---|
| 2492 | $resultSharedDefault2 = array(); |
---|
| 2493 | } |
---|
| 2494 | if ( $params && isset($params['folderType']) && $params['folderType'] == 'default' ) |
---|
[3790] | 2495 | return array_merge($resultDefault2, $arr_quota_info); |
---|
[1816] | 2496 | |
---|
[5134] | 2497 | if ( $params && array_key_exists('folderType', $params) && $params['folderType'] == 'personal' ) |
---|
[3790] | 2498 | return array_merge($result2, $arr_quota_info); |
---|
| 2499 | |
---|
[3553] | 2500 | // Merge default folders and personal |
---|
[3790] | 2501 | $result2 = array_merge($resultDefault2, $result2); |
---|
[5134] | 2502 | if(!empty($shareds)) |
---|
| 2503 | $result2 = array_merge($result2, $shareds); |
---|
[3553] | 2504 | return array_merge($result2, $arr_quota_info); |
---|
[2] | 2505 | } |
---|
[1472] | 2506 | |
---|
[2] | 2507 | function create_mailbox($arr) |
---|
| 2508 | { |
---|
| 2509 | $namebox = $arr['newp']; |
---|
| 2510 | $mbox_stream = $this->open_mbox(); |
---|
| 2511 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[51] | 2512 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); |
---|
[1472] | 2513 | |
---|
[2] | 2514 | $result = "Ok"; |
---|
[51] | 2515 | if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
[2] | 2516 | { |
---|
| 2517 | $result = implode("<br />\n", imap_errors()); |
---|
[1472] | 2518 | } |
---|
| 2519 | |
---|
[51] | 2520 | if($mbox_stream) |
---|
| 2521 | imap_close($mbox_stream); |
---|
[1472] | 2522 | |
---|
[2] | 2523 | return $result; |
---|
[1472] | 2524 | |
---|
[2] | 2525 | } |
---|
[1472] | 2526 | |
---|
[2] | 2527 | function create_extra_mailbox($arr) |
---|
| 2528 | { |
---|
| 2529 | $nameboxs = explode(";",$arr['nw_folders']); |
---|
| 2530 | $result = ""; |
---|
| 2531 | $mbox_stream = $this->open_mbox(); |
---|
| 2532 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[1472] | 2533 | foreach($nameboxs as $key=>$tmp){ |
---|
[2] | 2534 | if($tmp != ""){ |
---|
| 2535 | if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ |
---|
| 2536 | $result = implode("<br />\n", imap_errors()); |
---|
[51] | 2537 | if($mbox_stream) |
---|
[1472] | 2538 | imap_close($mbox_stream); |
---|
[2] | 2539 | return $result; |
---|
| 2540 | } |
---|
| 2541 | } |
---|
| 2542 | } |
---|
[51] | 2543 | if($mbox_stream) |
---|
| 2544 | imap_close($mbox_stream); |
---|
[2] | 2545 | return true; |
---|
| 2546 | } |
---|
[1472] | 2547 | |
---|
[2] | 2548 | function delete_mailbox($arr) |
---|
| 2549 | { |
---|
| 2550 | $namebox = $arr['del_past']; |
---|
| 2551 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[1953] | 2552 | $mbox_stream = $this->mbox ? $this->mbox : $this->open_mbox(); |
---|
[2] | 2553 | //$del_folder = imap_deletemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox"); |
---|
[1472] | 2554 | |
---|
[2] | 2555 | $result = "Ok"; |
---|
| 2556 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
| 2557 | if(!imap_deletemailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
| 2558 | { |
---|
| 2559 | $result = implode("<br />\n", imap_errors()); |
---|
| 2560 | } |
---|
[1953] | 2561 | /* |
---|
[51] | 2562 | if($mbox_stream) |
---|
| 2563 | imap_close($mbox_stream); |
---|
[1953] | 2564 | */ |
---|
[2] | 2565 | return $result; |
---|
| 2566 | } |
---|
[1472] | 2567 | |
---|
[2] | 2568 | function ren_mailbox($arr) |
---|
| 2569 | { |
---|
| 2570 | $namebox = $arr['current']; |
---|
| 2571 | $new_box = $arr['rename']; |
---|
| 2572 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 2573 | $mbox_stream = $this->open_mbox(); |
---|
| 2574 | //$ren_folder = imap_renamemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox","{".$imap_server."}INBOX.$new_box"); |
---|
[1472] | 2575 | |
---|
[2] | 2576 | $result = "Ok"; |
---|
| 2577 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
[51] | 2578 | $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); |
---|
[1472] | 2579 | |
---|
[2] | 2580 | if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) |
---|
| 2581 | { |
---|
[1472] | 2582 | $result = imap_errors(); |
---|
[2] | 2583 | } |
---|
[51] | 2584 | if($mbox_stream) |
---|
| 2585 | imap_close($mbox_stream); |
---|
[2] | 2586 | return $result; |
---|
[1472] | 2587 | |
---|
[2] | 2588 | } |
---|
[1472] | 2589 | |
---|
[2] | 2590 | function get_num_msgs($params) |
---|
| 2591 | { |
---|
| 2592 | $folder = $params['folder']; |
---|
[411] | 2593 | if(!$this->mbox || !is_resource($this->mbox)) { |
---|
[2] | 2594 | $this->mbox = $this->open_mbox($folder); |
---|
[411] | 2595 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[2] | 2596 | return imap_last_error(); |
---|
[1472] | 2597 | } |
---|
[2] | 2598 | $num_msgs = imap_num_msg($this->mbox); |
---|
[432] | 2599 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 2600 | imap_close($this->mbox); |
---|
[1472] | 2601 | |
---|
[2] | 2602 | return $num_msgs; |
---|
| 2603 | } |
---|
[1472] | 2604 | |
---|
[1912] | 2605 | function folder_exists($folder){ |
---|
| 2606 | $mbox = $this->open_mbox(); |
---|
| 2607 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 2608 | $list = imap_getmailboxes($mbox,$serverString, $folder); |
---|
| 2609 | $return = is_array($list); |
---|
| 2610 | imap_close($mbox); |
---|
| 2611 | return $return; |
---|
| 2612 | } |
---|
| 2613 | |
---|
[2] | 2614 | function send_mail($params) |
---|
| 2615 | { |
---|
[5134] | 2616 | require_once $_SESSION['rootPath'] . '/API/class.servicelocator.php'; |
---|
| 2617 | $mailService = ServiceLocator::getService('mail'); |
---|
| 2618 | |
---|
[2] | 2619 | include_once("class.db_functions.inc.php"); |
---|
| 2620 | $db = new db_functions(); |
---|
| 2621 | $fromaddress = $params['input_from'] ? explode(';',$params['input_from']) : ""; |
---|
[5134] | 2622 | $message_attachments_contents = (isset($params['message_attachments_content'])) ? $params['message_attachments_content'] : false; |
---|
| 2623 | |
---|
[449] | 2624 | ## |
---|
| 2625 | # @AUTHOR Rodrigo Souza dos Santos |
---|
[3369] | 2626 | # @DATE 2008/09/17$fileName |
---|
[449] | 2627 | # @BRIEF Checks if the user has permission to send an email with the email address used. |
---|
| 2628 | ## |
---|
| 2629 | if ( is_array($fromaddress) && ($fromaddress[1] != $_SESSION['phpgw_info']['expressomail']['user']['email']) ) |
---|
| 2630 | { |
---|
| 2631 | $deny = true; |
---|
| 2632 | foreach( $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] as $key => $val ) |
---|
| 2633 | if ( array_key_exists('mail', $val) && $val['mail'][0] == $fromaddress[1] ) |
---|
| 2634 | $deny = false and end($_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes']); |
---|
| 2635 | |
---|
| 2636 | if ( $deny ) |
---|
| 2637 | return "The server denied your request to send a mail, you cannot use this mail address."; |
---|
| 2638 | } |
---|
[828] | 2639 | |
---|
[2] | 2640 | $toaddress = implode(',',$db->getAddrs(explode(',',$params['input_to']))); |
---|
| 2641 | $ccaddress = implode(',',$db->getAddrs(explode(',',$params['input_cc']))); |
---|
| 2642 | $ccoaddress = implode(',',$db->getAddrs(explode(',',$params['input_cco']))); |
---|
[5134] | 2643 | |
---|
| 2644 | $toaddress = preg_replace('/<\s+/', '<', $toaddress); |
---|
| 2645 | $toaddress = preg_replace('/\s+>/', '>', $toaddress); |
---|
| 2646 | |
---|
| 2647 | $ccaddress = preg_replace('/<\s+/', '<', $ccaddress); |
---|
| 2648 | $ccaddress = preg_replace('/\s+>/', '>', $ccaddress); |
---|
| 2649 | |
---|
| 2650 | $ccoaddress = preg_replace('/<\s+/', '<', $ccoaddress); |
---|
| 2651 | $ccoaddress = preg_replace('/\s+>/', '>', $ccoaddress); |
---|
| 2652 | |
---|
[3527] | 2653 | $replytoaddress = $params['input_replyto']; |
---|
[2] | 2654 | $subject = $params['input_subject']; |
---|
[271] | 2655 | $msg_uid = $params['msg_id']; |
---|
[2] | 2656 | $return_receipt = $params['input_return_receipt']; |
---|
[614] | 2657 | $is_important = $params['input_important_message']; |
---|
[1035] | 2658 | $encrypt = $params['input_return_cripto']; |
---|
| 2659 | $signed = $params['input_return_digital']; |
---|
| 2660 | |
---|
[5134] | 2661 | $message_attachments = $params['message_attachments']; |
---|
| 2662 | |
---|
| 2663 | if(substr($params['input_to'],-1) == ',') |
---|
| 2664 | $params['input_to'] = substr($params['input_to'],0,-1); |
---|
| 2665 | |
---|
| 2666 | if(substr($params['input_cc'],-1) == ',') |
---|
| 2667 | $params['input_cc'] = substr($params['input_cc'],0,-1); |
---|
| 2668 | |
---|
| 2669 | if(substr($params['input_cco'],-1) == ',') |
---|
| 2670 | $params['input_cco'] = substr($params['input_cco'],0,-1); |
---|
| 2671 | |
---|
| 2672 | |
---|
| 2673 | // Valida numero Maximo de Destinatarios |
---|
| 2674 | if($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoAdmin_maximum_recipients'] > 0) |
---|
| 2675 | { |
---|
| 2676 | $sendersNumber = count(explode(',',$params['input_to'])); |
---|
| 2677 | |
---|
| 2678 | if($params['input_cc']) |
---|
| 2679 | $sendersNumber += count(explode(',',$params['input_cc'])); |
---|
| 2680 | if($params['input_cco']) |
---|
| 2681 | $sendersNumber += count(explode(',',$params['input_cco'])); |
---|
| 2682 | |
---|
| 2683 | $userMaxmimumSenders = $db->getMaximumRecipientsUser($this->username); |
---|
| 2684 | if($userMaxmimumSenders) |
---|
| 2685 | { |
---|
| 2686 | if($sendersNumber > $userMaxmimumSenders) |
---|
| 2687 | return $this->functions->getLang('Number of recipients greater than allowed'); |
---|
| 2688 | } |
---|
| 2689 | else |
---|
| 2690 | { |
---|
| 2691 | $ldap = new ldap_functions(); |
---|
| 2692 | $groupsToUser = $ldap->get_user_groups($this->username); |
---|
| 2693 | |
---|
| 2694 | $groupMaxmimumSenders = $db->getMaximumRecipientsGroup($groupsToUser); |
---|
| 2695 | |
---|
| 2696 | if($groupMaxmimumSenders > 0) |
---|
| 2697 | { |
---|
| 2698 | if($sendersNumber > $groupMaxmimumSenders) |
---|
| 2699 | return $this->functions->getLang('Number of recipients greater than allowed'); |
---|
| 2700 | } |
---|
| 2701 | else |
---|
| 2702 | { |
---|
| 2703 | if($sendersNumber > $_SESSION['phpgw_info']['expresso']['expressoMail']['expressoAdmin_maximum_recipients']) |
---|
| 2704 | return $this->functions->getLang('Number of recipients greater than allowed'); |
---|
| 2705 | } |
---|
| 2706 | } |
---|
| 2707 | |
---|
| 2708 | } |
---|
| 2709 | //Fim Valida numero maximo de destinatarios |
---|
| 2710 | |
---|
| 2711 | |
---|
| 2712 | //Valida envio de email para shared accounts |
---|
| 2713 | if($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_block_institutional_comunication'] == 'true') |
---|
| 2714 | { |
---|
| 2715 | $ldap = new ldap_functions(); |
---|
| 2716 | $arrayF = explode(';', $params['input_from']); |
---|
| 2717 | |
---|
| 2718 | /* |
---|
| 2719 | * Verifica se o remetente n?o ? uma conta compartilhada |
---|
| 2720 | */ |
---|
| 2721 | if(!$ldap->isSharedAccountByMail($arrayF[1])) |
---|
| 2722 | { |
---|
| 2723 | $groupsToUser = $ldap->get_user_groups($this->username); |
---|
| 2724 | $sharedAccounts = $ldap->returnSharedsAccounts($toaddress, $ccaddress, $ccoaddress); |
---|
| 2725 | |
---|
| 2726 | /* |
---|
| 2727 | * Pega o UID do remetente |
---|
| 2728 | */ |
---|
| 2729 | $uidFrom = $ldap->mail2uid($arrayF[1]); |
---|
| 2730 | |
---|
| 2731 | /* |
---|
| 2732 | * Remove a conta compartilhada caso o uid do remetente exista na conta compartilhada |
---|
| 2733 | */ |
---|
| 2734 | foreach ($sharedAccounts as $key => $value) |
---|
| 2735 | { |
---|
| 2736 | if($value) |
---|
| 2737 | $acl = $this->getaclfrombox($value); |
---|
| 2738 | |
---|
| 2739 | if (array_key_exists($uidFrom, $acl)) |
---|
| 2740 | unset($sharedAccounts[$key]); |
---|
| 2741 | |
---|
| 2742 | } |
---|
| 2743 | |
---|
| 2744 | /* |
---|
| 2745 | * Caso ainda exista contas compartilhadas, verifica se existe alguma exce??o para estas contas |
---|
| 2746 | */ |
---|
| 2747 | if(count($sharedAccounts) > 0) |
---|
| 2748 | $accountsBlockeds = $db->validadeSharedAccounts($this->username, $groupsToUser, $sharedAccounts); |
---|
| 2749 | |
---|
| 2750 | /* |
---|
| 2751 | * Retorna as contas compartilhadas bloqueadas |
---|
| 2752 | */ |
---|
| 2753 | if(count($accountsBlockeds) > 0) |
---|
| 2754 | { |
---|
| 2755 | $return = ''; |
---|
| 2756 | |
---|
| 2757 | foreach ($accountsBlockeds as $accountBlocked) |
---|
| 2758 | $return.= $accountBlocked.', '; |
---|
| 2759 | |
---|
| 2760 | $return = substr($return,0,-2); |
---|
| 2761 | |
---|
| 2762 | return $this->functions->getLang('you are blocked from sending mail to the following addresses').': '.$return; |
---|
| 2763 | } |
---|
| 2764 | } |
---|
| 2765 | } |
---|
| 2766 | // Fim Valida envio de email para shared accounts |
---|
| 2767 | |
---|
| 2768 | |
---|
| 2769 | // TODO - implementar tratamento SMIME no novo serviço de envio de emails e retirar o AND false abaixo |
---|
| 2770 | if($params['smime'] AND false) |
---|
[1035] | 2771 | { |
---|
| 2772 | $body = $params['smime']; |
---|
| 2773 | $mail->SMIME = true; |
---|
| 2774 | // A MSG assinada deve ser testada neste ponto. |
---|
| 2775 | // Testar o certificado e a integridade da msg.... |
---|
[3271] | 2776 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
[1035] | 2777 | $erros_acumulados = ''; |
---|
| 2778 | $certificado = new certificadoB(); |
---|
| 2779 | $validade = $certificado->verificar($body); |
---|
| 2780 | if(!$validade) |
---|
| 2781 | { |
---|
| 2782 | foreach($certificado->erros_ssl as $linha_erro) |
---|
| 2783 | { |
---|
| 2784 | $erros_acumulados .= $linha_erro; |
---|
| 2785 | } |
---|
| 2786 | } |
---|
| 2787 | else |
---|
| 2788 | { |
---|
| 2789 | // Testa o CERTIFICADO: se o CPF he o do usuario logado, se pode assinar msgs e se nao esta expirado... |
---|
| 2790 | if ($certificado->apresentado) |
---|
| 2791 | { |
---|
| 2792 | if($certificado->dados['EXPIRADO']) $erros_acumulados .='Certificado expirado.'; |
---|
[4291] | 2793 | $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; |
---|
| 2794 | if($certificado->dados['CPF'] != $this->cpf) $erros_acumulados .=' CPF no certificado diferente do logado no expresso.'; |
---|
[1035] | 2795 | if(!($certificado->dados['KEYUSAGE']['digitalSignature'] && $certificado->dados['EXTKEYUSAGE']['emailProtection'])) $erros_acumulados .=' Certificado nao permite assinar mensagens.'; |
---|
| 2796 | } |
---|
| 2797 | else |
---|
| 2798 | { |
---|
| 2799 | $$erros_acumulados .= 'Nao foi possivel usar o certificado para assinar a msg'; |
---|
| 2800 | } |
---|
| 2801 | } |
---|
| 2802 | if(!$erros_acumulados =='') |
---|
| 2803 | { |
---|
| 2804 | return $erros_acumulados; |
---|
| 2805 | } |
---|
| 2806 | } |
---|
| 2807 | else |
---|
| 2808 | { |
---|
[3250] | 2809 | //Compatibilização com Outlook, ao encaminhar a mensagem |
---|
[5134] | 2810 | $body = mb_ereg_replace('<!--\[', '<!-- [', $params['body']); |
---|
[1035] | 2811 | } |
---|
[5134] | 2812 | |
---|
[3900] | 2813 | $attachments = $_FILES; |
---|
[2] | 2814 | $forwarding_attachments = $params['forwarding_attachments']; |
---|
[689] | 2815 | $local_attachments = $params['local_attachments']; |
---|
[3369] | 2816 | |
---|
[1912] | 2817 | //Test if must be saved in shared folder and change if necessary |
---|
| 2818 | if( $fromaddress[2] == 'y' ){ |
---|
| 2819 | //build shared folder path |
---|
| 2820 | $newfolder = "user".$this->imap_delimiter.$fromaddress[3].$this->imap_delimiter.$this->imap_sentfolder; |
---|
[5134] | 2821 | if($this->folder_exists($newfolder)) |
---|
| 2822 | $folder = $newfolder; |
---|
| 2823 | else |
---|
| 2824 | $folder = $params['folder']; |
---|
| 2825 | |
---|
[1912] | 2826 | } else { |
---|
| 2827 | $folder = $params['folder']; |
---|
| 2828 | } |
---|
| 2829 | |
---|
[5134] | 2830 | $folder = mb_convert_encoding($folder, 'UTF7-IMAP','ISO_8859-1'); |
---|
| 2831 | $folder = preg_replace('/INBOX[\/.]/i', 'INBOX'.$this->imap_delimiter, $folder); |
---|
[1472] | 2832 | $folder_name = $params['folder_name']; |
---|
[1035] | 2833 | |
---|
[5134] | 2834 | // TODO - tratar assinatura e remover o AND false |
---|
| 2835 | if($signed && !$params['smime'] AND false) |
---|
[1035] | 2836 | { |
---|
| 2837 | $mail->Mailer = "smime"; |
---|
| 2838 | $mail->SignedBody = true; |
---|
| 2839 | } |
---|
[1472] | 2840 | |
---|
[5134] | 2841 | |
---|
| 2842 | if($fromaddress) |
---|
| 2843 | $mailService->setFrom ('"'.$fromaddress[0].'" <'.$fromaddress[1].'>'); |
---|
| 2844 | else |
---|
| 2845 | $mailService->setFrom ('"'.$_SESSION['phpgw_info']['expressomail']['user']['firstname'].' '.$_SESSION['phpgw_info']['expressomail']['user']['lastname'].'" <'.$_SESSION['phpgw_info']['expressomail']['user']['email'].'>'); |
---|
| 2846 | //$mailService->addTo($toaddress); |
---|
| 2847 | //$mailService->addCc($ccaddress); |
---|
| 2848 | $bol = $this->add_recipients('to', $toaddress, $mailService); |
---|
| 2849 | if(!$bol){ |
---|
| 2850 | return $this->parse_error("Invalid Mail:", $toaddress); |
---|
[2] | 2851 | } |
---|
[5134] | 2852 | $bol = $this->add_recipients('cc', $ccaddress, $mailService); |
---|
| 2853 | if(!$bol){ |
---|
| 2854 | return $this->parse_error("Invalid Mail:", $ccaddress); |
---|
| 2855 | } |
---|
[4832] | 2856 | $allow = $_SESSION['phpgw_info']['server']['expressomail']['allow_hidden_copy']; |
---|
| 2857 | |
---|
[5134] | 2858 | if($allow) |
---|
[4832] | 2859 | { |
---|
[5134] | 2860 | //$mailService->addBcc($ccoaddress); |
---|
| 2861 | $bol = $this->add_recipients('cco', $ccoaddress, $mailService); |
---|
| 2862 | |
---|
| 2863 | if(!$bol){ |
---|
| 2864 | return $this->parse_error("Invalid Mail:", $ccoaddress); |
---|
| 2865 | } |
---|
[4832] | 2866 | } |
---|
[271] | 2867 | |
---|
[5134] | 2868 | $mailService->setSubject($subject); |
---|
| 2869 | $isHTML = ( (array_key_exists('type', $params) && in_array(strtolower($params['type']), array('html', 'plain')) ) ? |
---|
| 2870 | strtolower($params['type']) != 'plain' : true ); |
---|
| 2871 | |
---|
| 2872 | |
---|
| 2873 | // TODO - tratar mensagem criptografada e remover o AND false abaixo |
---|
| 2874 | if (($encrypt && $signed && $params['smime']) || ($encrypt && !$signed) AND false) // a msg deve ser enviada cifrada... |
---|
[1035] | 2875 | { |
---|
| 2876 | $email = $this->add_recipients_cert($toaddress . ',' . $ccaddress. ',' .$ccoaddress); |
---|
| 2877 | $email = explode(",",$email); |
---|
| 2878 | // Deve ser testado se foram obtidos os certificados de todos os destinatarios. |
---|
| 2879 | // Deve ser verificado um numero limite de destinatarios. |
---|
| 2880 | // Deve ser verificado se os certificados sao validos. |
---|
| 2881 | // Se uma das verificacoes falhar, nao enviar o e-mail e avisar o usuario. |
---|
| 2882 | // O array $mail->Certs_crypt soh deve ser preenchido se os certificados passarem nas verificacoes. |
---|
| 2883 | $numero_maximo = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['num_max_certs_to_cipher']; // Este valor dever ser configurado pelo administrador do site .... |
---|
| 2884 | $erros_acumulados = ""; |
---|
| 2885 | $aux_mails = array(); |
---|
| 2886 | $mail_list = array(); |
---|
| 2887 | if(count($email) > $numero_maximo) |
---|
| 2888 | { |
---|
| 2889 | $erros_acumulados .= "Excedido o numero maximo (" . $numero_maximo . ") de destinatarios para uma msg cifrada...." . chr(0x0A); |
---|
| 2890 | return $erros_acumulados; |
---|
| 2891 | } |
---|
| 2892 | // adiciona o email do remetente. eh para cifrar a msg para ele tambem. Assim vai poder visualizar a msg na pasta enviados.. |
---|
| 2893 | $email[] = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 2894 | foreach($email as $item) |
---|
| 2895 | { |
---|
| 2896 | $certificate = $db->get_certificate(strtolower($item)); |
---|
| 2897 | if(!$certificate) |
---|
| 2898 | { |
---|
| 2899 | $erros_acumulados .= "Chamada com parametro invalido. e-Mail nao pode ser vazio." . chr(0x0A); |
---|
| 2900 | return $erros_acumulados; |
---|
| 2901 | } |
---|
| 2902 | |
---|
| 2903 | if (array_key_exists("dberr1", $certificate)) |
---|
| 2904 | { |
---|
| 2905 | |
---|
| 2906 | $erros_acumulados .= "Ocorreu um erro quando pesquisava certificados dos destinatarios para cifrar a msg." . chr(0x0A); |
---|
| 2907 | return $erros_acumulados; |
---|
| 2908 | } |
---|
| 2909 | if (array_key_exists("dberr2", $certificate)) |
---|
| 2910 | { |
---|
| 2911 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado nao localizado.' . chr(0x0A); |
---|
| 2912 | //continue; |
---|
| 2913 | } |
---|
| 2914 | /* Retirado este teste para evitar mensagem de erro duplicada. |
---|
| 2915 | if (!array_key_exists("certs", $certificate)) |
---|
| 2916 | { |
---|
| 2917 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado nao localizado.' . chr(0x0A); |
---|
| 2918 | continue; |
---|
| 2919 | } |
---|
| 2920 | */ |
---|
[3271] | 2921 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
[1035] | 2922 | |
---|
| 2923 | foreach ($certificate['certs'] as $registro) |
---|
| 2924 | { |
---|
| 2925 | $c1 = new certificadoB(); |
---|
| 2926 | $c1->certificado($registro['chave_publica']); |
---|
| 2927 | if ($c1->apresentado) |
---|
| 2928 | { |
---|
| 2929 | $c2 = new Verifica_Certificado($c1->dados,$registro['chave_publica']); |
---|
| 2930 | if (!$c1->dados['EXPIRADO'] && !$c2->revogado && $c2->status) |
---|
| 2931 | { |
---|
| 2932 | $aux_mails[] = $registro['chave_publica']; |
---|
| 2933 | $mail_list[] = strtolower($item); |
---|
| 2934 | } |
---|
| 2935 | else |
---|
| 2936 | { |
---|
| 2937 | if ($c1->dados['EXPIRADO'] || $c2->revogado) |
---|
| 2938 | { |
---|
| 2939 | $db->update_certificate($c1->dados['SERIALNUMBER'],$c1->dados['EMAIL'],$c1->dados['AUTHORITYKEYIDENTIFIER'], |
---|
| 2940 | $c1->dados['EXPIRADO'],$c2->revogado); |
---|
| 2941 | } |
---|
| 2942 | |
---|
| 2943 | $erros_acumulados .= $item . ': ' . $c2->msgerro . chr(0x0A); |
---|
| 2944 | foreach($c2->erros_ssl as $linha) |
---|
| 2945 | { |
---|
| 2946 | $erros_acumulados .= $linha . chr(0x0A); |
---|
| 2947 | } |
---|
| 2948 | $erros_acumulados .= 'Emissor: ' . $c1->dados['EMISSOR'] . chr(0x0A); |
---|
| 2949 | $erros_acumulados .= $c1->dados['CRLDISTRIBUTIONPOINTS'] . chr(0x0A); |
---|
| 2950 | } |
---|
| 2951 | } |
---|
| 2952 | else |
---|
| 2953 | { |
---|
| 2954 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado invalido.' . chr(0x0A); |
---|
| 2955 | } |
---|
| 2956 | } |
---|
| 2957 | if(!(in_array(strtolower($item),$mail_list)) && !empty($erros_acumulados)) |
---|
| 2958 | { |
---|
| 2959 | return $erros_acumulados; |
---|
| 2960 | } |
---|
| 2961 | } |
---|
| 2962 | |
---|
| 2963 | $mail->Certs_crypt = $aux_mails; |
---|
| 2964 | } |
---|
[5134] | 2965 | |
---|
| 2966 | if( count($forwarding_attachments) > 0 )// Build CID images |
---|
| 2967 | $this->buildEmbeddedImages($mailService,$msg_uid,$forwarding_attachments, $body); |
---|
[1035] | 2968 | |
---|
[2] | 2969 | // Build Uploading Attachments!!! |
---|
[3387] | 2970 | if (count($attachments)>0) //Caso seja forward normal... |
---|
[2] | 2971 | { |
---|
| 2972 | $total_uploaded_size = 0; |
---|
| 2973 | foreach ($attachments as $attach) |
---|
| 2974 | { |
---|
[3900] | 2975 | if($attach['error'] == UPLOAD_ERR_INI_SIZE) |
---|
| 2976 | return $this->parse_error("message file too big"); |
---|
[3387] | 2977 | if($attach['name']=='Unknown') |
---|
| 2978 | continue; |
---|
[5134] | 2979 | $mailService->addFileAttachment($attach['tmp_name'], $attach['name'], $this->get_file_type($attach['name']), 'base64', 'attachment'); |
---|
[2] | 2980 | $total_uploaded_size = $total_uploaded_size + $attach['size']; |
---|
| 2981 | } |
---|
[5134] | 2982 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) |
---|
| 2983 | { |
---|
| 2984 | |
---|
| 2985 | $upload_max_filesize = str_replace('M','',$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) * 1024 * 1024; |
---|
| 2986 | if( $total_uploaded_size > $upload_max_filesize) |
---|
[1472] | 2987 | return $this->parse_error("message file too big"); |
---|
[3387] | 2988 | } |
---|
[828] | 2989 | } |
---|
[3387] | 2990 | if(count($local_attachments)>0) { //Caso seja forward de mensagens locais |
---|
[828] | 2991 | |
---|
[689] | 2992 | $total_uploaded_size = 0; |
---|
[5134] | 2993 | |
---|
[689] | 2994 | foreach($local_attachments as $local_attachment) { |
---|
| 2995 | $file_description = unserialize(rawurldecode($local_attachment)); |
---|
| 2996 | $tmp = array_values($file_description); |
---|
[1472] | 2997 | foreach($file_description as $i => $descriptor){ |
---|
[689] | 2998 | $tmp[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 2999 | } |
---|
[5134] | 3000 | $mailService->addFileAttachment($_FILES[$tmp[1]]['tmp_name'], $tmp[2], $this->get_file_type($tmp[2]), 'base64', 'attachment'); |
---|
[689] | 3001 | $total_uploaded_size = $total_uploaded_size + $_FILES[$tmp[1]]['size']; |
---|
| 3002 | } |
---|
[5134] | 3003 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) |
---|
| 3004 | { |
---|
| 3005 | $upload_max_filesize = str_replace('M','',$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) * 1024 * 1024; |
---|
| 3006 | if( $total_uploaded_size > $upload_max_filesize) |
---|
| 3007 | return $this->parse_error("message file too big"); |
---|
| 3008 | } |
---|
[689] | 3009 | } |
---|
[5134] | 3010 | |
---|
[271] | 3011 | // Build Forwarding Attachments!!! |
---|
[2] | 3012 | if (count($forwarding_attachments) > 0) |
---|
| 3013 | { |
---|
| 3014 | // Bug fixed for array_search function |
---|
[3018] | 3015 | $name_cid_files = array(); |
---|
[2] | 3016 | if(count($name_cid_files) > 0) { |
---|
| 3017 | $name_cid_files[count($name_cid_files)] = $name_cid_files[0]; |
---|
| 3018 | $name_cid_files[0] = null; |
---|
[1472] | 3019 | } |
---|
| 3020 | |
---|
[2] | 3021 | foreach($forwarding_attachments as $forwarding_attachment) |
---|
| 3022 | { |
---|
[5134] | 3023 | $file_description = unserialize(rawurldecode($forwarding_attachment)); |
---|
| 3024 | $tmp = array_values($file_description); |
---|
| 3025 | foreach($file_description as $i => $descriptor){ |
---|
| 3026 | $tmp[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 3027 | } |
---|
| 3028 | $file_description = $tmp; |
---|
| 3029 | $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); |
---|
| 3030 | $fileName = $file_description[2]; |
---|
| 3031 | if(!array_search(trim($fileName),$name_cid_files)) { |
---|
| 3032 | $filename_dec = html_entity_decode(rawurldecode($fileName)); |
---|
| 3033 | $mailService->addStringAttachment($fileContent, $filename_dec, $this->get_file_type($file_description[2]), $file_description[4] ); |
---|
| 3034 | |
---|
| 3035 | } |
---|
| 3036 | } |
---|
| 3037 | } |
---|
| 3038 | |
---|
| 3039 | //Build Message Attachments!!! |
---|
| 3040 | if(count($message_attachments) > 0 ) |
---|
| 3041 | { |
---|
| 3042 | foreach($message_attachments as $folder_name => $messages) |
---|
| 3043 | { |
---|
| 3044 | foreach ($messages as $message_number => $message_subject) |
---|
| 3045 | { |
---|
| 3046 | if (!$message_subject) |
---|
| 3047 | $message_subject = 'no title.eml'; |
---|
| 3048 | else |
---|
| 3049 | $message_subject .= '.eml'; |
---|
| 3050 | |
---|
| 3051 | if( $message_attachments_contents && isset($message_attachments_contents[$folder_name]) ) |
---|
| 3052 | $rawmsg = base64_decode( $message_attachments_contents[$folder_name][$message_number] ); |
---|
| 3053 | else{ |
---|
| 3054 | $mbox_stream = $this->open_mbox($folder_name); |
---|
| 3055 | $rawmsg = $this->getRawHeader($message_number) . "\r\n\r\n" . $this->getRawBody($message_number); |
---|
[271] | 3056 | } |
---|
[5134] | 3057 | |
---|
| 3058 | $return_forward[] = array( 'name' => $message_subject, 'size' => mb_strlen($rawmsg)); |
---|
| 3059 | $mailService->addStringAttachment($rawmsg, $message_subject, 'message/rfc822', '7bit', 'attachment' ); |
---|
[63] | 3060 | } |
---|
[2] | 3061 | } |
---|
| 3062 | } |
---|
[5134] | 3063 | |
---|
| 3064 | $message_size_total += strlen($params['body']); /* Tamanho do corpo da mensagem. */ |
---|
| 3065 | $message_size_total += $total_uploaded_size; /* Incrementa com os anexos da nova mensagem, se houver. */ |
---|
| 3066 | |
---|
| 3067 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 3068 | /** |
---|
| 3069 | * Faz a validação pelo tamanho máximo de mensagem permitido para o usuário. Se o usuário não estiver em nenhuma regra, usa o tamanho padrão. |
---|
| 3070 | */ |
---|
| 3071 | $default_max_size_rule = $db->get_default_max_size_rule(); |
---|
| 3072 | if(!$default_max_size_rule) |
---|
| 3073 | { |
---|
| 3074 | $default_max_size_rule = str_replace("M","",ini_get('upload_max_filesize')) * 1024 * 1024; /* hack para não bloquear o envio de email quando não for configurado um tamanho padrão */ |
---|
| 3075 | } |
---|
| 3076 | else |
---|
| 3077 | { |
---|
| 3078 | foreach($default_max_size_rule as $i=>$value) |
---|
| 3079 | { |
---|
| 3080 | $default_max_size_rule = $value['config_value']; |
---|
| 3081 | } |
---|
| 3082 | } |
---|
| 3083 | |
---|
| 3084 | $default_max_size_rule = $default_max_size_rule * 1024 * 1024; /* Tamanho da regra padrão, em bytes */ |
---|
| 3085 | $id_user = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 3086 | |
---|
| 3087 | |
---|
| 3088 | $ldap = new ldap_functions(); |
---|
| 3089 | $groups_user = $ldap->get_user_groups($id_user); |
---|
[37] | 3090 | |
---|
[5134] | 3091 | $size_rule_by_group = array(); |
---|
| 3092 | foreach($groups_user as $k=>$value_) |
---|
| 3093 | { |
---|
| 3094 | $rule_in_group = $db->get_rule_by_user_in_groups($k); |
---|
| 3095 | if ($rule_in_group != "") |
---|
| 3096 | array_push($size_rule_by_group, $rule_in_group); |
---|
| 3097 | } |
---|
| 3098 | |
---|
| 3099 | $n_rule_groups = 0; |
---|
| 3100 | $maior_valor_regra_grupo = 0; |
---|
| 3101 | foreach($size_rule_by_group as $i=>$value) |
---|
| 3102 | { |
---|
| 3103 | if(is_array($value[0])) |
---|
| 3104 | { |
---|
| 3105 | $n_rule_groups++; |
---|
| 3106 | if($value[0]['email_max_recipient'] > $maior_valor_regra_grupo) |
---|
| 3107 | $maior_valor_regra_grupo = $value[0]['email_max_recipient']; |
---|
| 3108 | } |
---|
| 3109 | } |
---|
| 3110 | |
---|
| 3111 | if($default_max_size_rule) |
---|
| 3112 | { |
---|
| 3113 | $size_rule = $db->get_rule_by_user($_SESSION['phpgw_info']['expressomail']['user']['userid']); |
---|
| 3114 | |
---|
| 3115 | if(!$size_rule && $n_rule_groups == 0) /* O usuário não está em nenhuma regra por usuário nem por grupo. Vai usar a regra padrão. */ |
---|
| 3116 | { |
---|
| 3117 | if($message_size_total > $default_max_size_rule) |
---|
| 3118 | return $this->functions->getLang("Message size greateruler than allowed (Default rule)"); |
---|
| 3119 | } |
---|
| 3120 | |
---|
| 3121 | else |
---|
| 3122 | { |
---|
| 3123 | if(count($size_rule) > 0) /* Verifica se existe regra por usuário. Se houver, ela vai se sobresair das regras por grupo. */ |
---|
| 3124 | { |
---|
| 3125 | $regra_mais_permissiva = 0; |
---|
| 3126 | foreach($size_rule as $i=>$value) |
---|
| 3127 | { |
---|
| 3128 | if($regra_mais_permissiva < $value['email_max_recipient']) |
---|
| 3129 | $regra_mais_permissiva = $value['email_max_recipient']; |
---|
| 3130 | } |
---|
| 3131 | $regra_mais_permissiva = $regra_mais_permissiva * 1024 * 1024; |
---|
| 3132 | if($message_size_total > $regra_mais_permissiva) |
---|
| 3133 | return $this->functions->getLang("Message size greater than allowed (Rule By User)"); |
---|
| 3134 | } |
---|
| 3135 | else /* Regra por grupo */ |
---|
| 3136 | { |
---|
| 3137 | $maior_valor_regra_grupo = $maior_valor_regra_grupo * 1024 * 1024; |
---|
| 3138 | if($message_size_total > $maior_valor_regra_grupo) |
---|
| 3139 | return $this->functions->getLang("Message size greater than allowed (Rule By Group)"); |
---|
| 3140 | |
---|
| 3141 | |
---|
| 3142 | } |
---|
| 3143 | } |
---|
| 3144 | } |
---|
| 3145 | /** |
---|
| 3146 | * Fim da validação do tamanho da regra do tamanho de mensagem. |
---|
| 3147 | */ |
---|
| 3148 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 3149 | |
---|
| 3150 | |
---|
| 3151 | |
---|
| 3152 | |
---|
| 3153 | |
---|
| 3154 | if($isHTML) |
---|
| 3155 | $mailService->setBodyHtml($body); |
---|
| 3156 | else |
---|
| 3157 | $mailService->setBodyText($body); |
---|
| 3158 | |
---|
[614] | 3159 | if($is_important) |
---|
[5134] | 3160 | $mailService->addHeaderField('Importance','High'); |
---|
[614] | 3161 | |
---|
[5134] | 3162 | if($return_receipt) |
---|
| 3163 | $mailService->addHeaderField('Disposition-Notification-To', $_SESSION['phpgw_info']['expressomail']['user']['email']); |
---|
[504] | 3164 | |
---|
[1472] | 3165 | |
---|
[5134] | 3166 | if ($folder != 'null'){ |
---|
| 3167 | $mbox_stream = $this->open_mbox($folder); |
---|
| 3168 | @imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, $mailService->getMessage(), "\\Seen"); |
---|
| 3169 | } |
---|
| 3170 | |
---|
| 3171 | $sent = $mailService->send(); |
---|
| 3172 | |
---|
| 3173 | if($sent !== true) |
---|
[2] | 3174 | { |
---|
[5134] | 3175 | return $this->parse_error($sent); |
---|
[2] | 3176 | } |
---|
| 3177 | else |
---|
| 3178 | { |
---|
[1035] | 3179 | if ($signed && !$params['smime']) |
---|
| 3180 | { |
---|
| 3181 | return $sent; |
---|
| 3182 | } |
---|
[1472] | 3183 | if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") |
---|
[117] | 3184 | { |
---|
| 3185 | $userid = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 3186 | $userip = $_SESSION['phpgw_info']['expressomail']['user']['session_ip']; |
---|
| 3187 | $now = date("d/m/y H:i:s"); |
---|
| 3188 | $addrs = $toaddress.$ccaddress.$ccoaddress; |
---|
[1472] | 3189 | $sent = trim($sent); |
---|
[117] | 3190 | error_log("$now - $userip - $sent [$subject] - $userid => $addrs\r\n", 3, "/home/expressolivre/mail_senders.log"); |
---|
| 3191 | } |
---|
[5134] | 3192 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts']) { |
---|
[469] | 3193 | $contacts = new dynamic_contacts(); |
---|
[485] | 3194 | $new_contacts = $contacts->add_dynamic_contacts($toaddress.",".$ccaddress.",".$ccoaddress); |
---|
| 3195 | return array("success" => true, "new_contacts" => $new_contacts); |
---|
[413] | 3196 | } |
---|
[485] | 3197 | return array("success" => true); |
---|
[2] | 3198 | } |
---|
| 3199 | } |
---|
[4416] | 3200 | |
---|
[4436] | 3201 | |
---|
| 3202 | /** |
---|
| 3203 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 3204 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 3205 | * @param $mail email |
---|
| 3206 | * @param $msg_uid uid da mensagem |
---|
| 3207 | * @param $forwarding_attachments anexos |
---|
| 3208 | */ |
---|
[5134] | 3209 | |
---|
| 3210 | function buildEmbeddedImages(&$mail,$msg_uid,&$forwarding_attachments ,&$body) |
---|
[4795] | 3211 | { |
---|
[5134] | 3212 | //Procura e retorna em $cids_imgs imagens embarcadas no corpo do e-mail |
---|
| 3213 | $pattern = '/src=("[^"]*?get_archive.php\?msgFolder=(.+)?&(amp;)?msgNumber=(.+)?&(amp;)?indexPart=(.+)?")/isU'; |
---|
[4795] | 3214 | $cid_imgs = ''; |
---|
[5134] | 3215 | preg_match_all( $pattern , $body , $cid_imgs , PREG_PATTERN_ORDER ); |
---|
| 3216 | //-------------------------------------------------------------------// |
---|
[2] | 3217 | |
---|
[5134] | 3218 | $attPostions = array(); //Array que linka a possição da imagem com o indice que esta se encontra no array $forwarding_attachments |
---|
[3018] | 3219 | |
---|
[5134] | 3220 | foreach ($forwarding_attachments as $i => $v){ // Monta o array de link |
---|
| 3221 | $desc = unserialize(rawurldecode($v)); |
---|
| 3222 | $attPostions[$desc[3]] = $i; |
---|
| 3223 | } |
---|
[3018] | 3224 | |
---|
[5134] | 3225 | //Intera as imagens encontradas |
---|
| 3226 | foreach($cid_imgs[6] as $j => $val) |
---|
| 3227 | { |
---|
| 3228 | $cid = base_convert(microtime().$j, 10, 36); //Gera um cid |
---|
[5158] | 3229 | $body = str_replace($cid_imgs[1][$j], '"cid:'.$cid.'"', $body ); //tira o src da imagem e coloca o cid. |
---|
[4416] | 3230 | $count = strlen($cid_imgs[6][$j]); |
---|
| 3231 | |
---|
[5134] | 3232 | $attach_img = $forwarding_attachments[$attPostions['\''.$cid_imgs[6][$j].'\'']]; |
---|
[4416] | 3233 | $file_description = unserialize(rawurldecode($attach_img)); |
---|
| 3234 | |
---|
| 3235 | if (is_array($file_description)) |
---|
| 3236 | foreach($file_description as $i => $descriptor) |
---|
[5134] | 3237 | $file_description[$i] = mb_ereg_replace('\'*\'','',$descriptor); |
---|
[4416] | 3238 | |
---|
| 3239 | // The image is not in the same mail? |
---|
| 3240 | if ($msg_uid != $cid_imgs[4][$j]) |
---|
[4795] | 3241 | { |
---|
[5134] | 3242 | $fa = $this->get_forwarding_attachment2($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); |
---|
| 3243 | $fileContent = &$fa['binary']; |
---|
| 3244 | $fileName = $fa['name']; |
---|
| 3245 | $fileCode = $fa['encoding']; |
---|
| 3246 | $fileType = $fa['type']; |
---|
[4795] | 3247 | $file_attached[0] = $cid_imgs[2][$j]; |
---|
| 3248 | $file_attached[1] = $cid_imgs[4][$j]; |
---|
| 3249 | $file_attached[2] = $fileName; |
---|
[5134] | 3250 | $file_attached[3] = '0.'.(string)($j+1); |
---|
[4795] | 3251 | $file_attached[4] = 'base64'; |
---|
| 3252 | $file_attached[5] = strlen($fileContent); //Size of file |
---|
[4416] | 3253 | $file_attached[6] = $cid_imgs[6][$j]; |
---|
[4795] | 3254 | $return_forward[] = $file_attached; |
---|
[4416] | 3255 | |
---|
| 3256 | if ($file_attached[3] == $file_description[3] || $msg_uid == 'undefined') |
---|
[5134] | 3257 | unset($forwarding_attachments[$attPostions['\''.$cid_imgs[6][$j].'\'']]); |
---|
[4416] | 3258 | |
---|
[4795] | 3259 | } |
---|
| 3260 | else |
---|
| 3261 | { |
---|
| 3262 | $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64'); |
---|
| 3263 | $fileName = $file_description[2]; |
---|
| 3264 | $fileCode = $file_description[4]; |
---|
[5134] | 3265 | $file_description[3] = '0.'.(string)($j+1); |
---|
[4416] | 3266 | $file_description[6] = $cid_imgs[6][$j]; |
---|
[4795] | 3267 | $fileType = $this->get_file_type($file_description[2]); |
---|
[5134] | 3268 | unset($forwarding_attachments[$attPostions['\''.$cid_imgs[6][$j].'\'']]); |
---|
[4795] | 3269 | if (!empty($file_description)) |
---|
| 3270 | { |
---|
| 3271 | $file_description[5] = strlen($fileContent); //Size of file |
---|
| 3272 | $return_forward[] = $file_description; |
---|
| 3273 | } |
---|
| 3274 | } |
---|
[4416] | 3275 | |
---|
[4795] | 3276 | if ($fileContent) |
---|
[5134] | 3277 | $mail->addStringImage($fileContent,$fileType,$fileName, $cid); |
---|
[4416] | 3278 | } |
---|
[4795] | 3279 | |
---|
| 3280 | return $return_forward; |
---|
| 3281 | } |
---|
[3018] | 3282 | function add_recipients_cert($full_address) |
---|
[1035] | 3283 | { |
---|
| 3284 | $result = ""; |
---|
| 3285 | $parse_address = imap_rfc822_parse_adrlist($full_address, ""); |
---|
| 3286 | foreach ($parse_address as $val) |
---|
| 3287 | { |
---|
| 3288 | //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; |
---|
| 3289 | if ($val->mailbox == "INVALID_ADDRESS") |
---|
| 3290 | continue; |
---|
| 3291 | if ($val->mailbox == "UNEXPECTED_DATA_AFTER_ADDRESS") |
---|
| 3292 | continue; |
---|
| 3293 | if (empty($val->personal)) |
---|
| 3294 | $result .= $val->mailbox."@".$val->host . ","; |
---|
| 3295 | else |
---|
| 3296 | $result .= $val->mailbox."@".$val->host . ","; |
---|
| 3297 | } |
---|
| 3298 | |
---|
| 3299 | return substr($result,0,-1); |
---|
| 3300 | } |
---|
| 3301 | |
---|
[2] | 3302 | function add_recipients($recipient_type, $full_address, $mail) |
---|
| 3303 | { |
---|
[3932] | 3304 | //remove a comma if is given two unexpected commas |
---|
| 3305 | $full_address = preg_replace("/, ?,/",",",$full_address); |
---|
[1472] | 3306 | $parse_address = imap_rfc822_parse_adrlist($full_address, ""); |
---|
[5134] | 3307 | $bolean = true; |
---|
[1472] | 3308 | foreach ($parse_address as $val) |
---|
[2] | 3309 | { |
---|
| 3310 | //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; |
---|
| 3311 | if ($val->mailbox == "INVALID_ADDRESS") |
---|
| 3312 | continue; |
---|
[1472] | 3313 | |
---|
[2] | 3314 | if (empty($val->personal)) |
---|
| 3315 | { |
---|
| 3316 | switch($recipient_type) |
---|
| 3317 | { |
---|
| 3318 | case "to": |
---|
[5134] | 3319 | $mail->AddTo($val->mailbox."@".$val->host); |
---|
[2] | 3320 | break; |
---|
| 3321 | case "cc": |
---|
[5134] | 3322 | $mail->AddCc($val->mailbox."@".$val->host); |
---|
[2] | 3323 | break; |
---|
| 3324 | case "cco": |
---|
[5134] | 3325 | $mail->AddBcc($val->mailbox."@".$val->host); |
---|
[2] | 3326 | break; |
---|
| 3327 | } |
---|
| 3328 | } |
---|
| 3329 | else |
---|
| 3330 | { |
---|
| 3331 | switch($recipient_type) |
---|
| 3332 | { |
---|
| 3333 | case "to": |
---|
[5134] | 3334 | $mail->AddTo($val->mailbox."@".$val->host, $val->personal); |
---|
[2] | 3335 | break; |
---|
| 3336 | case "cc": |
---|
[5134] | 3337 | $mail->AddCc($val->mailbox."@".$val->host, $val->personal); |
---|
[2] | 3338 | break; |
---|
| 3339 | case "cco": |
---|
[5134] | 3340 | $mail->AddBcc($val->mailbox."@".$val->host, $val->personal); |
---|
[2] | 3341 | break; |
---|
| 3342 | } |
---|
| 3343 | } |
---|
[5134] | 3344 | if($val->mailbox == "UNEXPECTED_DATA_AFTER_ADDRESS"){ |
---|
| 3345 | $bolean = false; |
---|
[2] | 3346 | } |
---|
[5134] | 3347 | |
---|
| 3348 | } |
---|
| 3349 | return $bolean; |
---|
[2] | 3350 | } |
---|
[1472] | 3351 | |
---|
[2] | 3352 | function get_forwarding_attachment($msg_folder, $msg_number, $msg_part, $encoding) |
---|
| 3353 | { |
---|
[4416] | 3354 | include_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; |
---|
| 3355 | $attachment = new attachment(); |
---|
[5134] | 3356 | $attachment->decodeConf['rfc_822bodies'] = true; //Forçar a não decodificação de mensagens em anexo. |
---|
[4416] | 3357 | $attachment->setStructureFromMail($msg_folder, $msg_number); |
---|
| 3358 | return $attachment->getAttachment($msg_part); |
---|
[2] | 3359 | } |
---|
[1472] | 3360 | |
---|
[5134] | 3361 | function get_forwarding_attachment2($msg_folder, $msg_number, $msg_part, $encoding) |
---|
| 3362 | { |
---|
| 3363 | include_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; |
---|
| 3364 | $attachment = new attachment(); |
---|
| 3365 | $attachment->setStructureFromMail($msg_folder, $msg_number); |
---|
| 3366 | $return = $attachment->getAttachmentInfo($msg_part); |
---|
| 3367 | $return['binary'] = $attachment->getAttachment($msg_part); |
---|
| 3368 | return $return; |
---|
| 3369 | } |
---|
| 3370 | |
---|
[2] | 3371 | function del_last_caracter($string) |
---|
| 3372 | { |
---|
| 3373 | $string = substr($string,0,(strlen($string) - 1)); |
---|
[1472] | 3374 | return $string; |
---|
[2] | 3375 | } |
---|
[1472] | 3376 | |
---|
[2] | 3377 | function del_last_two_caracters($string) |
---|
| 3378 | { |
---|
| 3379 | $string = substr($string,0,(strlen($string) - 2)); |
---|
[1472] | 3380 | return $string; |
---|
[2] | 3381 | } |
---|
[1472] | 3382 | |
---|
[828] | 3383 | function messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd) |
---|
[659] | 3384 | { |
---|
[1625] | 3385 | if ($sort_box_type != "SORTFROM" && $search_box_type!= "FLAGGED"){ |
---|
[970] | 3386 | $imapsort = imap_sort($this->mbox,constant($sort_box_type),$sort_box_reverse,SE_UID,$search_box_type); |
---|
| 3387 | foreach($imapsort as $iuid) |
---|
| 3388 | $sort[$iuid] = ""; |
---|
[1518] | 3389 | |
---|
| 3390 | if ($offsetBegin == -1 && $offsetEnd ==-1 ) |
---|
| 3391 | $slice_array = false; |
---|
| 3392 | else |
---|
| 3393 | $slice_array = true; |
---|
[970] | 3394 | } |
---|
| 3395 | else |
---|
[659] | 3396 | { |
---|
[970] | 3397 | $sort = array(); |
---|
| 3398 | if ($offsetBegin > $offsetEnd) {$temp=$offsetEnd; $offsetEnd=$offsetBegin; $offsetBegin=$temp;} |
---|
| 3399 | $num_msgs = imap_num_msg($this->mbox); |
---|
| 3400 | if ($offsetEnd > $num_msgs) {$offsetEnd = $num_msgs;} |
---|
[975] | 3401 | $slice_array = true; |
---|
| 3402 | |
---|
[983] | 3403 | for ($i=$num_msgs; $i>0; $i--) |
---|
[828] | 3404 | { |
---|
[983] | 3405 | if ($sort_box_type == "SORTARRIVAL" && $sort_box_reverse && count($sort) >= $offsetEnd) |
---|
| 3406 | break; |
---|
[970] | 3407 | $iuid = @imap_uid($this->mbox,$i); |
---|
| 3408 | $header = $this->get_header($iuid); |
---|
| 3409 | // List UNSEEN messages. |
---|
| 3410 | if($search_box_type == "UNSEEN" && (!trim($header->Recent) && !trim($header->Unseen))){ |
---|
| 3411 | continue; |
---|
| 3412 | } |
---|
| 3413 | // List SEEN messages. |
---|
| 3414 | elseif($search_box_type == "SEEN" && (trim($header->Recent) || trim($header->Unseen))){ |
---|
| 3415 | continue; |
---|
| 3416 | } |
---|
| 3417 | // List ANSWERED messages. |
---|
| 3418 | elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ |
---|
| 3419 | continue; |
---|
| 3420 | } |
---|
| 3421 | // List FLAGGED messages. |
---|
| 3422 | elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ |
---|
| 3423 | continue; |
---|
| 3424 | } |
---|
| 3425 | |
---|
| 3426 | if($sort_box_type=='SORTFROM') { |
---|
| 3427 | if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) |
---|
| 3428 | $from = $header->to; |
---|
| 3429 | else |
---|
| 3430 | $from = $header->from; |
---|
[5134] | 3431 | if(isset($from[0]->personal)) |
---|
[970] | 3432 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
[5134] | 3433 | else |
---|
| 3434 | $tmp = null; |
---|
| 3435 | if (isset($tmp[0]->text)) |
---|
[970] | 3436 | $sort[$iuid] = $tmp[0]->text; |
---|
| 3437 | else |
---|
| 3438 | $sort[$iuid] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
| 3439 | } |
---|
| 3440 | else if($sort_box_type=='SORTSUBJECT') { |
---|
| 3441 | $sort[$iuid] = $header->subject; |
---|
| 3442 | } |
---|
| 3443 | else if($sort_box_type=='SORTSIZE') { |
---|
| 3444 | $sort[$iuid] = $header->Size; |
---|
| 3445 | } |
---|
| 3446 | else { |
---|
| 3447 | $sort[$iuid] = $header->udate; |
---|
| 3448 | } |
---|
| 3449 | |
---|
[659] | 3450 | } |
---|
[970] | 3451 | natcasesort($sort); |
---|
[828] | 3452 | |
---|
[970] | 3453 | if ($sort_box_reverse) |
---|
| 3454 | $sort = array_reverse($sort,true); |
---|
[659] | 3455 | } |
---|
[5134] | 3456 | if(empty($sort) or !is_array($sort)){ |
---|
[972] | 3457 | $sort = array(); |
---|
[5134] | 3458 | } |
---|
| 3459 | |
---|
| 3460 | |
---|
[1472] | 3461 | |
---|
[1808] | 3462 | |
---|
[972] | 3463 | if ($slice_array) |
---|
[828] | 3464 | $sort = array_slice($sort,$offsetBegin-1,$offsetEnd-($offsetBegin-1),true); |
---|
[970] | 3465 | |
---|
[1472] | 3466 | |
---|
[828] | 3467 | return $sort; |
---|
| 3468 | |
---|
[659] | 3469 | } |
---|
[970] | 3470 | |
---|
| 3471 | |
---|
[1472] | 3472 | function move_search_messages($params){ |
---|
| 3473 | $params['selected_messages'] = urldecode($params['selected_messages']); |
---|
[163] | 3474 | $params['new_folder'] = urldecode($params['new_folder']); |
---|
| 3475 | $params['new_folder_name'] = urldecode($params['new_folder_name']); |
---|
| 3476 | $sel_msgs = explode(",", $params['selected_messages']); |
---|
[1472] | 3477 | @reset($sel_msgs); |
---|
[163] | 3478 | $sorted_msgs = array(); |
---|
| 3479 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 3480 | $sel_msg = explode(";", $sel_msg); |
---|
| 3481 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 3482 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
[1472] | 3483 | } |
---|
[163] | 3484 | else { |
---|
| 3485 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 3486 | } |
---|
| 3487 | } |
---|
| 3488 | @ksort($sorted_msgs); |
---|
[1472] | 3489 | $last_return = false; |
---|
| 3490 | foreach($sorted_msgs as $folder => $msgs_number) { |
---|
[163] | 3491 | $params['msgs_number'] = $msgs_number; |
---|
[1472] | 3492 | $params['folder'] = $folder; |
---|
[163] | 3493 | if($params['new_folder'] && $folder != $params['new_folder']){ |
---|
[1472] | 3494 | $last_return = $this -> move_messages($params); |
---|
[163] | 3495 | } |
---|
| 3496 | elseif(!$params['new_folder'] || $params['delete'] ){ |
---|
| 3497 | $last_return = $this -> delete_msgs($params); |
---|
| 3498 | $last_return['deleted'] = true; |
---|
| 3499 | } |
---|
| 3500 | } |
---|
| 3501 | return $last_return; |
---|
| 3502 | } |
---|
[1472] | 3503 | |
---|
[2] | 3504 | function move_messages($params) |
---|
| 3505 | { |
---|
[1472] | 3506 | $folder = $params['folder']; |
---|
| 3507 | $mbox_stream = $this->open_mbox($folder); |
---|
[5134] | 3508 | $newmailbox = ($params['new_folder']); |
---|
[4997] | 3509 | $newmailbox = mb_convert_encoding($newmailbox, "UTF7-IMAP","ISO_8859-1"); |
---|
[5134] | 3510 | $new_folder_name = $params['new_folder_name']; |
---|
[4997] | 3511 | $msgs_number = $params['msgs_number']; |
---|
[2] | 3512 | $return = array('msgs_number' => $msgs_number, |
---|
| 3513 | 'folder' => $folder, |
---|
| 3514 | 'new_folder_name' => $new_folder_name, |
---|
[325] | 3515 | 'border_ID' => $params['border_ID'], |
---|
| 3516 | 'status' => true); //Status foi adicionado para validar as permissoes ACL |
---|
[1472] | 3517 | |
---|
[325] | 3518 | //Este bloco tem a finalidade de averiguar as permissoes para pastas compartilhadas |
---|
| 3519 | if (substr($folder,0,4) == 'user'){ |
---|
| 3520 | $acl = $this->getacltouser($folder); |
---|
| 3521 | /* |
---|
| 3522 | * l - lookup (mailbox is visible to LIST/LSUB commands) |
---|
| 3523 | * r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL, SEARCH, COPY from mailbox) |
---|
| 3524 | * s - keep seen/unseen information across sessions (STORE SEEN flag) |
---|
| 3525 | * w - write (STORE flags other than SEEN and DELETED) |
---|
| 3526 | * i - insert (perform APPEND, COPY into mailbox) |
---|
| 3527 | * p - post (send mail to submission address for mailbox, not enforced by IMAP4 itself) |
---|
| 3528 | * c - create (CREATE new sub-mailboxes in any implementation-defined hierarchy) |
---|
| 3529 | * d - delete (STORE DELETED flag, perform EXPUNGE) |
---|
| 3530 | * a - administer (perform SETACL) |
---|
| 3531 | */ |
---|
| 3532 | if (strpos($acl, "d") === false){ |
---|
| 3533 | $return['status'] = false; |
---|
| 3534 | return $return; |
---|
| 3535 | } |
---|
| 3536 | } |
---|
[432] | 3537 | //Este bloco tem a finalidade de transformar o CPF das pastas compartilhadas em common name |
---|
[5134] | 3538 | if(array_key_exists('uid2cn', $_SESSION['phpgw_info']['user']['preferences']['expressoMail'])){ |
---|
[1747] | 3539 | if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn']){ |
---|
| 3540 | if (substr($new_folder_name,0,4) == 'user'){ |
---|
| 3541 | $this->ldap = new ldap_functions(); |
---|
| 3542 | $tmp_folder_name = explode($this->imap_delimiter, $new_folder_name); |
---|
| 3543 | $return['new_folder_name'] = array_pop($tmp_folder_name); |
---|
| 3544 | if( $cn = $this->ldap->uid2cn($return['new_folder_name'])) |
---|
| 3545 | { |
---|
| 3546 | $return['new_folder_name'] = $cn; |
---|
| 3547 | } |
---|
| 3548 | } |
---|
[432] | 3549 | } |
---|
[5134] | 3550 | } |
---|
[1472] | 3551 | |
---|
| 3552 | // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior. |
---|
[51] | 3553 | if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) |
---|
[449] | 3554 | { |
---|
[2] | 3555 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
[449] | 3556 | // Fix problem in unserialize function JS. |
---|
[5134] | 3557 | if(array_key_exists('body', $return['previous_msg'])) |
---|
[449] | 3558 | $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); |
---|
| 3559 | } |
---|
[1472] | 3560 | |
---|
| 3561 | $mbox_stream = $this->open_mbox($folder); |
---|
[2] | 3562 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
| 3563 | imap_expunge($mbox_stream); |
---|
[51] | 3564 | if($mbox_stream) |
---|
| 3565 | imap_close($mbox_stream); |
---|
[2] | 3566 | return $return; |
---|
| 3567 | }else { |
---|
[1472] | 3568 | if(strstr(imap_last_error(),'Over quota')) { |
---|
[2] | 3569 | $accountID = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminUsername']; |
---|
[1472] | 3570 | $pass = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; |
---|
| 3571 | $userID = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
[2] | 3572 | $server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[504] | 3573 | $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] | 3574 | if(!$mbox) |
---|
| 3575 | return imap_last_error(); |
---|
[1472] | 3576 | $quota = imap_get_quotaroot($mbox_stream, "INBOX"); |
---|
[2] | 3577 | if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { |
---|
[51] | 3578 | if($mbox_stream) |
---|
| 3579 | imap_close($mbox_stream); |
---|
[1472] | 3580 | if($mbox) |
---|
[51] | 3581 | imap_close($mbox); |
---|
[1472] | 3582 | return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; |
---|
[2] | 3583 | } |
---|
| 3584 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
| 3585 | imap_expunge($mbox_stream); |
---|
[51] | 3586 | if($mbox_stream) |
---|
| 3587 | imap_close($mbox_stream); |
---|
[2] | 3588 | // return to original quota limit. |
---|
| 3589 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
[51] | 3590 | if($mbox) |
---|
| 3591 | imap_close($mbox); |
---|
[1472] | 3592 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
[2] | 3593 | } |
---|
[1472] | 3594 | return $return; |
---|
[2] | 3595 | } |
---|
| 3596 | else { |
---|
[51] | 3597 | if($mbox_stream) |
---|
| 3598 | imap_close($mbox_stream); |
---|
[2] | 3599 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
[51] | 3600 | if($mbox) |
---|
| 3601 | imap_close($mbox); |
---|
[1472] | 3602 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
[2] | 3603 | } |
---|
[1472] | 3604 | return imap_last_error(); |
---|
[2] | 3605 | } |
---|
[1472] | 3606 | |
---|
[2] | 3607 | } |
---|
| 3608 | else { |
---|
[51] | 3609 | if($mbox_stream) |
---|
| 3610 | imap_close($mbox_stream); |
---|
| 3611 | return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; |
---|
[2] | 3612 | } |
---|
[1472] | 3613 | } |
---|
[2] | 3614 | } |
---|
[1472] | 3615 | |
---|
[5134] | 3616 | |
---|
[2] | 3617 | function save_msg($params) |
---|
| 3618 | { |
---|
[5134] | 3619 | require_once $_SESSION['rootPath'] . '/API/class.servicelocator.php'; |
---|
| 3620 | $mailService = ServiceLocator::getService('mail'); |
---|
[1472] | 3621 | |
---|
[4795] | 3622 | $return_receipt = $params['input_return_receipt']; |
---|
| 3623 | $is_important = $params['input_important_message']; |
---|
[5134] | 3624 | |
---|
[4795] | 3625 | $msg_uid = $params['msg_id']; |
---|
| 3626 | $body = $params['body']; |
---|
[4416] | 3627 | $body = str_replace("%nbsp;"," ",$body); |
---|
[155] | 3628 | $body = preg_replace("/\n/"," ",$body); |
---|
[5134] | 3629 | $body = preg_replace("/\r/","" ,$body); |
---|
| 3630 | $body = html_entity_decode ( $body, ENT_QUOTES , 'ISO-8859-1' ); |
---|
[271] | 3631 | $forwarding_attachments = $params['forwarding_attachments']; |
---|
[5134] | 3632 | $message_attachments = $params['message_attachments']; |
---|
[4795] | 3633 | $attachments = $params['FILES']; |
---|
[271] | 3634 | $return_files = $params['FILES']; |
---|
[5134] | 3635 | $message_attachments_contents = (isset($params['message_attachments_content'])) ? $params['message_attachments_content'] : false; |
---|
[1472] | 3636 | |
---|
[4800] | 3637 | if(is_array($params['local_attachments'])){ |
---|
| 3638 | foreach ($params['local_attachments'] as $key => $local_attach) { |
---|
| 3639 | $tmp = unserialize(urldecode($local_attach)); |
---|
[5134] | 3640 | $attachments[$key]['name'] = urldecode($tmp[2]); |
---|
| 3641 | $return_files[$key]['name'] = urldecode($tmp[2]); |
---|
[4800] | 3642 | } |
---|
| 3643 | } |
---|
| 3644 | |
---|
[5134] | 3645 | $folder = mb_convert_encoding($params['folder'], "UTF7-IMAP","ISO_8859-1"); |
---|
| 3646 | $folder = @eregi_replace("INBOX[/.]", "INBOX".$this->imap_delimiter, $folder); |
---|
[4800] | 3647 | |
---|
[5134] | 3648 | $mailService->setFrom ('"'.$fromaddress[0].'" <'.$fromaddress[1].'>'); |
---|
| 3649 | $mailService->addTo($params['input_to']); |
---|
| 3650 | $mailService->addCc( $params['input_cc']); |
---|
| 3651 | $mailService->addBcc($params['input_cco']); |
---|
| 3652 | $mailService->setSubject($params['input_subject']); |
---|
[4795] | 3653 | |
---|
[5134] | 3654 | if($is_important){ |
---|
| 3655 | $mailService->addHeaderField('Importance','High'); |
---|
| 3656 | } |
---|
[4795] | 3657 | |
---|
[5134] | 3658 | if($return_receipt) |
---|
| 3659 | $mailService->addHeaderField('Disposition-Notification-To', $_SESSION['phpgw_info']['expressomail']['user']['email']); |
---|
[4795] | 3660 | |
---|
[5134] | 3661 | $isHTML = ( ( array_key_exists( 'type', $params ) && in_array( strtolower( $params[ 'type' ] ), array( 'html', 'plain' ) ) ) ? strtolower( $params[ 'type' ] ) != 'plain' : true ); |
---|
[4795] | 3662 | |
---|
| 3663 | |
---|
[5134] | 3664 | if( count($forwarding_attachments) > 0 ) |
---|
| 3665 | $return_forward = $this->buildEmbeddedImages($mailService, $msg_uid, $forwarding_attachments , $body); |
---|
| 3666 | |
---|
| 3667 | //Build Message Attachments!!! |
---|
| 3668 | if(count($message_attachments) > 0 ) |
---|
| 3669 | { |
---|
| 3670 | foreach($message_attachments as $folder_name => $messages) |
---|
| 3671 | { |
---|
| 3672 | foreach ($messages as $message_number => $message_subject) |
---|
| 3673 | { |
---|
| 3674 | if (!$message_subject) |
---|
| 3675 | $message_subject = 'no title.eml'; |
---|
| 3676 | else |
---|
| 3677 | $message_subject .= '.eml'; |
---|
| 3678 | |
---|
| 3679 | if( $message_attachments_contents && isset($message_attachments_contents[$folder_name]) ) |
---|
| 3680 | $rawmsg = base64_decode( $message_attachments_contents[$folder_name][$message_number] ); |
---|
| 3681 | else{ |
---|
| 3682 | $mbox_stream = $this->open_mbox($folder_name);$mbox_stream = $this->open_mbox($folder_name); |
---|
| 3683 | $rawmsg = $this->getRawHeader($message_number) . "\r\n\r\n" . $this->getRawBody($message_number); |
---|
| 3684 | } |
---|
| 3685 | |
---|
| 3686 | $return_forward[] = array( 'name' => $message_subject, 'size' => mb_strlen($rawmsg)); |
---|
| 3687 | $mailService->addStringAttachment($rawmsg, $message_subject, 'message/rfc822', '7bit', 'attachment' ); |
---|
| 3688 | } |
---|
| 3689 | } |
---|
| 3690 | } |
---|
| 3691 | |
---|
[4416] | 3692 | $imagesParts = array(); |
---|
[4795] | 3693 | |
---|
[5134] | 3694 | if(count($return_forward) > 0 ) |
---|
[4416] | 3695 | foreach ($return_forward as $value) |
---|
| 3696 | $imagesParts[$value[6]] = $value[3]; |
---|
[1472] | 3697 | |
---|
[5134] | 3698 | //Build Forwarding Attachments!!! |
---|
| 3699 | if(count($forwarding_attachments) > 0 ) |
---|
| 3700 | { |
---|
[4795] | 3701 | foreach($forwarding_attachments as $forwarding_attachment) |
---|
| 3702 | { |
---|
| 3703 | $file_description = unserialize(rawurldecode($forwarding_attachment)); |
---|
[5134] | 3704 | |
---|
| 3705 | |
---|
[4457] | 3706 | $file_description = array_values($file_description); |
---|
| 3707 | |
---|
[5134] | 3708 | foreach($file_description as $i => $descriptor) |
---|
[4457] | 3709 | $file_description[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
[5134] | 3710 | |
---|
[4795] | 3711 | $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); |
---|
[5134] | 3712 | $file_description[2] = html_entity_decode($file_description[2]); |
---|
[4795] | 3713 | |
---|
| 3714 | $file_description[5] = strlen($fileContent); //Size of file |
---|
| 3715 | $return_forward[] = $file_description; |
---|
[5134] | 3716 | $mailService->addStringAttachment($fileContent, $file_description[2], $this->get_file_type($file_description[2]), $file_description[4] ); |
---|
[4795] | 3717 | } |
---|
[5134] | 3718 | } |
---|
[4795] | 3719 | |
---|
[271] | 3720 | if ((count($return_forward) > 0) && (count($return_files) > 0)) |
---|
| 3721 | $return_files = array_merge_recursive($return_forward,$return_files); |
---|
[4416] | 3722 | else if (count($return_files) < 1) |
---|
[4795] | 3723 | $return_files = $return_forward; |
---|
[1472] | 3724 | |
---|
[5134] | 3725 | //Build Uploading Attachments!!! |
---|
[1005] | 3726 | $sizeof_attachments = count($attachments); |
---|
| 3727 | if ($sizeof_attachments) |
---|
[4416] | 3728 | foreach ($attachments as $numb => $attach) |
---|
[5134] | 3729 | $mailService->addFileAttachment($attach['tmp_name'], $attach['name'],$attach['type'], 'base64', 'attachment'); |
---|
[4416] | 3730 | |
---|
[4795] | 3731 | |
---|
[5134] | 3732 | if (!$body) |
---|
| 3733 | $body = ' '; |
---|
| 3734 | |
---|
| 3735 | if($isHTML) |
---|
| 3736 | $mailService->setBodyHtml($body); |
---|
| 3737 | else |
---|
| 3738 | $mailService->setBodyText($body); |
---|
[271] | 3739 | |
---|
[828] | 3740 | |
---|
[4795] | 3741 | $mbox_stream = $this->open_mbox($folder); |
---|
[5134] | 3742 | $return['append'] = imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, $mailService->getMessage(), "\\Seen \\Draft"); |
---|
| 3743 | |
---|
[4795] | 3744 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); |
---|
[271] | 3745 | $return['msg_no'] = $status->uidnext - 1; |
---|
| 3746 | $return['folder_id'] = $folder; |
---|
[4416] | 3747 | $return['imagesParts'] = $imagesParts; |
---|
[828] | 3748 | |
---|
[51] | 3749 | if($mbox_stream) |
---|
| 3750 | imap_close($mbox_stream); |
---|
[4416] | 3751 | |
---|
[5134] | 3752 | $returnFiles = array(); |
---|
| 3753 | $ii = 0; |
---|
| 3754 | |
---|
| 3755 | if(count($return_files) > 0) |
---|
[4416] | 3756 | { |
---|
| 3757 | foreach ($return_files as $index => $_attachment) |
---|
[271] | 3758 | { |
---|
[4416] | 3759 | if (array_key_exists("name", $_attachment)) |
---|
| 3760 | { |
---|
[5134] | 3761 | $returnFiles[$ii]['name'] = base64_encode($_attachment['name']); |
---|
| 3762 | $returnFiles[$ii]['size'] = $_attachment['size']; |
---|
| 3763 | $ii++; |
---|
[271] | 3764 | } |
---|
[5134] | 3765 | else if($_attachment[2]) |
---|
[4795] | 3766 | { |
---|
[5134] | 3767 | $returnFiles[$ii]['name'] = base64_encode($_attachment[2]); |
---|
| 3768 | $returnFiles[$ii]['size'] = $_attachment[5]; |
---|
| 3769 | $ii++; |
---|
[4795] | 3770 | } |
---|
[271] | 3771 | } |
---|
[4795] | 3772 | } |
---|
[5134] | 3773 | $return['files'] = serialize($returnFiles); |
---|
| 3774 | $return["subject"] = $params['input_subject']; |
---|
| 3775 | if (!$return['append']) $return['append'] = imap_last_error(); |
---|
[2] | 3776 | return $return; |
---|
| 3777 | } |
---|
[1472] | 3778 | |
---|
[2] | 3779 | function set_messages_flag($params) |
---|
| 3780 | { |
---|
| 3781 | $folder = $params['folder']; |
---|
[5134] | 3782 | $msgs_to_set = $params['msgs_to_set']; |
---|
[2] | 3783 | $flag = $params['flag']; |
---|
| 3784 | $return = array(); |
---|
[5134] | 3785 | $return["msgs_to_set"] = $msgs_to_set; |
---|
[2] | 3786 | $return["flag"] = $flag; |
---|
[1472] | 3787 | |
---|
[411] | 3788 | if(!$this->mbox && !is_resource($this->mbox)) |
---|
[51] | 3789 | $this->mbox = $this->open_mbox($folder); |
---|
[1472] | 3790 | |
---|
[2] | 3791 | if ($flag == "unseen") |
---|
[51] | 3792 | $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); |
---|
[2] | 3793 | elseif ($flag == "seen") |
---|
[51] | 3794 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); |
---|
[2] | 3795 | elseif ($flag == "answered"){ |
---|
[51] | 3796 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered", ST_UID); |
---|
| 3797 | imap_clearflag_full($this->mbox, $msgs_to_set, "\\Draft", ST_UID); |
---|
[2] | 3798 | } |
---|
| 3799 | elseif ($flag == "forwarded") |
---|
[51] | 3800 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered \\Draft", ST_UID); |
---|
[2] | 3801 | elseif ($flag == "flagged") |
---|
[51] | 3802 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); |
---|
[614] | 3803 | elseif ($flag == "unflagged") { |
---|
| 3804 | $flag_importance = false; |
---|
| 3805 | $msgs_number = explode(",",$msgs_to_set); |
---|
[659] | 3806 | $unflagged_msgs = ""; |
---|
[614] | 3807 | foreach($msgs_number as $msg_number) { |
---|
| 3808 | preg_match('/importance *: *(.*)\r/i', |
---|
| 3809 | imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) |
---|
[1472] | 3810 | ,$importance); |
---|
[673] | 3811 | if(strtolower($importance[1])=="high" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { |
---|
[614] | 3812 | $flag_importance=true; |
---|
| 3813 | } |
---|
[659] | 3814 | else { |
---|
| 3815 | $unflagged_msgs.=$msg_number.","; |
---|
[1472] | 3816 | } |
---|
[614] | 3817 | } |
---|
| 3818 | |
---|
[659] | 3819 | if($unflagged_msgs!="") { |
---|
| 3820 | imap_clearflag_full($this->mbox,substr($unflagged_msgs,0,strlen($unflagged_msgs)-1), "\\Flagged", ST_UID); |
---|
| 3821 | $return["msgs_unflageds"] = substr($unflagged_msgs,0,strlen($unflagged_msgs)-1); |
---|
| 3822 | } |
---|
| 3823 | else { |
---|
| 3824 | $return["msgs_unflageds"] = false; |
---|
| 3825 | } |
---|
| 3826 | |
---|
[673] | 3827 | if($flag_importance && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { |
---|
[614] | 3828 | $return["status"] = false; |
---|
| 3829 | $return["msg"] = $this->functions->getLang("At least one of selected message cant be marked as normal"); |
---|
| 3830 | } |
---|
[659] | 3831 | else { |
---|
| 3832 | $return["status"] = true; |
---|
| 3833 | } |
---|
[614] | 3834 | } |
---|
[1472] | 3835 | |
---|
[411] | 3836 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 3837 | imap_close($this->mbox); |
---|
[2] | 3838 | return $return; |
---|
| 3839 | } |
---|
[1472] | 3840 | |
---|
[2] | 3841 | function get_file_type($file_name) |
---|
| 3842 | { |
---|
| 3843 | $file_name = strtolower($file_name); |
---|
| 3844 | $strFileType = strrev(substr(strrev($file_name),0,4)); |
---|
[5134] | 3845 | if ($strFileType == ".eml") |
---|
| 3846 | return "message/rfc822"; |
---|
[1472] | 3847 | if ($strFileType == ".asf") |
---|
[2] | 3848 | return "video/x-ms-asf"; |
---|
| 3849 | if ($strFileType == ".avi") |
---|
| 3850 | return "video/avi"; |
---|
| 3851 | if ($strFileType == ".doc") |
---|
| 3852 | return "application/msword"; |
---|
| 3853 | if ($strFileType == ".zip") |
---|
| 3854 | return "application/zip"; |
---|
| 3855 | if ($strFileType == ".xls") |
---|
| 3856 | return "application/vnd.ms-excel"; |
---|
| 3857 | if ($strFileType == ".gif") |
---|
| 3858 | return "image/gif"; |
---|
| 3859 | if ($strFileType == ".jpg" || $strFileType == "jpeg") |
---|
| 3860 | return "image/jpeg"; |
---|
| 3861 | if ($strFileType == ".png") |
---|
| 3862 | return "image/png"; |
---|
| 3863 | if ($strFileType == ".wav") |
---|
| 3864 | return "audio/wav"; |
---|
| 3865 | if ($strFileType == ".mp3") |
---|
| 3866 | return "audio/mpeg3"; |
---|
| 3867 | if ($strFileType == ".mpg" || $strFileType == "mpeg") |
---|
| 3868 | return "video/mpeg"; |
---|
| 3869 | if ($strFileType == ".rtf") |
---|
| 3870 | return "application/rtf"; |
---|
| 3871 | if ($strFileType == ".htm" || $strFileType == "html") |
---|
| 3872 | return "text/html"; |
---|
[1472] | 3873 | if ($strFileType == ".xml") |
---|
[2] | 3874 | return "text/xml"; |
---|
[1472] | 3875 | if ($strFileType == ".xsl") |
---|
[2] | 3876 | return "text/xsl"; |
---|
[1472] | 3877 | if ($strFileType == ".css") |
---|
[2] | 3878 | return "text/css"; |
---|
[1472] | 3879 | if ($strFileType == ".php") |
---|
[2] | 3880 | return "text/php"; |
---|
[1472] | 3881 | if ($strFileType == ".asp") |
---|
[2] | 3882 | return "text/asp"; |
---|
| 3883 | if ($strFileType == ".pdf") |
---|
| 3884 | return "application/pdf"; |
---|
| 3885 | if ($strFileType == ".txt") |
---|
| 3886 | return "text/plain"; |
---|
| 3887 | if ($strFileType == ".wmv") |
---|
| 3888 | return "video/x-ms-wmv"; |
---|
| 3889 | if ($strFileType == ".sxc") |
---|
| 3890 | return "application/vnd.sun.xml.calc"; |
---|
| 3891 | if ($strFileType == ".stc") |
---|
| 3892 | return "application/vnd.sun.xml.calc.template"; |
---|
| 3893 | if ($strFileType == ".sxd") |
---|
| 3894 | return "application/vnd.sun.xml.draw"; |
---|
| 3895 | if ($strFileType == ".std") |
---|
| 3896 | return "application/vnd.sun.xml.draw.template"; |
---|
| 3897 | if ($strFileType == ".sxi") |
---|
| 3898 | return "application/vnd.sun.xml.impress"; |
---|
| 3899 | if ($strFileType == ".sti") |
---|
| 3900 | return "application/vnd.sun.xml.impress.template"; |
---|
| 3901 | if ($strFileType == ".sxm") |
---|
| 3902 | return "application/vnd.sun.xml.math"; |
---|
| 3903 | if ($strFileType == ".sxw") |
---|
| 3904 | return "application/vnd.sun.xml.writer"; |
---|
| 3905 | if ($strFileType == ".sxq") |
---|
| 3906 | return "application/vnd.sun.xml.writer.global"; |
---|
| 3907 | if ($strFileType == ".stw") |
---|
| 3908 | return "application/vnd.sun.xml.writer.template"; |
---|
[1472] | 3909 | |
---|
| 3910 | |
---|
| 3911 | return "application/octet-stream"; |
---|
[2] | 3912 | } |
---|
[1472] | 3913 | |
---|
[2] | 3914 | function htmlspecialchars_encode($str) |
---|
| 3915 | { |
---|
[449] | 3916 | return str_replace( array('&', '"','\'','<','>','{','}'), array('&','"',''','<','>','{','}'), $str); |
---|
[2] | 3917 | } |
---|
| 3918 | function htmlspecialchars_decode($str) |
---|
| 3919 | { |
---|
[449] | 3920 | return str_replace( array('&','"',''','<','>','{','}'), array('&', '"','\'','<','>','{','}'), $str); |
---|
[2] | 3921 | } |
---|
[1472] | 3922 | |
---|
[828] | 3923 | function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$offsetBegin = 0,$offsetEnd = 0) |
---|
| 3924 | { |
---|
| 3925 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[51] | 3926 | $this->mbox = $this->open_mbox($folder); |
---|
[432] | 3927 | |
---|
[828] | 3928 | return $this->messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd); |
---|
| 3929 | } |
---|
[1472] | 3930 | |
---|
[53] | 3931 | function get_info_next_msg($params) |
---|
| 3932 | { |
---|
| 3933 | $msg_number = $params['msg_number']; |
---|
| 3934 | $folder = $params['msg_folder']; |
---|
| 3935 | $sort_box_type = $params['sort_box_type']; |
---|
| 3936 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 3937 | $reuse_border = $params['reuse_border']; |
---|
| 3938 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
[1472] | 3939 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
| 3940 | |
---|
[320] | 3941 | $success = false; |
---|
| 3942 | if (is_array($sort_array_msg)) |
---|
[2] | 3943 | { |
---|
[320] | 3944 | foreach ($sort_array_msg as $i => $value){ |
---|
| 3945 | if ($value == $msg_number) |
---|
| 3946 | { |
---|
| 3947 | $success = true; |
---|
| 3948 | break; |
---|
| 3949 | } |
---|
| 3950 | } |
---|
[2] | 3951 | } |
---|
| 3952 | |
---|
[320] | 3953 | if (! $success || $i >= sizeof($sort_array_msg)-1) |
---|
[2] | 3954 | { |
---|
| 3955 | $params['status'] = 'false'; |
---|
| 3956 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
| 3957 | return $params; |
---|
| 3958 | } |
---|
[1472] | 3959 | |
---|
[2] | 3960 | $params = array(); |
---|
| 3961 | $params['msg_number'] = $sort_array_msg[($i+1)]; |
---|
| 3962 | $params['msg_folder'] = $folder; |
---|
[1472] | 3963 | |
---|
| 3964 | $return = $this->get_info_msg($params); |
---|
[2] | 3965 | $return["reuse_border"] = $reuse_border; |
---|
| 3966 | return $return; |
---|
| 3967 | } |
---|
| 3968 | |
---|
| 3969 | function get_info_previous_msg($params) |
---|
| 3970 | { |
---|
| 3971 | $msg_number = $params['msgs_number']; |
---|
| 3972 | $folder = $params['folder']; |
---|
| 3973 | $sort_box_type = $params['sort_box_type']; |
---|
| 3974 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 3975 | $reuse_border = $params['reuse_border']; |
---|
[53] | 3976 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
| 3977 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
[1472] | 3978 | |
---|
[320] | 3979 | $success = false; |
---|
| 3980 | if (is_array($sort_array_msg)) |
---|
[2] | 3981 | { |
---|
[320] | 3982 | foreach ($sort_array_msg as $i => $value){ |
---|
| 3983 | if ($value == $msg_number) |
---|
| 3984 | { |
---|
| 3985 | $success = true; |
---|
| 3986 | break; |
---|
| 3987 | } |
---|
| 3988 | } |
---|
[2] | 3989 | } |
---|
[320] | 3990 | if (! $success || $i == 0) |
---|
| 3991 | { |
---|
[2] | 3992 | $params['status'] = 'false'; |
---|
| 3993 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
| 3994 | return $params; |
---|
| 3995 | } |
---|
[1472] | 3996 | |
---|
[2] | 3997 | $params = array(); |
---|
| 3998 | $params['msg_number'] = $sort_array_msg[($i-1)]; |
---|
| 3999 | $params['msg_folder'] = $folder; |
---|
[1472] | 4000 | |
---|
[2] | 4001 | $return = $this->get_info_msg($params); |
---|
| 4002 | $return["reuse_border"] = $reuse_border; |
---|
| 4003 | return $return; |
---|
| 4004 | } |
---|
[1472] | 4005 | |
---|
[2] | 4006 | // This function updates the values: quota, paging and new messages menu. |
---|
| 4007 | function get_menu_values($params){ |
---|
| 4008 | $return_array = array(); |
---|
| 4009 | $return_array = $this->get_quota($params); |
---|
[1472] | 4010 | |
---|
[2] | 4011 | $mbox_stream = $this->open_mbox($params['folder']); |
---|
[1472] | 4012 | $return_array['num_msgs'] = imap_num_msg($mbox_stream); |
---|
[51] | 4013 | if($mbox_stream) |
---|
| 4014 | imap_close($mbox_stream); |
---|
[1472] | 4015 | |
---|
| 4016 | return $return_array; |
---|
[2] | 4017 | } |
---|
[1472] | 4018 | |
---|
[325] | 4019 | function get_quota($params){ |
---|
[449] | 4020 | // folder_id = user/{uid} for shared folders |
---|
| 4021 | if(substr($params['folder_id'],0,5) != 'INBOX' && preg_match('/user\\'.$this->imap_delimiter.'/i', $params['folder_id'])){ |
---|
| 4022 | $array_folder = explode($this->imap_delimiter,$params['folder_id']); |
---|
[1472] | 4023 | $folder_id = "user".$this->imap_delimiter.$array_folder[1]; |
---|
[449] | 4024 | } |
---|
| 4025 | // folder_id = INBOX for inbox folders |
---|
| 4026 | else |
---|
| 4027 | $folder_id = "INBOX"; |
---|
[1472] | 4028 | |
---|
[1035] | 4029 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[51] | 4030 | $this->mbox = $this->open_mbox(); |
---|
[345] | 4031 | |
---|
[325] | 4032 | $quota = imap_get_quotaroot($this->mbox, $folder_id); |
---|
[411] | 4033 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 4034 | imap_close($this->mbox); |
---|
[1472] | 4035 | |
---|
[2] | 4036 | if (!$quota){ |
---|
| 4037 | return array( |
---|
| 4038 | 'quota_percent' => 0, |
---|
| 4039 | 'quota_used' => 0, |
---|
| 4040 | 'quota_limit' => 0 |
---|
| 4041 | ); |
---|
| 4042 | } |
---|
[1472] | 4043 | |
---|
[2] | 4044 | if(count($quota) && $quota['limit']) { |
---|
[3064] | 4045 | $quota_limit = $quota['limit']; |
---|
| 4046 | $quota_used = $quota['usage']; |
---|
[2] | 4047 | if($quota_used >= $quota_limit) |
---|
[650] | 4048 | { |
---|
| 4049 | $quotaPercent = 100; |
---|
| 4050 | } |
---|
| 4051 | else |
---|
| 4052 | { |
---|
[2] | 4053 | $quotaPercent = ($quota_used / $quota_limit)*100; |
---|
| 4054 | $quotaPercent = (($quotaPercent)* 100 + .5 )* .01; |
---|
[650] | 4055 | } |
---|
[2] | 4056 | return array( |
---|
| 4057 | 'quota_percent' => floor($quotaPercent), |
---|
[3064] | 4058 | 'quota_used' => $quota_used, |
---|
| 4059 | 'quota_limit' => $quota_limit |
---|
[2] | 4060 | ); |
---|
| 4061 | } |
---|
[1472] | 4062 | else |
---|
[2] | 4063 | return array(); |
---|
| 4064 | } |
---|
[1472] | 4065 | |
---|
[2] | 4066 | function send_notification($params){ |
---|
[3231] | 4067 | include("../header.inc.php"); |
---|
[2] | 4068 | require_once("class.phpmailer.php"); |
---|
| 4069 | $mail = new PHPMailer(); |
---|
[1472] | 4070 | |
---|
[2] | 4071 | $toaddress = $params['notificationto']; |
---|
[1472] | 4072 | |
---|
[3231] | 4073 | $subject = lang("Read receipt: %1",$params['subject']); |
---|
| 4074 | $body = lang("Your message: %1",$params['subject']) . '<br>'; |
---|
[4739] | 4075 | $body .= lang("Received in: %1",date("d/m/Y H:i",$params['date'])) . '<br>'; |
---|
[3231] | 4076 | $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] | 4077 | $mail->SMTPDebug = false; |
---|
| 4078 | $mail->IsSMTP(); |
---|
| 4079 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
| 4080 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
| 4081 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 4082 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
| 4083 | $mail->AddAddress($toaddress); |
---|
| 4084 | $mail->Subject = $this->htmlspecialchars_decode($subject); |
---|
| 4085 | |
---|
| 4086 | $mail->IsHTML(true); |
---|
| 4087 | $mail->Body = $body; |
---|
[1472] | 4088 | |
---|
[2] | 4089 | if(!$mail->Send()){ |
---|
| 4090 | return $mail->ErrorInfo; |
---|
| 4091 | } |
---|
| 4092 | else |
---|
| 4093 | return true; |
---|
| 4094 | } |
---|
[1472] | 4095 | |
---|
[1965] | 4096 | function empty_folder($params) |
---|
[2] | 4097 | { |
---|
[1965] | 4098 | $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server'][$params['clean_folder']]; |
---|
[2] | 4099 | $mbox_stream = $this->open_mbox($folder); |
---|
| 4100 | $return = imap_delete($mbox_stream,'1:*'); |
---|
[51] | 4101 | if($mbox_stream) |
---|
| 4102 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 4103 | return $return; |
---|
| 4104 | } |
---|
[1472] | 4105 | |
---|
[2] | 4106 | function search($params) |
---|
| 4107 | { |
---|
[673] | 4108 | include("class.imap_attachment.inc.php"); |
---|
[1472] | 4109 | $imap_attachment = new imap_attachment(); |
---|
[2] | 4110 | $criteria = $params['criteria']; |
---|
| 4111 | $return = array(); |
---|
| 4112 | $folders = $this->get_folders_list(); |
---|
[1472] | 4113 | |
---|
[2] | 4114 | $j = 0; |
---|
| 4115 | foreach($folders as $folder) |
---|
| 4116 | { |
---|
| 4117 | $mbox_stream = $this->open_mbox($folder); |
---|
| 4118 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
[1472] | 4119 | |
---|
[2] | 4120 | if ($messages == '') |
---|
| 4121 | continue; |
---|
[1472] | 4122 | |
---|
[2] | 4123 | $i = 0; |
---|
| 4124 | $return[$j] = array(); |
---|
| 4125 | $return[$j]['folder_name'] = $folder['name']; |
---|
[1472] | 4126 | |
---|
[2] | 4127 | foreach($messages as $msg_number) |
---|
| 4128 | { |
---|
[535] | 4129 | $header = $this->get_header($msg_number); |
---|
[2] | 4130 | if (!is_object($header)) |
---|
| 4131 | return false; |
---|
[1472] | 4132 | |
---|
[2] | 4133 | $return[$j][$i]['msg_folder'] = $folder['name']; |
---|
| 4134 | $return[$j][$i]['msg_number'] = $msg_number; |
---|
| 4135 | $return[$j][$i]['Recent'] = $header->Recent; |
---|
| 4136 | $return[$j][$i]['Unseen'] = $header->Unseen; |
---|
| 4137 | $return[$j][$i]['Answered'] = $header->Answered; |
---|
| 4138 | $return[$j][$i]['Deleted'] = $header->Deleted; |
---|
| 4139 | $return[$j][$i]['Draft'] = $header->Draft; |
---|
| 4140 | $return[$j][$i]['Flagged'] = $header->Flagged; |
---|
[1472] | 4141 | |
---|
[535] | 4142 | $date_msg = gmdate("d/m/Y",$header->udate); |
---|
| 4143 | if (gmdate("d/m/Y") == $date_msg) |
---|
| 4144 | $return[$j][$i]['udate'] = gmdate("H:i",$header->udate); |
---|
[2] | 4145 | else |
---|
| 4146 | $return[$j][$i]['udate'] = $date_msg; |
---|
[1472] | 4147 | |
---|
[2] | 4148 | $fromaddress = imap_mime_header_decode($header->fromaddress); |
---|
| 4149 | $return[$j][$i]['fromaddress'] = ''; |
---|
| 4150 | foreach ($fromaddress as $tmp) |
---|
| 4151 | $return[$j][$i]['fromaddress'] .= $this->replace_maior_menor($tmp->text); |
---|
[1472] | 4152 | |
---|
[2] | 4153 | $from = $header->from; |
---|
| 4154 | $return[$j][$i]['from'] = array(); |
---|
| 4155 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 4156 | $return[$j][$i]['from']['name'] = $tmp[0]->text; |
---|
| 4157 | $return[$j][$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
[1472] | 4158 | $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; |
---|
[2] | 4159 | |
---|
| 4160 | $to = $header->to; |
---|
| 4161 | $return[$j][$i]['to'] = array(); |
---|
| 4162 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
| 4163 | $return[$j][$i]['to']['name'] = $tmp[0]->text; |
---|
| 4164 | $return[$j][$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
[1472] | 4165 | $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; |
---|
[2] | 4166 | |
---|
| 4167 | $subject = imap_mime_header_decode($header->fetchsubject); |
---|
| 4168 | $return[$j][$i]['subject'] = ''; |
---|
| 4169 | foreach ($subject as $tmp) |
---|
| 4170 | $return[$j][$i]['subject'] .= $tmp->text; |
---|
| 4171 | |
---|
| 4172 | $return[$j][$i]['Size'] = $header->Size; |
---|
| 4173 | $return[$j][$i]['reply_toaddress'] = $header->reply_toaddress; |
---|
[1472] | 4174 | |
---|
[2] | 4175 | $return[$j][$i]['attachment'] = array(); |
---|
| 4176 | $return[$j][$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($mbox_stream, $msg_number); |
---|
[1472] | 4177 | |
---|
[2] | 4178 | $i++; |
---|
| 4179 | } |
---|
| 4180 | $j++; |
---|
[51] | 4181 | if($mbox_stream) |
---|
| 4182 | imap_close($mbox_stream); |
---|
[2] | 4183 | } |
---|
[1472] | 4184 | |
---|
[2] | 4185 | return $return; |
---|
| 4186 | } |
---|
[3923] | 4187 | |
---|
| 4188 | |
---|
[1709] | 4189 | function mobile_search($params) |
---|
| 4190 | { |
---|
| 4191 | include("class.imap_attachment.inc.php"); |
---|
| 4192 | $imap_attachment = new imap_attachment(); |
---|
| 4193 | $criterias = array ("TO","SUBJECT","FROM","CC"); |
---|
| 4194 | $return = array(); |
---|
[3589] | 4195 | if(!isset($params['folder'])) { |
---|
| 4196 | $folder_params = array("noSharedFolders"=>1); |
---|
| 4197 | if(isset($params['folderType'])) |
---|
| 4198 | $folder_params['folderType'] = $params['folderType']; |
---|
| 4199 | $folders = $this->get_folders_list($folder_params); |
---|
| 4200 | } |
---|
| 4201 | else |
---|
| 4202 | $folders = array(0=>array('folder_id'=>$params['folder'])); |
---|
[1709] | 4203 | $num_msgs = 0; |
---|
[3923] | 4204 | $max_msgs = $params['max_msgs'] + 1; //get one more because mobile paginate |
---|
| 4205 | $return["msgs"] = array(); |
---|
| 4206 | |
---|
| 4207 | //get max_msgs of each folder order by date and later order all messages together and retur only max_msgs msgs |
---|
[1709] | 4208 | foreach($folders as $id =>$folder) |
---|
| 4209 | { |
---|
| 4210 | if(strpos($folder['folder_id'],'user')===false && is_array($folder)) { |
---|
| 4211 | foreach($criterias as $criteria_fixed) |
---|
[3923] | 4212 | { |
---|
| 4213 | $_filter = $criteria_fixed . ' "'.$params['filter'].'"'; |
---|
| 4214 | |
---|
[3573] | 4215 | $mbox_stream = $this->open_mbox($folder['folder_id']); |
---|
[3923] | 4216 | |
---|
| 4217 | $messages = imap_sort($mbox_stream,SORTARRIVAL,1,SE_UID,$_filter); |
---|
[1709] | 4218 | |
---|
| 4219 | if ($messages == ''){ |
---|
| 4220 | if($mbox_stream) |
---|
| 4221 | imap_close($mbox_stream); |
---|
| 4222 | continue; |
---|
| 4223 | } |
---|
[3923] | 4224 | |
---|
[1709] | 4225 | foreach($messages as $msg_number) |
---|
[3923] | 4226 | { |
---|
[1709] | 4227 | $temp = $this->get_info_head_msg($msg_number); |
---|
| 4228 | if(!$temp) |
---|
| 4229 | return false; |
---|
[3573] | 4230 | $temp['msg_folder'] = $folder['folder_id']; |
---|
[3923] | 4231 | $return["msgs"][$num_msgs] = $temp; |
---|
[1709] | 4232 | $num_msgs++; |
---|
| 4233 | } |
---|
[3923] | 4234 | |
---|
[1709] | 4235 | if($mbox_stream) |
---|
| 4236 | imap_close($mbox_stream); |
---|
| 4237 | } |
---|
[3923] | 4238 | } |
---|
[1709] | 4239 | } |
---|
[3923] | 4240 | |
---|
| 4241 | if(!function_exists("cmp_date")) { |
---|
| 4242 | function cmp_date($obj1, $obj2){ |
---|
| 4243 | if($obj1['timestamp'] == $obj2['timestamp']) return 0; |
---|
| 4244 | return ($obj1['timestamp'] < $obj2['timestamp']) ? 1 : -1; |
---|
| 4245 | } |
---|
| 4246 | } |
---|
| 4247 | usort($return["msgs"], "cmp_date"); |
---|
| 4248 | $return["has_more_msg"] = (sizeof($return["msgs"]) > $max_msgs); |
---|
| 4249 | $return["msgs"] = array_slice($return["msgs"], 0, $max_msgs); |
---|
[4560] | 4250 | $return["msgs"]['num_msgs'] = $num_msgs; |
---|
[3923] | 4251 | |
---|
[1709] | 4252 | return $return; |
---|
| 4253 | } |
---|
[1472] | 4254 | |
---|
[2] | 4255 | function delete_and_show_previous_message($params) |
---|
| 4256 | { |
---|
| 4257 | $return = $this->get_info_previous_msg($params); |
---|
[1472] | 4258 | |
---|
[2] | 4259 | $params_tmp1 = array(); |
---|
| 4260 | $params_tmp1['msgs_to_delete'] = $params['msg_number']; |
---|
| 4261 | $params_tmp1['folder'] = $params['msg_folder']; |
---|
| 4262 | $return_tmp1 = $this->delete_msg($params_tmp1); |
---|
[1472] | 4263 | |
---|
[2] | 4264 | $return['msg_number_deleted'] = $return_tmp1; |
---|
[1472] | 4265 | |
---|
[2] | 4266 | return $return; |
---|
| 4267 | } |
---|
[1472] | 4268 | |
---|
| 4269 | |
---|
[2] | 4270 | function automatic_trash_cleanness($params) |
---|
| 4271 | { |
---|
| 4272 | $before_date = date("m/d/Y", strtotime("-".$params['before_date']." day")); |
---|
| 4273 | $criteria = 'BEFORE "'.$before_date.'"'; |
---|
[325] | 4274 | $mbox_stream = $this->open_mbox('INBOX'.$this->imap_delimiter.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']); |
---|
[3018] | 4275 | // Free others requests |
---|
| 4276 | session_write_close(); |
---|
[2] | 4277 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
| 4278 | if (is_array($messages)){ |
---|
| 4279 | foreach ($messages as $msg_number){ |
---|
| 4280 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
| 4281 | } |
---|
| 4282 | } |
---|
[51] | 4283 | if($mbox_stream) |
---|
| 4284 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 4285 | return $messages; |
---|
| 4286 | } |
---|
| 4287 | // Fix the search problem with special characters!!!! |
---|
| 4288 | function remove_accents($string) { |
---|
[1472] | 4289 | return strtr($string, |
---|
| 4290 | "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ", |
---|
[2] | 4291 | "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); |
---|
| 4292 | } |
---|
| 4293 | |
---|
[4795] | 4294 | function make_search_date($date,$before = false){ |
---|
| 4295 | |
---|
[1622] | 4296 | //TODO: Adaptar a data de acordo com o locale do sistema. |
---|
| 4297 | list($day,$month,$year) = explode("/", $date); |
---|
[4795] | 4298 | $before?$day=(int)$day+1:$day=(int)$day; |
---|
| 4299 | $timestamp = mktime(0,0,0,(int)$month,$day,(int)$year); |
---|
| 4300 | $search_date = date('d-M-Y',$timestamp); |
---|
[1622] | 4301 | return $search_date; |
---|
| 4302 | |
---|
[4795] | 4303 | } |
---|
[1622] | 4304 | |
---|
[3843] | 4305 | function search_msg( $params = false ) |
---|
| 4306 | { |
---|
| 4307 | $mbox_stream = ""; |
---|
| 4308 | |
---|
| 4309 | if(strpos($params['condition'],"#")===false) |
---|
| 4310 | { //local messages |
---|
| 4311 | $search=false; |
---|
| 4312 | } |
---|
| 4313 | else |
---|
| 4314 | { |
---|
| 4315 | $search = explode(",",$params['condition']); |
---|
| 4316 | } |
---|
| 4317 | |
---|
| 4318 | $params['page'] = $params['page'] * 1; |
---|
[689] | 4319 | |
---|
[3843] | 4320 | if( is_array($search) ) |
---|
| 4321 | { |
---|
| 4322 | $search = array_unique($search); // Remove duplicated folders |
---|
| 4323 | $search_criteria = ''; |
---|
| 4324 | $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; |
---|
| 4325 | foreach($search as $tmp) |
---|
| 4326 | { |
---|
| 4327 | $tmp1 = explode("##",$tmp); |
---|
| 4328 | $sum = 0; |
---|
| 4329 | $name_box = $tmp1[0]; |
---|
| 4330 | unset($filter); |
---|
| 4331 | foreach($tmp1 as $index => $criteria) |
---|
| 4332 | { |
---|
| 4333 | if ($index != 0 && strlen($criteria) != 0) |
---|
| 4334 | { |
---|
| 4335 | $filter_array = explode("<=>",html_entity_decode(rawurldecode($criteria))); |
---|
| 4336 | $filter .= " ".$filter_array[0]; |
---|
| 4337 | if (strlen($filter_array[1]) != 0) |
---|
| 4338 | { |
---|
| 4339 | if ( trim($filter_array[0]) != 'BEFORE' && |
---|
| 4340 | trim($filter_array[0]) != 'SINCE' && |
---|
| 4341 | trim($filter_array[0]) != 'ON') |
---|
| 4342 | { |
---|
| 4343 | $filter .= '"'.$filter_array[1].'"'; |
---|
[5134] | 4344 | }else if(trim($filter_array[0]) == 'BEFORE' ){ |
---|
[4795] | 4345 | $filter .= '"'.$this->make_search_date($filter_array[1],true).'"'; |
---|
| 4346 | }else{ |
---|
| 4347 | $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; |
---|
| 4348 | } |
---|
[3843] | 4349 | } |
---|
| 4350 | } |
---|
| 4351 | } |
---|
| 4352 | |
---|
[5134] | 4353 | $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO-8859-1" ); |
---|
[3843] | 4354 | $filter = $this->remove_accents($filter); |
---|
[1472] | 4355 | |
---|
[3843] | 4356 | //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name |
---|
| 4357 | if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user') |
---|
| 4358 | { |
---|
| 4359 | $folder_name = explode($this->imap_delimiter,$name_box); |
---|
| 4360 | $this->ldap = new ldap_functions(); |
---|
| 4361 | |
---|
| 4362 | if ($cn = $this->ldap->uid2cn($folder_name[1])) |
---|
| 4363 | { |
---|
| 4364 | $folder_name[1] = $cn; |
---|
| 4365 | } |
---|
| 4366 | $folder_name = implode($this->imap_delimiter,$folder_name); |
---|
[3391] | 4367 | } |
---|
[3843] | 4368 | else |
---|
[5134] | 4369 | $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO-8859-1" ); |
---|
[3843] | 4370 | |
---|
| 4371 | if(!is_resource($mbox_stream)) |
---|
| 4372 | $mbox_stream = $this->open_mbox($name_box); |
---|
| 4373 | else |
---|
| 4374 | imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); |
---|
| 4375 | |
---|
| 4376 | if (preg_match("/^.?\bALL\b/", $filter)) |
---|
| 4377 | { |
---|
| 4378 | // Quick Search, note: this ALL isn't the same ALL from imap_search |
---|
| 4379 | $all_criterias = array ("TO","SUBJECT","FROM","CC"); |
---|
| 4380 | |
---|
| 4381 | foreach($all_criterias as $criteria_fixed) |
---|
| 4382 | { |
---|
| 4383 | $_filter = $criteria_fixed . substr($filter,4); |
---|
| 4384 | |
---|
| 4385 | $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); |
---|
| 4386 | |
---|
| 4387 | if(is_array($search_criteria)) |
---|
| 4388 | { |
---|
| 4389 | foreach($search_criteria as $new_search) |
---|
| 4390 | { |
---|
| 4391 | $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); |
---|
[5134] | 4392 | $elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); |
---|
[4795] | 4393 | $elem['uid'] = $new_search; |
---|
| 4394 | /* compare dates in ordering */ |
---|
| 4395 | $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); |
---|
[3843] | 4396 | $retorno[] = $elem; |
---|
| 4397 | } |
---|
| 4398 | } |
---|
| 4399 | } |
---|
| 4400 | } |
---|
[4068] | 4401 | else{ |
---|
[5134] | 4402 | $search_criteria = imap_search($mbox_stream, $filter, SE_UID); |
---|
[4941] | 4403 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) |
---|
| 4404 | { |
---|
| 4405 | if((!strpos($filter,"FLAGGED") === false) || (!strpos($filter,"UNFLAGGED") === false)) |
---|
| 4406 | { |
---|
| 4407 | $num_msgs = imap_num_msg($mbox_stream); |
---|
| 4408 | $flagged_msgs = array(); |
---|
| 4409 | for ($i=$num_msgs; $i>0; $i--) |
---|
[4068] | 4410 | { |
---|
[4941] | 4411 | $iuid = @imap_uid($this->mbox,$i); |
---|
| 4412 | $header = $this->get_header($iuid); |
---|
| 4413 | if(trim($header->Flagged)) |
---|
| 4414 | { |
---|
| 4415 | $flagged_msgs[$i] = $iuid; |
---|
| 4416 | } |
---|
[4068] | 4417 | } |
---|
[5134] | 4418 | if((count($flagged_msgs) >0) && (strpos($filter,"UNFLAGGED") === false)) |
---|
[4941] | 4419 | { |
---|
[5134] | 4420 | $arry_diff = is_array($search_criteria) ? array_diff($flagged_msgs,$search_criteria):$flagged_msgs; |
---|
| 4421 | foreach($arry_diff as $msg) |
---|
[4941] | 4422 | { |
---|
[5134] | 4423 | $search_criteria[] = $msg; |
---|
[4941] | 4424 | } |
---|
| 4425 | } |
---|
[5134] | 4426 | else if((count($flagged_msgs) >0) && (is_array($search_criteria)) && (!strpos($filter,"UNFLAGGED") === false)) |
---|
[4941] | 4427 | { |
---|
[5134] | 4428 | $search_criteria = array_diff($search_criteria,$flagged_msgs); |
---|
[4941] | 4429 | } |
---|
| 4430 | } |
---|
| 4431 | } |
---|
| 4432 | |
---|
| 4433 | if( is_array( $search_criteria) ) |
---|
| 4434 | { |
---|
| 4435 | foreach($search_criteria as $new_search) |
---|
| 4436 | { |
---|
| 4437 | $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); |
---|
[5134] | 4438 | $elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); |
---|
[4941] | 4439 | $elem['uid'] = $new_search; |
---|
| 4440 | /* compare dates in ordering */ |
---|
| 4441 | $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); |
---|
| 4442 | $retorno[] = $elem; |
---|
| 4443 | } |
---|
| 4444 | } |
---|
[3843] | 4445 | } |
---|
| 4446 | } |
---|
| 4447 | } |
---|
| 4448 | |
---|
| 4449 | if($mbox_stream) |
---|
| 4450 | { |
---|
| 4451 | imap_close($mbox_stream); |
---|
[3803] | 4452 | } |
---|
[3843] | 4453 | |
---|
[3803] | 4454 | $num_msgs = count($retorno); |
---|
[3223] | 4455 | |
---|
[3803] | 4456 | /* Comparison functions, descendent is ascendent with parms inverted */ |
---|
[4515] | 4457 | function SORTDATE($a, $b){ return ($a['udatecomp'] < $b['udatecomp']); } |
---|
[3803] | 4458 | function SORTDATE_REVERSE($b, $a) { return SORTDATE($a,$b); } |
---|
[3391] | 4459 | |
---|
[3803] | 4460 | function SORTWHO($a, $b) { return (strtoupper($a['from']) > strtoupper($b['from'])); } |
---|
| 4461 | function SORTWHO_REVERSE($b, $a) { return SORTWHO($a,$b); } |
---|
| 4462 | |
---|
| 4463 | function SORTSUBJECT($a, $b) { return (strtoupper($a['subject']) > strtoupper($b['subject'])); } |
---|
| 4464 | function SORTSUBJECT_REVERSE($b, $a) { return SORTSUBJECT($a,$b); } |
---|
| 4465 | |
---|
| 4466 | function SORTBOX($a, $b) { return ($a['boxname'] > $b['boxname']); } |
---|
| 4467 | function SORTBOX_REVERSE($b, $a) { return SORTBOX($a,$b); } |
---|
| 4468 | |
---|
| 4469 | function SORTSIZE($a, $b) { return ($a['size'] > $b['size']); } |
---|
| 4470 | function SORTSIZE_REVERSE($b, $a) { return SORTSIZE($a,$b); } |
---|
| 4471 | |
---|
[3843] | 4472 | usort( $retorno, $params['sort_type']); |
---|
| 4473 | $pageret = array_slice( $retorno, $params['page'] * $this->prefs['max_email_per_page'], $this->prefs['max_email_per_page']); |
---|
| 4474 | |
---|
| 4475 | $arrayRetorno['num_msgs'] = $num_msgs; |
---|
| 4476 | $arrayRetorno['data'] = $pageret; |
---|
[4158] | 4477 | $arrayRetorno['currentTab'] = $params['current_tab']; |
---|
[3803] | 4478 | |
---|
[3843] | 4479 | if ($pageret) |
---|
| 4480 | { |
---|
| 4481 | return $arrayRetorno; |
---|
| 4482 | } |
---|
| 4483 | else |
---|
| 4484 | { |
---|
| 4485 | return 'none'; |
---|
| 4486 | } |
---|
[2] | 4487 | } |
---|
[1472] | 4488 | |
---|
[3803] | 4489 | function get_msg_detail($uid_msg,$name_box, $mbox_stream ) |
---|
[271] | 4490 | { |
---|
[828] | 4491 | $header = $this->get_header($uid_msg); |
---|
[3803] | 4492 | require_once("class.imap_attachment.inc.php"); |
---|
[828] | 4493 | $imap_attachment = new imap_attachment(); |
---|
| 4494 | $attachments = $imap_attachment->get_attachment_headerinfo($mbox_stream, $uid_msg); |
---|
| 4495 | $attachments = $attachments['number_attachments'] > 0?"T".$attachments['number_attachments']:""; |
---|
| 4496 | $flag = $header->Unseen |
---|
| 4497 | .$header->Recent |
---|
| 4498 | .$header->Flagged |
---|
| 4499 | .$header->Draft |
---|
| 4500 | .$header->Answered |
---|
| 4501 | .$header->Deleted |
---|
| 4502 | .$attachments; |
---|
| 4503 | |
---|
| 4504 | |
---|
[163] | 4505 | $subject = $this->decode_string($header->fetchsubject); |
---|
| 4506 | $from = $header->from[0]->mailbox; |
---|
[2] | 4507 | if($header->from[0]->personal != "") |
---|
| 4508 | $from = $header->from[0]->personal; |
---|
[3843] | 4509 | $ret_msg['from'] = $this->decode_string($from); |
---|
| 4510 | $ret_msg['subject'] = $subject; |
---|
| 4511 | $ret_msg['udate'] = gmdate("d/m/Y",$header->udate + $this->functions->CalculateDateOffset()); |
---|
| 4512 | $ret_msg['size'] = $header->Size; |
---|
| 4513 | $ret_msg['flag'] = $flag; |
---|
[1472] | 4514 | return $ret_msg; |
---|
| 4515 | } |
---|
[3391] | 4516 | |
---|
| 4517 | |
---|
| 4518 | function size_msg($size){ |
---|
| 4519 | $var = floor($size/1024); |
---|
| 4520 | if($var >= 1){ |
---|
| 4521 | return $var." kb"; |
---|
| 4522 | }else{ |
---|
| 4523 | return $size ." b"; |
---|
| 4524 | } |
---|
| 4525 | } |
---|
| 4526 | |
---|
[2] | 4527 | function ob_array($the_object) |
---|
| 4528 | { |
---|
| 4529 | $the_array=array(); |
---|
| 4530 | if(!is_scalar($the_object)) |
---|
| 4531 | { |
---|
| 4532 | foreach($the_object as $id => $object) |
---|
| 4533 | { |
---|
| 4534 | if(is_scalar($object)) |
---|
| 4535 | { |
---|
| 4536 | $the_array[$id]=$object; |
---|
| 4537 | } |
---|
| 4538 | else |
---|
| 4539 | { |
---|
| 4540 | $the_array[$id]=$this->ob_array($object); |
---|
| 4541 | } |
---|
| 4542 | } |
---|
| 4543 | return $the_array; |
---|
| 4544 | } |
---|
| 4545 | else |
---|
| 4546 | { |
---|
| 4547 | return $the_object; |
---|
| 4548 | } |
---|
| 4549 | } |
---|
[1472] | 4550 | |
---|
[2] | 4551 | function getacl() |
---|
| 4552 | { |
---|
| 4553 | $this->ldap = new ldap_functions(); |
---|
[1472] | 4554 | |
---|
[2] | 4555 | $return = array(); |
---|
[1472] | 4556 | $mbox_stream = $this->open_mbox(); |
---|
[2] | 4557 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
[1472] | 4558 | |
---|
[2] | 4559 | $i = 0; |
---|
| 4560 | foreach ($mbox_acl as $user => $acl) |
---|
| 4561 | { |
---|
| 4562 | if ($user != $this->username) |
---|
| 4563 | { |
---|
| 4564 | $return[$i]['uid'] = $user; |
---|
| 4565 | $return[$i]['cn'] = $this->ldap->uid2cn($user); |
---|
| 4566 | } |
---|
| 4567 | $i++; |
---|
| 4568 | } |
---|
| 4569 | return $return; |
---|
| 4570 | } |
---|
[1472] | 4571 | |
---|
[2] | 4572 | function setacl($params) |
---|
| 4573 | { |
---|
| 4574 | $old_users = $this->getacl(); |
---|
| 4575 | if (!count($old_users)) |
---|
| 4576 | $old_users = array(); |
---|
[1472] | 4577 | |
---|
[2] | 4578 | $tmp_array = array(); |
---|
| 4579 | foreach ($old_users as $index => $user_info) |
---|
| 4580 | { |
---|
| 4581 | $tmp_array[$index] = $user_info['uid']; |
---|
| 4582 | } |
---|
| 4583 | $old_users = $tmp_array; |
---|
[1472] | 4584 | |
---|
[2] | 4585 | $users = unserialize($params['users']); |
---|
| 4586 | if (!count($users)) |
---|
| 4587 | $users = array(); |
---|
[1472] | 4588 | |
---|
[2] | 4589 | //$add_share = array_diff($users, $old_users); |
---|
| 4590 | $remove_share = array_diff($old_users, $users); |
---|
| 4591 | |
---|
| 4592 | $mbox_stream = $this->open_mbox(); |
---|
| 4593 | |
---|
| 4594 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 4595 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
| 4596 | |
---|
| 4597 | /*if (count($add_share)) |
---|
| 4598 | { |
---|
| 4599 | foreach ($add_share as $index=>$uid) |
---|
| 4600 | { |
---|
| 4601 | if (is_array($mailboxes_list)) |
---|
| 4602 | { |
---|
| 4603 | foreach ($mailboxes_list as $key => $val) |
---|
| 4604 | { |
---|
| 4605 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
| 4606 | imap_setacl ($mbox_stream, $folder, "$uid", "lrswipcda"); |
---|
| 4607 | } |
---|
| 4608 | } |
---|
| 4609 | } |
---|
| 4610 | }*/ |
---|
[1472] | 4611 | |
---|
[2] | 4612 | if (count($remove_share)) |
---|
| 4613 | { |
---|
| 4614 | foreach ($remove_share as $index=>$uid) |
---|
| 4615 | { |
---|
[4741] | 4616 | if (is_array($mailboxes_list)) |
---|
| 4617 | { |
---|
| 4618 | foreach ($mailboxes_list as $key => $val) |
---|
| 4619 | { |
---|
| 4620 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
| 4621 | $folder = str_replace("&-", "&", $folder); |
---|
| 4622 | imap_setacl ($mbox_stream, $folder, "$uid", ""); |
---|
| 4623 | } |
---|
| 4624 | } |
---|
[1472] | 4625 | } |
---|
[2] | 4626 | } |
---|
[1472] | 4627 | |
---|
[2] | 4628 | return true; |
---|
| 4629 | } |
---|
[1472] | 4630 | |
---|
[2] | 4631 | function getaclfromuser($params) |
---|
| 4632 | { |
---|
| 4633 | $useracl = $params['user']; |
---|
[1472] | 4634 | |
---|
[2] | 4635 | $return = array(); |
---|
| 4636 | $return[$useracl] = 'false'; |
---|
[1472] | 4637 | $mbox_stream = $this->open_mbox(); |
---|
[2] | 4638 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
[1472] | 4639 | |
---|
[2] | 4640 | foreach ($mbox_acl as $user => $acl) |
---|
| 4641 | { |
---|
| 4642 | if (($user != $this->username) && ($user == $useracl)) |
---|
| 4643 | { |
---|
| 4644 | $return[$user] = $acl; |
---|
| 4645 | } |
---|
| 4646 | } |
---|
| 4647 | return $return; |
---|
| 4648 | } |
---|
| 4649 | |
---|
| 4650 | function getacltouser($user) |
---|
| 4651 | { |
---|
| 4652 | $return = array(); |
---|
| 4653 | $mbox_stream = $this->open_mbox(); |
---|
[325] | 4654 | //Alterado, antes era 'imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); |
---|
| 4655 | //Afim de tratar as pastas compartilhadas, verificandos as permissoes de operacao sobre as mesmas |
---|
| 4656 | //No caso de se tratar da caixa do proprio usuario logado, utiliza a sintaxe abaixo |
---|
| 4657 | if(substr($user,0,4) != 'user') |
---|
[449] | 4658 | $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); |
---|
[325] | 4659 | else |
---|
[5134] | 4660 | $mbox_acl = @imap_getacl($mbox_stream, $user); |
---|
| 4661 | if(isset($mbox_acl[$this->username])) |
---|
[2] | 4662 | return $mbox_acl[$this->username]; |
---|
[5134] | 4663 | else |
---|
| 4664 | return ''; |
---|
[2] | 4665 | } |
---|
| 4666 | |
---|
[1472] | 4667 | |
---|
[2] | 4668 | function setaclfromuser($params) |
---|
| 4669 | { |
---|
| 4670 | $user = $params['user']; |
---|
| 4671 | $acl = $params['acl']; |
---|
[1472] | 4672 | |
---|
[2] | 4673 | $mbox_stream = $this->open_mbox(); |
---|
| 4674 | |
---|
| 4675 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 4676 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
| 4677 | |
---|
| 4678 | if (is_array($mailboxes_list)) |
---|
| 4679 | { |
---|
| 4680 | foreach ($mailboxes_list as $key => $val) |
---|
| 4681 | { |
---|
[449] | 4682 | $folder = str_replace($serverString, "", imap_utf7_encode($val->name)); |
---|
| 4683 | $folder = str_replace("&-", "&", $folder); |
---|
[2] | 4684 | if (!imap_setacl ($mbox_stream, $folder, $user, $acl)) |
---|
| 4685 | { |
---|
[449] | 4686 | $return = imap_last_error(); |
---|
[2] | 4687 | } |
---|
| 4688 | } |
---|
| 4689 | } |
---|
[449] | 4690 | if (isset($return)) |
---|
| 4691 | return $return; |
---|
| 4692 | else |
---|
| 4693 | return true; |
---|
[2] | 4694 | } |
---|
[1472] | 4695 | |
---|
[51] | 4696 | function download_attachment($msg,$msgno) |
---|
| 4697 | { |
---|
[1472] | 4698 | $array_parts_attachments = array(); |
---|
[3289] | 4699 | //$array_parts_attachments['names'] = ''; |
---|
[689] | 4700 | include_once("class.imap_attachment.inc.php"); |
---|
[1472] | 4701 | $imap_attachment = new imap_attachment(); |
---|
| 4702 | |
---|
[51] | 4703 | if (count($msg->fname[$msgno]) > 0) |
---|
| 4704 | { |
---|
| 4705 | $i = 0; |
---|
| 4706 | foreach ($msg->fname[$msgno] as $index=>$fname) |
---|
| 4707 | { |
---|
| 4708 | $array_parts_attachments[$i]['pid'] = $msg->pid[$msgno][$index]; |
---|
[1397] | 4709 | $array_parts_attachments[$i]['name'] = $imap_attachment->flat_mime_decode($this->decode_string($fname)); |
---|
[51] | 4710 | $array_parts_attachments[$i]['name'] = $array_parts_attachments[$i]['name'] ? $array_parts_attachments[$i]['name'] : "attachment.bin"; |
---|
| 4711 | $array_parts_attachments[$i]['encoding'] = $msg->encoding[$msgno][$index]; |
---|
[3289] | 4712 | //$array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', '; |
---|
[51] | 4713 | $array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index]; |
---|
| 4714 | $i++; |
---|
| 4715 | } |
---|
| 4716 | } |
---|
[3289] | 4717 | //$array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); |
---|
[51] | 4718 | return $array_parts_attachments; |
---|
[1472] | 4719 | } |
---|
[69] | 4720 | |
---|
[4436] | 4721 | |
---|
| 4722 | /** |
---|
| 4723 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 4724 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 4725 | * @param $params |
---|
| 4726 | */ |
---|
| 4727 | function spam($params) |
---|
[69] | 4728 | { |
---|
[4416] | 4729 | |
---|
| 4730 | $mbox_stream = $this->open_mbox($params['folder']); |
---|
[69] | 4731 | $msgs_number = explode(',',$params['msgs_number']); |
---|
| 4732 | |
---|
[4416] | 4733 | $user = Array(); |
---|
| 4734 | |
---|
| 4735 | if(substr($params['folder'], 0, 4) == 'user') |
---|
| 4736 | { |
---|
| 4737 | $ldapObject = new ldap_functions(); |
---|
| 4738 | |
---|
| 4739 | $folderArray = Array(); |
---|
| 4740 | $folderArray = explode($this->imap_delimiter, $params['folder']); |
---|
| 4741 | |
---|
| 4742 | $user['name'] = $folderArray[1]; |
---|
| 4743 | $user['email'] = $ldapObject->getMailByUid($user['name']); |
---|
| 4744 | |
---|
| 4745 | } |
---|
| 4746 | else |
---|
| 4747 | { |
---|
| 4748 | $user['name'] = $this->username; |
---|
| 4749 | $user['email'] = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 4750 | } |
---|
| 4751 | |
---|
| 4752 | foreach($msgs_number as $msg_number) |
---|
| 4753 | { |
---|
[877] | 4754 | $imap_msg_number = imap_msgno($mbox_stream, $msg_number); |
---|
| 4755 | $header = imap_fetchheader($mbox_stream, $imap_msg_number); |
---|
| 4756 | $body = imap_body($mbox_stream, $imap_msg_number); |
---|
[69] | 4757 | $msg = $header . $body; |
---|
[4416] | 4758 | strtok($user['email'], '@'); |
---|
[69] | 4759 | $domain = strtok('@'); |
---|
| 4760 | |
---|
[4416] | 4761 | |
---|
| 4762 | |
---|
[449] | 4763 | //Encontrar a assinatura do dspam no cabecalho |
---|
| 4764 | $v = explode("\r\n", $header); |
---|
| 4765 | foreach ($v as $linha){ |
---|
[877] | 4766 | if (eregi("^Message-ID", $linha)) { |
---|
| 4767 | $args = explode(" ", $linha); |
---|
| 4768 | $msg_id = "'$args[1]'"; |
---|
| 4769 | } elseif (eregi("^X-DSPAM-Signature", $linha)) { |
---|
[449] | 4770 | $args = explode(" ",$linha); |
---|
| 4771 | $signature = $args[1]; |
---|
| 4772 | } |
---|
| 4773 | } |
---|
| 4774 | |
---|
[877] | 4775 | // Seleciona qual comando a ser executado |
---|
[4416] | 4776 | switch($params['spam']){ |
---|
[449] | 4777 | case 'true': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam']; break; |
---|
| 4778 | case 'false': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham']; break; |
---|
| 4779 | } |
---|
[877] | 4780 | |
---|
[4416] | 4781 | |
---|
[877] | 4782 | $tags = array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##', '##MSGID##'); |
---|
[4416] | 4783 | $cmd = str_replace($tags, array($user['email'], $user['name'], $domain, $signature, $msg_id), $cmd); |
---|
| 4784 | |
---|
[78] | 4785 | system($cmd); |
---|
[69] | 4786 | } |
---|
[4416] | 4787 | |
---|
[69] | 4788 | imap_close($mbox_stream); |
---|
| 4789 | return false; |
---|
| 4790 | } |
---|
[4436] | 4791 | |
---|
| 4792 | |
---|
[5134] | 4793 | /** |
---|
| 4794 | * Descrição do método |
---|
| 4795 | * |
---|
| 4796 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 4797 | * @author |
---|
| 4798 | * @sponsor Caixa Econômica Federal |
---|
| 4799 | * @author |
---|
| 4800 | * @param <tipo> <$msg_number> <Número da mensagem> |
---|
| 4801 | * @return <cabeçalho da mensagem> |
---|
| 4802 | * @access <public> |
---|
| 4803 | */ |
---|
[4436] | 4804 | function get_header($msg_number) |
---|
| 4805 | { |
---|
[4795] | 4806 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); |
---|
[535] | 4807 | if (!is_object($header)) |
---|
| 4808 | return false; |
---|
[1472] | 4809 | |
---|
[5134] | 4810 | if($header->Flagged != "F" ) { |
---|
[659] | 4811 | $flag = preg_match('/importance *: *(.*)\r/i', |
---|
| 4812 | imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) |
---|
[1472] | 4813 | ,$importance); |
---|
[659] | 4814 | $header->Flagged = $flag==0?false:strtolower($importance[1])=="high"?"F":false; |
---|
| 4815 | } |
---|
[1472] | 4816 | |
---|
[535] | 4817 | return $header; |
---|
| 4818 | } |
---|
[1000] | 4819 | |
---|
| 4820 | //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 |
---|
| 4821 | ///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. |
---|
| 4822 | |
---|
[3911] | 4823 | function insert_email($source,$folder,$timestamp,$flags){ |
---|
[1000] | 4824 | $username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 4825 | $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
| 4826 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 4827 | $imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
| 4828 | $imap_options = '/notls/novalidate-cert'; |
---|
[5134] | 4829 | |
---|
| 4830 | |
---|
| 4831 | $folder = mb_convert_encoding( $folder, "UTF7-IMAP","ISO-8859-1"); |
---|
| 4832 | |
---|
[1000] | 4833 | $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); |
---|
[5134] | 4834 | |
---|
| 4835 | if(imap_last_error() === 'Mailbox already exists') |
---|
[1000] | 4836 | imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}".$folder)); |
---|
| 4837 | if($timestamp){ |
---|
[4436] | 4838 | $pdate = date_parse(date('r')); // pega a data atual do servidor (TODO: pegar a data da mensagem local) |
---|
| 4839 | $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] | 4840 | /* TODO: o diretorio /tmp deve ser substituido pelo diretorio temporario configurado no setup */ |
---|
| 4841 | $file = "/tmp/sess_".$_SESSION[ 'phpgw_session' ][ 'session_id' ]; |
---|
| 4842 | |
---|
[1000] | 4843 | $f = fopen($file,"w"); |
---|
| 4844 | fputs($f,base64_encode($source)); |
---|
[4795] | 4845 | fclose($f); |
---|
[5134] | 4846 | $command = "python ".$_SESSION['rootPath']."/expressoMail1_2/imap.py \"$imap_server\" \"$imap_port\" \"$username\" \"$password\" \"$timestamp\" \"$folder\" \"$file\""; |
---|
| 4847 | $return['command']= exec($command); |
---|
[1000] | 4848 | }else{ |
---|
| 4849 | $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $source, "\\Seen"); |
---|
| 4850 | } |
---|
| 4851 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); |
---|
[3872] | 4852 | |
---|
[1000] | 4853 | $return['msg_no'] = $status->uidnext - 1; |
---|
[3911] | 4854 | $return['error'] = imap_last_error(); |
---|
| 4855 | if(!$return['error'] && $flags != '' ){ |
---|
[3872] | 4856 | |
---|
[3911] | 4857 | $flags_array=explode(':',$flags); |
---|
| 4858 | //"Answered","Draft","Flagged","Unseen" |
---|
| 4859 | $flags_fixed = ""; |
---|
| 4860 | if($flags_array[0] == 'A') |
---|
| 4861 | $flags_fixed.="\\Answered "; |
---|
| 4862 | if($flags_array[1] == 'X') |
---|
| 4863 | $flags_fixed.="\\Draft "; |
---|
| 4864 | if($flags_array[2] == 'F') |
---|
| 4865 | $flags_fixed.="\\Flagged "; |
---|
| 4866 | if($flags_array[3] != 'U') |
---|
| 4867 | $flags_fixed.="\\Seen "; |
---|
| 4868 | |
---|
| 4869 | imap_setflag_full($mbox_stream, $return['msg_no'], $flags_fixed, ST_UID); |
---|
| 4870 | } |
---|
[5134] | 4871 | |
---|
| 4872 | //Ignorando erro de AUTH=Plain |
---|
| 4873 | if($return['error'] === 'SECURITY PROBLEM: insecure server advertised AUTH=PLAIN') |
---|
| 4874 | $return['error'] = false; |
---|
| 4875 | |
---|
[1000] | 4876 | if($mbox_stream) |
---|
[3911] | 4877 | imap_close($mbox_stream); |
---|
[1000] | 4878 | return $return; |
---|
| 4879 | } |
---|
| 4880 | |
---|
[5134] | 4881 | function show_decript($params,$dec=0){ |
---|
[1035] | 4882 | $source = $params['source']; |
---|
[5083] | 4883 | |
---|
[5134] | 4884 | //error_log("source: $source\nversao: " . PHP_VERSION); |
---|
| 4885 | if ($dec == 0) |
---|
| 4886 | { |
---|
| 4887 | $source = str_replace(" ", "+", $source,$i); |
---|
[5083] | 4888 | if (version_compare(PHP_VERSION, '5.2.0', '>=')){ |
---|
| 4889 | if(!$source = base64_decode($source,true)) |
---|
[5134] | 4890 | return "error ".$source."Espaï¿?os ".$i; |
---|
[5083] | 4891 | |
---|
| 4892 | } |
---|
| 4893 | else { |
---|
| 4894 | if(!$source = base64_decode($source)) |
---|
[5134] | 4895 | return "error ".$source."Espaï¿?os ".$i; |
---|
| 4896 | } |
---|
[1035] | 4897 | } |
---|
[3803] | 4898 | |
---|
[1035] | 4899 | $insert = $this->insert_email($source,'INBOX'.$this->imap_delimiter.'decifradas'); |
---|
| 4900 | |
---|
| 4901 | $get['msg_number'] = $insert['msg_no']; |
---|
| 4902 | $get['msg_folder'] = 'INBOX'.$this->imap_delimiter.'decifradas'; |
---|
| 4903 | $return = $this->get_info_msg($get); |
---|
| 4904 | $get['msg_number'] = $params['ID']; |
---|
| 4905 | $get['msg_folder'] = $params['folder']; |
---|
| 4906 | $tmp = $this->get_info_msg($get); |
---|
| 4907 | if(!$tmp['status_get_msg_info']) |
---|
| 4908 | { |
---|
| 4909 | $return['msg_day']=$tmp['msg_day']; |
---|
| 4910 | $return['msg_hour']=$tmp['msg_hour']; |
---|
| 4911 | $return['fulldate']=$tmp['fulldate']; |
---|
| 4912 | $return['smalldate']=$tmp['smalldate']; |
---|
| 4913 | } |
---|
| 4914 | else |
---|
| 4915 | { |
---|
| 4916 | $return['msg_day']=''; |
---|
| 4917 | $return['msg_hour']=''; |
---|
| 4918 | $return['fulldate']=''; |
---|
| 4919 | $return['smalldate']=''; |
---|
| 4920 | } |
---|
| 4921 | $return['msg_no'] =$insert['msg_no']; |
---|
| 4922 | $return['error'] = $insert['error']; |
---|
| 4923 | $return['folder'] = $params['folder']; |
---|
| 4924 | //$return['acls'] = $insert['acls']; |
---|
| 4925 | $return['original_ID'] = $params['ID']; |
---|
| 4926 | |
---|
| 4927 | return $return; |
---|
| 4928 | |
---|
| 4929 | } |
---|
[1472] | 4930 | |
---|
[1000] | 4931 | //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 |
---|
| 4932 | //Base64 os "+" são substituidos por " " no envio e essa função arruma esse efeito. |
---|
| 4933 | |
---|
| 4934 | function treat_base64_from_post($source){ |
---|
| 4935 | $offset = 0; |
---|
| 4936 | do |
---|
| 4937 | { |
---|
| 4938 | if($inicio = strpos($source, 'Content-Transfer-Encoding: base64', $offset)) |
---|
| 4939 | { |
---|
| 4940 | $inicio = strpos($source, "\n\r", $inicio); |
---|
| 4941 | $fim = strpos($source, '--', $inicio); |
---|
| 4942 | if(!$fim) |
---|
| 4943 | $fim = strpos($source,"\n\r", $inicio); |
---|
| 4944 | $length = $fim-$inicio; |
---|
| 4945 | $parte = substr( $source,$inicio,$length-1); |
---|
| 4946 | $parte = str_replace(" ", "+", $parte); |
---|
| 4947 | $source = substr_replace($source, $parte, $inicio, $length-1); |
---|
| 4948 | } |
---|
| 4949 | if($offset > $inicio) |
---|
| 4950 | $offset=FALSE; |
---|
| 4951 | else |
---|
| 4952 | $offset = $inicio; |
---|
| 4953 | } |
---|
| 4954 | while($offset); |
---|
| 4955 | return $source; |
---|
| 4956 | } |
---|
| 4957 | |
---|
| 4958 | //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. |
---|
| 4959 | |
---|
| 4960 | function unarchive_mail($params) |
---|
| 4961 | { |
---|
| 4962 | $dest_folder = $params['folder']; |
---|
| 4963 | $sources = explode("#@#@#@",$params['source']); |
---|
[5134] | 4964 | //Add user timeszone |
---|
| 4965 | $timestamps = $params['timestamp'] + $this->functions->CalculateDateOffset(); |
---|
[3911] | 4966 | $flags = explode("#@#@#@",$params['flags']); |
---|
[3872] | 4967 | |
---|
[5134] | 4968 | foreach($sources as $index=>$src) { |
---|
| 4969 | if($src!=""){ |
---|
[3911] | 4970 | $source = $this->treat_base64_from_post($src); |
---|
[5134] | 4971 | $insert = $this->insert_email($source, mb_convert_encoding( $dest_folder,"ISO-8859-1","UTF-8"), $timestamps,$flags[$index]); |
---|
[3911] | 4972 | } |
---|
| 4973 | } |
---|
[1000] | 4974 | return $insert; |
---|
| 4975 | } |
---|
| 4976 | |
---|
| 4977 | function download_all_local_attachments($params) |
---|
| 4978 | { |
---|
| 4979 | $source = $params['source']; |
---|
| 4980 | $source = $this->treat_base64_from_post($source); |
---|
| 4981 | $insert = $this->insert_email($source,'INBOX'.$this->imap_delimiter.'decifradas'); |
---|
| 4982 | $exporteml = new ExportEml(); |
---|
| 4983 | $params['num_msg']=$insert['msg_no']; |
---|
| 4984 | $params['folder']='INBOX'.$this->imap_delimiter.'decifradas'; |
---|
| 4985 | return $exporteml->download_all_attachments($params); |
---|
| 4986 | } |
---|
[4830] | 4987 | |
---|
| 4988 | /** |
---|
| 4989 | * Método que envia um email reportando um erro no email do usuário |
---|
| 4990 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 4991 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
| 4992 | */ |
---|
| 4993 | function report_mail_error($params) |
---|
| 4994 | { |
---|
| 4995 | $params = $params['params']; |
---|
| 4996 | $array_params = explode(";;", $params); |
---|
| 4997 | $id_msg = $array_params[0]; |
---|
| 4998 | $msg_user = $array_params[1]; |
---|
| 4999 | |
---|
| 5000 | if($msg_user == '') |
---|
| 5001 | $msg_user = "Sem mensagem!"; |
---|
| 5002 | |
---|
| 5003 | $toname = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
| 5004 | |
---|
| 5005 | $exporteml = new ExportEml(); |
---|
| 5006 | $mail_content = $exporteml->export_msg_data($id_msg, $msg_folder); |
---|
| 5007 | $this->open_mbox($msg_folder); |
---|
| 5008 | $title = "Erro de email reportado"; |
---|
| 5009 | $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>" . |
---|
| 5010 | "$msg_user</body><br><br><hr>"; |
---|
| 5011 | |
---|
[5134] | 5012 | require_once $_SESSION['rootPath'] . '/API/class.servicelocator.php'; |
---|
[4830] | 5013 | $mailService = ServiceLocator::getService('mail'); |
---|
[5134] | 5014 | $mailService->addStringAttachment($mail_content, 'report.eml', 'application/text'); |
---|
| 5015 | $mailService->sendMail($_SESSION['phpgw_info']['expressomail']['server']['sugestoes_email_to'], $GLOBALS['phpgw_info']['user']['email'], $title, $body); |
---|
[4830] | 5016 | } |
---|
| 5017 | |
---|
[5134] | 5018 | function array_msort($array, $cols) |
---|
| 5019 | { |
---|
| 5020 | $colarr = array(); |
---|
| 5021 | foreach ($cols as $col => $order) { |
---|
| 5022 | $colarr[$col] = array(); |
---|
| 5023 | foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } |
---|
| 5024 | } |
---|
| 5025 | $params = array(); |
---|
| 5026 | foreach ($cols as $col => $order) { |
---|
| 5027 | $params[] =& $colarr[$col]; |
---|
| 5028 | $params = array_merge($params, (array)$order); |
---|
| 5029 | } |
---|
| 5030 | call_user_func_array('array_multisort', $params); |
---|
| 5031 | $ret = array(); |
---|
| 5032 | $keys = array(); |
---|
| 5033 | $first = true; |
---|
| 5034 | foreach ($colarr as $col => $arr) { |
---|
| 5035 | foreach ($arr as $k => $v) { |
---|
| 5036 | if ($first) { $keys[$k] = substr($k,1); } |
---|
| 5037 | $k = $keys[$k]; |
---|
| 5038 | if (!isset($ret[$k])) $ret[$k] = $array[$k]; |
---|
| 5039 | $ret[$k][$col] = $array[$k][$col]; |
---|
| 5040 | } |
---|
| 5041 | $first = false; |
---|
| 5042 | } |
---|
| 5043 | |
---|
| 5044 | return $ret; |
---|
| 5045 | |
---|
| 5046 | } |
---|
| 5047 | |
---|
| 5048 | function parseCriteriaSearchMail($search) |
---|
| 5049 | { |
---|
| 5050 | $criteria = ''; |
---|
| 5051 | $searchArray = explode(' ', $search); |
---|
| 5052 | |
---|
| 5053 | foreach ($searchArray as $v) |
---|
| 5054 | if(trim($v) !== '' ) |
---|
| 5055 | $criteria .= 'TEXT "'.$v.'" ' ; |
---|
| 5056 | |
---|
| 5057 | return $criteria; |
---|
| 5058 | } |
---|
| 5059 | |
---|
| 5060 | function quickSearchMail( $params ) |
---|
| 5061 | { |
---|
| 5062 | $return = array(); |
---|
| 5063 | $return['folder'] = $params['folder']; |
---|
| 5064 | if(!is_array($params['folder'])) |
---|
| 5065 | $params['folder'] = array( $params['folder'] ); |
---|
| 5066 | |
---|
| 5067 | if(!isset($params['sort'])) |
---|
| 5068 | $params['sort'] = SORTDATE; |
---|
| 5069 | |
---|
| 5070 | $params['search'] = mb_convert_encoding($params['search'], 'UTF-8',mb_detect_encoding($params['search'].'x', 'UTF-8, ISO-8859-1')); |
---|
| 5071 | |
---|
| 5072 | $i = 0; |
---|
| 5073 | if(!isset($params['page'])) $params['page'] = 0; |
---|
| 5074 | $end = ($this->prefs['max_email_per_page'] * ((int)$params['page'] + 1)); |
---|
| 5075 | $ini = $end - $this->prefs['max_email_per_page'] ; |
---|
| 5076 | $count = 0; |
---|
| 5077 | |
---|
| 5078 | $search = $this->parseCriteriaSearchMail($params['search']); |
---|
| 5079 | |
---|
| 5080 | foreach ($params['folder'] as $folder) |
---|
| 5081 | { |
---|
| 5082 | $imap = $this->open_mbox( $folder ) ; |
---|
| 5083 | $msgIds = imap_sort( $imap , SORTDATE , 0 , SE_UID , $search ,'UTF-8'); |
---|
| 5084 | |
---|
| 5085 | $count += count($msgIds); |
---|
| 5086 | |
---|
| 5087 | foreach ($msgIds as $ii => $v) |
---|
| 5088 | { |
---|
| 5089 | $msg = imap_headerinfo ( $imap, imap_msgno($imap, $v) ); |
---|
| 5090 | $return['msgs'][$i]['from'] = ''; |
---|
| 5091 | |
---|
| 5092 | $from = $msg->from[0]->mailbox; |
---|
| 5093 | if($msg->from[0]->personal != "") |
---|
| 5094 | $from = $msg->from[0]->personal; |
---|
| 5095 | $return['msgs'][$i]['from'] = mb_convert_encoding($this->decode_string($from), 'UTF-8'); |
---|
| 5096 | |
---|
| 5097 | $return['msgs'][$i]['subject'] = ' '; |
---|
| 5098 | |
---|
| 5099 | $subject = imap_mime_header_decode($msg->subject); |
---|
| 5100 | foreach ($subject as $tmp) |
---|
| 5101 | $return['msgs'][$i]['subject'] .= mb_convert_encoding($tmp->text, 'UTF-8'); |
---|
| 5102 | |
---|
| 5103 | $return['msgs'][$i]['flag'] = ' '; |
---|
| 5104 | $return['msgs'][$i]['flag'] .= $msg->Unseen ? $msg->Unseen : ''; |
---|
| 5105 | $return['msgs'][$i]['flag'] .= $msg->Recent ? $msg->Recent : ''; |
---|
| 5106 | $return['msgs'][$i]['flag'] .= $msg->Flagged ? $msg->Flagged : ''; |
---|
| 5107 | $return['msgs'][$i]['flag'] .= $msg->Draft ? $msg->Draft : ''; |
---|
| 5108 | $return['msgs'][$i]['flag'] .= $msg->Answered ? $msg->Answered : ''; |
---|
| 5109 | $return['msgs'][$i]['flag'] .= $msg->Deleted ? $msg->Deleted : ''; |
---|
| 5110 | |
---|
| 5111 | $return['msgs'][$i]['udate'] = gmdate("d/m/Y",$msg->udate + $this->functions->CalculateDateOffset()); |
---|
| 5112 | $return['msgs'][$i]['udatecomp'] = substr ($return['msgs'][$i]['udate'], -4) ."-". substr ($return['msgs'][$i]['udate'], 3, 2) ."-". substr ($return['msgs'][$i]['udate'], 0, 2); |
---|
| 5113 | $return['msgs'][$i]['date'] = $msg->udate; |
---|
| 5114 | $return['msgs'][$i]['size'] = $msg->Size; |
---|
| 5115 | $return['msgs'][$i]['boxname'] = $folder; |
---|
| 5116 | $return['msgs'][$i]['uid'] = $v; |
---|
| 5117 | $i++; |
---|
| 5118 | } |
---|
| 5119 | } |
---|
| 5120 | |
---|
| 5121 | $return['num_msgs'] = $count; |
---|
| 5122 | |
---|
| 5123 | if(!isset($return['msgs'])) |
---|
| 5124 | $return['msgs'] = array(); |
---|
| 5125 | |
---|
| 5126 | define('SORTBOX', 69); |
---|
| 5127 | define('SORTWHO', 2); |
---|
| 5128 | define('SORTBOX_REVERSE', 69); |
---|
| 5129 | define('SORTWHO_REVERSE', 2); |
---|
| 5130 | define('SORTDATE_REVERSE', 0); |
---|
| 5131 | define('SORTSUBJECT_REVERSE', 3); |
---|
| 5132 | define('SORTSIZE_REVERSE', 6); |
---|
| 5133 | |
---|
| 5134 | switch (constant( $params['sort'] )){ |
---|
| 5135 | case 0 : $sA = 'date'; break; |
---|
| 5136 | case 2 : $sA = 'from'; break; |
---|
| 5137 | case 69 : $sA = 'boxname'; break; |
---|
| 5138 | case 3 : $sA = 'subject'; break; |
---|
| 5139 | case 6 : $sA = 'size'; break; |
---|
| 5140 | } |
---|
[4830] | 5141 | |
---|
[5134] | 5142 | $return['msgs'] = $this->array_msort($return['msgs'] , array( $sA => SORT_ASC)); |
---|
| 5143 | |
---|
| 5144 | if(strpos($params['sort'],'REVERSE') !== false) |
---|
| 5145 | $return['msgs'] = array_reverse($return['msgs']); |
---|
| 5146 | |
---|
| 5147 | |
---|
| 5148 | $k = -1; |
---|
| 5149 | $nMsgs = array(); |
---|
| 5150 | |
---|
| 5151 | foreach ($return['msgs'] as $v) |
---|
| 5152 | { |
---|
| 5153 | $k++; |
---|
| 5154 | if($k < $ini || $k >= $end ) continue; |
---|
| 5155 | $nMsgs[] = $v; |
---|
| 5156 | } |
---|
| 5157 | $return['msgs'] = $nMsgs; |
---|
| 5158 | $return = json_encode($return); |
---|
| 5159 | $return = base64_encode($return); |
---|
[4830] | 5160 | |
---|
[5134] | 5161 | return $return; |
---|
| 5162 | } |
---|
| 5163 | |
---|
[3157] | 5164 | function get_quota_folders(){ |
---|
| 5165 | |
---|
| 5166 | // Additional Imap Class for not-implemented functions into PHP-IMAP extension. |
---|
| 5167 | include_once("class.imapfp.inc.php"); |
---|
| 5168 | $imapfp = new imapfp(); |
---|
| 5169 | |
---|
| 5170 | if(!$imapfp->open($this->imap_server,$this->imap_port)) |
---|
| 5171 | return $imapfp->get_error(); |
---|
| 5172 | if (!$imapfp->login( $this->username,$this->password )) |
---|
| 5173 | return $imapfp->get_error(); |
---|
| 5174 | |
---|
| 5175 | $response_array = $imapfp->get_mailboxes_size(); |
---|
| 5176 | if ($imapfp->error) |
---|
| 5177 | return $imapfp->get_error(); |
---|
| 5178 | |
---|
| 5179 | $data = array(); |
---|
| 5180 | $quota_root = $this->get_quota(array('folder_id' => "INBOX")); |
---|
| 5181 | $data["quota_root"] = $quota_root; |
---|
| 5182 | |
---|
| 5183 | foreach ($response_array as $idx=>$line) { |
---|
| 5184 | $line2 = str_replace('"', "", $line); |
---|
| 5185 | $line2 = str_replace(" /vendor/cmu/cyrus-imapd/size (value.shared ",";",str_replace("* ANNOTATION ","",$line2)); |
---|
| 5186 | list($folder,$size) = explode(";",$line2); |
---|
[3854] | 5187 | $quota_used = str_replace(")","",$size); |
---|
| 5188 | $quotaPercent = (($quota_used / 1024) / $data["quota_root"]["quota_limit"])*100; |
---|
[3157] | 5189 | $folder = mb_convert_encoding($folder, "ISO_8859-1", "UTF7-IMAP"); |
---|
| 5190 | if(!preg_match('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i',$folder)){ |
---|
| 5191 | $folder = $this->functions->getLang("Inbox"); |
---|
| 5192 | } |
---|
| 5193 | else |
---|
| 5194 | $folder = preg_replace('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i','', $folder); |
---|
| 5195 | |
---|
| 5196 | $data[$folder] = array("quota_percent" => sprintf("%.1f",round($quotaPercent,1)), "quota_used" => $quota_used); |
---|
| 5197 | } |
---|
| 5198 | $imapfp->close(); |
---|
| 5199 | return $data; |
---|
| 5200 | } |
---|
[5134] | 5201 | |
---|
| 5202 | function getaclfrombox($mail) |
---|
| 5203 | { |
---|
| 5204 | $mailArray = explode('@', $mail); |
---|
| 5205 | $boxacl = $mailArray[0]; |
---|
| 5206 | $return = array(); |
---|
| 5207 | |
---|
| 5208 | if(!$this->mbox) |
---|
| 5209 | $this->open_mbox(); |
---|
| 5210 | |
---|
| 5211 | $mbox_acl = imap_getacl($this->mbox, 'user' . $this->imap_delimiter . $boxacl); |
---|
| 5212 | |
---|
| 5213 | foreach ($mbox_acl as $user => $acl) |
---|
| 5214 | { |
---|
| 5215 | if ($user != $boxacl ) |
---|
| 5216 | $return[$user] = $acl; |
---|
| 5217 | } |
---|
| 5218 | return $return; |
---|
| 5219 | } |
---|
[2] | 5220 | } |
---|
[278] | 5221 | ?> |
---|