[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 | { |
---|
[5223] | 60 | $folder = mb_convert_encoding($folder, "UTF7-IMAP",'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"); |
---|
[5172] | 597 | |
---|
| 598 | if(array_key_exists('messages', $params)){ |
---|
| 599 | $sel_msgs = explode(",", $params['messages']); |
---|
| 600 | @reset($sel_msgs); |
---|
| 601 | $sorted_msgs = array(); |
---|
| 602 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 603 | $sel_msg = explode(";", $sel_msg); |
---|
| 604 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 605 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
| 606 | } |
---|
| 607 | else { |
---|
| 608 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 609 | } |
---|
| 610 | } |
---|
| 611 | unset($sorted_msgs['']); |
---|
| 612 | |
---|
| 613 | $return = array(); |
---|
| 614 | $array_names_keys = array_keys($sorted_msgs); |
---|
| 615 | |
---|
| 616 | for($i = 0; $i < count($sorted_msgs); $i++){ |
---|
| 617 | |
---|
| 618 | $new_params = array(); |
---|
| 619 | $attach_params = array(); |
---|
| 620 | |
---|
| 621 | $new_params["msg_folder"]= $array_names_keys[$i]; |
---|
| 622 | $attach_params["folder"] = $params["folder"]; |
---|
| 623 | $msgs = explode(",",$sorted_msgs[$array_names_keys[$i]]); |
---|
| 624 | $exporteml = new ExportEml(); |
---|
| 625 | $unseen_msgs = array(); |
---|
| 626 | foreach($msgs as $msg_number) { |
---|
| 627 | $new_params["msg_number"] = $msg_number; |
---|
| 628 | //ini_set("display_errors","1"); |
---|
| 629 | $msg_info = $this->get_info_msg($new_params); |
---|
| 630 | |
---|
| 631 | $this->mbox = $this->open_mbox($array_names_keys[$i]); //Não sei porque, mas se não abrir de novo a caixa dá erro. |
---|
| 632 | $msg_info['header'] = $this->get_info_head_msg($msg_number); |
---|
| 633 | |
---|
| 634 | $attach_params["num_msg"] = $msg_number; |
---|
| 635 | $msg_info['array_attach'] = $exporteml->get_attachments_in_array($attach_params); |
---|
| 636 | imap_close($this->mbox); |
---|
| 637 | $this->mbox=false; |
---|
| 638 | array_push($return,serialize($msg_info)); |
---|
| 639 | |
---|
| 640 | if($msg_info['Unseen'] == "U" || $msg_info['Recent'] == "N"){ |
---|
| 641 | array_push($unseen_msgs,$msg_number); |
---|
| 642 | } |
---|
| 643 | } |
---|
| 644 | } |
---|
| 645 | if($unseen_msgs){ |
---|
| 646 | $msgs_list = implode(",",$unseen_msgs); |
---|
| 647 | $array_msgs = array('folder' => $new_params["msg_folder"], "msgs_to_set" => $msgs_list, "flag" => "unseen"); |
---|
| 648 | $this->set_messages_flag($array_msgs); |
---|
| 649 | } |
---|
| 650 | return $return; |
---|
| 651 | }else{ |
---|
[689] | 652 | $return = array(); |
---|
| 653 | $new_params = array(); |
---|
| 654 | $attach_params = array(); |
---|
| 655 | $new_params["msg_folder"]=$params["folder"]; |
---|
| 656 | $attach_params["folder"] = $params["folder"]; |
---|
| 657 | $msgs = explode(",",$params["msgs_number"]); |
---|
| 658 | $exporteml = new ExportEml(); |
---|
[1382] | 659 | $unseen_msgs = array(); |
---|
[689] | 660 | foreach($msgs as $msg_number) { |
---|
| 661 | $new_params["msg_number"] = $msg_number; |
---|
| 662 | //ini_set("display_errors","1"); |
---|
| 663 | $msg_info = $this->get_info_msg($new_params); |
---|
| 664 | |
---|
| 665 | $this->mbox = $this->open_mbox($params['folder']); //Não sei porque, mas se não abrir de novo a caixa dá erro. |
---|
| 666 | $msg_info['header'] = $this->get_info_head_msg($msg_number); |
---|
| 667 | |
---|
| 668 | $attach_params["num_msg"] = $msg_number; |
---|
| 669 | $msg_info['array_attach'] = $exporteml->get_attachments_in_array($attach_params); |
---|
| 670 | imap_close($this->mbox); |
---|
| 671 | $this->mbox=false; |
---|
| 672 | array_push($return,serialize($msg_info)); |
---|
[1472] | 673 | |
---|
[1388] | 674 | if($msg_info['Unseen'] == "U" || $msg_info['Recent'] == "N"){ |
---|
[1472] | 675 | array_push($unseen_msgs,$msg_number); |
---|
| 676 | } |
---|
| 677 | } |
---|
[1382] | 678 | if($unseen_msgs){ |
---|
| 679 | $msgs_list = implode(",",$unseen_msgs); |
---|
| 680 | $array_msgs = array('folder' => $new_params["msg_folder"], "msgs_to_set" => $msgs_list, "flag" => "unseen"); |
---|
[1472] | 681 | $this->set_messages_flag($array_msgs); |
---|
[689] | 682 | } |
---|
| 683 | return $return; |
---|
| 684 | } |
---|
[5172] | 685 | } |
---|
[4795] | 686 | |
---|
[4436] | 687 | /** |
---|
[5079] | 688 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 689 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 690 | * @param $msg_number numero da mensagem |
---|
[4436] | 691 | */ |
---|
[4416] | 692 | function getRawHeader($msg_number) |
---|
| 693 | { |
---|
| 694 | return imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
| 695 | } |
---|
| 696 | |
---|
[4436] | 697 | /** |
---|
[5079] | 698 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 699 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 700 | * @param $msg_number numero da mensagem |
---|
[4436] | 701 | */ |
---|
[4416] | 702 | function getRawBody($msg_number) |
---|
| 703 | { |
---|
| 704 | return imap_body($this->mbox, $msg_number, FT_UID); |
---|
| 705 | } |
---|
[689] | 706 | |
---|
[4436] | 707 | |
---|
| 708 | /** |
---|
[5079] | 709 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 710 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 711 | * @param $msg mensagem |
---|
[4436] | 712 | */ |
---|
[4416] | 713 | function builderMsgHeader($msg) |
---|
| 714 | { |
---|
| 715 | |
---|
| 716 | |
---|
| 717 | $fromMail = str_replace('<','', str_replace('>','',$msg->headers['from'])); |
---|
| 718 | $tosMails = str_replace('<','', str_replace('>','',$msg->headers['to'])); |
---|
| 719 | |
---|
| 720 | $tos = explode(',',$tosMails); |
---|
| 721 | $to = ''; |
---|
| 722 | foreach ($tos as $value) |
---|
| 723 | { |
---|
| 724 | $to .= '<a href="mailto:'.str_replace(' ','',$value).'">'.$value.'</a>, '; |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | $header = ' |
---|
| 728 | <table style="margin: 2px; border: 1px solid black; background: none repeat scroll 0% 0% rgb(234, 234, 234);"> |
---|
| 729 | <tbody> |
---|
| 730 | <tr><td><b>'.$this->functions->getLang('Subject').':</b></td><td>'.$msg->headers['subject'].'</td></tr> |
---|
| 731 | <tr><td><b>'.$this->functions->getLang('From').':</b></td><td><a href="mailto:'.$fromMail.'">'.$fromMail.'</a></td></tr> |
---|
| 732 | <tr><td><b>'.$this->functions->getLang('Date').':</b></td><td>'.$msg->headers['date'].'</td></tr> |
---|
| 733 | <tr><td><b>'.$this->functions->getLang('To').':</b></td><td>'.$to.'</td></tr> |
---|
| 734 | </tbody> |
---|
| 735 | </table> |
---|
| 736 | <br />' |
---|
| 737 | ; |
---|
| 738 | |
---|
| 739 | return $header; |
---|
| 740 | } |
---|
| 741 | |
---|
[5079] | 742 | /** |
---|
[5134] | 743 | * Constroe o corpo da msg direto na variavel de conteudo |
---|
| 744 | * @param Mail_mimeDecode $structure |
---|
| 745 | * @param <type> $content Ponteiro para Variavel de conteudo da msg |
---|
[5079] | 746 | */ |
---|
[4416] | 747 | function builderMsgBody($structure , &$content , $printHeader = false) |
---|
| 748 | { |
---|
| 749 | if(strtolower($structure->ctype_primary) == 'multipart' && strtolower($structure->ctype_secondary) == 'alternative') |
---|
| 750 | { |
---|
| 751 | $numParts = count($structure->parts) - 1; |
---|
| 752 | |
---|
| 753 | for($i = $numParts; $i >= 0; $i--) |
---|
| 754 | { |
---|
| 755 | $part = $structure->parts[$i]; |
---|
| 756 | |
---|
| 757 | switch (strtolower($part->ctype_primary)) |
---|
| 758 | { |
---|
| 759 | case 'text': |
---|
[5134] | 760 | $disposition = isset($part->disposition) ? strtolower($part->disposition) : ''; |
---|
[4416] | 761 | if($disposition != 'attachment') |
---|
| 762 | { |
---|
| 763 | if(strtolower($part->ctype_secondary) == 'html') |
---|
| 764 | { |
---|
| 765 | if($printHeader) |
---|
| 766 | $content .= $this->builderMsgHeader($part); |
---|
| 767 | |
---|
| 768 | $content .= $this->decodeMailPart($part->body,$part->ctype_parameters['charset']); |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | if(strtolower($part->ctype_secondary) == 'plain' ) |
---|
| 772 | { |
---|
| 773 | if($printHeader) |
---|
| 774 | $content .= $this->builderMsgHeader($part); |
---|
| 775 | |
---|
[4781] | 776 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body,$part->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 777 | } |
---|
[5134] | 778 | if(strtolower($part->ctype_secondary) == 'calendar') |
---|
| 779 | $content.= $this->builderMsgCalendar($this->decodeMailPart($part->body, $part->ctype_parameters['charset'])); |
---|
[4416] | 780 | |
---|
| 781 | } |
---|
| 782 | |
---|
| 783 | $i = -1; |
---|
| 784 | break; |
---|
| 785 | |
---|
| 786 | case 'multipart': |
---|
| 787 | |
---|
| 788 | if($printHeader) |
---|
| 789 | $content .= $this->builderMsgHeader($part); |
---|
| 790 | |
---|
| 791 | $this->builderMsgBody($part,$content); |
---|
| 792 | |
---|
| 793 | $i = -1; |
---|
| 794 | break; |
---|
| 795 | |
---|
| 796 | case 'message': |
---|
| 797 | |
---|
| 798 | if(!is_array($part->parts)) |
---|
| 799 | { |
---|
| 800 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4781] | 801 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body, $structure->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 802 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
| 803 | } |
---|
| 804 | else |
---|
| 805 | $this->builderMsgBody($part,$content,true); |
---|
| 806 | |
---|
| 807 | $i = -1; |
---|
| 808 | break; |
---|
| 809 | } |
---|
| 810 | } |
---|
| 811 | } |
---|
| 812 | else |
---|
| 813 | { |
---|
| 814 | foreach ($structure->parts as $index => $part) |
---|
| 815 | { |
---|
| 816 | switch (strtolower($part->ctype_primary)) |
---|
| 817 | { |
---|
| 818 | case 'text': |
---|
[5134] | 819 | $disposition = ''; |
---|
| 820 | if(isset($part->disposition)) |
---|
| 821 | $disposition = isset($part->disposition) ? strtolower($part->disposition) : ''; |
---|
[4416] | 822 | if($disposition != 'attachment') |
---|
| 823 | { |
---|
| 824 | if(strtolower($part->ctype_secondary) == 'html') |
---|
| 825 | { |
---|
| 826 | if($printHeader) |
---|
| 827 | $content .= $this->builderMsgHeader($part); |
---|
| 828 | |
---|
| 829 | $content .= $this->decodeMailPart($part->body,$part->ctype_parameters['charset']); |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | if(strtolower($part->ctype_secondary) == 'plain') |
---|
| 833 | { |
---|
| 834 | if($printHeader) |
---|
| 835 | $content .= $this->builderMsgHeader($part); |
---|
| 836 | |
---|
[4781] | 837 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body,$part->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 838 | } |
---|
[5134] | 839 | if(strtolower($part->ctype_secondary) == 'calendar') |
---|
| 840 | $content .= $this->builderMsgCalendar($part->body); |
---|
[4416] | 841 | |
---|
| 842 | } |
---|
| 843 | break; |
---|
| 844 | case 'multipart': |
---|
| 845 | |
---|
| 846 | if($printHeader) |
---|
| 847 | $content .= $this->builderMsgHeader($part); |
---|
| 848 | |
---|
| 849 | $this->builderMsgBody($part,$content); |
---|
| 850 | |
---|
| 851 | break; |
---|
| 852 | case 'message': |
---|
[5134] | 853 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['nested_messages_are_shown'] != '1') |
---|
| 854 | { |
---|
[4416] | 855 | if(!is_array($part->parts)) |
---|
| 856 | { |
---|
| 857 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4781] | 858 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body, $structure->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 859 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
| 860 | } |
---|
| 861 | else |
---|
| 862 | $this->builderMsgBody($part,$content,true); |
---|
| 863 | break; |
---|
| 864 | } |
---|
| 865 | } |
---|
| 866 | } |
---|
| 867 | } |
---|
[5134] | 868 | } |
---|
[4416] | 869 | |
---|
| 870 | |
---|
[4436] | 871 | /** |
---|
[5079] | 872 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 873 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 874 | * @param $msg_number numero da mensagem |
---|
[4436] | 875 | */ |
---|
| 876 | function get_msg_sample($msg_number) |
---|
[4416] | 877 | { |
---|
[5134] | 878 | $content = ''; |
---|
[4416] | 879 | |
---|
| 880 | $return = ""; |
---|
| 881 | if( (!isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] != "1")) && |
---|
| 882 | (!isset($this->prefs['preview_msg_tip'] ) || ($this->prefs['preview_msg_tip'] != "1")) ) |
---|
| 883 | { |
---|
| 884 | $return['body'] = ""; |
---|
| 885 | return $return; |
---|
| 886 | } |
---|
| 887 | |
---|
| 888 | include_once("class.message_components.inc.php"); |
---|
[5134] | 889 | $msg = new message_components($this->mbox); |
---|
[4416] | 890 | $msg->fetch_structure($msg_number); |
---|
| 891 | |
---|
[5134] | 892 | if(!isset($msg->structure[$msg_number]->parts)) |
---|
[4416] | 893 | { |
---|
| 894 | $content = ''; |
---|
| 895 | if (strtolower($msg->structure[$msg_number]->subtype) == "plain" || strtolower($msg->structure[$msg_number]->subtype) == "html") |
---|
| 896 | { |
---|
| 897 | $content = $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID|FT_PEEK), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]); |
---|
| 898 | } |
---|
| 899 | } |
---|
| 900 | else |
---|
| 901 | { |
---|
| 902 | foreach($msg->pid[$msg_number] as $values => $msg_part) |
---|
| 903 | { |
---|
| 904 | |
---|
| 905 | $file_type = strtolower($msg->file_type[$msg_number][$values]); |
---|
| 906 | if($file_type == "text/plain" || $file_type == "text/html") { |
---|
| 907 | $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]); |
---|
| 908 | break; |
---|
| 909 | } |
---|
| 910 | } |
---|
| 911 | } |
---|
[5134] | 912 | |
---|
[4416] | 913 | $tags_replace = array("<br>","<br/>","<br />"); |
---|
[5134] | 914 | $content = str_replace($tags_replace," ", nl2br($content)); |
---|
| 915 | $content = $this->html2txt($content); |
---|
[4416] | 916 | $content != "" ? $return['body'] = " - " . $content: $return['body'] = ""; |
---|
[5134] | 917 | $return['body'] = base64_encode(mb_convert_encoding(substr($return['body'], 0, 305),'ISO-8859-1')); |
---|
[4416] | 918 | return $return; |
---|
| 919 | } |
---|
[5134] | 920 | function html2txt($document){ |
---|
| 921 | $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript |
---|
| 922 | '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags |
---|
| 923 | '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly |
---|
| 924 | '@<![\s\S]*?--[ \t\n\r]*>@si' // Strip multi-line comments including CDATA |
---|
| 925 | ); |
---|
| 926 | $text = preg_replace($search, '', $document); |
---|
| 927 | return html_entity_decode($text); |
---|
| 928 | } |
---|
| 929 | |
---|
| 930 | function ope_msg_part($params) |
---|
| 931 | { |
---|
| 932 | $return = array(); |
---|
| 933 | require_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; |
---|
[4416] | 934 | |
---|
[5134] | 935 | $atObj = new attachment(); |
---|
| 936 | $atObj->setStructureFromMail($params['msg_folder'],$params['msg_number']); |
---|
| 937 | $mbox_stream = $this->open_mbox($params['save_folder']); |
---|
| 938 | $return['append'] = imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$params['save_folder'], $atObj->getAttachment($params['msg_part']), "\\Seen \\Draft"); |
---|
| 939 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$params['save_folder'], SA_UIDNEXT); |
---|
[4416] | 940 | |
---|
[5134] | 941 | $return['msg_folder'] = $params['save_folder']; |
---|
| 942 | $return['msg_number'] = $status->uidnext - 1; |
---|
| 943 | |
---|
| 944 | return $return; |
---|
| 945 | |
---|
| 946 | } |
---|
[5079] | 947 | |
---|
[2] | 948 | function get_info_msg($params) |
---|
| 949 | { |
---|
[51] | 950 | $return = array(); |
---|
[2] | 951 | $msg_number = $params['msg_number']; |
---|
[1724] | 952 | $msg_folder = urldecode($params['msg_folder']); |
---|
[4416] | 953 | |
---|
[5134] | 954 | if(preg_match('/(.+)(_[a-zA-Z0-9]+)/',$msg_number,$matches)) { //Verifies if it comes from a tab diferent of the main one. |
---|
[4795] | 955 | $msg_number = $matches[1]; |
---|
| 956 | $plus_id = $matches[2]; |
---|
| 957 | } |
---|
| 958 | else { |
---|
| 959 | $plus_id = ''; |
---|
| 960 | } |
---|
| 961 | |
---|
[411] | 962 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[4795] | 963 | $this->mbox = $this->open_mbox($msg_folder); |
---|
[4416] | 964 | |
---|
[535] | 965 | $header = $this->get_header($msg_number); |
---|
[205] | 966 | if (!$header) { |
---|
[4795] | 967 | $return['status_get_msg_info'] = "false"; |
---|
[205] | 968 | return $return; |
---|
| 969 | } |
---|
[4795] | 970 | |
---|
| 971 | $header_ = imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
[51] | 972 | $return_get_body = $this->get_body_msg($msg_number, $msg_folder); |
---|
[4416] | 973 | $body = $return_get_body['body']; |
---|
[1035] | 974 | if($return_get_body['body']=='isCripted'){ |
---|
| 975 | $exporteml = new ExportEml(); |
---|
| 976 | $return['source']=$exporteml->export_msg_data($msg_number,$msg_folder); |
---|
| 977 | $return['body'] = ""; |
---|
| 978 | $return['attachments'] = ""; |
---|
| 979 | $return['thumbs'] = ""; |
---|
| 980 | $return['signature'] = ""; |
---|
| 981 | //return $return; |
---|
| 982 | }else{ |
---|
[4795] | 983 | $return['body'] = $body; |
---|
| 984 | $return['attachments'] = $return_get_body['attachments']; |
---|
| 985 | $return['thumbs'] = $return_get_body['thumbs']; |
---|
[5134] | 986 | //$return['signature'] = $return_get_body['signature']; |
---|
[4795] | 987 | } |
---|
[3018] | 988 | $pattern = '/^[ \t]*Disposition-Notification-To:[ ]*<?[[:alnum:]\._-]+@[[:alnum:]_-]+[\.[:alnum:]]+>?/sm'; |
---|
[828] | 989 | if (preg_match($pattern, $header_, $fields)) |
---|
| 990 | { |
---|
[4795] | 991 | if(preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$fields[0], $matches)){ |
---|
| 992 | $return['DispositionNotificationTo'] = "<".$matches[0].">"; |
---|
| 993 | } |
---|
[2] | 994 | } |
---|
[828] | 995 | |
---|
[2] | 996 | $return['Recent'] = $header->Recent; |
---|
| 997 | $return['Unseen'] = $header->Unseen; |
---|
[4795] | 998 | $return['Deleted'] = $header->Deleted; |
---|
[2] | 999 | $return['Flagged'] = $header->Flagged; |
---|
| 1000 | |
---|
| 1001 | if($header->Answered =='A' && $header->Draft == 'X'){ |
---|
| 1002 | $return['Forwarded'] = 'F'; |
---|
| 1003 | } |
---|
[4795] | 1004 | |
---|
[2] | 1005 | else { |
---|
| 1006 | $return['Answered'] = $header->Answered; |
---|
[4795] | 1007 | $return['Draft'] = $header->Draft; |
---|
[2] | 1008 | } |
---|
| 1009 | |
---|
[4795] | 1010 | $return['msg_number'] = $msg_number.$plus_id; |
---|
[2] | 1011 | $return['msg_folder'] = $msg_folder; |
---|
[4795] | 1012 | |
---|
[5134] | 1013 | |
---|
| 1014 | |
---|
| 1015 | $msgTimesTamp = $header->udate + $this->functions->CalculateDateOffset(); //Aplica offset do usuario |
---|
| 1016 | $date_msg = gmdate("d/m/Y",$msgTimesTamp); |
---|
[4795] | 1017 | |
---|
[5134] | 1018 | // Removido codigo pois a o método send_nofication precisa da data completa. |
---|
| 1019 | // if (date("d/m/Y") == $date_msg) |
---|
| 1020 | // $return['udate'] = gmdate("H:i",$header->udate); |
---|
| 1021 | // else |
---|
| 1022 | |
---|
| 1023 | // Passa o a data completa para mensagem. |
---|
| 1024 | $return['udate'] = $header->udate; |
---|
| 1025 | |
---|
[4795] | 1026 | $return['msg_day'] = $date_msg; |
---|
[5134] | 1027 | $return['msg_hour'] = gmdate("H:i",$msgTimesTamp); |
---|
[4795] | 1028 | |
---|
[2] | 1029 | if (date("d/m/Y") == $date_msg) //no dia |
---|
| 1030 | { |
---|
[5134] | 1031 | $return['fulldate'] = gmdate("d/m/Y H:i",$msgTimesTamp); |
---|
| 1032 | $return['smalldate'] = gmdate("H:i",$msgTimesTamp); |
---|
| 1033 | |
---|
[605] | 1034 | |
---|
[5134] | 1035 | $timestamp_now = strtotime("now"); |
---|
| 1036 | // removido offset nao esta sendo parametrizado |
---|
| 1037 | // $timestamp_now = strtotime("now") + $offset; |
---|
| 1038 | |
---|
| 1039 | |
---|
| 1040 | $timestamp_msg_time = $msgTimesTamp; |
---|
[4416] | 1041 | // $timestamp_now is GMT and $timestamp_msg_time is MailDate TZ. |
---|
[535] | 1042 | // The variable $timestamp_diff is calculated without MailDate TZ. |
---|
[4416] | 1043 | $pdate = date_parse($header->MailDate); |
---|
| 1044 | $timestamp_diff = $timestamp_now - $timestamp_msg_time + ($pdate['zone']*(-60)); |
---|
[4795] | 1045 | |
---|
[2] | 1046 | if (gmdate("H",$timestamp_diff) > 0) |
---|
| 1047 | { |
---|
[197] | 1048 | $return['fulldate'] .= " (" . gmdate("H:i", $timestamp_diff) . ' ' . $this->functions->getLang('hours ago') . ')'; |
---|
[2] | 1049 | } |
---|
| 1050 | else |
---|
| 1051 | { |
---|
| 1052 | if (gmdate("i",$timestamp_diff) == 0){ |
---|
[197] | 1053 | $return['fulldate'] .= ' ('. $this->functions->getLang('now').')'; |
---|
[2] | 1054 | } |
---|
| 1055 | elseif (gmdate("i",$timestamp_diff) == 1){ |
---|
[197] | 1056 | $return['fulldate'] .= ' (1 '. $this->functions->getLang('minute ago').')'; |
---|
[2] | 1057 | } |
---|
| 1058 | else{ |
---|
[197] | 1059 | $return['fulldate'] .= " (" . gmdate("i",$timestamp_diff) .' '. $this->functions->getLang('minutes ago') . ')'; |
---|
[2] | 1060 | } |
---|
| 1061 | } |
---|
| 1062 | } |
---|
| 1063 | else{ |
---|
[5134] | 1064 | $return['fulldate'] = gmdate("d/m/Y H:i",$msgTimesTamp); |
---|
| 1065 | $return['smalldate'] = gmdate("d/m/Y",$msgTimesTamp); |
---|
[2] | 1066 | } |
---|
[4795] | 1067 | |
---|
[2] | 1068 | $from = $header->from; |
---|
| 1069 | $return['from'] = array(); |
---|
[5134] | 1070 | $return['from']['name'] = isset($sender[0]->personal) ? $this->decode_string($from[0]->personal) : ''; |
---|
[2] | 1071 | $return['from']['email'] = $this->decode_string($from[0]->mailbox . "@" . $from[0]->host); |
---|
| 1072 | if ($return['from']['name']) |
---|
| 1073 | { |
---|
| 1074 | if (substr($return['from']['name'], 0, 1) == '"') |
---|
| 1075 | $return['from']['full'] = $return['from']['name'] . ' ' . '<' . $return['from']['email'] . '>'; |
---|
| 1076 | else |
---|
| 1077 | $return['from']['full'] = '"' . $return['from']['name'] . '" ' . '<' . $return['from']['email'] . '>'; |
---|
| 1078 | } |
---|
| 1079 | else |
---|
| 1080 | $return['from']['full'] = $return['from']['email']; |
---|
[4795] | 1081 | |
---|
[2] | 1082 | // Sender attribute |
---|
| 1083 | $sender = $header->sender; |
---|
[4795] | 1084 | $return['sender'] = array(); |
---|
[5134] | 1085 | $return['sender']['name'] = isset($sender[0]->personal) ? $this->decode_string($sender[0]->personal): ''; |
---|
[2] | 1086 | $return['sender']['email'] = $this->decode_string($sender[0]->mailbox . "@" . $sender[0]->host); |
---|
[5134] | 1087 | |
---|
[2] | 1088 | if ($return['sender']['name']) |
---|
| 1089 | { |
---|
| 1090 | if (substr($return['sender']['name'], 0, 1) == '"') |
---|
| 1091 | $return['sender']['full'] = $return['sender']['name'] . ' ' . '<' . $return['sender']['email'] . '>'; |
---|
| 1092 | else |
---|
| 1093 | $return['sender']['full'] = '"' . $return['sender']['name'] . '" ' . '<' . $return['sender']['email'] . '>'; |
---|
| 1094 | } |
---|
| 1095 | else |
---|
| 1096 | $return['sender']['full'] = $return['sender']['email']; |
---|
| 1097 | |
---|
| 1098 | if($return['from']['full'] == $return['sender']['full']) |
---|
| 1099 | $return['sender'] = null; |
---|
| 1100 | $to = $header->to; |
---|
| 1101 | $return['toaddress2'] = ""; |
---|
| 1102 | if (!empty($to)) |
---|
| 1103 | { |
---|
| 1104 | foreach ($to as $tmp) |
---|
| 1105 | { |
---|
| 1106 | if (!empty($tmp->personal)) |
---|
| 1107 | { |
---|
| 1108 | $personal_tmp = imap_mime_header_decode($tmp->personal); |
---|
| 1109 | $return['toaddress2'] .= '"' . $personal_tmp[0]->text . '"'; |
---|
| 1110 | $return['toaddress2'] .= " "; |
---|
| 1111 | $return['toaddress2'] .= "<"; |
---|
[320] | 1112 | if ($tmp->host != 'unspecified-domain') |
---|
| 1113 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
| 1114 | else |
---|
| 1115 | $return['toaddress2'] .= $tmp->mailbox; |
---|
[2] | 1116 | $return['toaddress2'] .= ">"; |
---|
| 1117 | $return['toaddress2'] .= ", "; |
---|
| 1118 | } |
---|
| 1119 | else |
---|
| 1120 | { |
---|
[320] | 1121 | if ($tmp->host != 'unspecified-domain') |
---|
| 1122 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
| 1123 | else |
---|
| 1124 | $return['toaddress2'] .= $tmp->mailbox; |
---|
[2] | 1125 | $return['toaddress2'] .= ", "; |
---|
| 1126 | } |
---|
| 1127 | } |
---|
| 1128 | $return['toaddress2'] = $this->del_last_two_caracters($return['toaddress2']); |
---|
| 1129 | } |
---|
[4416] | 1130 | else |
---|
| 1131 | { |
---|
[4730] | 1132 | $return['toaddress2'] = ""; |
---|
[4416] | 1133 | } |
---|
[5134] | 1134 | if(isset($header->cc)) |
---|
[2] | 1135 | $cc = $header->cc; |
---|
| 1136 | $return['cc'] = ""; |
---|
| 1137 | if (!empty($cc)) |
---|
| 1138 | { |
---|
| 1139 | foreach ($cc as $tmp_cc) |
---|
| 1140 | { |
---|
| 1141 | if (!empty($tmp_cc->personal)) |
---|
| 1142 | { |
---|
| 1143 | $personal_tmp_cc = imap_mime_header_decode($tmp_cc->personal); |
---|
| 1144 | $return['cc'] .= '"' . $personal_tmp_cc[0]->text . '"'; |
---|
| 1145 | $return['cc'] .= " "; |
---|
| 1146 | $return['cc'] .= "<"; |
---|
[5134] | 1147 | if ($tmp_cc->host != 'unspecified-domain') |
---|
[2] | 1148 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[5134] | 1149 | else |
---|
| 1150 | $return['cc'] .= $tmp_cc->mailbox; |
---|
| 1151 | //$return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[2] | 1152 | $return['cc'] .= ">"; |
---|
| 1153 | $return['cc'] .= ", "; |
---|
| 1154 | } |
---|
| 1155 | else |
---|
| 1156 | { |
---|
[5134] | 1157 | if ($tmp_cc->host != 'unspecified-domain') |
---|
[2] | 1158 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[5134] | 1159 | else |
---|
| 1160 | $return['cc'] .= $tmp_cc->mailbox; |
---|
| 1161 | //$return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[2] | 1162 | $return['cc'] .= ", "; |
---|
| 1163 | } |
---|
| 1164 | } |
---|
| 1165 | $return['cc'] = $this->del_last_two_caracters($return['cc']); |
---|
| 1166 | } |
---|
| 1167 | else |
---|
| 1168 | { |
---|
| 1169 | $return['cc'] = ""; |
---|
[4795] | 1170 | } |
---|
[449] | 1171 | |
---|
| 1172 | ## |
---|
| 1173 | # @AUTHOR Rodrigo Souza dos Santos |
---|
| 1174 | # @DATE 2008/09/12 |
---|
| 1175 | # @BRIEF Adding the BCC field. |
---|
| 1176 | ## |
---|
[5134] | 1177 | if(isset($header->bcc)){ |
---|
[4795] | 1178 | $bcc = $header->bcc; |
---|
[5134] | 1179 | } |
---|
[449] | 1180 | $return['bcc'] = ""; |
---|
| 1181 | if (!empty($bcc)) |
---|
| 1182 | { |
---|
| 1183 | foreach ($bcc as $tmp_bcc) |
---|
| 1184 | { |
---|
| 1185 | if (!empty($tmp_bcc->personal)) |
---|
| 1186 | { |
---|
| 1187 | $personal_tmp_bcc = imap_mime_header_decode($tmp_bcc->personal); |
---|
| 1188 | $return['bcc'] .= '"' . $personal_tmp_bcc[0]->text . '"'; |
---|
| 1189 | $return['bcc'] .= " "; |
---|
| 1190 | $return['bcc'] .= "<"; |
---|
[5134] | 1191 | if ($tmp_bcc->host != 'unspecified-domain') |
---|
[449] | 1192 | $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
[5134] | 1193 | else |
---|
| 1194 | $return['bcc'] .= $tmp_bcc->mailbox; |
---|
[449] | 1195 | $return['bcc'] .= ">"; |
---|
| 1196 | $return['bcc'] .= ", "; |
---|
| 1197 | } |
---|
| 1198 | else |
---|
| 1199 | { |
---|
[5134] | 1200 | if ($tmp_bcc->host != 'unspecified-domain') |
---|
[449] | 1201 | $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
[5134] | 1202 | else |
---|
| 1203 | $return['bcc'] .= $tmp_bcc->mailbox; |
---|
| 1204 | //$return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
[449] | 1205 | $return['bcc'] .= ", "; |
---|
| 1206 | } |
---|
| 1207 | } |
---|
| 1208 | $return['bcc'] = $this->del_last_two_caracters($return['bcc']); |
---|
[426] | 1209 | } |
---|
[449] | 1210 | else |
---|
| 1211 | { |
---|
| 1212 | $return['bcc'] = ""; |
---|
[4795] | 1213 | } |
---|
[426] | 1214 | |
---|
[2] | 1215 | $reply_to = $header->reply_to; |
---|
| 1216 | $return['reply_to'] = ""; |
---|
| 1217 | if (is_object($reply_to[0])) |
---|
| 1218 | { |
---|
| 1219 | if ($return['from']['email'] != ($reply_to[0]->mailbox."@".$reply_to[0]->host)) |
---|
| 1220 | { |
---|
| 1221 | if (!empty($reply_to[0]->personal)) |
---|
| 1222 | { |
---|
| 1223 | $personal_reply_to = imap_mime_header_decode($tmp_reply_to->personal); |
---|
[41] | 1224 | if(!empty($personal_reply_to[0]->text)) { |
---|
| 1225 | $return['reply_to'] .= '"' . $personal_reply_to[0]->text . '"'; |
---|
| 1226 | $return['reply_to'] .= " "; |
---|
| 1227 | $return['reply_to'] .= "<"; |
---|
| 1228 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 1229 | $return['reply_to'] .= ">"; |
---|
| 1230 | } |
---|
| 1231 | else { |
---|
| 1232 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 1233 | } |
---|
[2] | 1234 | } |
---|
| 1235 | else |
---|
| 1236 | { |
---|
| 1237 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 1238 | } |
---|
| 1239 | } |
---|
| 1240 | } |
---|
| 1241 | $return['reply_to'] = $this->decode_string($return['reply_to']); |
---|
| 1242 | $return['subject'] = $this->decode_string($header->fetchsubject); |
---|
[5134] | 1243 | |
---|
| 1244 | if($return['subject'] == $this->functions->getLang("(no subject) ")){ |
---|
| 1245 | $return['subject'] = str_replace(" ","", $return['subject']); |
---|
| 1246 | } |
---|
| 1247 | if($return['subject'] == '' || $return['subject'] == null){ |
---|
| 1248 | $return['subject'] = $this->functions->getLang("(no subject) "); |
---|
| 1249 | } |
---|
[4795] | 1250 | $return['Size'] = $header->Size; |
---|
[828] | 1251 | $return['reply_toaddress'] = $header->reply_toaddress; |
---|
[4795] | 1252 | |
---|
[689] | 1253 | //All this is to help in local messages |
---|
[4795] | 1254 | $return['timestamp'] = $header->udate; |
---|
[689] | 1255 | $return['login'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];//$GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 1256 | $return['reply_toaddress'] = $header->reply_toaddress; |
---|
[4795] | 1257 | |
---|
[5134] | 1258 | if(($return['from']['email'] == '@unspecified-domain' || $return['sender']['email'] == null) && $return['msg_folder'] == 'INBOX/Drafts'){ |
---|
| 1259 | $return['from']['email'] = "Rascunho"; |
---|
| 1260 | } |
---|
| 1261 | if($return['toaddress2'] == 'undisclosed-recipients@, @'){ |
---|
| 1262 | $return['toaddress2'] = $this->functions->getLang('without destination'); |
---|
| 1263 | } |
---|
[2] | 1264 | return $return; |
---|
| 1265 | } |
---|
[1472] | 1266 | |
---|
[5079] | 1267 | |
---|
[5134] | 1268 | /* |
---|
[5079] | 1269 | * Converte textos utf8 para o padrão html. |
---|
[5134] | 1270 | * Modificado por Cristiano Corrêa Schmidt |
---|
| 1271 | * @link http://php.net/manual/en/function.utf8-decode.php |
---|
[5079] | 1272 | * @author luka8088 <luka8088@gmail.com> |
---|
| 1273 | */ |
---|
[4781] | 1274 | function utf8_to_html ($data) |
---|
[4795] | 1275 | { |
---|
[4781] | 1276 | return preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e", '$this->_utf8_to_html("\\1")', $data); |
---|
| 1277 | } |
---|
[4795] | 1278 | |
---|
[4781] | 1279 | function _utf8_to_html ($data) |
---|
[4795] | 1280 | { |
---|
[4781] | 1281 | $ret = 0; |
---|
| 1282 | foreach((str_split(strrev(chr((ord($data{0}) % 252 % 248 % 240 % 224 % 192) + 128) . substr($data, 1)))) as $k => $v) |
---|
| 1283 | $ret += (ord($v) % 128) * pow(64, $k); |
---|
[5134] | 1284 | return html_entity_decode("&#$ret;" , ENT_QUOTES); |
---|
[4795] | 1285 | } |
---|
[4781] | 1286 | //------------------------------------------------------------------------------// |
---|
[4795] | 1287 | |
---|
| 1288 | |
---|
[4416] | 1289 | /** |
---|
[5134] | 1290 | * Decodifica uma part da mensagem para iso-8859-1 |
---|
| 1291 | * @param <type> $part parte do email |
---|
| 1292 | * @param <type> $encode codificação da parte |
---|
| 1293 | * @return <type> string decodificada |
---|
[5079] | 1294 | */ |
---|
[4781] | 1295 | function decodeMailPart($part, $encode, $html = true) |
---|
[4795] | 1296 | { |
---|
[4416] | 1297 | switch (strtolower($encode)) |
---|
[4795] | 1298 | { |
---|
[4416] | 1299 | case 'iso-8859-1': |
---|
| 1300 | return $part; |
---|
| 1301 | break; |
---|
[1752] | 1302 | |
---|
[4416] | 1303 | case 'utf-8': |
---|
[5134] | 1304 | if ($html) return $this->utf8_to_html($part); |
---|
| 1305 | else return utf8_decode ($part); |
---|
[4416] | 1306 | break; |
---|
[1752] | 1307 | |
---|
[4416] | 1308 | default: |
---|
| 1309 | return mb_convert_encoding($part, 'iso-8859-1'); |
---|
[4795] | 1310 | break; |
---|
| 1311 | } |
---|
| 1312 | } |
---|
| 1313 | |
---|
[4416] | 1314 | |
---|
[2] | 1315 | function get_body_msg($msg_number, $msg_folder) |
---|
| 1316 | { |
---|
[4429] | 1317 | /* |
---|
[4416] | 1318 | * Requires of librarys |
---|
| 1319 | */ |
---|
| 1320 | require_once $_SESSION['rootPath'].'/library/mime/mimePart.php'; |
---|
| 1321 | require_once $_SESSION['rootPath'].'/library/mime/mimeDecode.php'; |
---|
| 1322 | require_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; |
---|
[5134] | 1323 | //include_once("class.message_components.inc.php"); |
---|
[4416] | 1324 | //--------------------------------------------------------------------// |
---|
[1472] | 1325 | |
---|
[4416] | 1326 | $return = array(); |
---|
[1035] | 1327 | |
---|
[5134] | 1328 | // $msg = new message_components($this->mbox); |
---|
| 1329 | // $msg->fetch_structure($msg_number); |
---|
[1035] | 1330 | |
---|
[4416] | 1331 | $content = ''; |
---|
[1035] | 1332 | |
---|
[5134] | 1333 | /* |
---|
| 1334 | * Chamada original $this->getRawHeader($msg_number)."\r\n".$this->getRawBody($msg_number); |
---|
| 1335 | * Inserido replace para corrigir um bug que acontece raramente em mensagens vindas do outlook com muitos destinatarios |
---|
| 1336 | */ |
---|
| 1337 | $rawMessageData = str_replace("\r\n\t", '', $this->getRawHeader($msg_number))."\r\n".$this->getRawBody($msg_number); |
---|
[3018] | 1338 | |
---|
[4416] | 1339 | $decoder = new Mail_mimeDecode($rawMessageData); |
---|
[3018] | 1340 | |
---|
[4416] | 1341 | $params['include_bodies'] = true; |
---|
| 1342 | $params['decode_bodies'] = true; |
---|
| 1343 | $params['decode_headers'] = true; |
---|
[5134] | 1344 | 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')) |
---|
| 1345 | $params['rfc_822bodies'] = true; |
---|
[4416] | 1346 | $structure = $decoder->decode($params); |
---|
[3018] | 1347 | |
---|
[4416] | 1348 | /* |
---|
| 1349 | * Inicia Gerenciador de Anexos |
---|
| 1350 | */ |
---|
| 1351 | $attachmentManager = new attachment(); |
---|
| 1352 | $attachmentManager->setStructure($structure); |
---|
| 1353 | //----------------------------------------------// |
---|
[1472] | 1354 | |
---|
[4416] | 1355 | /* |
---|
[4429] | 1356 | * Monta informações dos anexos para o cabecalhos |
---|
[4416] | 1357 | */ |
---|
| 1358 | $attachments = $attachmentManager->getAttachmentsInfo(); |
---|
| 1359 | $return['attachments'] = $attachments; |
---|
| 1360 | //----------------------------------------------// |
---|
[2] | 1361 | |
---|
[4416] | 1362 | /* |
---|
[4429] | 1363 | * Monta informações das imagens |
---|
| 1364 | */ |
---|
[4416] | 1365 | $images = $attachmentManager->getEmbeddedImagesInfo(); |
---|
| 1366 | //----------------------------------------------// |
---|
[1472] | 1367 | |
---|
[4795] | 1368 | if(!$this->has_cid) |
---|
| 1369 | { |
---|
[4416] | 1370 | $return['thumbs'] = $this->get_thumbs($images,$msg_number,$msg_folder); |
---|
[5134] | 1371 | // $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); |
---|
[4795] | 1372 | } |
---|
[1472] | 1373 | |
---|
[4416] | 1374 | switch (strtolower($structure->ctype_primary)) |
---|
[4795] | 1375 | { |
---|
[4908] | 1376 | case 'text': |
---|
| 1377 | if(strtolower($structure->ctype_secondary) == 'x-pkcs7-mime') |
---|
| 1378 | { |
---|
[4795] | 1379 | $return['body']='isCripted'; |
---|
| 1380 | return $return; |
---|
| 1381 | } |
---|
[4416] | 1382 | $attachment = array(); |
---|
[3414] | 1383 | |
---|
[4416] | 1384 | $msg_subtype = strtolower($structure->ctype_secondary); |
---|
[5134] | 1385 | if(isset($structure->disposition)) |
---|
[4416] | 1386 | $disposition = strtolower($structure->disposition); |
---|
[5134] | 1387 | else |
---|
| 1388 | $disposition = ''; |
---|
[1472] | 1389 | |
---|
[4908] | 1390 | if(($msg_subtype == "html" || $msg_subtype == 'plain') && ($disposition != 'attachment')) |
---|
[4795] | 1391 | { |
---|
[4416] | 1392 | if(strtolower($msg_subtype) == 'plain') |
---|
[4795] | 1393 | { |
---|
[5134] | 1394 | if(isset($structure->ctype_parameters['charset'])) |
---|
[4781] | 1395 | $content = $this->decodeMailPart($structure->body, $structure->ctype_parameters['charset'],false); |
---|
[5134] | 1396 | else |
---|
| 1397 | $content = $this->decodeMailPart($structure->body, null,false); |
---|
[4795] | 1398 | $content = str_replace( array( '<', '>' ), array( ' #$<$# ', ' #$>$# ' ), $content ); |
---|
| 1399 | $content = htmlentities( $content ); |
---|
[4784] | 1400 | $this->replace_links($content); |
---|
[4795] | 1401 | $content = str_replace( array( ' #$<$# ', ' #$>$# ' ), array( '<', '>' ), $content ); |
---|
| 1402 | $content = '<pre>' . $content . '</pre>'; |
---|
| 1403 | $return[ 'body' ] = $content; |
---|
| 1404 | return $return; |
---|
| 1405 | } |
---|
[4781] | 1406 | $content = $this->decodeMailPart($structure->body, $structure->ctype_parameters['charset']); |
---|
[4795] | 1407 | } |
---|
[5134] | 1408 | if(strtolower($structure->ctype_secondary) == 'calendar') |
---|
| 1409 | $content .= $this->builderMsgCalendar($structure->body); |
---|
[1897] | 1410 | |
---|
[4416] | 1411 | break; |
---|
[1897] | 1412 | |
---|
[4429] | 1413 | case 'multipart': |
---|
[5134] | 1414 | $this->builderMsgBody($structure , $content); |
---|
[1897] | 1415 | |
---|
[4416] | 1416 | break; |
---|
[1897] | 1417 | |
---|
[4416] | 1418 | case 'message': |
---|
[5134] | 1419 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['nested_messages_are_shown'] != 1) |
---|
| 1420 | { |
---|
[4416] | 1421 | if(!is_array($structure->parts)) |
---|
[4795] | 1422 | { |
---|
[4416] | 1423 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4781] | 1424 | $content .= '<pre>'.htmlentities($this->decodeMailPart($structure->body, $structure->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 1425 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4795] | 1426 | } |
---|
| 1427 | else |
---|
[4416] | 1428 | $this->builderMsgBody($structure , $content,true); |
---|
[5134] | 1429 | } |
---|
[4429] | 1430 | break; |
---|
[3018] | 1431 | |
---|
[5134] | 1432 | case 'application': |
---|
| 1433 | if(strtolower($structure->ctype_secondary) == 'x-pkcs7-mime') |
---|
| 1434 | { |
---|
| 1435 | // $return['body']='isCripted'; |
---|
| 1436 | // return $return; |
---|
| 1437 | |
---|
| 1438 | //TODO: Descartar código após atualização do módulo de segurança da SERPRO |
---|
| 1439 | $rawMessageData2 = $this->extractSignedContents($rawMessageData); |
---|
| 1440 | if($rawMessageData2 === false){ |
---|
| 1441 | $return['body']='isCripted'; |
---|
| 1442 | return $return; |
---|
| 1443 | } |
---|
| 1444 | $decoder2 = new Mail_mimeDecode($rawMessageData2); |
---|
| 1445 | $structure2 = $decoder2->decode($params); |
---|
| 1446 | $this-> builderMsgBody($structure2 , $content); |
---|
| 1447 | |
---|
| 1448 | $attachmentManager->setStructure($structure2); |
---|
| 1449 | /* |
---|
| 1450 | * Monta informações dos anexos para o cabecarios |
---|
| 1451 | */ |
---|
| 1452 | $attachments = $attachmentManager->getAttachmentsInfo(); |
---|
| 1453 | $return['attachments'] = $attachments; |
---|
| 1454 | |
---|
| 1455 | //----------------------------------------------// |
---|
| 1456 | |
---|
| 1457 | /* |
---|
| 1458 | * Monta informações das imagens |
---|
| 1459 | */ |
---|
| 1460 | $images = $attachmentManager->getEmbeddedImagesInfo(); |
---|
| 1461 | //----------------------------------------------// |
---|
| 1462 | |
---|
| 1463 | if(!$this->has_cid){ |
---|
| 1464 | $return['thumbs'] = $this->get_thumbs($images,$msg_number,$msg_folder); |
---|
| 1465 | $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); |
---|
| 1466 | } |
---|
| 1467 | } |
---|
| 1468 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[4429] | 1469 | default: |
---|
| 1470 | if(count($attachments) > 0) |
---|
| 1471 | $content .= ''; |
---|
| 1472 | break; |
---|
[4795] | 1473 | } |
---|
[3018] | 1474 | |
---|
[1472] | 1475 | $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); |
---|
[2] | 1476 | $this->set_messages_flag($params); |
---|
[4416] | 1477 | $content = $this->process_embedded_images($images,$msg_number,$content, $msg_folder); |
---|
[4795] | 1478 | $content = $this->replace_special_characters($content); |
---|
[4416] | 1479 | $this->replace_links($content); |
---|
| 1480 | $return['body'] = &$content; |
---|
| 1481 | |
---|
[4795] | 1482 | return $return; |
---|
[2] | 1483 | } |
---|
[1472] | 1484 | |
---|
[5134] | 1485 | |
---|
| 1486 | //TODO: Descartar código após atualização do módulo de segurança da SERPRO |
---|
| 1487 | function extractSignedContents( $data ) |
---|
| 1488 | { |
---|
| 1489 | $pipes_desc = array( |
---|
| 1490 | 0 => array('pipe', 'r'), |
---|
| 1491 | 1 => array('pipe', 'w') |
---|
| 1492 | ); |
---|
| 1493 | |
---|
| 1494 | $fp = proc_open( 'openssl smime -verify -noverify -nochain', $pipes_desc, $pipes); |
---|
| 1495 | if (!is_resource($fp)) { |
---|
| 1496 | return false; |
---|
| 1497 | } |
---|
| 1498 | |
---|
| 1499 | $output = ''; |
---|
| 1500 | |
---|
| 1501 | /* $pipes[0] => writeable handle connected to child stdin |
---|
| 1502 | $pipes[1] => readable handle connected to child stdout */ |
---|
| 1503 | fwrite($pipes[0], $data); |
---|
| 1504 | fclose($pipes[0]); |
---|
| 1505 | |
---|
| 1506 | while (!feof($pipes[1])) { |
---|
| 1507 | $output .= fgets($pipes[1], 1024); |
---|
| 1508 | } |
---|
| 1509 | fclose($pipes[1]); |
---|
| 1510 | proc_close($fp); |
---|
| 1511 | |
---|
| 1512 | return $output; |
---|
| 1513 | } |
---|
| 1514 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1515 | |
---|
| 1516 | function builderMsgCalendar($calendar) |
---|
| 1517 | { |
---|
| 1518 | $icalService = ServiceLocator::getService('ical'); |
---|
| 1519 | |
---|
| 1520 | $codificao = mb_detect_encoding($calendar.'x', 'UTF-8, ISO-8859-1'); |
---|
| 1521 | if($codificao == 'UTF-8') |
---|
| 1522 | $calendar = utf8_decode($calendar); |
---|
| 1523 | |
---|
| 1524 | if($icalService->setIcal($calendar)) |
---|
| 1525 | { |
---|
| 1526 | $content = ''; |
---|
| 1527 | |
---|
| 1528 | switch ($icalService->getMethod()) { |
---|
| 1529 | |
---|
| 1530 | case 'REPLY': |
---|
| 1531 | include_once($_SESSION['rootPath'].'/header.inc.php'); |
---|
| 1532 | include_once($_SESSION['rootPath'].'/calendar/inc/class.boicalendar.inc.php'); |
---|
| 1533 | $boicalendar = new boicalendar(); |
---|
| 1534 | |
---|
| 1535 | $ical = $icalService->getComponent('vevent'); |
---|
| 1536 | $content.= '<b>'.$this->functions->getLang('Event Calendar').'</b><br /><br />'; |
---|
| 1537 | $content.= '<span style="font-size: 12" >'; |
---|
| 1538 | $notExist = false; |
---|
| 1539 | |
---|
| 1540 | foreach ($ical['attendee'] as $attendee) |
---|
| 1541 | { |
---|
| 1542 | if($attendee['params']['PARTSTAT'] == 'ACCEPTED') |
---|
| 1543 | { |
---|
| 1544 | if($boicalendar->updateExParticipantState($ical['uid']['value'],$attendee['value'],'ACCEPTED',$attendee['params']['CN'])) |
---|
| 1545 | { |
---|
| 1546 | $content.= $this->functions->getLang('User').' '; |
---|
| 1547 | if($attendee['params']['CN']) |
---|
| 1548 | $content.= '<b>'.$attendee['params']['CN'].'</b> '; |
---|
| 1549 | else |
---|
| 1550 | $content.= '<b>'.$attendee['value'].'</b> '; |
---|
| 1551 | |
---|
| 1552 | $content.= $this->functions->getLang('accepted your event'); |
---|
| 1553 | } |
---|
| 1554 | else |
---|
| 1555 | $notExist = true; |
---|
| 1556 | } |
---|
| 1557 | |
---|
| 1558 | if($attendee['params']['PARTSTAT'] == 'TENTATIVE') |
---|
| 1559 | { |
---|
| 1560 | if($boicalendar->updateExParticipantState($ical['uid']['value'],$attendee['value'],'TENTATIVE',$attendee['params']['CN'])) |
---|
| 1561 | { |
---|
| 1562 | $content.= $this->functions->getLang('User').' '; |
---|
| 1563 | if($attendee['params']['CN']) |
---|
| 1564 | $content.= '<b>'.$attendee['params']['CN'].'</b> '; |
---|
| 1565 | else |
---|
| 1566 | $content.= '<b>'.$attendee['value'].'</b> '; |
---|
| 1567 | |
---|
| 1568 | if($ical['description']['value']) |
---|
| 1569 | $content.= ' <br /> '.str_replace('\n','<br />',nl2br($ical['description']['value'])); |
---|
| 1570 | else |
---|
| 1571 | $content.= $this->functions->getLang('provisionally accepted you event'); |
---|
| 1572 | } |
---|
| 1573 | else |
---|
| 1574 | $notExist = true; |
---|
| 1575 | } |
---|
| 1576 | |
---|
| 1577 | if($attendee['params']['PARTSTAT'] == 'DECLINED') |
---|
| 1578 | { |
---|
| 1579 | if($boicalendar->updateExParticipantState($ical['uid']['value'],$attendee['value'],'DECLINED',$attendee['params']['CN'])) |
---|
| 1580 | { |
---|
| 1581 | $content.= $this->functions->getLang('User').' '; |
---|
| 1582 | if($attendee['params']['CN']) |
---|
| 1583 | $content.= '<b>'.$attendee['params']['CN'].'</b> '; |
---|
| 1584 | else |
---|
| 1585 | $content.= '<b>'.$attendee['value'].'</b> '; |
---|
| 1586 | |
---|
| 1587 | if($ical['description']['value']) |
---|
| 1588 | $content.= ' <br /> '.str_replace('\n','<br />',nl2br($ical['description']['value'])); |
---|
| 1589 | else |
---|
| 1590 | $content.= $this->functions->getLang('provisionally decline you event'); |
---|
| 1591 | } |
---|
| 1592 | else |
---|
| 1593 | $notExist = true; |
---|
| 1594 | } |
---|
| 1595 | } |
---|
| 1596 | if($notExist) |
---|
| 1597 | $content.= '<b><span style="color:red">'.$this->functions->getLang('This event does not exist on its agenda').'.</span></b>'; |
---|
| 1598 | $content.= '</span><br /><br />'; |
---|
| 1599 | |
---|
| 1600 | break; |
---|
| 1601 | |
---|
| 1602 | case 'CANCEL': |
---|
| 1603 | |
---|
| 1604 | $ical = $icalService->getComponent('vevent'); |
---|
| 1605 | $content.= '<b>'.$this->functions->getLang('Event Calendar').'</b><br /><br />'; |
---|
| 1606 | $content.= '<span style="font-size: 12" >'; |
---|
| 1607 | $content.= '<b><span style="color:red">'.$this->functions->getLang('Your event has been canceled').'</span></b>'; |
---|
| 1608 | |
---|
| 1609 | if($ical['description']['value']) |
---|
| 1610 | $content.= ' <br /> <br /> '.str_replace('\n','<br />',nl2br($ical['description']['value'])); |
---|
| 1611 | |
---|
| 1612 | $content.= '<br /><b>* '.$this->functions->getLang('To remove the event from your calendar to import the iCal file attached').'.</b>'; |
---|
| 1613 | $content.= '</span><br /><br />'; |
---|
| 1614 | break; |
---|
| 1615 | |
---|
| 1616 | case 'REQUEST': |
---|
| 1617 | |
---|
| 1618 | $ical = $icalService->getComponent('vevent'); |
---|
| 1619 | if($ical['dtstart']['value']['tz'] == 'Z') |
---|
| 1620 | { |
---|
| 1621 | $tz = $_SESSION['phpgw_info']['user']['preferences']['common']['tz_offset']; |
---|
| 1622 | $ical['dtstart']['value']['hour'] += $tz; |
---|
| 1623 | $ical['dtend']['value']['hour'] += $tz; |
---|
| 1624 | } |
---|
| 1625 | |
---|
| 1626 | $content.= '<b>'.$this->functions->getLang('Event Calendar').'</b><br />'. |
---|
| 1627 | ' <br /> <b>'.$this->functions->getLang('Title').': </b>'.$ical['summary']['value']. |
---|
| 1628 | ' <br /> <b>'.$this->functions->getLang('Location').': </b>'.$ical['location']['value']. |
---|
| 1629 | ' <br /> <b>'.$this->functions->getLang('Details').': </b>'. str_replace('\n','<br />',nl2br($ical['description']['value'])); |
---|
| 1630 | $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'] ; |
---|
| 1631 | $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'] ; |
---|
| 1632 | |
---|
| 1633 | if($ical['organizer']['params']['CN']) |
---|
| 1634 | $content.= ' <br /> <b>'.$this->functions->getLang('Organizer').': </b>'.$ical['organizer']['params']['CN'].' - <a href="MAILTO:'.$ical['organizer']['value'].'">'.$ical['organizer']['value'].'</a></li>' ; |
---|
| 1635 | else |
---|
| 1636 | $content.= ' <br /> <b>'.$this->functions->getLang('Organizer').': </b> <a href="MAILTO:'.$ical['organizer']['value'].'">'.$ical['organizer']['value'].'</a>' ; |
---|
| 1637 | |
---|
| 1638 | if($ical['attendee']) |
---|
| 1639 | { |
---|
| 1640 | $att = ' <br /> <b>'.$this->functions->getLang('Participants').': </b>'; |
---|
| 1641 | $att .= '<ul> '; |
---|
| 1642 | foreach ($ical['attendee'] as $attendee) |
---|
| 1643 | { |
---|
| 1644 | if($attendee['params']['CN']) |
---|
| 1645 | $att .= '<li>'.$attendee['params']['CN'].' - <a href="MAILTO:'.$attendee['value'].'">'.$attendee['value'].'</a></li>' ; |
---|
| 1646 | else |
---|
| 1647 | $att .= '<li><a href="MAILTO:'.$attendee['value'].'">'.$attendee['value'].'</a></li>' ; |
---|
| 1648 | } |
---|
| 1649 | $att .= '</ul> <br />' ; |
---|
| 1650 | } |
---|
| 1651 | $content.= $att; |
---|
| 1652 | |
---|
| 1653 | break; |
---|
| 1654 | default: |
---|
| 1655 | break; |
---|
| 1656 | } |
---|
| 1657 | |
---|
| 1658 | } |
---|
| 1659 | return $content; |
---|
| 1660 | } |
---|
| 1661 | |
---|
[2] | 1662 | function htmlfilter($body) |
---|
| 1663 | { |
---|
| 1664 | require_once('htmlfilter.inc'); |
---|
[1472] | 1665 | |
---|
[2] | 1666 | $tag_list = Array( |
---|
| 1667 | false, |
---|
| 1668 | 'blink', |
---|
| 1669 | 'object', |
---|
| 1670 | 'meta', |
---|
| 1671 | 'html', |
---|
| 1672 | 'link', |
---|
| 1673 | 'frame', |
---|
| 1674 | 'iframe', |
---|
| 1675 | 'layer', |
---|
| 1676 | 'ilayer', |
---|
| 1677 | 'plaintext' |
---|
| 1678 | ); |
---|
| 1679 | |
---|
| 1680 | /** |
---|
| 1681 | * A very exclusive set: |
---|
| 1682 | */ |
---|
| 1683 | // $tag_list = Array(true, "b", "a", "i", "img", "strong", "em", "p"); |
---|
| 1684 | $rm_tags_with_content = Array( |
---|
| 1685 | 'script', |
---|
| 1686 | 'style', |
---|
| 1687 | 'applet', |
---|
| 1688 | 'embed', |
---|
| 1689 | 'head', |
---|
| 1690 | 'frameset', |
---|
| 1691 | 'xml', |
---|
| 1692 | 'xmp' |
---|
| 1693 | ); |
---|
| 1694 | |
---|
| 1695 | $self_closing_tags = Array( |
---|
| 1696 | 'img', |
---|
| 1697 | 'br', |
---|
| 1698 | 'hr', |
---|
| 1699 | 'input' |
---|
| 1700 | ); |
---|
| 1701 | |
---|
| 1702 | $force_tag_closing = true; |
---|
| 1703 | |
---|
| 1704 | $rm_attnames = Array( |
---|
| 1705 | '/.*/' => |
---|
| 1706 | Array( |
---|
| 1707 | '/target/i', |
---|
| 1708 | //'/^on.*/i', -> onClick, dos compromissos da agenda. |
---|
| 1709 | '/^dynsrc/i', |
---|
| 1710 | '/^datasrc/i', |
---|
| 1711 | '/^data.*/i', |
---|
| 1712 | '/^lowsrc/i' |
---|
| 1713 | ) |
---|
| 1714 | ); |
---|
| 1715 | |
---|
| 1716 | /** |
---|
| 1717 | * Yeah-yeah, so this looks horrible. Check out htmlfilter.inc for |
---|
| 1718 | * some idea of what's going on here. :) |
---|
| 1719 | */ |
---|
| 1720 | |
---|
| 1721 | $bad_attvals = Array( |
---|
| 1722 | '/.*/' => |
---|
| 1723 | Array( |
---|
| 1724 | '/.*/' => |
---|
| 1725 | Array( |
---|
| 1726 | Array( |
---|
| 1727 | '/^([\'\"])\s*\S+\s*script\s*:*(.*)([\'\"])/si', |
---|
| 1728 | //'/^([\'\"])\s*https*\s*:(.*)([\'\"])/si', -> doclinks notes |
---|
| 1729 | '/^([\'\"])\s*mocha\s*:*(.*)([\'\"])/si', |
---|
| 1730 | '/^([\'\"])\s*about\s*:(.*)([\'\"])/si' |
---|
| 1731 | ), |
---|
| 1732 | Array( |
---|
| 1733 | '\\1oddjob:\\2\\1', |
---|
| 1734 | //'\\1uucp:\\2\\1', -> doclinks notes |
---|
| 1735 | '\\1amaretto:\\2\\1', |
---|
| 1736 | '\\1round:\\2\\1' |
---|
| 1737 | ) |
---|
[1472] | 1738 | ), |
---|
| 1739 | |
---|
[2] | 1740 | '/^style/i' => |
---|
| 1741 | Array( |
---|
| 1742 | Array( |
---|
| 1743 | '/expression/i', |
---|
| 1744 | '/behaviou*r/i', |
---|
| 1745 | '/binding/i', |
---|
| 1746 | '/include-source/i', |
---|
| 1747 | '/url\s*\(\s*([\'\"]*)\s*https*:.*([\'\"]*)\s*\)/si', |
---|
| 1748 | '/url\s*\(\s*([\'\"]*)\s*\S+\s*script:.*([\'\"]*)\s*\)/si' |
---|
| 1749 | ), |
---|
| 1750 | Array( |
---|
| 1751 | 'idiocy', |
---|
| 1752 | 'idiocy', |
---|
| 1753 | 'idiocy', |
---|
| 1754 | 'idiocy', |
---|
| 1755 | 'url(\\1http://securityfocus.com/\\1)', |
---|
| 1756 | 'url(\\1http://securityfocus.com/\\1)' |
---|
| 1757 | ) |
---|
| 1758 | ) |
---|
| 1759 | ) |
---|
| 1760 | ); |
---|
| 1761 | |
---|
| 1762 | $add_attr_to_tag = Array( |
---|
| 1763 | '/^a$/i' => Array('target' => '"_new"') |
---|
| 1764 | ); |
---|
[1472] | 1765 | |
---|
| 1766 | |
---|
[2] | 1767 | $trusted_body = sanitize($body, |
---|
| 1768 | $tag_list, |
---|
| 1769 | $rm_tags_with_content, |
---|
| 1770 | $self_closing_tags, |
---|
| 1771 | $force_tag_closing, |
---|
| 1772 | $rm_attnames, |
---|
| 1773 | $bad_attvals, |
---|
| 1774 | $add_attr_to_tag |
---|
| 1775 | ); |
---|
[1472] | 1776 | |
---|
[2] | 1777 | return $trusted_body; |
---|
| 1778 | } |
---|
[1472] | 1779 | |
---|
[2] | 1780 | function decodeBody($body, $encoding, $charset=null) |
---|
| 1781 | { |
---|
[4416] | 1782 | |
---|
[2] | 1783 | if ($encoding == 'quoted-printable') |
---|
[828] | 1784 | { |
---|
[2] | 1785 | $body = quoted_printable_decode($body); |
---|
[1792] | 1786 | |
---|
[4795] | 1787 | } |
---|
| 1788 | else if ($encoding == 'base64') |
---|
| 1789 | { |
---|
| 1790 | $body = base64_decode($body); |
---|
| 1791 | } |
---|
| 1792 | // All other encodings are returned raw. |
---|
| 1793 | if (strtolower($charset) == "utf-8") |
---|
| 1794 | return utf8_decode($body); |
---|
| 1795 | else |
---|
| 1796 | return $body; |
---|
| 1797 | } |
---|
| 1798 | |
---|
[4436] | 1799 | |
---|
| 1800 | /** |
---|
| 1801 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 1802 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 1803 | * @param $images |
---|
| 1804 | * @param $msgno |
---|
| 1805 | * @param $body |
---|
| 1806 | * @param $msg_folder |
---|
| 1807 | */ |
---|
[4416] | 1808 | function process_embedded_images($images, $msgno, $body, $msg_folder) |
---|
[2] | 1809 | { |
---|
[1472] | 1810 | |
---|
[4416] | 1811 | foreach ($images as $image) |
---|
[4795] | 1812 | { |
---|
[4416] | 1813 | $image['cid'] = eregi_replace("<", "", $image['cid']); |
---|
| 1814 | $image['cid'] = eregi_replace(">", "", $image['cid']); |
---|
[5134] | 1815 | |
---|
| 1816 | $body = str_replace("src=\"cid:".$image['cid']."\"", " src=\"./inc/get_archive.php?msgFolder=$msg_folder&msgNumber=$msgno&indexPart=".$image['pid']."\" ", $body); |
---|
| 1817 | $body = str_replace("src='cid:".$image['cid']."'", " src=\"./inc/get_archive.php?msgFolder=$msg_folder&msgNumber=$msgno&indexPart=".$image['pid']."\"", $body); |
---|
| 1818 | $body = str_replace("src=cid:".$image['cid'], " src=\"./inc/get_archive.php?msgFolder=$msg_folder&msgNumber=$msgno&indexPart=".$image['pid']."\"", $body); |
---|
[4795] | 1819 | } |
---|
| 1820 | return $body; |
---|
[2] | 1821 | } |
---|
[1472] | 1822 | |
---|
[2] | 1823 | function replace_special_characters($body) |
---|
| 1824 | { |
---|
| 1825 | // Suspected TAGS! |
---|
[4416] | 1826 | // $tag_list = Array('blink','object','meta','html','link','frame','iframe','layer','ilayer','plaintext','script','style','img','applet','embed','head','frameset','xml','xmp'); |
---|
[4795] | 1827 | |
---|
[4416] | 1828 | // remove MS Office's proprietary tag |
---|
| 1829 | //$body = mb_ereg_replace('<!\-\-\[if [^!]* mso .*\]>.*<!\[endif\]\-\->', '', $body); |
---|
| 1830 | |
---|
[4795] | 1831 | // Layout problem: Change html elements |
---|
| 1832 | // with absolute position to relate position, CASE INSENSITIVE. |
---|
| 1833 | $body = @mb_eregi_replace("POSITION: ABSOLUTE;","",$body); |
---|
[2] | 1834 | |
---|
[5134] | 1835 | //Remove Comentario Expresso |
---|
| 1836 | $findExpCom[] = '<!-- TAG <'; |
---|
| 1837 | $findExpCom[] = '> Removed by ExpressoMail -->'; |
---|
| 1838 | $body = str_replace($findExpCom, '', $body); |
---|
| 1839 | ///--------------------------------// |
---|
| 1840 | |
---|
[4416] | 1841 | // tags to be removed doe to security reasons |
---|
| 1842 | $tag_list = Array( |
---|
[5134] | 1843 | 'blink','object','frame','iframe', |
---|
[4416] | 1844 | 'layer','ilayer','plaintext','script', |
---|
| 1845 | 'applet','embed','frameset','xml','xmp' |
---|
| 1846 | ); |
---|
[4795] | 1847 | |
---|
[4416] | 1848 | foreach($tag_list as $index => $tag) { |
---|
[5134] | 1849 | $body = @mb_eregi_replace("<$tag\\b[^>]*>(.*?)</$tag>", '', $body); |
---|
[4795] | 1850 | } |
---|
[4416] | 1851 | |
---|
[5134] | 1852 | $body = @mb_eregi_replace("<meta[^>]*>", '', $body); |
---|
| 1853 | $body = @mb_eregi_replace("<base[^>]*>", '', $body); |
---|
| 1854 | |
---|
[4416] | 1855 | //try to wrap CSS code instead of remove STYLE tags |
---|
| 1856 | require_once('../library/csstidy/class.csstidy.php'); |
---|
| 1857 | $css = new csstidy(); |
---|
| 1858 | $css->set_cfg('preserve_css', false); |
---|
[6] | 1859 | |
---|
[4416] | 1860 | $regs_found = array(); |
---|
| 1861 | $tags_found = @mb_eregi("<style\b[^>]*>(.*?)</style>", $body, $regs_found); |
---|
[5134] | 1862 | $wrapper_class = 'ExpressoCssWrapper'.time(); |
---|
[4416] | 1863 | |
---|
| 1864 | foreach ($regs_found as $block_found) { |
---|
| 1865 | $n_start = strpos($block_found, '>')+1; |
---|
| 1866 | $n_length = strrpos($block_found, '<')-$n_start; |
---|
| 1867 | $bf_innerHTML = substr($block_found, $n_start, $n_length); |
---|
| 1868 | |
---|
| 1869 | $bf_innerHTML = mb_ereg_replace('<!--', '', $bf_innerHTML); |
---|
| 1870 | $bf_innerHTML = mb_ereg_replace('-->', '', $bf_innerHTML); |
---|
[2] | 1871 | |
---|
[4416] | 1872 | $css->parse($bf_innerHTML); |
---|
| 1873 | |
---|
| 1874 | $prefix = ".$wrapper_class "; |
---|
[5134] | 1875 | if( isset($css->css[41]) && count($css->css[41] > 0)) |
---|
[4416] | 1876 | foreach ($css->css[41] as $key => $value) { |
---|
[4457] | 1877 | //explode multiple selectors per block |
---|
| 1878 | $selectors = explode(',', $key); |
---|
| 1879 | |
---|
| 1880 | foreach ($selectors as $selector) { |
---|
| 1881 | if (ereg('\*', $key)) { |
---|
| 1882 | //skip selecto '*' |
---|
| 1883 | continue; |
---|
[4795] | 1884 | } |
---|
[4457] | 1885 | |
---|
| 1886 | $selector = eregi_replace('[^#\.]*body.*', '', $selector); |
---|
| 1887 | $css->css[41][$prefix.trim($selector)] = $value; |
---|
| 1888 | } |
---|
[4416] | 1889 | unset($css->css[41][$key]); |
---|
[2] | 1890 | } |
---|
[4416] | 1891 | |
---|
| 1892 | $body = str_replace($block_found, '<style>'.$css->print->plain().'</style>', $body); |
---|
[2] | 1893 | } |
---|
[4416] | 1894 | |
---|
| 1895 | |
---|
[650] | 1896 | // Malicious Code Remove |
---|
[1923] | 1897 | $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] | 1898 | preg_match_all($dirtyCodePattern,$body,$rest,PREG_PATTERN_ORDER); |
---|
[4416] | 1899 | foreach($rest[0] as $i => $val) { |
---|
[1270] | 1900 | 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] | 1901 | $body = str_replace($rest[1][$i],"<".$rest[2][$i].$rest[3][$i].$rest[7][$i].">",$body); |
---|
[4416] | 1902 | } |
---|
[4795] | 1903 | |
---|
[4777] | 1904 | /* |
---|
| 1905 | * Remove deslocamento a esquerda colocado pelo Outlook. |
---|
| 1906 | * Este delocamento faz com que algumas palavras fiquem escondidas atras da barra lateral do expresso. |
---|
| 1907 | */ |
---|
| 1908 | $body = mb_ereg_replace("(<p[^>]*)(text-indent:[^>;]*-[^>;]*;)([^>]*>)","\\1\\3",$body); |
---|
| 1909 | $body = mb_ereg_replace("(<p[^>]*)(margin-right:[^>;]*-[^>;]*;)([^>]*>)","\\1\\3",$body); |
---|
| 1910 | $body = mb_ereg_replace("(<p[^>]*)(margin-left:[^>;]*-[^>;]*;)([^>]*>)","\\1\\3",$body); |
---|
| 1911 | //--------------------------------------------------------------------------------------------// |
---|
[4795] | 1912 | |
---|
[4989] | 1913 | //Remoção de tags <span></span> para correção de erro no firefox |
---|
[5134] | 1914 | //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>. |
---|
| 1915 | //Caso realmente haja a nescessidade de remover estes spans deve ser repensado a forma de como faze-lo. |
---|
| 1916 | // $body = mb_eregi_replace("<span><span>","",$body); |
---|
| 1917 | // $body = mb_eregi_replace("</span></span>","",$body); |
---|
[4996] | 1918 | |
---|
[5134] | 1919 | //Correção para compatibilização com Outlook, ao visualizar a mensagem |
---|
[4795] | 1920 | $body = mb_ereg_replace('<!--\[','<!-- [',$body); |
---|
[3294] | 1921 | $body = mb_ereg_replace('<!\[endif\]-->', '<![endif]-->', $body); |
---|
[4795] | 1922 | |
---|
[4416] | 1923 | return "<div class=\"$wrapper_class\"><span>".$body.'</span></div>'; |
---|
[5134] | 1924 | |
---|
[4795] | 1925 | } |
---|
[5079] | 1926 | |
---|
[4784] | 1927 | function replace_links_callback($matches) |
---|
[4800] | 1928 | { |
---|
[5247] | 1929 | if($matches[3]) |
---|
| 1930 | $pref = $matches[3]; |
---|
| 1931 | else |
---|
| 1932 | $pref = $matches[3] = 'http'; |
---|
[4795] | 1933 | |
---|
[5247] | 1934 | return '<a href="'.$pref.'://'.$matches[4].$matches[5].'" target="_blank">'.$matches[0].'</a>'; |
---|
[4784] | 1935 | } |
---|
[4795] | 1936 | |
---|
| 1937 | |
---|
[4436] | 1938 | /** |
---|
| 1939 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 1940 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 1941 | * @param $body corpo da mensagem |
---|
| 1942 | */ |
---|
| 1943 | function replace_links(&$body) |
---|
[5247] | 1944 | { |
---|
[4784] | 1945 | // Trata urls do tipo aaaa.bbb.empresa |
---|
| 1946 | // Usadas na intranet. |
---|
[5247] | 1947 | $pattern = '/(?<=[\s|(<br>)|\n|\r|;])(((http|https|ftp|ftps)?:\/\/((?:[\w]\.?)+(?::[\d]+)?[:\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\:\/\w.\-~&=?%;@+]*))/i'; |
---|
| 1948 | $body = preg_replace_callback($pattern,array( &$this, 'replace_links_callback'), $body); |
---|
[1897] | 1949 | |
---|
[4795] | 1950 | } |
---|
| 1951 | |
---|
[91] | 1952 | function get_signature($msg, $msg_number, $msg_folder) |
---|
[1035] | 1953 | { |
---|
[3352] | 1954 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
| 1955 | include_once("class.db_functions.inc.php"); |
---|
| 1956 | foreach ($msg->file_type[$msg_number] as $index => $file_type) |
---|
| 1957 | { |
---|
| 1958 | $sign = array(); |
---|
| 1959 | $temp = $this->get_info_head_msg($msg_number); |
---|
| 1960 | if($temp['ContentType'] =='normal') return $sign; |
---|
| 1961 | $file_type = strtolower($file_type); |
---|
| 1962 | if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') |
---|
[91] | 1963 | { |
---|
[3394] | 1964 | if ($temp['ContentType'] == 'signature') |
---|
[3352] | 1965 | { |
---|
[3394] | 1966 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 1967 | $this->mbox = $this->open_mbox($msg_folder); |
---|
[1035] | 1968 | |
---|
[3352] | 1969 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); |
---|
[1035] | 1970 | |
---|
[3352] | 1971 | $imap_msg = @imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
| 1972 | $imap_msg .= @imap_body($this->mbox, $msg_number, FT_UID); |
---|
[1035] | 1973 | |
---|
[3352] | 1974 | $certificado = new certificadoB(); |
---|
| 1975 | $validade = $certificado->verificar($imap_msg); |
---|
[3394] | 1976 | $sign[] = $certificado->msg_sem_assinatura; |
---|
[3352] | 1977 | if ($certificado->apresentado) |
---|
| 1978 | { |
---|
| 1979 | $from = $header->from; |
---|
| 1980 | foreach ($from as $id => $object) |
---|
| 1981 | { |
---|
| 1982 | $fromname = $object->personal; |
---|
| 1983 | $fromaddress = $object->mailbox . "@" . $object->host; |
---|
| 1984 | } |
---|
| 1985 | foreach ($certificado->erros_ssl as $item) |
---|
| 1986 | { |
---|
| 1987 | $sign[] = $item . "#@#"; |
---|
| 1988 | } |
---|
[1035] | 1989 | |
---|
[3352] | 1990 | if (count($certificado->erros_ssl) < 1) |
---|
| 1991 | { |
---|
| 1992 | $check_msg = 'Message untouched'; |
---|
| 1993 | if(strtoupper($fromaddress) == strtoupper($certificado->dados['EMAIL'])) |
---|
| 1994 | { |
---|
| 1995 | $check_msg .= ' and authentic###'; |
---|
| 1996 | } |
---|
| 1997 | else |
---|
| 1998 | { |
---|
| 1999 | $check_msg .= ' with signer different from sender#@#'; |
---|
| 2000 | } |
---|
| 2001 | $sign[] = $check_msg; |
---|
| 2002 | } |
---|
| 2003 | |
---|
| 2004 | $sign[] = 'Message signed by: ###' . $certificado->dados['NOME']; |
---|
| 2005 | $sign[] = 'Certificate email: ###' . $certificado->dados['EMAIL']; |
---|
| 2006 | $sign[] = 'Mail from: ###' . $fromaddress; |
---|
| 2007 | $sign[] = 'Certificate Authority: ###' . $certificado->dados['EMISSOR']; |
---|
| 2008 | $sign[] = 'Validity of certificate: ###' . gmdate('r',openssl_to_timestamp($certificado->dados['FIM_VALIDADE'])); |
---|
| 2009 | $sign[] = 'Message date: ###' . $header->Date; |
---|
[1035] | 2010 | |
---|
[3352] | 2011 | $cert = openssl_x509_parse($certificado->cert_assinante); |
---|
[1035] | 2012 | |
---|
[3352] | 2013 | $sign_alert = array(); |
---|
| 2014 | $sign_alert[] = 'Certificate Owner###:\n'; |
---|
| 2015 | $sign_alert[] = 'Common Name (CN)### ' . $cert[subject]['CN'] . '\n'; |
---|
| 2016 | $X = substr($certificado->dados['NASCIMENTO'] ,0,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,2,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,4,4); |
---|
| 2017 | $sign_alert[]= 'Organization (O)### ' . $cert[subject]['O'] . '\n'; |
---|
| 2018 | $sign_alert[]= 'Organizational Unit (OU)### ' . $cert[subject]['OU'][0] . '\n'; |
---|
| 2019 | //$sign_alert[] = 'Serial Number### ' . $cert['serialNumber'] . '\n'; |
---|
| 2020 | $sign_alert[] = 'Personal Data###:' . '\n'; |
---|
| 2021 | $sign_alert[] = 'Birthday### ' . $X . '\n'; |
---|
| 2022 | $sign_alert[]= 'Fiscal Id### ' . $certificado->dados['CPF'] . '\n'; |
---|
| 2023 | $sign_alert[]= 'Identification### ' . $certificado->dados['RG'] . '\n\n'; |
---|
| 2024 | $sign_alert[]= 'Certificate Issuer###:\n'; |
---|
| 2025 | $sign_alert[]= 'Common Name (CN)### ' . $cert[issuer]['CN'] . '\n'; |
---|
| 2026 | $sign_alert[]= 'Organization (O)### ' . $cert[issuer]['O'] . '\n'; |
---|
| 2027 | $sign_alert[]= 'Organizational Unit (OU)### ' . $cert[issuer]['OU'][0] . '\n\n'; |
---|
| 2028 | $sign_alert[]= 'Validity###:\n'; |
---|
| 2029 | $H = data_hora($cert[validFrom]); |
---|
| 2030 | $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); |
---|
| 2031 | $sign_alert[]= 'Valid From### ' . $X . '\n'; |
---|
| 2032 | $H = data_hora($cert[validTo]); |
---|
| 2033 | $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); |
---|
| 2034 | $sign_alert[]= 'Valid Until### ' . $X; |
---|
| 2035 | $sign[] = $sign_alert; |
---|
| 2036 | |
---|
| 2037 | $this->db = new db_functions(); |
---|
| 2038 | |
---|
| 2039 | // TODO: testar se existe um certificado no banco e verificar qual ᅵ o mais atual. |
---|
| 2040 | if(!$certificado->dados['EXPIRADO'] && !$certificado->dados['REVOGADO'] && count($certificado->erros_ssl) < 1) |
---|
| 2041 | $this->db->insert_certificate(strtolower($certificado->dados['EMAIL']), $certificado->cert_assinante, $certificado->dados['SERIALNUMBER'], $certificado->dados['AUTHORITYKEYIDENTIFIER']); |
---|
[91] | 2042 | } |
---|
[3352] | 2043 | else |
---|
| 2044 | { |
---|
| 2045 | $sign[] = "<span style=color:red>" . $this->functions->getLang('Invalid signature') . "</span>"; |
---|
| 2046 | foreach($certificado->erros_ssl as $item) |
---|
| 2047 | $sign[] = "<span style=color:red>" . $this->functions->getLang($item) . "</span>"; |
---|
| 2048 | } |
---|
| 2049 | } |
---|
[91] | 2050 | } |
---|
[3352] | 2051 | } |
---|
| 2052 | return $sign; |
---|
[91] | 2053 | } |
---|
| 2054 | |
---|
[4436] | 2055 | |
---|
| 2056 | /** |
---|
| 2057 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 2058 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 2059 | * @param $images |
---|
| 2060 | * @param $msg_number |
---|
| 2061 | * @param $msg_folder |
---|
| 2062 | */ |
---|
[4416] | 2063 | function get_thumbs($images, $msg_number, $msg_folder) |
---|
[2] | 2064 | { |
---|
[4416] | 2065 | |
---|
[5134] | 2066 | if (!count($images)) return ''; |
---|
[4416] | 2067 | |
---|
[5134] | 2068 | foreach ($images as $key => $value) { |
---|
| 2069 | $images[$key]['width'] = 160; |
---|
| 2070 | $images[$key]['height'] = 120; |
---|
| 2071 | $images[$key]['url'] = "inc/get_archive.php?msgFolder=".$msg_folder."&msgNumber=".$msg_number."&indexPart=".$image['pid']."&image=true"; |
---|
[4795] | 2072 | } |
---|
[5134] | 2073 | |
---|
| 2074 | return json_encode($images); |
---|
[2] | 2075 | } |
---|
[1472] | 2076 | |
---|
[2] | 2077 | /*function delete_msg($params) |
---|
| 2078 | { |
---|
| 2079 | $folder = $params['folder']; |
---|
| 2080 | $msgs_to_delete = explode(",",$params['msgs_to_delete']); |
---|
[1472] | 2081 | |
---|
[2] | 2082 | $mbox_stream = $this->open_mbox($folder); |
---|
[1472] | 2083 | |
---|
[2] | 2084 | foreach ($msgs_to_delete as $msg_number){ |
---|
| 2085 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
| 2086 | } |
---|
| 2087 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
| 2088 | return $params['msgs_to_delete']; |
---|
| 2089 | }*/ |
---|
| 2090 | |
---|
| 2091 | // Novo |
---|
| 2092 | function delete_msgs($params) |
---|
| 2093 | { |
---|
[4795] | 2094 | |
---|
[2] | 2095 | $folder = $params['folder']; |
---|
[51] | 2096 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); |
---|
[2] | 2097 | $msgs_number = explode(",",$params['msgs_number']); |
---|
[5134] | 2098 | if(array_key_exists('border_ID' ,$params)) |
---|
[2] | 2099 | $border_ID = $params['border_ID']; |
---|
[5134] | 2100 | else |
---|
| 2101 | $border_ID = ''; |
---|
[2] | 2102 | $return = array(); |
---|
[4795] | 2103 | |
---|
[5134] | 2104 | if (array_key_exists('get_previous_msg' , $params) && $params['get_previous_msg']){ |
---|
[2] | 2105 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
[449] | 2106 | // Fix problem in unserialize function JS. |
---|
| 2107 | $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); |
---|
| 2108 | } |
---|
[2] | 2109 | |
---|
[4795] | 2110 | //$mbox_stream = $this->open_mbox($folder); |
---|
[504] | 2111 | $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] | 2112 | |
---|
[2] | 2113 | foreach ($msgs_number as $msg_number) |
---|
| 2114 | { |
---|
| 2115 | if (imap_delete($mbox_stream, $msg_number, FT_UID)); |
---|
| 2116 | $return['msgs_number'][] = $msg_number; |
---|
| 2117 | } |
---|
[4795] | 2118 | |
---|
[2] | 2119 | $return['folder'] = $folder; |
---|
| 2120 | $return['border_ID'] = $border_ID; |
---|
[4795] | 2121 | |
---|
[51] | 2122 | if($mbox_stream) |
---|
| 2123 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[5172] | 2124 | |
---|
| 2125 | $return['status'] = true; |
---|
[2] | 2126 | return $return; |
---|
| 2127 | } |
---|
| 2128 | |
---|
[1472] | 2129 | |
---|
[2] | 2130 | function refresh($params) |
---|
| 2131 | { |
---|
[3265] | 2132 | |
---|
[5134] | 2133 | $return = array(); |
---|
| 2134 | $return['new_msgs'] = 0; |
---|
[2] | 2135 | $folder = $params['folder']; |
---|
| 2136 | $msg_range_begin = $params['msg_range_begin']; |
---|
| 2137 | $msg_range_end = $params['msg_range_end']; |
---|
| 2138 | $msgs_existent = $params['msgs_existent']; |
---|
[1472] | 2139 | $sort_box_type = $params['sort_box_type']; |
---|
[2] | 2140 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 2141 | $msgs_in_the_server = array(); |
---|
[53] | 2142 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
[828] | 2143 | $msgs_in_the_server = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); |
---|
| 2144 | $msgs_in_the_server = array_keys($msgs_in_the_server); |
---|
[1472] | 2145 | |
---|
[828] | 2146 | $num_msgs = (count($msgs_in_the_server) - imap_num_recent($this->mbox)); |
---|
[5134] | 2147 | |
---|
[5158] | 2148 | $dif = ($params['msg_range_end'] - $params['msg_range_begin']) +1; |
---|
| 2149 | if(!count($msgs_in_the_server)){ |
---|
| 2150 | $msg_range_begin -= $dif; |
---|
| 2151 | $msg_range_end -= $dif; |
---|
| 2152 | $msgs_in_the_server = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); |
---|
| 2153 | $msgs_in_the_server = array_keys($msgs_in_the_server); |
---|
| 2154 | $num_msgs = NULL; |
---|
| 2155 | $return['msg_range_begin'] = $msg_range_begin; |
---|
| 2156 | $return['msg_range_end'] = $msg_range_end; |
---|
| 2157 | } |
---|
| 2158 | $return['new_msgs'] = imap_num_recent($this->mbox); |
---|
| 2159 | |
---|
[1472] | 2160 | $msgs_in_the_client = explode(",", $msgs_existent); |
---|
[51] | 2161 | |
---|
[2] | 2162 | $msg_to_insert = array_diff($msgs_in_the_server, $msgs_in_the_client); |
---|
[5134] | 2163 | |
---|
| 2164 | if(count($msg_to_insert) > 0 && $return['new_msgs'] == 0 && $msgs_in_the_client[0] != ""){ |
---|
| 2165 | $aux = 0; |
---|
| 2166 | while(array_key_exists($aux, $msg_to_insert)){ |
---|
| 2167 | if($msg_to_insert[$aux] > $msgs_in_the_client[0]){ |
---|
| 2168 | $return['new_msgs'] += 1; |
---|
| 2169 | } |
---|
| 2170 | $aux++; |
---|
| 2171 | } |
---|
| 2172 | }else if(count($msg_to_insert) > 0 && $msgs_in_the_server && $msgs_in_the_client[0] != "" && $return['new_msgs'] == 0){ |
---|
| 2173 | $aux = 0; |
---|
| 2174 | while(array_key_exists($aux, $msg_to_insert)){ |
---|
| 2175 | if($msg_to_insert[$aux] == $msgs_in_the_server[$aux]){ |
---|
| 2176 | $return['new_msgs'] += 1; |
---|
| 2177 | } |
---|
| 2178 | $aux++; |
---|
| 2179 | } |
---|
[5158] | 2180 | }else if($num_msgs < $msg_range_end && $return['new_msgs'] == 0 && count($msg_to_insert) > 0 && $msg_range_end == $dif){ |
---|
[5134] | 2181 | $return['tot_msgs'] = $num_msgs; |
---|
| 2182 | } |
---|
| 2183 | |
---|
[5158] | 2184 | if(!count($msgs_in_the_server)){ |
---|
| 2185 | return Array(); |
---|
| 2186 | } |
---|
| 2187 | |
---|
[271] | 2188 | $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); |
---|
[2] | 2189 | $msgs_to_exec = array(); |
---|
[3265] | 2190 | foreach($msg_to_insert as $msg_number) |
---|
| 2191 | $msgs_to_exec[] = $msg_number; |
---|
[4764] | 2192 | //sort($msgs_to_exec); |
---|
[2] | 2193 | $i = 0; |
---|
[3265] | 2194 | foreach($msgs_to_exec as $msg_number) |
---|
[2] | 2195 | { |
---|
[614] | 2196 | /*A função imap_headerinfo não traz o cabeçalho completo, e sim alguns |
---|
[1472] | 2197 | * atributos do cabeçalho. Como eu preciso do atributo Importance |
---|
[614] | 2198 | * para saber se o email é importante ou não, uso abaixo a função |
---|
| 2199 | * imap_fetchheader e busco o atributo importance nela para passar |
---|
| 2200 | * para as funções ajax. Isso faz com que eu acesse o cabeçalho |
---|
| 2201 | * duas vezes e de duas formas diferentes, mas em contrapartida, eu |
---|
| 2202 | * não preciso reimplementar o método utilizando o fetchheader. |
---|
| 2203 | */ |
---|
[3955] | 2204 | |
---|
| 2205 | $tempHeader = @imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); |
---|
[1035] | 2206 | $flag = preg_match('/importance *: *(.*)\r/i', $tempHeader, $importance); |
---|
[689] | 2207 | $return[$i]['Importance'] = $flag==0?"Normal":$importance[1]; |
---|
[1472] | 2208 | |
---|
[1752] | 2209 | $msg_sample = $this->get_msg_sample($msg_number); |
---|
| 2210 | $return[$i]['msg_sample'] = $msg_sample; |
---|
| 2211 | |
---|
[535] | 2212 | $header = $this->get_header($msg_number); |
---|
[2] | 2213 | if (!is_object($header)) |
---|
[828] | 2214 | continue; |
---|
| 2215 | |
---|
[2] | 2216 | $return[$i]['msg_number'] = $msg_number; |
---|
[3955] | 2217 | |
---|
| 2218 | //get the next msg number to append this msg in the view in a correct place |
---|
| 2219 | $msg_key_position = array_search($msg_number, $msgs_in_the_server); |
---|
| 2220 | |
---|
[4764] | 2221 | $return[$i]['msg_key_position'] = $msg_key_position; |
---|
| 2222 | if($msg_key_position !== false && array_key_exists($msg_key_position + 1,$msgs_in_the_server) !== false) |
---|
[3955] | 2223 | $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position + 1]; |
---|
[4764] | 2224 | else |
---|
| 2225 | $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position]; |
---|
[1472] | 2226 | |
---|
[2] | 2227 | $return[$i]['msg_folder'] = $folder; |
---|
[3955] | 2228 | // Atribui o tipo (normal, signature ou cipher) ao campo Content-Type |
---|
[3265] | 2229 | $return[$i]['ContentType'] = $this->getMessageType($msg_number, $tempHeader); |
---|
[2] | 2230 | $return[$i]['Recent'] = $header->Recent; |
---|
| 2231 | $return[$i]['Unseen'] = $header->Unseen; |
---|
| 2232 | $return[$i]['Answered'] = $header->Answered; |
---|
| 2233 | $return[$i]['Deleted'] = $header->Deleted; |
---|
| 2234 | $return[$i]['Draft'] = $header->Draft; |
---|
| 2235 | $return[$i]['Flagged'] = $header->Flagged; |
---|
| 2236 | |
---|
[3106] | 2237 | $return[$i]['udate'] = $header->udate; |
---|
| 2238 | |
---|
[2] | 2239 | $from = $header->from; |
---|
| 2240 | $return[$i]['from'] = array(); |
---|
| 2241 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 2242 | $return[$i]['from']['name'] = $tmp[0]->text; |
---|
| 2243 | $return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
[1472] | 2244 | //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; |
---|
[5134] | 2245 | if(!$return[$i]['from']['name'] || trim($return[$i]['from']['name']) === '') |
---|
[2] | 2246 | $return[$i]['from']['name'] = $return[$i]['from']['email']; |
---|
[1472] | 2247 | |
---|
[2] | 2248 | /*$toaddress = imap_mime_header_decode($header->toaddress); |
---|
| 2249 | $return[$i]['toaddress'] = ''; |
---|
| 2250 | foreach ($toaddress as $tmp) |
---|
| 2251 | $return[$i]['toaddress'] .= $tmp->text;*/ |
---|
| 2252 | $to = $header->to; |
---|
| 2253 | $return[$i]['to'] = array(); |
---|
[5134] | 2254 | if(isset($to[0]->personal)) |
---|
[2] | 2255 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
[5134] | 2256 | if(trim($return[$i]['to']['name']) === '') |
---|
| 2257 | $return[$i]['to']['name'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
| 2258 | else |
---|
[2] | 2259 | $return[$i]['to']['name'] = $tmp[0]->text; |
---|
| 2260 | $return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
| 2261 | $return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; |
---|
[5134] | 2262 | if(isset($header->cc)) |
---|
[3777] | 2263 | $cc = $header->cc; |
---|
[5134] | 2264 | |
---|
| 2265 | if ( isset($cc) && (!$return[$i]['to']['name'] || $return[$i]['to']['name'] == '@') ){ |
---|
[3777] | 2266 | $return[$i]['to']['name'] = $cc[0]->personal; |
---|
| 2267 | $return[$i]['to']['email'] = $cc[0]->mailbox . "@" . $cc[0]->host; |
---|
| 2268 | } |
---|
[5134] | 2269 | $return[$i]['subject'] = ( isset( $header->fetchsubject ) ) ? $this->decode_string($header->fetchsubject) : ''; |
---|
| 2270 | if($return[$i]['subject'] == "" || $return[$i]['subject'] == '' || $return[$i]['subject'] == null ){ |
---|
| 2271 | $return[$i]['subject'] = $this->functions->getLang("(no subject) "); |
---|
| 2272 | } |
---|
[2] | 2273 | $return[$i]['Size'] = $header->Size; |
---|
| 2274 | $return[$i]['reply_toaddress'] = $header->reply_toaddress; |
---|
[1472] | 2275 | |
---|
[5134] | 2276 | if($return[$i]['to']['email'] == '@' || $return[$i]['to']['email'] =='undisclosed-recipients@' || $return[$i]['to']['name'] =='undisclosed-recipients@' |
---|
| 2277 | || $return[$i]['to']['name'] == null){ |
---|
| 2278 | $return[$i]['to']['email'] = $return[$i]['from']['email']; |
---|
| 2279 | $return[$i]['to']['name'] = $return[$i]['from']['name']; |
---|
| 2280 | $return[$i]['to']['full'] = $return[$i]['reply_toaddress']; |
---|
| 2281 | } |
---|
| 2282 | |
---|
[2] | 2283 | $return[$i]['attachment'] = array(); |
---|
[3265] | 2284 | if (!isset($imap_attachment)) |
---|
| 2285 | { |
---|
| 2286 | include_once("class.imap_attachment.inc.php"); |
---|
| 2287 | $imap_attachment = new imap_attachment(); |
---|
| 2288 | } |
---|
[51] | 2289 | $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); |
---|
[2] | 2290 | $i++; |
---|
| 2291 | } |
---|
[3265] | 2292 | $return['quota'] = $this->get_quota(array('folder_id' => $folder)); |
---|
| 2293 | $return['sort_box_type'] = $params['sort_box_type']; |
---|
[3427] | 2294 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 2295 | { |
---|
| 2296 | $this->open_mbox($folder); |
---|
| 2297 | } |
---|
[4819] | 2298 | |
---|
[271] | 2299 | $return['msgs_to_delete'] = $msg_to_delete; |
---|
[3493] | 2300 | $return['offsetToGMT'] = $this->functions->CalculateDateOffset(); |
---|
[411] | 2301 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 2302 | imap_close($this->mbox); |
---|
[828] | 2303 | |
---|
[2] | 2304 | return $return; |
---|
| 2305 | } |
---|
| 2306 | |
---|
[1035] | 2307 | /** |
---|
| 2308 | * Método que faz a verificação do Content-Type do e-mail e verifica se é um e-mail normal, |
---|
| 2309 | * assinado ou cifrado. |
---|
| 2310 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
| 2311 | * @param $headers Uma String contendo os Headers do e-mail retornados pela função imap_imap_fetchheader |
---|
| 2312 | * @param $msg_number O número da mesagem |
---|
| 2313 | * @return Retorna o tipo da mensagem (normal, signature, cipher). |
---|
| 2314 | */ |
---|
| 2315 | function getMessageType($msg_number, $headers = false){ |
---|
[3394] | 2316 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
[1035] | 2317 | $contentType = "normal"; |
---|
| 2318 | if (!$headers){ |
---|
| 2319 | $headers = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); |
---|
| 2320 | } |
---|
[3394] | 2321 | |
---|
| 2322 | if (preg_match("/pkcs7-signature/i", $headers) == 1){ |
---|
[1035] | 2323 | $contentType = "signature"; |
---|
[3394] | 2324 | } else if (preg_match("/pkcs7-mime/i", $headers) == 1){ |
---|
| 2325 | $contentType = testa_p7m( imap_body($this->mbox, imap_msgno($this->mbox, $msg_number)) ); |
---|
[1035] | 2326 | } |
---|
| 2327 | |
---|
| 2328 | return $contentType; |
---|
| 2329 | } |
---|
[5216] | 2330 | |
---|
[5218] | 2331 | /** |
---|
| 2332 | * Retorna a posição que a pasta esta dentro do array de pastas |
---|
| 2333 | * |
---|
| 2334 | * @license www.gnu.org/copyleft/gpl.html GPL |
---|
| 2335 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 2336 | * @sponsor Caixa Econômica Federal |
---|
| 2337 | * @author Cristiano Corrêa Schmidt |
---|
| 2338 | * @access public |
---|
| 2339 | */ |
---|
| 2340 | |
---|
[5216] | 2341 | function getFolderPos(&$array , $find) |
---|
| 2342 | { |
---|
| 2343 | foreach($array as $i => $v) |
---|
| 2344 | if($v['id'] === $find) |
---|
| 2345 | return $i; |
---|
| 2346 | return false; |
---|
| 2347 | } |
---|
| 2348 | |
---|
| 2349 | /** |
---|
| 2350 | * Ordenas as pastas padrões do usuario na ordem INBOX > SENT > DRAFTS > SPAM > TRASH > OTHERS |
---|
| 2351 | * |
---|
| 2352 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 2353 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 2354 | * @sponsor Caixa Econômica Federal |
---|
| 2355 | * @author Cristiano Corrêa Schmidt |
---|
| 2356 | * @access public |
---|
| 2357 | */ |
---|
| 2358 | function orderDefaultFolders( &$folders , $user) |
---|
[2] | 2359 | { |
---|
[5216] | 2360 | $principals = array(); |
---|
| 2361 | for($x = 0; $x < 5 ; $x++) |
---|
| 2362 | { |
---|
| 2363 | switch ($x) { |
---|
| 2364 | case 0: |
---|
| 2365 | if( ($p = $this->getFolderPos($folders , $user )) || $p === 0 ) |
---|
| 2366 | $principals[] = $folders[$p]; |
---|
| 2367 | break; |
---|
| 2368 | case 1: |
---|
| 2369 | if( ($p = $this->getFolderPos($folders , $user . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] )) || $p === 0 ) |
---|
| 2370 | $principals[] = $folders[$p]; |
---|
| 2371 | break; |
---|
| 2372 | case 2: |
---|
| 2373 | if( ($p = $this->getFolderPos($folders , $user . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] )) || $p === 0 ) |
---|
| 2374 | $principals[] = $folders[$p]; |
---|
| 2375 | break; |
---|
| 2376 | case 3: |
---|
| 2377 | if( ($p = $this->getFolderPos($folders , $user . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'] )) || $p === 0 ) |
---|
| 2378 | $principals[] = $folders[$p]; |
---|
| 2379 | break; |
---|
| 2380 | case 4: |
---|
| 2381 | if( ($p = $this->getFolderPos($folders , $user . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'] )) || $p === 0 ) |
---|
| 2382 | $principals[] = $folders[$p]; |
---|
| 2383 | break; |
---|
| 2384 | } |
---|
| 2385 | if($p !== false) |
---|
| 2386 | unset($folders[$p]); |
---|
[1953] | 2387 | } |
---|
[5216] | 2388 | $folders = array_merge($principals, $folders); |
---|
| 2389 | } |
---|
| 2390 | |
---|
| 2391 | /** |
---|
| 2392 | * Retorna lista de pastas do usuario no padrão que a lib javascript espera. |
---|
| 2393 | * |
---|
| 2394 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 2395 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 2396 | * @sponsor Caixa Econômica Federal |
---|
| 2397 | * @author Cristiano Corrêa Schmidt |
---|
| 2398 | * @access public |
---|
| 2399 | */ |
---|
| 2400 | function get_folders_list($params = null) |
---|
| 2401 | { |
---|
| 2402 | ///Define Variaveis |
---|
| 2403 | $prefixShared = 'user'; //Prefixo das pastas compartilhadas |
---|
| 2404 | $uid2cn = (isset($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'])) ? $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] : false; |
---|
| 2405 | $mboxStream = $this->open_mbox(); //abre conexão imap |
---|
| 2406 | $currentFolder = isset($params['folder']) ? $params['folder'] : 'INBOX'; |
---|
| 2407 | $folders = array(); |
---|
| 2408 | $return = array(); |
---|
| 2409 | /////////////////////////////////////////////////////////////// |
---|
| 2410 | |
---|
| 2411 | if( isset($params['onload']) && $_SESSION['phpgw_info']['expressomail']['server']['certificado']) |
---|
| 2412 | $this->delete_mailbox(array('del_past' => 'INBOX'.$this->imap_delimiter.'decifradas')); //Deleta Pasta decifradas |
---|
| 2413 | |
---|
| 2414 | session_write_close(); // Free others requests |
---|
[3018] | 2415 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
[3790] | 2416 | |
---|
[5216] | 2417 | if ( isset($params['noSharedFolders']) ) |
---|
| 2418 | $folders_list = array_merge(imap_getmailboxes($mboxStream, $serverString, 'INBOX' ), imap_getmailboxes($mboxStream, $serverString, 'INBOX/*' ) ); |
---|
[3790] | 2419 | else |
---|
[5216] | 2420 | $folders_list = imap_getmailboxes($mboxStream, $serverString, '*' ); |
---|
[3761] | 2421 | |
---|
[3018] | 2422 | $folders_list = array_slice($folders_list,0,$this->foldersLimit); |
---|
| 2423 | |
---|
[5216] | 2424 | if (!is_array($folders_list)) return false; |
---|
| 2425 | if($uid2cn) |
---|
| 2426 | $this->ldap = new ldap_functions(); |
---|
| 2427 | |
---|
| 2428 | foreach ($folders_list as $i => $v ) //Separando Pastas e informações |
---|
[1816] | 2429 | { |
---|
[5216] | 2430 | $folderId = substr($v->name,(strpos($v->name , '}') + 1)); |
---|
| 2431 | $nameArray = explode($this->imap_delimiter, $folderId); |
---|
| 2432 | $nameCount = count($nameArray); |
---|
| 2433 | $decifrada = mb_convert_encoding('INBOX'.$this->imap_delimiter.'decifradas','UTF7-IMAP','ISO-8859-1'); //Ignorar esta pasta decifrada |
---|
| 2434 | $parent = ($nameCount > 1 && $nameArray[($nameCount - 2)] !== 'INBOX') ? implode($this->imap_delimiter, array_slice($nameArray, 0, ($nameCount - 1))): ''; //Pega folder pai |
---|
| 2435 | if($nameArray[0] === 'user') |
---|
| 2436 | $folders[$prefixShared.$this->imap_delimiter.$nameArray[1]][] = array('id' => $folderId , 'stream' => $v->name , 'attributes' => $v->attributes , 'name' => $nameArray[($nameCount-1)] , 'user' => $nameArray[1] ,'parent' => $parent); |
---|
| 2437 | else if( $folderId !== $decifrada) //Escapa pasta decifrada |
---|
| 2438 | $folders['INBOX'][] = array('id' => $folderId , 'stream' => $v->name , 'attributes' => $v->attributes ,'name' => $nameArray[($nameCount-1)] , 'parent' => $parent); |
---|
[1816] | 2439 | } |
---|
[5216] | 2440 | unset($folders_list); //destroy array de objetos desnecessarios |
---|
| 2441 | foreach($folders as $i => $v) //Ordenando e resgatando novas informações |
---|
| 2442 | { |
---|
| 2443 | $this->orderDefaultFolders($folders[$i] , $i); //Ordenando Pastas Padrões |
---|
| 2444 | |
---|
| 2445 | foreach ($folders[$i] as $ii => $vv) |
---|
[5134] | 2446 | { |
---|
[5216] | 2447 | $append = array(); |
---|
| 2448 | $append['folder_id'] = mb_convert_encoding($vv['id'],'ISO-8859-1','UTF7-IMAP');//DECODIFICA ID DAS PASTAS COM ACENTOS |
---|
| 2449 | $append['folder_name'] = (($uid2cn && isset($vv['user'])) && ($cn = $this->ldap->uid2cn($vv['user']))) ? $cn : $vv['name']; |
---|
| 2450 | $append['folder_name'] = mb_convert_encoding($append['folder_name'],'ISO-8859-1','UTF7-IMAP');//DECODIFICA NOME DAS PASTAS COM ACENTOS |
---|
| 2451 | $status = imap_status($mboxStream, $vv['stream'], SA_UNSEEN); //Resgata Numero de mensagens não lidas |
---|
| 2452 | $append['folder_unseen'] = isset($status->unseen) ? $status->unseen : 0 ; |
---|
| 2453 | $append['folder_hasChildren'] = (($vv['attributes'] == 32) && ($vv['name'] != 'INBOX')) ? 1 : 0; |
---|
[5228] | 2454 | $append['folder_parent'] = mb_convert_encoding($vv['parent'],'ISO-8859-1','UTF7-IMAP'); |
---|
[5216] | 2455 | $return[] = $append; |
---|
[5134] | 2456 | } |
---|
| 2457 | } |
---|
[5216] | 2458 | |
---|
| 2459 | $quotaInfo = (!isset($params['noQuotaInfo'])) ? $this->get_quota( array('folder_id' => $currentFolder)) : false; //VERIFICA SE O USUARIO TEM COTA |
---|
[5243] | 2460 | |
---|
[5216] | 2461 | return ( ( is_array($quotaInfo) ) ? array_merge($return, $quotaInfo) : $return ); |
---|
[2] | 2462 | } |
---|
[5216] | 2463 | |
---|
[1472] | 2464 | |
---|
[2] | 2465 | function create_mailbox($arr) |
---|
| 2466 | { |
---|
| 2467 | $namebox = $arr['newp']; |
---|
| 2468 | $mbox_stream = $this->open_mbox(); |
---|
| 2469 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[51] | 2470 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); |
---|
[1472] | 2471 | |
---|
[2] | 2472 | $result = "Ok"; |
---|
[51] | 2473 | if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
[2] | 2474 | { |
---|
| 2475 | $result = implode("<br />\n", imap_errors()); |
---|
[1472] | 2476 | } |
---|
| 2477 | |
---|
[51] | 2478 | if($mbox_stream) |
---|
| 2479 | imap_close($mbox_stream); |
---|
[1472] | 2480 | |
---|
[2] | 2481 | return $result; |
---|
[1472] | 2482 | |
---|
[2] | 2483 | } |
---|
[1472] | 2484 | |
---|
[2] | 2485 | function create_extra_mailbox($arr) |
---|
| 2486 | { |
---|
| 2487 | $nameboxs = explode(";",$arr['nw_folders']); |
---|
| 2488 | $result = ""; |
---|
| 2489 | $mbox_stream = $this->open_mbox(); |
---|
| 2490 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[1472] | 2491 | foreach($nameboxs as $key=>$tmp){ |
---|
[2] | 2492 | if($tmp != ""){ |
---|
| 2493 | if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ |
---|
| 2494 | $result = implode("<br />\n", imap_errors()); |
---|
[51] | 2495 | if($mbox_stream) |
---|
[1472] | 2496 | imap_close($mbox_stream); |
---|
[2] | 2497 | return $result; |
---|
| 2498 | } |
---|
| 2499 | } |
---|
| 2500 | } |
---|
[51] | 2501 | if($mbox_stream) |
---|
| 2502 | imap_close($mbox_stream); |
---|
[2] | 2503 | return true; |
---|
| 2504 | } |
---|
[1472] | 2505 | |
---|
[2] | 2506 | function delete_mailbox($arr) |
---|
| 2507 | { |
---|
| 2508 | $namebox = $arr['del_past']; |
---|
| 2509 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[1953] | 2510 | $mbox_stream = $this->mbox ? $this->mbox : $this->open_mbox(); |
---|
[2] | 2511 | //$del_folder = imap_deletemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox"); |
---|
[1472] | 2512 | |
---|
[2] | 2513 | $result = "Ok"; |
---|
| 2514 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
| 2515 | if(!imap_deletemailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
| 2516 | { |
---|
| 2517 | $result = implode("<br />\n", imap_errors()); |
---|
| 2518 | } |
---|
[1953] | 2519 | /* |
---|
[51] | 2520 | if($mbox_stream) |
---|
| 2521 | imap_close($mbox_stream); |
---|
[1953] | 2522 | */ |
---|
[2] | 2523 | return $result; |
---|
| 2524 | } |
---|
[1472] | 2525 | |
---|
[2] | 2526 | function ren_mailbox($arr) |
---|
| 2527 | { |
---|
| 2528 | $namebox = $arr['current']; |
---|
| 2529 | $new_box = $arr['rename']; |
---|
| 2530 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 2531 | $mbox_stream = $this->open_mbox(); |
---|
| 2532 | //$ren_folder = imap_renamemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox","{".$imap_server."}INBOX.$new_box"); |
---|
[1472] | 2533 | |
---|
[2] | 2534 | $result = "Ok"; |
---|
| 2535 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
[51] | 2536 | $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); |
---|
[1472] | 2537 | |
---|
[2] | 2538 | if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) |
---|
| 2539 | { |
---|
[1472] | 2540 | $result = imap_errors(); |
---|
[2] | 2541 | } |
---|
[51] | 2542 | if($mbox_stream) |
---|
| 2543 | imap_close($mbox_stream); |
---|
[2] | 2544 | return $result; |
---|
[1472] | 2545 | |
---|
[2] | 2546 | } |
---|
[1472] | 2547 | |
---|
[2] | 2548 | function get_num_msgs($params) |
---|
| 2549 | { |
---|
| 2550 | $folder = $params['folder']; |
---|
[411] | 2551 | if(!$this->mbox || !is_resource($this->mbox)) { |
---|
[2] | 2552 | $this->mbox = $this->open_mbox($folder); |
---|
[411] | 2553 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[2] | 2554 | return imap_last_error(); |
---|
[1472] | 2555 | } |
---|
[2] | 2556 | $num_msgs = imap_num_msg($this->mbox); |
---|
[432] | 2557 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 2558 | imap_close($this->mbox); |
---|
[1472] | 2559 | |
---|
[2] | 2560 | return $num_msgs; |
---|
| 2561 | } |
---|
[1472] | 2562 | |
---|
[1912] | 2563 | function folder_exists($folder){ |
---|
| 2564 | $mbox = $this->open_mbox(); |
---|
| 2565 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 2566 | $list = imap_getmailboxes($mbox,$serverString, $folder); |
---|
| 2567 | $return = is_array($list); |
---|
| 2568 | imap_close($mbox); |
---|
| 2569 | return $return; |
---|
| 2570 | } |
---|
| 2571 | |
---|
[2] | 2572 | function send_mail($params) |
---|
| 2573 | { |
---|
[5134] | 2574 | require_once $_SESSION['rootPath'] . '/API/class.servicelocator.php'; |
---|
| 2575 | $mailService = ServiceLocator::getService('mail'); |
---|
| 2576 | |
---|
[2] | 2577 | include_once("class.db_functions.inc.php"); |
---|
| 2578 | $db = new db_functions(); |
---|
| 2579 | $fromaddress = $params['input_from'] ? explode(';',$params['input_from']) : ""; |
---|
[5134] | 2580 | $message_attachments_contents = (isset($params['message_attachments_content'])) ? $params['message_attachments_content'] : false; |
---|
| 2581 | |
---|
[449] | 2582 | ## |
---|
| 2583 | # @AUTHOR Rodrigo Souza dos Santos |
---|
[3369] | 2584 | # @DATE 2008/09/17$fileName |
---|
[449] | 2585 | # @BRIEF Checks if the user has permission to send an email with the email address used. |
---|
| 2586 | ## |
---|
| 2587 | if ( is_array($fromaddress) && ($fromaddress[1] != $_SESSION['phpgw_info']['expressomail']['user']['email']) ) |
---|
| 2588 | { |
---|
| 2589 | $deny = true; |
---|
| 2590 | foreach( $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] as $key => $val ) |
---|
| 2591 | if ( array_key_exists('mail', $val) && $val['mail'][0] == $fromaddress[1] ) |
---|
| 2592 | $deny = false and end($_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes']); |
---|
| 2593 | |
---|
| 2594 | if ( $deny ) |
---|
| 2595 | return "The server denied your request to send a mail, you cannot use this mail address."; |
---|
| 2596 | } |
---|
[828] | 2597 | |
---|
[2] | 2598 | $toaddress = implode(',',$db->getAddrs(explode(',',$params['input_to']))); |
---|
| 2599 | $ccaddress = implode(',',$db->getAddrs(explode(',',$params['input_cc']))); |
---|
| 2600 | $ccoaddress = implode(',',$db->getAddrs(explode(',',$params['input_cco']))); |
---|
[5134] | 2601 | |
---|
| 2602 | $toaddress = preg_replace('/<\s+/', '<', $toaddress); |
---|
| 2603 | $toaddress = preg_replace('/\s+>/', '>', $toaddress); |
---|
| 2604 | |
---|
| 2605 | $ccaddress = preg_replace('/<\s+/', '<', $ccaddress); |
---|
| 2606 | $ccaddress = preg_replace('/\s+>/', '>', $ccaddress); |
---|
| 2607 | |
---|
| 2608 | $ccoaddress = preg_replace('/<\s+/', '<', $ccoaddress); |
---|
| 2609 | $ccoaddress = preg_replace('/\s+>/', '>', $ccoaddress); |
---|
| 2610 | |
---|
[3527] | 2611 | $replytoaddress = $params['input_replyto']; |
---|
[2] | 2612 | $subject = $params['input_subject']; |
---|
[271] | 2613 | $msg_uid = $params['msg_id']; |
---|
[2] | 2614 | $return_receipt = $params['input_return_receipt']; |
---|
[614] | 2615 | $is_important = $params['input_important_message']; |
---|
[1035] | 2616 | $encrypt = $params['input_return_cripto']; |
---|
| 2617 | $signed = $params['input_return_digital']; |
---|
| 2618 | |
---|
[5134] | 2619 | $message_attachments = $params['message_attachments']; |
---|
| 2620 | |
---|
| 2621 | if(substr($params['input_to'],-1) == ',') |
---|
| 2622 | $params['input_to'] = substr($params['input_to'],0,-1); |
---|
| 2623 | |
---|
| 2624 | if(substr($params['input_cc'],-1) == ',') |
---|
| 2625 | $params['input_cc'] = substr($params['input_cc'],0,-1); |
---|
| 2626 | |
---|
| 2627 | if(substr($params['input_cco'],-1) == ',') |
---|
| 2628 | $params['input_cco'] = substr($params['input_cco'],0,-1); |
---|
| 2629 | |
---|
| 2630 | |
---|
| 2631 | // Valida numero Maximo de Destinatarios |
---|
| 2632 | if($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoAdmin_maximum_recipients'] > 0) |
---|
| 2633 | { |
---|
| 2634 | $sendersNumber = count(explode(',',$params['input_to'])); |
---|
| 2635 | |
---|
| 2636 | if($params['input_cc']) |
---|
| 2637 | $sendersNumber += count(explode(',',$params['input_cc'])); |
---|
| 2638 | if($params['input_cco']) |
---|
| 2639 | $sendersNumber += count(explode(',',$params['input_cco'])); |
---|
| 2640 | |
---|
| 2641 | $userMaxmimumSenders = $db->getMaximumRecipientsUser($this->username); |
---|
| 2642 | if($userMaxmimumSenders) |
---|
| 2643 | { |
---|
| 2644 | if($sendersNumber > $userMaxmimumSenders) |
---|
| 2645 | return $this->functions->getLang('Number of recipients greater than allowed'); |
---|
| 2646 | } |
---|
| 2647 | else |
---|
| 2648 | { |
---|
| 2649 | $ldap = new ldap_functions(); |
---|
| 2650 | $groupsToUser = $ldap->get_user_groups($this->username); |
---|
| 2651 | |
---|
| 2652 | $groupMaxmimumSenders = $db->getMaximumRecipientsGroup($groupsToUser); |
---|
| 2653 | |
---|
| 2654 | if($groupMaxmimumSenders > 0) |
---|
| 2655 | { |
---|
| 2656 | if($sendersNumber > $groupMaxmimumSenders) |
---|
| 2657 | return $this->functions->getLang('Number of recipients greater than allowed'); |
---|
| 2658 | } |
---|
| 2659 | else |
---|
| 2660 | { |
---|
| 2661 | if($sendersNumber > $_SESSION['phpgw_info']['expresso']['expressoMail']['expressoAdmin_maximum_recipients']) |
---|
| 2662 | return $this->functions->getLang('Number of recipients greater than allowed'); |
---|
| 2663 | } |
---|
| 2664 | } |
---|
| 2665 | |
---|
| 2666 | } |
---|
| 2667 | //Fim Valida numero maximo de destinatarios |
---|
| 2668 | |
---|
| 2669 | |
---|
| 2670 | //Valida envio de email para shared accounts |
---|
| 2671 | if($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_block_institutional_comunication'] == 'true') |
---|
| 2672 | { |
---|
| 2673 | $ldap = new ldap_functions(); |
---|
| 2674 | $arrayF = explode(';', $params['input_from']); |
---|
| 2675 | |
---|
| 2676 | /* |
---|
| 2677 | * Verifica se o remetente n?o ? uma conta compartilhada |
---|
| 2678 | */ |
---|
| 2679 | if(!$ldap->isSharedAccountByMail($arrayF[1])) |
---|
| 2680 | { |
---|
| 2681 | $groupsToUser = $ldap->get_user_groups($this->username); |
---|
| 2682 | $sharedAccounts = $ldap->returnSharedsAccounts($toaddress, $ccaddress, $ccoaddress); |
---|
| 2683 | |
---|
| 2684 | /* |
---|
| 2685 | * Pega o UID do remetente |
---|
| 2686 | */ |
---|
| 2687 | $uidFrom = $ldap->mail2uid($arrayF[1]); |
---|
| 2688 | |
---|
| 2689 | /* |
---|
| 2690 | * Remove a conta compartilhada caso o uid do remetente exista na conta compartilhada |
---|
| 2691 | */ |
---|
| 2692 | foreach ($sharedAccounts as $key => $value) |
---|
| 2693 | { |
---|
| 2694 | if($value) |
---|
| 2695 | $acl = $this->getaclfrombox($value); |
---|
| 2696 | |
---|
| 2697 | if (array_key_exists($uidFrom, $acl)) |
---|
| 2698 | unset($sharedAccounts[$key]); |
---|
| 2699 | |
---|
| 2700 | } |
---|
| 2701 | |
---|
| 2702 | /* |
---|
| 2703 | * Caso ainda exista contas compartilhadas, verifica se existe alguma exce??o para estas contas |
---|
| 2704 | */ |
---|
| 2705 | if(count($sharedAccounts) > 0) |
---|
| 2706 | $accountsBlockeds = $db->validadeSharedAccounts($this->username, $groupsToUser, $sharedAccounts); |
---|
| 2707 | |
---|
| 2708 | /* |
---|
| 2709 | * Retorna as contas compartilhadas bloqueadas |
---|
| 2710 | */ |
---|
| 2711 | if(count($accountsBlockeds) > 0) |
---|
| 2712 | { |
---|
| 2713 | $return = ''; |
---|
| 2714 | |
---|
| 2715 | foreach ($accountsBlockeds as $accountBlocked) |
---|
| 2716 | $return.= $accountBlocked.', '; |
---|
| 2717 | |
---|
| 2718 | $return = substr($return,0,-2); |
---|
| 2719 | |
---|
| 2720 | return $this->functions->getLang('you are blocked from sending mail to the following addresses').': '.$return; |
---|
| 2721 | } |
---|
| 2722 | } |
---|
| 2723 | } |
---|
| 2724 | // Fim Valida envio de email para shared accounts |
---|
| 2725 | |
---|
| 2726 | |
---|
| 2727 | // TODO - implementar tratamento SMIME no novo serviço de envio de emails e retirar o AND false abaixo |
---|
| 2728 | if($params['smime'] AND false) |
---|
[1035] | 2729 | { |
---|
| 2730 | $body = $params['smime']; |
---|
| 2731 | $mail->SMIME = true; |
---|
| 2732 | // A MSG assinada deve ser testada neste ponto. |
---|
| 2733 | // Testar o certificado e a integridade da msg.... |
---|
[3271] | 2734 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
[1035] | 2735 | $erros_acumulados = ''; |
---|
| 2736 | $certificado = new certificadoB(); |
---|
| 2737 | $validade = $certificado->verificar($body); |
---|
| 2738 | if(!$validade) |
---|
| 2739 | { |
---|
| 2740 | foreach($certificado->erros_ssl as $linha_erro) |
---|
| 2741 | { |
---|
| 2742 | $erros_acumulados .= $linha_erro; |
---|
| 2743 | } |
---|
| 2744 | } |
---|
| 2745 | else |
---|
| 2746 | { |
---|
| 2747 | // Testa o CERTIFICADO: se o CPF he o do usuario logado, se pode assinar msgs e se nao esta expirado... |
---|
| 2748 | if ($certificado->apresentado) |
---|
| 2749 | { |
---|
| 2750 | if($certificado->dados['EXPIRADO']) $erros_acumulados .='Certificado expirado.'; |
---|
[4291] | 2751 | $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; |
---|
| 2752 | if($certificado->dados['CPF'] != $this->cpf) $erros_acumulados .=' CPF no certificado diferente do logado no expresso.'; |
---|
[1035] | 2753 | if(!($certificado->dados['KEYUSAGE']['digitalSignature'] && $certificado->dados['EXTKEYUSAGE']['emailProtection'])) $erros_acumulados .=' Certificado nao permite assinar mensagens.'; |
---|
| 2754 | } |
---|
| 2755 | else |
---|
| 2756 | { |
---|
| 2757 | $$erros_acumulados .= 'Nao foi possivel usar o certificado para assinar a msg'; |
---|
| 2758 | } |
---|
| 2759 | } |
---|
| 2760 | if(!$erros_acumulados =='') |
---|
| 2761 | { |
---|
| 2762 | return $erros_acumulados; |
---|
| 2763 | } |
---|
| 2764 | } |
---|
| 2765 | else |
---|
| 2766 | { |
---|
[3250] | 2767 | //Compatibilização com Outlook, ao encaminhar a mensagem |
---|
[5134] | 2768 | $body = mb_ereg_replace('<!--\[', '<!-- [', $params['body']); |
---|
[1035] | 2769 | } |
---|
[5134] | 2770 | |
---|
[3900] | 2771 | $attachments = $_FILES; |
---|
[2] | 2772 | $forwarding_attachments = $params['forwarding_attachments']; |
---|
[689] | 2773 | $local_attachments = $params['local_attachments']; |
---|
[3369] | 2774 | |
---|
[1912] | 2775 | //Test if must be saved in shared folder and change if necessary |
---|
| 2776 | if( $fromaddress[2] == 'y' ){ |
---|
| 2777 | //build shared folder path |
---|
| 2778 | $newfolder = "user".$this->imap_delimiter.$fromaddress[3].$this->imap_delimiter.$this->imap_sentfolder; |
---|
[5134] | 2779 | if($this->folder_exists($newfolder)) |
---|
| 2780 | $folder = $newfolder; |
---|
| 2781 | else |
---|
| 2782 | $folder = $params['folder']; |
---|
| 2783 | |
---|
[1912] | 2784 | } else { |
---|
| 2785 | $folder = $params['folder']; |
---|
| 2786 | } |
---|
| 2787 | |
---|
[5134] | 2788 | $folder = mb_convert_encoding($folder, 'UTF7-IMAP','ISO_8859-1'); |
---|
| 2789 | $folder = preg_replace('/INBOX[\/.]/i', 'INBOX'.$this->imap_delimiter, $folder); |
---|
[1472] | 2790 | $folder_name = $params['folder_name']; |
---|
[1035] | 2791 | |
---|
[5134] | 2792 | // TODO - tratar assinatura e remover o AND false |
---|
| 2793 | if($signed && !$params['smime'] AND false) |
---|
[1035] | 2794 | { |
---|
| 2795 | $mail->Mailer = "smime"; |
---|
| 2796 | $mail->SignedBody = true; |
---|
| 2797 | } |
---|
[1472] | 2798 | |
---|
[5134] | 2799 | |
---|
| 2800 | if($fromaddress) |
---|
| 2801 | $mailService->setFrom ('"'.$fromaddress[0].'" <'.$fromaddress[1].'>'); |
---|
| 2802 | else |
---|
| 2803 | $mailService->setFrom ('"'.$_SESSION['phpgw_info']['expressomail']['user']['firstname'].' '.$_SESSION['phpgw_info']['expressomail']['user']['lastname'].'" <'.$_SESSION['phpgw_info']['expressomail']['user']['email'].'>'); |
---|
| 2804 | //$mailService->addTo($toaddress); |
---|
| 2805 | //$mailService->addCc($ccaddress); |
---|
[5254] | 2806 | $bol = $this->add_recipients('to', $params['input_to'], $mailService); |
---|
[5134] | 2807 | if(!$bol){ |
---|
| 2808 | return $this->parse_error("Invalid Mail:", $toaddress); |
---|
[2] | 2809 | } |
---|
[5254] | 2810 | $bol = $this->add_recipients('cc', $params['input_cc'], $mailService); |
---|
[5134] | 2811 | if(!$bol){ |
---|
| 2812 | return $this->parse_error("Invalid Mail:", $ccaddress); |
---|
| 2813 | } |
---|
[4832] | 2814 | $allow = $_SESSION['phpgw_info']['server']['expressomail']['allow_hidden_copy']; |
---|
| 2815 | |
---|
[5134] | 2816 | if($allow) |
---|
[4832] | 2817 | { |
---|
[5134] | 2818 | //$mailService->addBcc($ccoaddress); |
---|
[5254] | 2819 | $bol = $this->add_recipients('cco', $params['input_cco'], $mailService); |
---|
[5134] | 2820 | |
---|
| 2821 | if(!$bol){ |
---|
| 2822 | return $this->parse_error("Invalid Mail:", $ccoaddress); |
---|
| 2823 | } |
---|
[4832] | 2824 | } |
---|
[271] | 2825 | |
---|
[5134] | 2826 | $mailService->setSubject($subject); |
---|
| 2827 | $isHTML = ( (array_key_exists('type', $params) && in_array(strtolower($params['type']), array('html', 'plain')) ) ? |
---|
| 2828 | strtolower($params['type']) != 'plain' : true ); |
---|
| 2829 | |
---|
| 2830 | |
---|
| 2831 | // TODO - tratar mensagem criptografada e remover o AND false abaixo |
---|
| 2832 | if (($encrypt && $signed && $params['smime']) || ($encrypt && !$signed) AND false) // a msg deve ser enviada cifrada... |
---|
[1035] | 2833 | { |
---|
| 2834 | $email = $this->add_recipients_cert($toaddress . ',' . $ccaddress. ',' .$ccoaddress); |
---|
| 2835 | $email = explode(",",$email); |
---|
| 2836 | // Deve ser testado se foram obtidos os certificados de todos os destinatarios. |
---|
| 2837 | // Deve ser verificado um numero limite de destinatarios. |
---|
| 2838 | // Deve ser verificado se os certificados sao validos. |
---|
| 2839 | // Se uma das verificacoes falhar, nao enviar o e-mail e avisar o usuario. |
---|
| 2840 | // O array $mail->Certs_crypt soh deve ser preenchido se os certificados passarem nas verificacoes. |
---|
| 2841 | $numero_maximo = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['num_max_certs_to_cipher']; // Este valor dever ser configurado pelo administrador do site .... |
---|
| 2842 | $erros_acumulados = ""; |
---|
| 2843 | $aux_mails = array(); |
---|
| 2844 | $mail_list = array(); |
---|
| 2845 | if(count($email) > $numero_maximo) |
---|
| 2846 | { |
---|
| 2847 | $erros_acumulados .= "Excedido o numero maximo (" . $numero_maximo . ") de destinatarios para uma msg cifrada...." . chr(0x0A); |
---|
| 2848 | return $erros_acumulados; |
---|
| 2849 | } |
---|
| 2850 | // adiciona o email do remetente. eh para cifrar a msg para ele tambem. Assim vai poder visualizar a msg na pasta enviados.. |
---|
| 2851 | $email[] = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 2852 | foreach($email as $item) |
---|
| 2853 | { |
---|
| 2854 | $certificate = $db->get_certificate(strtolower($item)); |
---|
| 2855 | if(!$certificate) |
---|
| 2856 | { |
---|
| 2857 | $erros_acumulados .= "Chamada com parametro invalido. e-Mail nao pode ser vazio." . chr(0x0A); |
---|
| 2858 | return $erros_acumulados; |
---|
| 2859 | } |
---|
| 2860 | |
---|
| 2861 | if (array_key_exists("dberr1", $certificate)) |
---|
| 2862 | { |
---|
| 2863 | |
---|
| 2864 | $erros_acumulados .= "Ocorreu um erro quando pesquisava certificados dos destinatarios para cifrar a msg." . chr(0x0A); |
---|
| 2865 | return $erros_acumulados; |
---|
| 2866 | } |
---|
| 2867 | if (array_key_exists("dberr2", $certificate)) |
---|
| 2868 | { |
---|
| 2869 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado nao localizado.' . chr(0x0A); |
---|
| 2870 | //continue; |
---|
| 2871 | } |
---|
| 2872 | /* Retirado este teste para evitar mensagem de erro duplicada. |
---|
| 2873 | if (!array_key_exists("certs", $certificate)) |
---|
| 2874 | { |
---|
| 2875 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado nao localizado.' . chr(0x0A); |
---|
| 2876 | continue; |
---|
| 2877 | } |
---|
| 2878 | */ |
---|
[3271] | 2879 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
[1035] | 2880 | |
---|
| 2881 | foreach ($certificate['certs'] as $registro) |
---|
| 2882 | { |
---|
| 2883 | $c1 = new certificadoB(); |
---|
| 2884 | $c1->certificado($registro['chave_publica']); |
---|
| 2885 | if ($c1->apresentado) |
---|
| 2886 | { |
---|
| 2887 | $c2 = new Verifica_Certificado($c1->dados,$registro['chave_publica']); |
---|
| 2888 | if (!$c1->dados['EXPIRADO'] && !$c2->revogado && $c2->status) |
---|
| 2889 | { |
---|
| 2890 | $aux_mails[] = $registro['chave_publica']; |
---|
| 2891 | $mail_list[] = strtolower($item); |
---|
| 2892 | } |
---|
| 2893 | else |
---|
| 2894 | { |
---|
| 2895 | if ($c1->dados['EXPIRADO'] || $c2->revogado) |
---|
| 2896 | { |
---|
| 2897 | $db->update_certificate($c1->dados['SERIALNUMBER'],$c1->dados['EMAIL'],$c1->dados['AUTHORITYKEYIDENTIFIER'], |
---|
| 2898 | $c1->dados['EXPIRADO'],$c2->revogado); |
---|
| 2899 | } |
---|
| 2900 | |
---|
| 2901 | $erros_acumulados .= $item . ': ' . $c2->msgerro . chr(0x0A); |
---|
| 2902 | foreach($c2->erros_ssl as $linha) |
---|
| 2903 | { |
---|
| 2904 | $erros_acumulados .= $linha . chr(0x0A); |
---|
| 2905 | } |
---|
| 2906 | $erros_acumulados .= 'Emissor: ' . $c1->dados['EMISSOR'] . chr(0x0A); |
---|
| 2907 | $erros_acumulados .= $c1->dados['CRLDISTRIBUTIONPOINTS'] . chr(0x0A); |
---|
| 2908 | } |
---|
| 2909 | } |
---|
| 2910 | else |
---|
| 2911 | { |
---|
| 2912 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado invalido.' . chr(0x0A); |
---|
| 2913 | } |
---|
| 2914 | } |
---|
| 2915 | if(!(in_array(strtolower($item),$mail_list)) && !empty($erros_acumulados)) |
---|
| 2916 | { |
---|
| 2917 | return $erros_acumulados; |
---|
| 2918 | } |
---|
| 2919 | } |
---|
| 2920 | |
---|
| 2921 | $mail->Certs_crypt = $aux_mails; |
---|
| 2922 | } |
---|
[5134] | 2923 | |
---|
| 2924 | if( count($forwarding_attachments) > 0 )// Build CID images |
---|
| 2925 | $this->buildEmbeddedImages($mailService,$msg_uid,$forwarding_attachments, $body); |
---|
[1035] | 2926 | |
---|
[2] | 2927 | // Build Uploading Attachments!!! |
---|
[3387] | 2928 | if (count($attachments)>0) //Caso seja forward normal... |
---|
[2] | 2929 | { |
---|
| 2930 | $total_uploaded_size = 0; |
---|
| 2931 | foreach ($attachments as $attach) |
---|
| 2932 | { |
---|
[3900] | 2933 | if($attach['error'] == UPLOAD_ERR_INI_SIZE) |
---|
| 2934 | return $this->parse_error("message file too big"); |
---|
[3387] | 2935 | if($attach['name']=='Unknown') |
---|
| 2936 | continue; |
---|
[5134] | 2937 | $mailService->addFileAttachment($attach['tmp_name'], $attach['name'], $this->get_file_type($attach['name']), 'base64', 'attachment'); |
---|
[2] | 2938 | $total_uploaded_size = $total_uploaded_size + $attach['size']; |
---|
| 2939 | } |
---|
[5134] | 2940 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) |
---|
| 2941 | { |
---|
| 2942 | |
---|
| 2943 | $upload_max_filesize = str_replace('M','',$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) * 1024 * 1024; |
---|
| 2944 | if( $total_uploaded_size > $upload_max_filesize) |
---|
[1472] | 2945 | return $this->parse_error("message file too big"); |
---|
[3387] | 2946 | } |
---|
[828] | 2947 | } |
---|
[3387] | 2948 | if(count($local_attachments)>0) { //Caso seja forward de mensagens locais |
---|
[828] | 2949 | |
---|
[689] | 2950 | $total_uploaded_size = 0; |
---|
[5134] | 2951 | |
---|
[689] | 2952 | foreach($local_attachments as $local_attachment) { |
---|
| 2953 | $file_description = unserialize(rawurldecode($local_attachment)); |
---|
| 2954 | $tmp = array_values($file_description); |
---|
[1472] | 2955 | foreach($file_description as $i => $descriptor){ |
---|
[689] | 2956 | $tmp[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 2957 | } |
---|
[5134] | 2958 | $mailService->addFileAttachment($_FILES[$tmp[1]]['tmp_name'], $tmp[2], $this->get_file_type($tmp[2]), 'base64', 'attachment'); |
---|
[689] | 2959 | $total_uploaded_size = $total_uploaded_size + $_FILES[$tmp[1]]['size']; |
---|
| 2960 | } |
---|
[5134] | 2961 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) |
---|
| 2962 | { |
---|
| 2963 | $upload_max_filesize = str_replace('M','',$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) * 1024 * 1024; |
---|
| 2964 | if( $total_uploaded_size > $upload_max_filesize) |
---|
| 2965 | return $this->parse_error("message file too big"); |
---|
| 2966 | } |
---|
[689] | 2967 | } |
---|
[5134] | 2968 | |
---|
[271] | 2969 | // Build Forwarding Attachments!!! |
---|
[2] | 2970 | if (count($forwarding_attachments) > 0) |
---|
| 2971 | { |
---|
| 2972 | // Bug fixed for array_search function |
---|
[3018] | 2973 | $name_cid_files = array(); |
---|
[2] | 2974 | if(count($name_cid_files) > 0) { |
---|
| 2975 | $name_cid_files[count($name_cid_files)] = $name_cid_files[0]; |
---|
| 2976 | $name_cid_files[0] = null; |
---|
[1472] | 2977 | } |
---|
| 2978 | |
---|
[2] | 2979 | foreach($forwarding_attachments as $forwarding_attachment) |
---|
| 2980 | { |
---|
[5134] | 2981 | $file_description = unserialize(rawurldecode($forwarding_attachment)); |
---|
[5177] | 2982 | |
---|
| 2983 | foreach($file_description as $i => $item) |
---|
| 2984 | $file_description[$i] = urldecode($item); |
---|
| 2985 | |
---|
[5134] | 2986 | $tmp = array_values($file_description); |
---|
| 2987 | foreach($file_description as $i => $descriptor){ |
---|
| 2988 | $tmp[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 2989 | } |
---|
| 2990 | $file_description = $tmp; |
---|
| 2991 | $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); |
---|
| 2992 | $fileName = $file_description[2]; |
---|
| 2993 | if(!array_search(trim($fileName),$name_cid_files)) { |
---|
| 2994 | $filename_dec = html_entity_decode(rawurldecode($fileName)); |
---|
| 2995 | $mailService->addStringAttachment($fileContent, $filename_dec, $this->get_file_type($file_description[2]), $file_description[4] ); |
---|
| 2996 | |
---|
| 2997 | } |
---|
| 2998 | } |
---|
| 2999 | } |
---|
| 3000 | |
---|
| 3001 | //Build Message Attachments!!! |
---|
| 3002 | if(count($message_attachments) > 0 ) |
---|
| 3003 | { |
---|
| 3004 | foreach($message_attachments as $folder_name => $messages) |
---|
| 3005 | { |
---|
| 3006 | foreach ($messages as $message_number => $message_subject) |
---|
| 3007 | { |
---|
| 3008 | if (!$message_subject) |
---|
| 3009 | $message_subject = 'no title.eml'; |
---|
| 3010 | else |
---|
| 3011 | $message_subject .= '.eml'; |
---|
| 3012 | |
---|
| 3013 | if( $message_attachments_contents && isset($message_attachments_contents[$folder_name]) ) |
---|
| 3014 | $rawmsg = base64_decode( $message_attachments_contents[$folder_name][$message_number] ); |
---|
| 3015 | else{ |
---|
| 3016 | $mbox_stream = $this->open_mbox($folder_name); |
---|
| 3017 | $rawmsg = $this->getRawHeader($message_number) . "\r\n\r\n" . $this->getRawBody($message_number); |
---|
[271] | 3018 | } |
---|
[5134] | 3019 | |
---|
| 3020 | $return_forward[] = array( 'name' => $message_subject, 'size' => mb_strlen($rawmsg)); |
---|
| 3021 | $mailService->addStringAttachment($rawmsg, $message_subject, 'message/rfc822', '7bit', 'attachment' ); |
---|
[63] | 3022 | } |
---|
[2] | 3023 | } |
---|
| 3024 | } |
---|
[5134] | 3025 | |
---|
| 3026 | $message_size_total += strlen($params['body']); /* Tamanho do corpo da mensagem. */ |
---|
| 3027 | $message_size_total += $total_uploaded_size; /* Incrementa com os anexos da nova mensagem, se houver. */ |
---|
| 3028 | |
---|
| 3029 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 3030 | /** |
---|
| 3031 | * 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. |
---|
| 3032 | */ |
---|
| 3033 | $default_max_size_rule = $db->get_default_max_size_rule(); |
---|
| 3034 | if(!$default_max_size_rule) |
---|
| 3035 | { |
---|
| 3036 | $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 */ |
---|
| 3037 | } |
---|
| 3038 | else |
---|
| 3039 | { |
---|
| 3040 | foreach($default_max_size_rule as $i=>$value) |
---|
| 3041 | { |
---|
| 3042 | $default_max_size_rule = $value['config_value']; |
---|
| 3043 | } |
---|
| 3044 | } |
---|
| 3045 | |
---|
| 3046 | $default_max_size_rule = $default_max_size_rule * 1024 * 1024; /* Tamanho da regra padrão, em bytes */ |
---|
| 3047 | $id_user = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 3048 | |
---|
| 3049 | |
---|
| 3050 | $ldap = new ldap_functions(); |
---|
| 3051 | $groups_user = $ldap->get_user_groups($id_user); |
---|
[37] | 3052 | |
---|
[5134] | 3053 | $size_rule_by_group = array(); |
---|
| 3054 | foreach($groups_user as $k=>$value_) |
---|
| 3055 | { |
---|
| 3056 | $rule_in_group = $db->get_rule_by_user_in_groups($k); |
---|
| 3057 | if ($rule_in_group != "") |
---|
| 3058 | array_push($size_rule_by_group, $rule_in_group); |
---|
| 3059 | } |
---|
| 3060 | |
---|
| 3061 | $n_rule_groups = 0; |
---|
| 3062 | $maior_valor_regra_grupo = 0; |
---|
| 3063 | foreach($size_rule_by_group as $i=>$value) |
---|
| 3064 | { |
---|
| 3065 | if(is_array($value[0])) |
---|
| 3066 | { |
---|
| 3067 | $n_rule_groups++; |
---|
| 3068 | if($value[0]['email_max_recipient'] > $maior_valor_regra_grupo) |
---|
| 3069 | $maior_valor_regra_grupo = $value[0]['email_max_recipient']; |
---|
| 3070 | } |
---|
| 3071 | } |
---|
| 3072 | |
---|
| 3073 | if($default_max_size_rule) |
---|
| 3074 | { |
---|
| 3075 | $size_rule = $db->get_rule_by_user($_SESSION['phpgw_info']['expressomail']['user']['userid']); |
---|
| 3076 | |
---|
| 3077 | 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. */ |
---|
| 3078 | { |
---|
| 3079 | if($message_size_total > $default_max_size_rule) |
---|
| 3080 | return $this->functions->getLang("Message size greateruler than allowed (Default rule)"); |
---|
| 3081 | } |
---|
| 3082 | |
---|
| 3083 | else |
---|
| 3084 | { |
---|
| 3085 | if(count($size_rule) > 0) /* Verifica se existe regra por usuário. Se houver, ela vai se sobresair das regras por grupo. */ |
---|
| 3086 | { |
---|
| 3087 | $regra_mais_permissiva = 0; |
---|
| 3088 | foreach($size_rule as $i=>$value) |
---|
| 3089 | { |
---|
| 3090 | if($regra_mais_permissiva < $value['email_max_recipient']) |
---|
| 3091 | $regra_mais_permissiva = $value['email_max_recipient']; |
---|
| 3092 | } |
---|
| 3093 | $regra_mais_permissiva = $regra_mais_permissiva * 1024 * 1024; |
---|
| 3094 | if($message_size_total > $regra_mais_permissiva) |
---|
| 3095 | return $this->functions->getLang("Message size greater than allowed (Rule By User)"); |
---|
| 3096 | } |
---|
| 3097 | else /* Regra por grupo */ |
---|
| 3098 | { |
---|
| 3099 | $maior_valor_regra_grupo = $maior_valor_regra_grupo * 1024 * 1024; |
---|
| 3100 | if($message_size_total > $maior_valor_regra_grupo) |
---|
| 3101 | return $this->functions->getLang("Message size greater than allowed (Rule By Group)"); |
---|
| 3102 | |
---|
| 3103 | |
---|
| 3104 | } |
---|
| 3105 | } |
---|
| 3106 | } |
---|
| 3107 | /** |
---|
| 3108 | * Fim da validação do tamanho da regra do tamanho de mensagem. |
---|
| 3109 | */ |
---|
| 3110 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 3111 | |
---|
| 3112 | |
---|
| 3113 | |
---|
| 3114 | |
---|
| 3115 | |
---|
| 3116 | if($isHTML) |
---|
| 3117 | $mailService->setBodyHtml($body); |
---|
| 3118 | else |
---|
| 3119 | $mailService->setBodyText($body); |
---|
| 3120 | |
---|
[614] | 3121 | if($is_important) |
---|
[5134] | 3122 | $mailService->addHeaderField('Importance','High'); |
---|
[614] | 3123 | |
---|
[5134] | 3124 | if($return_receipt) |
---|
| 3125 | $mailService->addHeaderField('Disposition-Notification-To', $_SESSION['phpgw_info']['expressomail']['user']['email']); |
---|
[504] | 3126 | |
---|
[1472] | 3127 | |
---|
[5134] | 3128 | if ($folder != 'null'){ |
---|
| 3129 | $mbox_stream = $this->open_mbox($folder); |
---|
| 3130 | @imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, $mailService->getMessage(), "\\Seen"); |
---|
| 3131 | } |
---|
| 3132 | |
---|
| 3133 | $sent = $mailService->send(); |
---|
| 3134 | |
---|
| 3135 | if($sent !== true) |
---|
[2] | 3136 | { |
---|
[5134] | 3137 | return $this->parse_error($sent); |
---|
[2] | 3138 | } |
---|
| 3139 | else |
---|
| 3140 | { |
---|
[1035] | 3141 | if ($signed && !$params['smime']) |
---|
| 3142 | { |
---|
| 3143 | return $sent; |
---|
| 3144 | } |
---|
[1472] | 3145 | if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") |
---|
[117] | 3146 | { |
---|
| 3147 | $userid = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 3148 | $userip = $_SESSION['phpgw_info']['expressomail']['user']['session_ip']; |
---|
| 3149 | $now = date("d/m/y H:i:s"); |
---|
| 3150 | $addrs = $toaddress.$ccaddress.$ccoaddress; |
---|
[1472] | 3151 | $sent = trim($sent); |
---|
[117] | 3152 | error_log("$now - $userip - $sent [$subject] - $userid => $addrs\r\n", 3, "/home/expressolivre/mail_senders.log"); |
---|
| 3153 | } |
---|
[5134] | 3154 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts']) { |
---|
[469] | 3155 | $contacts = new dynamic_contacts(); |
---|
[485] | 3156 | $new_contacts = $contacts->add_dynamic_contacts($toaddress.",".$ccaddress.",".$ccoaddress); |
---|
| 3157 | return array("success" => true, "new_contacts" => $new_contacts); |
---|
[413] | 3158 | } |
---|
[485] | 3159 | return array("success" => true); |
---|
[2] | 3160 | } |
---|
| 3161 | } |
---|
[4416] | 3162 | |
---|
[4436] | 3163 | |
---|
| 3164 | /** |
---|
| 3165 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 3166 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 3167 | * @param $mail email |
---|
| 3168 | * @param $msg_uid uid da mensagem |
---|
| 3169 | * @param $forwarding_attachments anexos |
---|
| 3170 | */ |
---|
[5134] | 3171 | |
---|
| 3172 | function buildEmbeddedImages(&$mail,$msg_uid,&$forwarding_attachments ,&$body) |
---|
[4795] | 3173 | { |
---|
[5134] | 3174 | //Procura e retorna em $cids_imgs imagens embarcadas no corpo do e-mail |
---|
| 3175 | $pattern = '/src=("[^"]*?get_archive.php\?msgFolder=(.+)?&(amp;)?msgNumber=(.+)?&(amp;)?indexPart=(.+)?")/isU'; |
---|
[4795] | 3176 | $cid_imgs = ''; |
---|
[5134] | 3177 | preg_match_all( $pattern , $body , $cid_imgs , PREG_PATTERN_ORDER ); |
---|
| 3178 | //-------------------------------------------------------------------// |
---|
[2] | 3179 | |
---|
[5134] | 3180 | $attPostions = array(); //Array que linka a possição da imagem com o indice que esta se encontra no array $forwarding_attachments |
---|
[3018] | 3181 | |
---|
[5134] | 3182 | foreach ($forwarding_attachments as $i => $v){ // Monta o array de link |
---|
| 3183 | $desc = unserialize(rawurldecode($v)); |
---|
| 3184 | $attPostions[$desc[3]] = $i; |
---|
| 3185 | } |
---|
[3018] | 3186 | |
---|
[5134] | 3187 | //Intera as imagens encontradas |
---|
| 3188 | foreach($cid_imgs[6] as $j => $val) |
---|
| 3189 | { |
---|
| 3190 | $cid = base_convert(microtime().$j, 10, 36); //Gera um cid |
---|
[5158] | 3191 | $body = str_replace($cid_imgs[1][$j], '"cid:'.$cid.'"', $body ); //tira o src da imagem e coloca o cid. |
---|
[4416] | 3192 | $count = strlen($cid_imgs[6][$j]); |
---|
| 3193 | |
---|
[5134] | 3194 | $attach_img = $forwarding_attachments[$attPostions['\''.$cid_imgs[6][$j].'\'']]; |
---|
[4416] | 3195 | $file_description = unserialize(rawurldecode($attach_img)); |
---|
| 3196 | |
---|
| 3197 | if (is_array($file_description)) |
---|
| 3198 | foreach($file_description as $i => $descriptor) |
---|
[5134] | 3199 | $file_description[$i] = mb_ereg_replace('\'*\'','',$descriptor); |
---|
[4416] | 3200 | |
---|
| 3201 | // The image is not in the same mail? |
---|
| 3202 | if ($msg_uid != $cid_imgs[4][$j]) |
---|
[4795] | 3203 | { |
---|
[5134] | 3204 | $fa = $this->get_forwarding_attachment2($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); |
---|
| 3205 | $fileContent = &$fa['binary']; |
---|
| 3206 | $fileName = $fa['name']; |
---|
| 3207 | $fileCode = $fa['encoding']; |
---|
| 3208 | $fileType = $fa['type']; |
---|
[4795] | 3209 | $file_attached[0] = $cid_imgs[2][$j]; |
---|
| 3210 | $file_attached[1] = $cid_imgs[4][$j]; |
---|
| 3211 | $file_attached[2] = $fileName; |
---|
[5134] | 3212 | $file_attached[3] = '0.'.(string)($j+1); |
---|
[4795] | 3213 | $file_attached[4] = 'base64'; |
---|
| 3214 | $file_attached[5] = strlen($fileContent); //Size of file |
---|
[4416] | 3215 | $file_attached[6] = $cid_imgs[6][$j]; |
---|
[4795] | 3216 | $return_forward[] = $file_attached; |
---|
[4416] | 3217 | |
---|
| 3218 | if ($file_attached[3] == $file_description[3] || $msg_uid == 'undefined') |
---|
[5134] | 3219 | unset($forwarding_attachments[$attPostions['\''.$cid_imgs[6][$j].'\'']]); |
---|
[4416] | 3220 | |
---|
[4795] | 3221 | } |
---|
| 3222 | else |
---|
| 3223 | { |
---|
| 3224 | $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64'); |
---|
| 3225 | $fileName = $file_description[2]; |
---|
| 3226 | $fileCode = $file_description[4]; |
---|
[5134] | 3227 | $file_description[3] = '0.'.(string)($j+1); |
---|
[4416] | 3228 | $file_description[6] = $cid_imgs[6][$j]; |
---|
[4795] | 3229 | $fileType = $this->get_file_type($file_description[2]); |
---|
[5134] | 3230 | unset($forwarding_attachments[$attPostions['\''.$cid_imgs[6][$j].'\'']]); |
---|
[4795] | 3231 | if (!empty($file_description)) |
---|
| 3232 | { |
---|
| 3233 | $file_description[5] = strlen($fileContent); //Size of file |
---|
| 3234 | $return_forward[] = $file_description; |
---|
| 3235 | } |
---|
| 3236 | } |
---|
[4416] | 3237 | |
---|
[4795] | 3238 | if ($fileContent) |
---|
[5134] | 3239 | $mail->addStringImage($fileContent,$fileType,$fileName, $cid); |
---|
[4416] | 3240 | } |
---|
[4795] | 3241 | |
---|
| 3242 | return $return_forward; |
---|
| 3243 | } |
---|
[3018] | 3244 | function add_recipients_cert($full_address) |
---|
[1035] | 3245 | { |
---|
| 3246 | $result = ""; |
---|
| 3247 | $parse_address = imap_rfc822_parse_adrlist($full_address, ""); |
---|
| 3248 | foreach ($parse_address as $val) |
---|
| 3249 | { |
---|
| 3250 | //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; |
---|
| 3251 | if ($val->mailbox == "INVALID_ADDRESS") |
---|
| 3252 | continue; |
---|
| 3253 | if ($val->mailbox == "UNEXPECTED_DATA_AFTER_ADDRESS") |
---|
| 3254 | continue; |
---|
| 3255 | if (empty($val->personal)) |
---|
| 3256 | $result .= $val->mailbox."@".$val->host . ","; |
---|
| 3257 | else |
---|
| 3258 | $result .= $val->mailbox."@".$val->host . ","; |
---|
| 3259 | } |
---|
| 3260 | |
---|
| 3261 | return substr($result,0,-1); |
---|
| 3262 | } |
---|
| 3263 | |
---|
[5243] | 3264 | function add_recipients($recipient_type, $full_address, $mail, $mobile = false) |
---|
[2] | 3265 | { |
---|
[3932] | 3266 | //remove a comma if is given two unexpected commas |
---|
| 3267 | $full_address = preg_replace("/, ?,/",",",$full_address); |
---|
[1472] | 3268 | $parse_address = imap_rfc822_parse_adrlist($full_address, ""); |
---|
[5254] | 3269 | |
---|
[5255] | 3270 | $bolean = true; |
---|
| 3271 | foreach ($parse_address as $val) |
---|
| 3272 | { |
---|
| 3273 | //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; |
---|
| 3274 | if ($val->mailbox == "INVALID_ADDRESS") |
---|
| 3275 | continue; |
---|
| 3276 | switch($recipient_type) |
---|
[5243] | 3277 | { |
---|
[5255] | 3278 | case "to": |
---|
| 3279 | if($mobile){ |
---|
| 3280 | $mail->AddAddress($val->mailbox."@".$val->host, $val->personal); |
---|
| 3281 | }else{ |
---|
| 3282 | $mail->AddTo( ($val->personal ? "\"$val->personal\" <$val->mailbox@$val->host>" : "$val->mailbox@$val->host")); |
---|
| 3283 | } |
---|
| 3284 | break; |
---|
| 3285 | case "cc": |
---|
| 3286 | if($mobile){ |
---|
| 3287 | $mail->AddCC($val->mailbox."@".$val->host, $val->personal); |
---|
| 3288 | }else{ |
---|
| 3289 | $mail->AddCC( ($val->personal ? "\"$val->personal\" <$val->mailbox@$val->host>" : "$val->mailbox@$val->host")); |
---|
[5243] | 3290 | } |
---|
[5255] | 3291 | break; |
---|
| 3292 | case "cco": |
---|
| 3293 | $mail->AddBcc(($val->personal ? "\"$val->personal\" <$val->mailbox@$val->host>" : "$val->mailbox@$val->host")); |
---|
| 3294 | break; |
---|
[2] | 3295 | } |
---|
[5255] | 3296 | if($val->mailbox == "UNEXPECTED_DATA_AFTER_ADDRESS"){ |
---|
| 3297 | $bolean = false; |
---|
[2] | 3298 | } |
---|
| 3299 | } |
---|
[5134] | 3300 | return $bolean; |
---|
[2] | 3301 | } |
---|
[1472] | 3302 | |
---|
[2] | 3303 | function get_forwarding_attachment($msg_folder, $msg_number, $msg_part, $encoding) |
---|
| 3304 | { |
---|
[4416] | 3305 | include_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; |
---|
| 3306 | $attachment = new attachment(); |
---|
[5134] | 3307 | $attachment->decodeConf['rfc_822bodies'] = true; //Forçar a não decodificação de mensagens em anexo. |
---|
[4416] | 3308 | $attachment->setStructureFromMail($msg_folder, $msg_number); |
---|
| 3309 | return $attachment->getAttachment($msg_part); |
---|
[2] | 3310 | } |
---|
[1472] | 3311 | |
---|
[5134] | 3312 | function get_forwarding_attachment2($msg_folder, $msg_number, $msg_part, $encoding) |
---|
| 3313 | { |
---|
| 3314 | include_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; |
---|
| 3315 | $attachment = new attachment(); |
---|
| 3316 | $attachment->setStructureFromMail($msg_folder, $msg_number); |
---|
| 3317 | $return = $attachment->getAttachmentInfo($msg_part); |
---|
| 3318 | $return['binary'] = $attachment->getAttachment($msg_part); |
---|
| 3319 | return $return; |
---|
| 3320 | } |
---|
| 3321 | |
---|
[2] | 3322 | function del_last_caracter($string) |
---|
| 3323 | { |
---|
| 3324 | $string = substr($string,0,(strlen($string) - 1)); |
---|
[1472] | 3325 | return $string; |
---|
[2] | 3326 | } |
---|
[1472] | 3327 | |
---|
[2] | 3328 | function del_last_two_caracters($string) |
---|
| 3329 | { |
---|
| 3330 | $string = substr($string,0,(strlen($string) - 2)); |
---|
[1472] | 3331 | return $string; |
---|
[2] | 3332 | } |
---|
[1472] | 3333 | |
---|
[828] | 3334 | function messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd) |
---|
[659] | 3335 | { |
---|
[1625] | 3336 | if ($sort_box_type != "SORTFROM" && $search_box_type!= "FLAGGED"){ |
---|
[970] | 3337 | $imapsort = imap_sort($this->mbox,constant($sort_box_type),$sort_box_reverse,SE_UID,$search_box_type); |
---|
| 3338 | foreach($imapsort as $iuid) |
---|
| 3339 | $sort[$iuid] = ""; |
---|
[1518] | 3340 | |
---|
| 3341 | if ($offsetBegin == -1 && $offsetEnd ==-1 ) |
---|
| 3342 | $slice_array = false; |
---|
| 3343 | else |
---|
| 3344 | $slice_array = true; |
---|
[970] | 3345 | } |
---|
| 3346 | else |
---|
[659] | 3347 | { |
---|
[970] | 3348 | $sort = array(); |
---|
| 3349 | if ($offsetBegin > $offsetEnd) {$temp=$offsetEnd; $offsetEnd=$offsetBegin; $offsetBegin=$temp;} |
---|
| 3350 | $num_msgs = imap_num_msg($this->mbox); |
---|
| 3351 | if ($offsetEnd > $num_msgs) {$offsetEnd = $num_msgs;} |
---|
[975] | 3352 | $slice_array = true; |
---|
| 3353 | |
---|
[983] | 3354 | for ($i=$num_msgs; $i>0; $i--) |
---|
[828] | 3355 | { |
---|
[983] | 3356 | if ($sort_box_type == "SORTARRIVAL" && $sort_box_reverse && count($sort) >= $offsetEnd) |
---|
| 3357 | break; |
---|
[970] | 3358 | $iuid = @imap_uid($this->mbox,$i); |
---|
| 3359 | $header = $this->get_header($iuid); |
---|
| 3360 | // List UNSEEN messages. |
---|
| 3361 | if($search_box_type == "UNSEEN" && (!trim($header->Recent) && !trim($header->Unseen))){ |
---|
| 3362 | continue; |
---|
| 3363 | } |
---|
| 3364 | // List SEEN messages. |
---|
| 3365 | elseif($search_box_type == "SEEN" && (trim($header->Recent) || trim($header->Unseen))){ |
---|
| 3366 | continue; |
---|
| 3367 | } |
---|
| 3368 | // List ANSWERED messages. |
---|
| 3369 | elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ |
---|
| 3370 | continue; |
---|
| 3371 | } |
---|
| 3372 | // List FLAGGED messages. |
---|
| 3373 | elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ |
---|
| 3374 | continue; |
---|
| 3375 | } |
---|
| 3376 | |
---|
| 3377 | if($sort_box_type=='SORTFROM') { |
---|
| 3378 | if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) |
---|
| 3379 | $from = $header->to; |
---|
| 3380 | else |
---|
| 3381 | $from = $header->from; |
---|
[5134] | 3382 | if(isset($from[0]->personal)) |
---|
[970] | 3383 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
[5134] | 3384 | else |
---|
| 3385 | $tmp = null; |
---|
| 3386 | if (isset($tmp[0]->text)) |
---|
[970] | 3387 | $sort[$iuid] = $tmp[0]->text; |
---|
| 3388 | else |
---|
| 3389 | $sort[$iuid] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
| 3390 | } |
---|
| 3391 | else if($sort_box_type=='SORTSUBJECT') { |
---|
| 3392 | $sort[$iuid] = $header->subject; |
---|
| 3393 | } |
---|
| 3394 | else if($sort_box_type=='SORTSIZE') { |
---|
| 3395 | $sort[$iuid] = $header->Size; |
---|
| 3396 | } |
---|
| 3397 | else { |
---|
| 3398 | $sort[$iuid] = $header->udate; |
---|
| 3399 | } |
---|
| 3400 | |
---|
[659] | 3401 | } |
---|
[970] | 3402 | natcasesort($sort); |
---|
[828] | 3403 | |
---|
[970] | 3404 | if ($sort_box_reverse) |
---|
| 3405 | $sort = array_reverse($sort,true); |
---|
[659] | 3406 | } |
---|
[5134] | 3407 | if(empty($sort) or !is_array($sort)){ |
---|
[972] | 3408 | $sort = array(); |
---|
[5134] | 3409 | } |
---|
| 3410 | |
---|
| 3411 | |
---|
[1472] | 3412 | |
---|
[1808] | 3413 | |
---|
[972] | 3414 | if ($slice_array) |
---|
[828] | 3415 | $sort = array_slice($sort,$offsetBegin-1,$offsetEnd-($offsetBegin-1),true); |
---|
[970] | 3416 | |
---|
[1472] | 3417 | |
---|
[828] | 3418 | return $sort; |
---|
| 3419 | |
---|
[659] | 3420 | } |
---|
[970] | 3421 | |
---|
[5172] | 3422 | function move_delete_search_messages($params){ |
---|
| 3423 | $move = false; |
---|
| 3424 | $msg_no_move = ""; |
---|
| 3425 | |
---|
| 3426 | $params['selected_messages'] = urldecode($params['selected_messages_move']); |
---|
| 3427 | $params['new_folder'] = urldecode($params['new_folder_move']); |
---|
| 3428 | $params['new_folder_name'] = urldecode($params['new_folder_name_move']); |
---|
| 3429 | $sel_msgs = explode(",", $params['selected_messages']); |
---|
| 3430 | @reset($sel_msgs); |
---|
| 3431 | $sorted_msgs = array(); |
---|
| 3432 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 3433 | $sel_msg = explode(";", $sel_msg); |
---|
| 3434 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 3435 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
| 3436 | } |
---|
| 3437 | else { |
---|
| 3438 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 3439 | } |
---|
| 3440 | } |
---|
| 3441 | @ksort($sorted_msgs); |
---|
| 3442 | $last_return = false; |
---|
| 3443 | foreach($sorted_msgs as $folder => $msgs_number) { |
---|
| 3444 | $params['msgs_number'] = $msgs_number; |
---|
| 3445 | $params['folder'] = $folder; |
---|
| 3446 | |
---|
| 3447 | $last_return = $this->move_messages($params); |
---|
| 3448 | |
---|
| 3449 | if($last_return['status']){ |
---|
| 3450 | $move = true; |
---|
| 3451 | }else{ |
---|
| 3452 | $msg_no_move = $params['msgs_number']; |
---|
| 3453 | } |
---|
| 3454 | } |
---|
| 3455 | $sel_msgs = null; |
---|
| 3456 | $params['selected_messages'] = urldecode($params['selected_messages_delete']); |
---|
| 3457 | $params['new_folder'] = urldecode($params['new_folder_delete']); |
---|
| 3458 | $params['new_folder_name'] = urldecode($params['new_folder_name_delete']); |
---|
| 3459 | $sel_msgs = explode(",", $params['selected_messages']); |
---|
| 3460 | @reset($sel_msgs); |
---|
| 3461 | $sorted_msgs = array(); |
---|
| 3462 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 3463 | $sel_msg = explode(";", $sel_msg); |
---|
| 3464 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 3465 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
| 3466 | } |
---|
| 3467 | else { |
---|
| 3468 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 3469 | } |
---|
| 3470 | } |
---|
| 3471 | @ksort($sorted_msgs); |
---|
| 3472 | $last_return = false; |
---|
| 3473 | foreach($sorted_msgs as $folder => $msgs_number) { |
---|
| 3474 | $params['msgs_number'] = $msgs_number; |
---|
| 3475 | $params['folder'] = $folder; |
---|
| 3476 | |
---|
| 3477 | $params['folder'] = $params['new_folder_delete']; |
---|
| 3478 | $last_return = $this->delete_msgs($params); |
---|
| 3479 | $last_return['deleted'] = true; |
---|
| 3480 | if($last_return['status']){ |
---|
| 3481 | $move = true; |
---|
| 3482 | }else{ |
---|
| 3483 | $msg_no_move = $params['msgs_number']; |
---|
| 3484 | } |
---|
| 3485 | |
---|
| 3486 | } |
---|
| 3487 | |
---|
| 3488 | if($move) |
---|
| 3489 | $last_return['move'] = true; |
---|
| 3490 | |
---|
| 3491 | if($msg_no_move != "") |
---|
| 3492 | $last_return['no_move'] = $msg_no_move; |
---|
| 3493 | |
---|
| 3494 | return $last_return; |
---|
| 3495 | } |
---|
[970] | 3496 | |
---|
[1472] | 3497 | function move_search_messages($params){ |
---|
| 3498 | $params['selected_messages'] = urldecode($params['selected_messages']); |
---|
[163] | 3499 | $params['new_folder'] = urldecode($params['new_folder']); |
---|
| 3500 | $params['new_folder_name'] = urldecode($params['new_folder_name']); |
---|
| 3501 | $sel_msgs = explode(",", $params['selected_messages']); |
---|
[5172] | 3502 | $move = false; |
---|
| 3503 | $msg_no_move = ""; |
---|
| 3504 | |
---|
[1472] | 3505 | @reset($sel_msgs); |
---|
[163] | 3506 | $sorted_msgs = array(); |
---|
| 3507 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 3508 | $sel_msg = explode(";", $sel_msg); |
---|
| 3509 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 3510 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
[1472] | 3511 | } |
---|
[163] | 3512 | else { |
---|
| 3513 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 3514 | } |
---|
| 3515 | } |
---|
| 3516 | @ksort($sorted_msgs); |
---|
[1472] | 3517 | $last_return = false; |
---|
| 3518 | foreach($sorted_msgs as $folder => $msgs_number) { |
---|
[163] | 3519 | $params['msgs_number'] = $msgs_number; |
---|
[1472] | 3520 | $params['folder'] = $folder; |
---|
[5172] | 3521 | |
---|
| 3522 | if($params['delete'] === 'true'){ |
---|
| 3523 | $params['folder'] = $params['new_folder']; |
---|
| 3524 | $last_return = $this->delete_msgs($params); |
---|
[163] | 3525 | $last_return['deleted'] = true; |
---|
[5172] | 3526 | |
---|
| 3527 | if($last_return['status']){ |
---|
| 3528 | $move = true; |
---|
| 3529 | }else{ |
---|
| 3530 | $msg_no_move = $params['msgs_number']; |
---|
[163] | 3531 | } |
---|
[5172] | 3532 | |
---|
| 3533 | }else{ |
---|
| 3534 | $last_return = $this->move_messages($params); |
---|
| 3535 | |
---|
| 3536 | if($last_return['status']){ |
---|
| 3537 | $move = true; |
---|
| 3538 | }else{ |
---|
| 3539 | $msg_no_move = $params['msgs_number']; |
---|
| 3540 | } |
---|
[163] | 3541 | } |
---|
[5172] | 3542 | } |
---|
| 3543 | |
---|
| 3544 | if($move) |
---|
| 3545 | $last_return['move'] = true; |
---|
| 3546 | |
---|
| 3547 | if($msg_no_move != "") |
---|
| 3548 | $last_return['no_move'] = $msg_no_move; |
---|
| 3549 | |
---|
[163] | 3550 | return $last_return; |
---|
| 3551 | } |
---|
[1472] | 3552 | |
---|
[2] | 3553 | function move_messages($params) |
---|
| 3554 | { |
---|
[1472] | 3555 | $folder = $params['folder']; |
---|
| 3556 | $mbox_stream = $this->open_mbox($folder); |
---|
[5134] | 3557 | $newmailbox = ($params['new_folder']); |
---|
[5212] | 3558 | $newmailbox = mb_convert_encoding($newmailbox, "UTF7-IMAP","ISO-8859-1, UTF-8, UTF7-IMAP"); |
---|
[5134] | 3559 | $new_folder_name = $params['new_folder_name']; |
---|
[4997] | 3560 | $msgs_number = $params['msgs_number']; |
---|
[2] | 3561 | $return = array('msgs_number' => $msgs_number, |
---|
| 3562 | 'folder' => $folder, |
---|
| 3563 | 'new_folder_name' => $new_folder_name, |
---|
[325] | 3564 | 'border_ID' => $params['border_ID'], |
---|
| 3565 | 'status' => true); //Status foi adicionado para validar as permissoes ACL |
---|
[1472] | 3566 | |
---|
[325] | 3567 | //Este bloco tem a finalidade de averiguar as permissoes para pastas compartilhadas |
---|
| 3568 | if (substr($folder,0,4) == 'user'){ |
---|
| 3569 | $acl = $this->getacltouser($folder); |
---|
| 3570 | /* |
---|
| 3571 | * l - lookup (mailbox is visible to LIST/LSUB commands) |
---|
| 3572 | * r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL, SEARCH, COPY from mailbox) |
---|
| 3573 | * s - keep seen/unseen information across sessions (STORE SEEN flag) |
---|
| 3574 | * w - write (STORE flags other than SEEN and DELETED) |
---|
| 3575 | * i - insert (perform APPEND, COPY into mailbox) |
---|
| 3576 | * p - post (send mail to submission address for mailbox, not enforced by IMAP4 itself) |
---|
| 3577 | * c - create (CREATE new sub-mailboxes in any implementation-defined hierarchy) |
---|
| 3578 | * d - delete (STORE DELETED flag, perform EXPUNGE) |
---|
| 3579 | * a - administer (perform SETACL) |
---|
| 3580 | */ |
---|
| 3581 | if (strpos($acl, "d") === false){ |
---|
| 3582 | $return['status'] = false; |
---|
| 3583 | return $return; |
---|
| 3584 | } |
---|
| 3585 | } |
---|
[432] | 3586 | //Este bloco tem a finalidade de transformar o CPF das pastas compartilhadas em common name |
---|
[5134] | 3587 | if(array_key_exists('uid2cn', $_SESSION['phpgw_info']['user']['preferences']['expressoMail'])){ |
---|
[1747] | 3588 | if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn']){ |
---|
| 3589 | if (substr($new_folder_name,0,4) == 'user'){ |
---|
| 3590 | $this->ldap = new ldap_functions(); |
---|
| 3591 | $tmp_folder_name = explode($this->imap_delimiter, $new_folder_name); |
---|
| 3592 | $return['new_folder_name'] = array_pop($tmp_folder_name); |
---|
| 3593 | if( $cn = $this->ldap->uid2cn($return['new_folder_name'])) |
---|
| 3594 | { |
---|
| 3595 | $return['new_folder_name'] = $cn; |
---|
| 3596 | } |
---|
| 3597 | } |
---|
[432] | 3598 | } |
---|
[5134] | 3599 | } |
---|
[1472] | 3600 | |
---|
| 3601 | // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior. |
---|
[51] | 3602 | if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) |
---|
[449] | 3603 | { |
---|
[2] | 3604 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
[449] | 3605 | // Fix problem in unserialize function JS. |
---|
[5134] | 3606 | if(array_key_exists('body', $return['previous_msg'])) |
---|
[449] | 3607 | $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); |
---|
| 3608 | } |
---|
[1472] | 3609 | |
---|
| 3610 | $mbox_stream = $this->open_mbox($folder); |
---|
[2] | 3611 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
| 3612 | imap_expunge($mbox_stream); |
---|
[51] | 3613 | if($mbox_stream) |
---|
| 3614 | imap_close($mbox_stream); |
---|
[2] | 3615 | return $return; |
---|
| 3616 | }else { |
---|
[1472] | 3617 | if(strstr(imap_last_error(),'Over quota')) { |
---|
[2] | 3618 | $accountID = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminUsername']; |
---|
[1472] | 3619 | $pass = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; |
---|
| 3620 | $userID = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
[2] | 3621 | $server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[504] | 3622 | $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] | 3623 | if(!$mbox) |
---|
| 3624 | return imap_last_error(); |
---|
[1472] | 3625 | $quota = imap_get_quotaroot($mbox_stream, "INBOX"); |
---|
[2] | 3626 | if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { |
---|
[51] | 3627 | if($mbox_stream) |
---|
| 3628 | imap_close($mbox_stream); |
---|
[1472] | 3629 | if($mbox) |
---|
[51] | 3630 | imap_close($mbox); |
---|
[1472] | 3631 | return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; |
---|
[2] | 3632 | } |
---|
| 3633 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
| 3634 | imap_expunge($mbox_stream); |
---|
[51] | 3635 | if($mbox_stream) |
---|
| 3636 | imap_close($mbox_stream); |
---|
[2] | 3637 | // return to original quota limit. |
---|
| 3638 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
[51] | 3639 | if($mbox) |
---|
| 3640 | imap_close($mbox); |
---|
[1472] | 3641 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
[2] | 3642 | } |
---|
[1472] | 3643 | return $return; |
---|
[2] | 3644 | } |
---|
| 3645 | else { |
---|
[51] | 3646 | if($mbox_stream) |
---|
| 3647 | imap_close($mbox_stream); |
---|
[2] | 3648 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
[51] | 3649 | if($mbox) |
---|
| 3650 | imap_close($mbox); |
---|
[1472] | 3651 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
[2] | 3652 | } |
---|
[1472] | 3653 | return imap_last_error(); |
---|
[2] | 3654 | } |
---|
[1472] | 3655 | |
---|
[2] | 3656 | } |
---|
| 3657 | else { |
---|
[51] | 3658 | if($mbox_stream) |
---|
| 3659 | imap_close($mbox_stream); |
---|
| 3660 | return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; |
---|
[2] | 3661 | } |
---|
[1472] | 3662 | } |
---|
[2] | 3663 | } |
---|
[1472] | 3664 | |
---|
[5134] | 3665 | |
---|
[2] | 3666 | function save_msg($params) |
---|
| 3667 | { |
---|
[5206] | 3668 | |
---|
[5134] | 3669 | require_once $_SESSION['rootPath'] . '/API/class.servicelocator.php'; |
---|
| 3670 | $mailService = ServiceLocator::getService('mail'); |
---|
[1472] | 3671 | |
---|
[4795] | 3672 | $return_receipt = $params['input_return_receipt']; |
---|
| 3673 | $is_important = $params['input_important_message']; |
---|
[5134] | 3674 | |
---|
[4795] | 3675 | $msg_uid = $params['msg_id']; |
---|
| 3676 | $body = $params['body']; |
---|
[4416] | 3677 | $body = str_replace("%nbsp;"," ",$body); |
---|
[155] | 3678 | $body = preg_replace("/\n/"," ",$body); |
---|
[5134] | 3679 | $body = preg_replace("/\r/","" ,$body); |
---|
[5177] | 3680 | $body = html_entity_decode ( $body, ENT_QUOTES , 'ISO-8859-1' ); |
---|
[271] | 3681 | $forwarding_attachments = $params['forwarding_attachments']; |
---|
[5134] | 3682 | $message_attachments = $params['message_attachments']; |
---|
[4795] | 3683 | $attachments = $params['FILES']; |
---|
[271] | 3684 | $return_files = $params['FILES']; |
---|
[5134] | 3685 | $message_attachments_contents = (isset($params['message_attachments_content'])) ? $params['message_attachments_content'] : false; |
---|
[1472] | 3686 | |
---|
[4800] | 3687 | if(is_array($params['local_attachments'])){ |
---|
| 3688 | foreach ($params['local_attachments'] as $key => $local_attach) { |
---|
| 3689 | $tmp = unserialize(urldecode($local_attach)); |
---|
[5134] | 3690 | $attachments[$key]['name'] = urldecode($tmp[2]); |
---|
| 3691 | $return_files[$key]['name'] = urldecode($tmp[2]); |
---|
[4800] | 3692 | } |
---|
| 3693 | } |
---|
| 3694 | |
---|
[5206] | 3695 | $folder = mb_convert_encoding($params['folder'], "UTF7-IMAP","ISO-8859-1, UTF-8"); |
---|
[5134] | 3696 | $folder = @eregi_replace("INBOX[/.]", "INBOX".$this->imap_delimiter, $folder); |
---|
[4800] | 3697 | |
---|
[5134] | 3698 | $mailService->setFrom ('"'.$fromaddress[0].'" <'.$fromaddress[1].'>'); |
---|
| 3699 | $mailService->addTo($params['input_to']); |
---|
| 3700 | $mailService->addCc( $params['input_cc']); |
---|
| 3701 | $mailService->addBcc($params['input_cco']); |
---|
| 3702 | $mailService->setSubject($params['input_subject']); |
---|
[4795] | 3703 | |
---|
[5134] | 3704 | if($is_important){ |
---|
| 3705 | $mailService->addHeaderField('Importance','High'); |
---|
| 3706 | } |
---|
[4795] | 3707 | |
---|
[5134] | 3708 | if($return_receipt) |
---|
| 3709 | $mailService->addHeaderField('Disposition-Notification-To', $_SESSION['phpgw_info']['expressomail']['user']['email']); |
---|
[4795] | 3710 | |
---|
[5134] | 3711 | $isHTML = ( ( array_key_exists( 'type', $params ) && in_array( strtolower( $params[ 'type' ] ), array( 'html', 'plain' ) ) ) ? strtolower( $params[ 'type' ] ) != 'plain' : true ); |
---|
[4795] | 3712 | |
---|
| 3713 | |
---|
[5134] | 3714 | if( count($forwarding_attachments) > 0 ) |
---|
| 3715 | $return_forward = $this->buildEmbeddedImages($mailService, $msg_uid, $forwarding_attachments , $body); |
---|
| 3716 | |
---|
| 3717 | //Build Message Attachments!!! |
---|
| 3718 | if(count($message_attachments) > 0 ) |
---|
| 3719 | { |
---|
| 3720 | foreach($message_attachments as $folder_name => $messages) |
---|
| 3721 | { |
---|
| 3722 | foreach ($messages as $message_number => $message_subject) |
---|
| 3723 | { |
---|
| 3724 | if (!$message_subject) |
---|
| 3725 | $message_subject = 'no title.eml'; |
---|
| 3726 | else |
---|
| 3727 | $message_subject .= '.eml'; |
---|
| 3728 | |
---|
| 3729 | if( $message_attachments_contents && isset($message_attachments_contents[$folder_name]) ) |
---|
| 3730 | $rawmsg = base64_decode( $message_attachments_contents[$folder_name][$message_number] ); |
---|
| 3731 | else{ |
---|
| 3732 | $mbox_stream = $this->open_mbox($folder_name);$mbox_stream = $this->open_mbox($folder_name); |
---|
| 3733 | $rawmsg = $this->getRawHeader($message_number) . "\r\n\r\n" . $this->getRawBody($message_number); |
---|
| 3734 | } |
---|
| 3735 | |
---|
| 3736 | $return_forward[] = array( 'name' => $message_subject, 'size' => mb_strlen($rawmsg)); |
---|
| 3737 | $mailService->addStringAttachment($rawmsg, $message_subject, 'message/rfc822', '7bit', 'attachment' ); |
---|
| 3738 | } |
---|
| 3739 | } |
---|
| 3740 | } |
---|
| 3741 | |
---|
[4416] | 3742 | $imagesParts = array(); |
---|
[4795] | 3743 | |
---|
[5134] | 3744 | if(count($return_forward) > 0 ) |
---|
[4416] | 3745 | foreach ($return_forward as $value) |
---|
| 3746 | $imagesParts[$value[6]] = $value[3]; |
---|
[1472] | 3747 | |
---|
[5134] | 3748 | //Build Forwarding Attachments!!! |
---|
| 3749 | if(count($forwarding_attachments) > 0 ) |
---|
| 3750 | { |
---|
[4795] | 3751 | foreach($forwarding_attachments as $forwarding_attachment) |
---|
| 3752 | { |
---|
[5177] | 3753 | |
---|
[4795] | 3754 | $file_description = unserialize(rawurldecode($forwarding_attachment)); |
---|
[5177] | 3755 | foreach($file_description as $i => $item) |
---|
| 3756 | $file_description[$i] = urldecode($item); |
---|
| 3757 | |
---|
| 3758 | $file_description = array_values($file_description); |
---|
[4457] | 3759 | |
---|
[5134] | 3760 | foreach($file_description as $i => $descriptor) |
---|
[4457] | 3761 | $file_description[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
[5134] | 3762 | |
---|
[4795] | 3763 | $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); |
---|
[5134] | 3764 | $file_description[2] = html_entity_decode($file_description[2]); |
---|
[4795] | 3765 | |
---|
| 3766 | $file_description[5] = strlen($fileContent); //Size of file |
---|
| 3767 | $return_forward[] = $file_description; |
---|
[5134] | 3768 | $mailService->addStringAttachment($fileContent, $file_description[2], $this->get_file_type($file_description[2]), $file_description[4] ); |
---|
[4795] | 3769 | } |
---|
[5134] | 3770 | } |
---|
[4795] | 3771 | |
---|
[271] | 3772 | if ((count($return_forward) > 0) && (count($return_files) > 0)) |
---|
| 3773 | $return_files = array_merge_recursive($return_forward,$return_files); |
---|
[4416] | 3774 | else if (count($return_files) < 1) |
---|
[4795] | 3775 | $return_files = $return_forward; |
---|
[1472] | 3776 | |
---|
[5134] | 3777 | //Build Uploading Attachments!!! |
---|
[5206] | 3778 | $sizeof_attachments = count($attachments); |
---|
[1005] | 3779 | if ($sizeof_attachments) |
---|
[4416] | 3780 | foreach ($attachments as $numb => $attach) |
---|
[5134] | 3781 | $mailService->addFileAttachment($attach['tmp_name'], $attach['name'],$attach['type'], 'base64', 'attachment'); |
---|
[4416] | 3782 | |
---|
[4795] | 3783 | |
---|
[5134] | 3784 | if (!$body) |
---|
| 3785 | $body = ' '; |
---|
| 3786 | |
---|
| 3787 | if($isHTML) |
---|
| 3788 | $mailService->setBodyHtml($body); |
---|
| 3789 | else |
---|
| 3790 | $mailService->setBodyText($body); |
---|
[271] | 3791 | |
---|
[828] | 3792 | |
---|
[4795] | 3793 | $mbox_stream = $this->open_mbox($folder); |
---|
[5134] | 3794 | $return['append'] = imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, $mailService->getMessage(), "\\Seen \\Draft"); |
---|
| 3795 | |
---|
[4795] | 3796 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); |
---|
[271] | 3797 | $return['msg_no'] = $status->uidnext - 1; |
---|
| 3798 | $return['folder_id'] = $folder; |
---|
[4416] | 3799 | $return['imagesParts'] = $imagesParts; |
---|
[828] | 3800 | |
---|
[51] | 3801 | if($mbox_stream) |
---|
| 3802 | imap_close($mbox_stream); |
---|
[4416] | 3803 | |
---|
[5134] | 3804 | $returnFiles = array(); |
---|
| 3805 | $ii = 0; |
---|
| 3806 | |
---|
| 3807 | if(count($return_files) > 0) |
---|
[4416] | 3808 | { |
---|
| 3809 | foreach ($return_files as $index => $_attachment) |
---|
[271] | 3810 | { |
---|
[4416] | 3811 | if (array_key_exists("name", $_attachment)) |
---|
| 3812 | { |
---|
[5206] | 3813 | $returnFiles[$ii]['name'] = base64_encode(mb_convert_encoding( $_attachment['name'], 'UTF-8', 'UTF-8, ISO-8859-1') ); |
---|
[5134] | 3814 | $returnFiles[$ii]['size'] = $_attachment['size']; |
---|
| 3815 | $ii++; |
---|
[271] | 3816 | } |
---|
[5134] | 3817 | else if($_attachment[2]) |
---|
[4795] | 3818 | { |
---|
[5206] | 3819 | $returnFiles[$ii]['name'] = base64_encode(mb_convert_encoding( $_attachment[2], 'UTF-8', 'UTF-8, ISO-8859-1')); |
---|
[5134] | 3820 | $returnFiles[$ii]['size'] = $_attachment[5]; |
---|
| 3821 | $ii++; |
---|
[4795] | 3822 | } |
---|
[271] | 3823 | } |
---|
[4795] | 3824 | } |
---|
[5134] | 3825 | $return['files'] = serialize($returnFiles); |
---|
| 3826 | $return["subject"] = $params['input_subject']; |
---|
| 3827 | if (!$return['append']) $return['append'] = imap_last_error(); |
---|
[5207] | 3828 | |
---|
[2] | 3829 | return $return; |
---|
| 3830 | } |
---|
[1472] | 3831 | |
---|
[2] | 3832 | function set_messages_flag($params) |
---|
[5223] | 3833 | { |
---|
[2] | 3834 | $folder = $params['folder']; |
---|
[5134] | 3835 | $msgs_to_set = $params['msgs_to_set']; |
---|
[2] | 3836 | $flag = $params['flag']; |
---|
| 3837 | $return = array(); |
---|
[5134] | 3838 | $return["msgs_to_set"] = $msgs_to_set; |
---|
[2] | 3839 | $return["flag"] = $flag; |
---|
[5182] | 3840 | $return["msgs_not_to_set"] = ""; |
---|
| 3841 | |
---|
[411] | 3842 | if(!$this->mbox && !is_resource($this->mbox)) |
---|
[51] | 3843 | $this->mbox = $this->open_mbox($folder); |
---|
[5223] | 3844 | |
---|
[5182] | 3845 | if ($flag == "unseen"){ |
---|
| 3846 | $return["msgs_to_set"] = ""; |
---|
| 3847 | $msgs = explode(",",$msgs_to_set); |
---|
| 3848 | foreach($msgs as $men){ |
---|
| 3849 | if (imap_clearflag_full($this->mbox, $men, "\\Seen", ST_UID)) |
---|
| 3850 | $return["msgs_to_set"] .= $men.","; |
---|
| 3851 | else |
---|
| 3852 | $return["msgs_not_to_set"] .= $men.","; |
---|
| 3853 | } |
---|
| 3854 | $return["status"] = true; |
---|
| 3855 | }elseif ($flag == "seen"){ |
---|
| 3856 | $return["msgs_to_set"] = ""; |
---|
| 3857 | $msgs = explode(",",$msgs_to_set); |
---|
| 3858 | foreach($msgs as $men){ |
---|
| 3859 | if (imap_setflag_full($this->mbox, $men, "\\Seen", ST_UID)) |
---|
| 3860 | $return["msgs_to_set"] .= $men.","; |
---|
| 3861 | else |
---|
| 3862 | $return["msgs_not_to_set"] .= $men.","; |
---|
| 3863 | } |
---|
| 3864 | $return["status"] = true; |
---|
| 3865 | }elseif ($flag == "answered"){ |
---|
[51] | 3866 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered", ST_UID); |
---|
| 3867 | imap_clearflag_full($this->mbox, $msgs_to_set, "\\Draft", ST_UID); |
---|
[2] | 3868 | } |
---|
| 3869 | elseif ($flag == "forwarded") |
---|
[51] | 3870 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered \\Draft", ST_UID); |
---|
[2] | 3871 | elseif ($flag == "flagged") |
---|
[51] | 3872 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); |
---|
[614] | 3873 | elseif ($flag == "unflagged") { |
---|
| 3874 | $flag_importance = false; |
---|
| 3875 | $msgs_number = explode(",",$msgs_to_set); |
---|
[659] | 3876 | $unflagged_msgs = ""; |
---|
[614] | 3877 | foreach($msgs_number as $msg_number) { |
---|
| 3878 | preg_match('/importance *: *(.*)\r/i', |
---|
| 3879 | imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) |
---|
[1472] | 3880 | ,$importance); |
---|
[673] | 3881 | if(strtolower($importance[1])=="high" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { |
---|
[614] | 3882 | $flag_importance=true; |
---|
| 3883 | } |
---|
[659] | 3884 | else { |
---|
| 3885 | $unflagged_msgs.=$msg_number.","; |
---|
[1472] | 3886 | } |
---|
[614] | 3887 | } |
---|
| 3888 | |
---|
[659] | 3889 | if($unflagged_msgs!="") { |
---|
| 3890 | imap_clearflag_full($this->mbox,substr($unflagged_msgs,0,strlen($unflagged_msgs)-1), "\\Flagged", ST_UID); |
---|
| 3891 | $return["msgs_unflageds"] = substr($unflagged_msgs,0,strlen($unflagged_msgs)-1); |
---|
| 3892 | } |
---|
| 3893 | else { |
---|
| 3894 | $return["msgs_unflageds"] = false; |
---|
| 3895 | } |
---|
| 3896 | |
---|
[673] | 3897 | if($flag_importance && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { |
---|
[614] | 3898 | $return["status"] = false; |
---|
| 3899 | $return["msg"] = $this->functions->getLang("At least one of selected message cant be marked as normal"); |
---|
| 3900 | } |
---|
[659] | 3901 | else { |
---|
| 3902 | $return["status"] = true; |
---|
| 3903 | } |
---|
[614] | 3904 | } |
---|
[5182] | 3905 | |
---|
| 3906 | if(($flag == "seen") || ($flag == "unseen")){ |
---|
| 3907 | if ($return["msgs_not_to_set"] != ""){ |
---|
| 3908 | $return["msgs_not_to_set"] = substr($return["msgs_not_to_set"], 0, -1); |
---|
[5223] | 3909 | $return["status"] = false; |
---|
[5182] | 3910 | } |
---|
| 3911 | if($return["msgs_to_set"] != ""){ |
---|
| 3912 | $return["msgs_to_set"] = substr($return["msgs_to_set"], 0, -1); |
---|
| 3913 | } |
---|
| 3914 | } |
---|
[411] | 3915 | if($this->mbox && is_resource($this->mbox)) |
---|
[5223] | 3916 | imap_close($this->mbox); |
---|
[2] | 3917 | return $return; |
---|
| 3918 | } |
---|
[1472] | 3919 | |
---|
[2] | 3920 | function get_file_type($file_name) |
---|
| 3921 | { |
---|
| 3922 | $file_name = strtolower($file_name); |
---|
| 3923 | $strFileType = strrev(substr(strrev($file_name),0,4)); |
---|
[5134] | 3924 | if ($strFileType == ".eml") |
---|
| 3925 | return "message/rfc822"; |
---|
[1472] | 3926 | if ($strFileType == ".asf") |
---|
[2] | 3927 | return "video/x-ms-asf"; |
---|
| 3928 | if ($strFileType == ".avi") |
---|
| 3929 | return "video/avi"; |
---|
| 3930 | if ($strFileType == ".doc") |
---|
| 3931 | return "application/msword"; |
---|
| 3932 | if ($strFileType == ".zip") |
---|
| 3933 | return "application/zip"; |
---|
| 3934 | if ($strFileType == ".xls") |
---|
| 3935 | return "application/vnd.ms-excel"; |
---|
| 3936 | if ($strFileType == ".gif") |
---|
| 3937 | return "image/gif"; |
---|
| 3938 | if ($strFileType == ".jpg" || $strFileType == "jpeg") |
---|
| 3939 | return "image/jpeg"; |
---|
| 3940 | if ($strFileType == ".png") |
---|
| 3941 | return "image/png"; |
---|
| 3942 | if ($strFileType == ".wav") |
---|
| 3943 | return "audio/wav"; |
---|
| 3944 | if ($strFileType == ".mp3") |
---|
| 3945 | return "audio/mpeg3"; |
---|
| 3946 | if ($strFileType == ".mpg" || $strFileType == "mpeg") |
---|
| 3947 | return "video/mpeg"; |
---|
| 3948 | if ($strFileType == ".rtf") |
---|
| 3949 | return "application/rtf"; |
---|
| 3950 | if ($strFileType == ".htm" || $strFileType == "html") |
---|
| 3951 | return "text/html"; |
---|
[1472] | 3952 | if ($strFileType == ".xml") |
---|
[2] | 3953 | return "text/xml"; |
---|
[1472] | 3954 | if ($strFileType == ".xsl") |
---|
[2] | 3955 | return "text/xsl"; |
---|
[1472] | 3956 | if ($strFileType == ".css") |
---|
[2] | 3957 | return "text/css"; |
---|
[1472] | 3958 | if ($strFileType == ".php") |
---|
[2] | 3959 | return "text/php"; |
---|
[1472] | 3960 | if ($strFileType == ".asp") |
---|
[2] | 3961 | return "text/asp"; |
---|
| 3962 | if ($strFileType == ".pdf") |
---|
| 3963 | return "application/pdf"; |
---|
| 3964 | if ($strFileType == ".txt") |
---|
| 3965 | return "text/plain"; |
---|
| 3966 | if ($strFileType == ".wmv") |
---|
| 3967 | return "video/x-ms-wmv"; |
---|
| 3968 | if ($strFileType == ".sxc") |
---|
| 3969 | return "application/vnd.sun.xml.calc"; |
---|
| 3970 | if ($strFileType == ".stc") |
---|
| 3971 | return "application/vnd.sun.xml.calc.template"; |
---|
| 3972 | if ($strFileType == ".sxd") |
---|
| 3973 | return "application/vnd.sun.xml.draw"; |
---|
| 3974 | if ($strFileType == ".std") |
---|
| 3975 | return "application/vnd.sun.xml.draw.template"; |
---|
| 3976 | if ($strFileType == ".sxi") |
---|
| 3977 | return "application/vnd.sun.xml.impress"; |
---|
| 3978 | if ($strFileType == ".sti") |
---|
| 3979 | return "application/vnd.sun.xml.impress.template"; |
---|
| 3980 | if ($strFileType == ".sxm") |
---|
| 3981 | return "application/vnd.sun.xml.math"; |
---|
| 3982 | if ($strFileType == ".sxw") |
---|
| 3983 | return "application/vnd.sun.xml.writer"; |
---|
| 3984 | if ($strFileType == ".sxq") |
---|
| 3985 | return "application/vnd.sun.xml.writer.global"; |
---|
| 3986 | if ($strFileType == ".stw") |
---|
| 3987 | return "application/vnd.sun.xml.writer.template"; |
---|
[1472] | 3988 | |
---|
| 3989 | |
---|
| 3990 | return "application/octet-stream"; |
---|
[2] | 3991 | } |
---|
[1472] | 3992 | |
---|
[2] | 3993 | function htmlspecialchars_encode($str) |
---|
| 3994 | { |
---|
[449] | 3995 | return str_replace( array('&', '"','\'','<','>','{','}'), array('&','"',''','<','>','{','}'), $str); |
---|
[2] | 3996 | } |
---|
| 3997 | function htmlspecialchars_decode($str) |
---|
| 3998 | { |
---|
[449] | 3999 | return str_replace( array('&','"',''','<','>','{','}'), array('&', '"','\'','<','>','{','}'), $str); |
---|
[2] | 4000 | } |
---|
[1472] | 4001 | |
---|
[828] | 4002 | function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$offsetBegin = 0,$offsetEnd = 0) |
---|
| 4003 | { |
---|
| 4004 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[51] | 4005 | $this->mbox = $this->open_mbox($folder); |
---|
[432] | 4006 | |
---|
[828] | 4007 | return $this->messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd); |
---|
| 4008 | } |
---|
[1472] | 4009 | |
---|
[53] | 4010 | function get_info_next_msg($params) |
---|
| 4011 | { |
---|
| 4012 | $msg_number = $params['msg_number']; |
---|
| 4013 | $folder = $params['msg_folder']; |
---|
| 4014 | $sort_box_type = $params['sort_box_type']; |
---|
| 4015 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 4016 | $reuse_border = $params['reuse_border']; |
---|
| 4017 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
[1472] | 4018 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
| 4019 | |
---|
[320] | 4020 | $success = false; |
---|
| 4021 | if (is_array($sort_array_msg)) |
---|
[2] | 4022 | { |
---|
[320] | 4023 | foreach ($sort_array_msg as $i => $value){ |
---|
| 4024 | if ($value == $msg_number) |
---|
| 4025 | { |
---|
| 4026 | $success = true; |
---|
| 4027 | break; |
---|
| 4028 | } |
---|
| 4029 | } |
---|
[2] | 4030 | } |
---|
| 4031 | |
---|
[320] | 4032 | if (! $success || $i >= sizeof($sort_array_msg)-1) |
---|
[2] | 4033 | { |
---|
| 4034 | $params['status'] = 'false'; |
---|
| 4035 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
| 4036 | return $params; |
---|
| 4037 | } |
---|
[1472] | 4038 | |
---|
[2] | 4039 | $params = array(); |
---|
| 4040 | $params['msg_number'] = $sort_array_msg[($i+1)]; |
---|
| 4041 | $params['msg_folder'] = $folder; |
---|
[1472] | 4042 | |
---|
| 4043 | $return = $this->get_info_msg($params); |
---|
[2] | 4044 | $return["reuse_border"] = $reuse_border; |
---|
| 4045 | return $return; |
---|
| 4046 | } |
---|
| 4047 | |
---|
| 4048 | function get_info_previous_msg($params) |
---|
| 4049 | { |
---|
| 4050 | $msg_number = $params['msgs_number']; |
---|
| 4051 | $folder = $params['folder']; |
---|
| 4052 | $sort_box_type = $params['sort_box_type']; |
---|
| 4053 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 4054 | $reuse_border = $params['reuse_border']; |
---|
[53] | 4055 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
| 4056 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
[1472] | 4057 | |
---|
[320] | 4058 | $success = false; |
---|
| 4059 | if (is_array($sort_array_msg)) |
---|
[2] | 4060 | { |
---|
[320] | 4061 | foreach ($sort_array_msg as $i => $value){ |
---|
| 4062 | if ($value == $msg_number) |
---|
| 4063 | { |
---|
| 4064 | $success = true; |
---|
| 4065 | break; |
---|
| 4066 | } |
---|
| 4067 | } |
---|
[2] | 4068 | } |
---|
[320] | 4069 | if (! $success || $i == 0) |
---|
| 4070 | { |
---|
[2] | 4071 | $params['status'] = 'false'; |
---|
| 4072 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
| 4073 | return $params; |
---|
| 4074 | } |
---|
[1472] | 4075 | |
---|
[2] | 4076 | $params = array(); |
---|
| 4077 | $params['msg_number'] = $sort_array_msg[($i-1)]; |
---|
| 4078 | $params['msg_folder'] = $folder; |
---|
[1472] | 4079 | |
---|
[2] | 4080 | $return = $this->get_info_msg($params); |
---|
| 4081 | $return["reuse_border"] = $reuse_border; |
---|
| 4082 | return $return; |
---|
| 4083 | } |
---|
[1472] | 4084 | |
---|
[2] | 4085 | // This function updates the values: quota, paging and new messages menu. |
---|
| 4086 | function get_menu_values($params){ |
---|
| 4087 | $return_array = array(); |
---|
| 4088 | $return_array = $this->get_quota($params); |
---|
[1472] | 4089 | |
---|
[2] | 4090 | $mbox_stream = $this->open_mbox($params['folder']); |
---|
[1472] | 4091 | $return_array['num_msgs'] = imap_num_msg($mbox_stream); |
---|
[51] | 4092 | if($mbox_stream) |
---|
| 4093 | imap_close($mbox_stream); |
---|
[1472] | 4094 | |
---|
| 4095 | return $return_array; |
---|
[2] | 4096 | } |
---|
[1472] | 4097 | |
---|
[325] | 4098 | function get_quota($params){ |
---|
[449] | 4099 | // folder_id = user/{uid} for shared folders |
---|
| 4100 | if(substr($params['folder_id'],0,5) != 'INBOX' && preg_match('/user\\'.$this->imap_delimiter.'/i', $params['folder_id'])){ |
---|
| 4101 | $array_folder = explode($this->imap_delimiter,$params['folder_id']); |
---|
[1472] | 4102 | $folder_id = "user".$this->imap_delimiter.$array_folder[1]; |
---|
[449] | 4103 | } |
---|
| 4104 | // folder_id = INBOX for inbox folders |
---|
| 4105 | else |
---|
| 4106 | $folder_id = "INBOX"; |
---|
[1472] | 4107 | |
---|
[1035] | 4108 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[51] | 4109 | $this->mbox = $this->open_mbox(); |
---|
[345] | 4110 | |
---|
[325] | 4111 | $quota = imap_get_quotaroot($this->mbox, $folder_id); |
---|
[411] | 4112 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 4113 | imap_close($this->mbox); |
---|
[1472] | 4114 | |
---|
[2] | 4115 | if (!$quota){ |
---|
| 4116 | return array( |
---|
| 4117 | 'quota_percent' => 0, |
---|
| 4118 | 'quota_used' => 0, |
---|
| 4119 | 'quota_limit' => 0 |
---|
| 4120 | ); |
---|
| 4121 | } |
---|
[1472] | 4122 | |
---|
[2] | 4123 | if(count($quota) && $quota['limit']) { |
---|
[3064] | 4124 | $quota_limit = $quota['limit']; |
---|
| 4125 | $quota_used = $quota['usage']; |
---|
[2] | 4126 | if($quota_used >= $quota_limit) |
---|
[650] | 4127 | { |
---|
| 4128 | $quotaPercent = 100; |
---|
| 4129 | } |
---|
| 4130 | else |
---|
| 4131 | { |
---|
[2] | 4132 | $quotaPercent = ($quota_used / $quota_limit)*100; |
---|
| 4133 | $quotaPercent = (($quotaPercent)* 100 + .5 )* .01; |
---|
[650] | 4134 | } |
---|
[2] | 4135 | return array( |
---|
| 4136 | 'quota_percent' => floor($quotaPercent), |
---|
[3064] | 4137 | 'quota_used' => $quota_used, |
---|
| 4138 | 'quota_limit' => $quota_limit |
---|
[2] | 4139 | ); |
---|
| 4140 | } |
---|
[1472] | 4141 | else |
---|
[2] | 4142 | return array(); |
---|
| 4143 | } |
---|
[1472] | 4144 | |
---|
[2] | 4145 | function send_notification($params){ |
---|
[3231] | 4146 | include("../header.inc.php"); |
---|
[2] | 4147 | require_once("class.phpmailer.php"); |
---|
| 4148 | $mail = new PHPMailer(); |
---|
[1472] | 4149 | |
---|
[2] | 4150 | $toaddress = $params['notificationto']; |
---|
[1472] | 4151 | |
---|
[3231] | 4152 | $subject = lang("Read receipt: %1",$params['subject']); |
---|
| 4153 | $body = lang("Your message: %1",$params['subject']) . '<br>'; |
---|
[4739] | 4154 | $body .= lang("Received in: %1",date("d/m/Y H:i",$params['date'])) . '<br>'; |
---|
[3231] | 4155 | $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] | 4156 | $mail->SMTPDebug = false; |
---|
| 4157 | $mail->IsSMTP(); |
---|
| 4158 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
| 4159 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
| 4160 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 4161 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
| 4162 | $mail->AddAddress($toaddress); |
---|
| 4163 | $mail->Subject = $this->htmlspecialchars_decode($subject); |
---|
| 4164 | |
---|
| 4165 | $mail->IsHTML(true); |
---|
| 4166 | $mail->Body = $body; |
---|
[1472] | 4167 | |
---|
[2] | 4168 | if(!$mail->Send()){ |
---|
| 4169 | return $mail->ErrorInfo; |
---|
| 4170 | } |
---|
| 4171 | else |
---|
| 4172 | return true; |
---|
| 4173 | } |
---|
[1472] | 4174 | |
---|
[1965] | 4175 | function empty_folder($params) |
---|
[2] | 4176 | { |
---|
[1965] | 4177 | $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server'][$params['clean_folder']]; |
---|
[2] | 4178 | $mbox_stream = $this->open_mbox($folder); |
---|
| 4179 | $return = imap_delete($mbox_stream,'1:*'); |
---|
[51] | 4180 | if($mbox_stream) |
---|
| 4181 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 4182 | return $return; |
---|
| 4183 | } |
---|
[1472] | 4184 | |
---|
[2] | 4185 | function search($params) |
---|
| 4186 | { |
---|
[673] | 4187 | include("class.imap_attachment.inc.php"); |
---|
[1472] | 4188 | $imap_attachment = new imap_attachment(); |
---|
[2] | 4189 | $criteria = $params['criteria']; |
---|
| 4190 | $return = array(); |
---|
| 4191 | $folders = $this->get_folders_list(); |
---|
[1472] | 4192 | |
---|
[2] | 4193 | $j = 0; |
---|
| 4194 | foreach($folders as $folder) |
---|
| 4195 | { |
---|
| 4196 | $mbox_stream = $this->open_mbox($folder); |
---|
| 4197 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
[1472] | 4198 | |
---|
[2] | 4199 | if ($messages == '') |
---|
| 4200 | continue; |
---|
[1472] | 4201 | |
---|
[2] | 4202 | $i = 0; |
---|
| 4203 | $return[$j] = array(); |
---|
| 4204 | $return[$j]['folder_name'] = $folder['name']; |
---|
[1472] | 4205 | |
---|
[2] | 4206 | foreach($messages as $msg_number) |
---|
| 4207 | { |
---|
[535] | 4208 | $header = $this->get_header($msg_number); |
---|
[2] | 4209 | if (!is_object($header)) |
---|
| 4210 | return false; |
---|
[1472] | 4211 | |
---|
[2] | 4212 | $return[$j][$i]['msg_folder'] = $folder['name']; |
---|
| 4213 | $return[$j][$i]['msg_number'] = $msg_number; |
---|
| 4214 | $return[$j][$i]['Recent'] = $header->Recent; |
---|
| 4215 | $return[$j][$i]['Unseen'] = $header->Unseen; |
---|
| 4216 | $return[$j][$i]['Answered'] = $header->Answered; |
---|
| 4217 | $return[$j][$i]['Deleted'] = $header->Deleted; |
---|
| 4218 | $return[$j][$i]['Draft'] = $header->Draft; |
---|
| 4219 | $return[$j][$i]['Flagged'] = $header->Flagged; |
---|
[1472] | 4220 | |
---|
[535] | 4221 | $date_msg = gmdate("d/m/Y",$header->udate); |
---|
| 4222 | if (gmdate("d/m/Y") == $date_msg) |
---|
| 4223 | $return[$j][$i]['udate'] = gmdate("H:i",$header->udate); |
---|
[2] | 4224 | else |
---|
| 4225 | $return[$j][$i]['udate'] = $date_msg; |
---|
[1472] | 4226 | |
---|
[2] | 4227 | $fromaddress = imap_mime_header_decode($header->fromaddress); |
---|
| 4228 | $return[$j][$i]['fromaddress'] = ''; |
---|
| 4229 | foreach ($fromaddress as $tmp) |
---|
| 4230 | $return[$j][$i]['fromaddress'] .= $this->replace_maior_menor($tmp->text); |
---|
[1472] | 4231 | |
---|
[2] | 4232 | $from = $header->from; |
---|
| 4233 | $return[$j][$i]['from'] = array(); |
---|
| 4234 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 4235 | $return[$j][$i]['from']['name'] = $tmp[0]->text; |
---|
| 4236 | $return[$j][$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
[1472] | 4237 | $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; |
---|
[2] | 4238 | |
---|
| 4239 | $to = $header->to; |
---|
| 4240 | $return[$j][$i]['to'] = array(); |
---|
| 4241 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
| 4242 | $return[$j][$i]['to']['name'] = $tmp[0]->text; |
---|
| 4243 | $return[$j][$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
[1472] | 4244 | $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; |
---|
[2] | 4245 | |
---|
| 4246 | $subject = imap_mime_header_decode($header->fetchsubject); |
---|
| 4247 | $return[$j][$i]['subject'] = ''; |
---|
| 4248 | foreach ($subject as $tmp) |
---|
| 4249 | $return[$j][$i]['subject'] .= $tmp->text; |
---|
| 4250 | |
---|
| 4251 | $return[$j][$i]['Size'] = $header->Size; |
---|
| 4252 | $return[$j][$i]['reply_toaddress'] = $header->reply_toaddress; |
---|
[1472] | 4253 | |
---|
[2] | 4254 | $return[$j][$i]['attachment'] = array(); |
---|
| 4255 | $return[$j][$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($mbox_stream, $msg_number); |
---|
[1472] | 4256 | |
---|
[2] | 4257 | $i++; |
---|
| 4258 | } |
---|
| 4259 | $j++; |
---|
[51] | 4260 | if($mbox_stream) |
---|
| 4261 | imap_close($mbox_stream); |
---|
[2] | 4262 | } |
---|
[1472] | 4263 | |
---|
[2] | 4264 | return $return; |
---|
| 4265 | } |
---|
[3923] | 4266 | |
---|
| 4267 | |
---|
[1709] | 4268 | function mobile_search($params) |
---|
| 4269 | { |
---|
| 4270 | include("class.imap_attachment.inc.php"); |
---|
| 4271 | $imap_attachment = new imap_attachment(); |
---|
| 4272 | $criterias = array ("TO","SUBJECT","FROM","CC"); |
---|
| 4273 | $return = array(); |
---|
[3589] | 4274 | if(!isset($params['folder'])) { |
---|
| 4275 | $folder_params = array("noSharedFolders"=>1); |
---|
| 4276 | if(isset($params['folderType'])) |
---|
| 4277 | $folder_params['folderType'] = $params['folderType']; |
---|
| 4278 | $folders = $this->get_folders_list($folder_params); |
---|
| 4279 | } |
---|
| 4280 | else |
---|
| 4281 | $folders = array(0=>array('folder_id'=>$params['folder'])); |
---|
[1709] | 4282 | $num_msgs = 0; |
---|
[3923] | 4283 | $max_msgs = $params['max_msgs'] + 1; //get one more because mobile paginate |
---|
| 4284 | $return["msgs"] = array(); |
---|
| 4285 | |
---|
| 4286 | //get max_msgs of each folder order by date and later order all messages together and retur only max_msgs msgs |
---|
[1709] | 4287 | foreach($folders as $id =>$folder) |
---|
| 4288 | { |
---|
| 4289 | if(strpos($folder['folder_id'],'user')===false && is_array($folder)) { |
---|
| 4290 | foreach($criterias as $criteria_fixed) |
---|
[3923] | 4291 | { |
---|
| 4292 | $_filter = $criteria_fixed . ' "'.$params['filter'].'"'; |
---|
| 4293 | |
---|
[3573] | 4294 | $mbox_stream = $this->open_mbox($folder['folder_id']); |
---|
[3923] | 4295 | |
---|
| 4296 | $messages = imap_sort($mbox_stream,SORTARRIVAL,1,SE_UID,$_filter); |
---|
[1709] | 4297 | |
---|
| 4298 | if ($messages == ''){ |
---|
| 4299 | if($mbox_stream) |
---|
| 4300 | imap_close($mbox_stream); |
---|
| 4301 | continue; |
---|
| 4302 | } |
---|
[3923] | 4303 | |
---|
[1709] | 4304 | foreach($messages as $msg_number) |
---|
[3923] | 4305 | { |
---|
[1709] | 4306 | $temp = $this->get_info_head_msg($msg_number); |
---|
| 4307 | if(!$temp) |
---|
| 4308 | return false; |
---|
[3573] | 4309 | $temp['msg_folder'] = $folder['folder_id']; |
---|
[3923] | 4310 | $return["msgs"][$num_msgs] = $temp; |
---|
[1709] | 4311 | $num_msgs++; |
---|
| 4312 | } |
---|
[3923] | 4313 | |
---|
[1709] | 4314 | if($mbox_stream) |
---|
| 4315 | imap_close($mbox_stream); |
---|
| 4316 | } |
---|
[3923] | 4317 | } |
---|
[1709] | 4318 | } |
---|
[3923] | 4319 | |
---|
| 4320 | if(!function_exists("cmp_date")) { |
---|
| 4321 | function cmp_date($obj1, $obj2){ |
---|
| 4322 | if($obj1['timestamp'] == $obj2['timestamp']) return 0; |
---|
| 4323 | return ($obj1['timestamp'] < $obj2['timestamp']) ? 1 : -1; |
---|
| 4324 | } |
---|
| 4325 | } |
---|
| 4326 | usort($return["msgs"], "cmp_date"); |
---|
| 4327 | $return["has_more_msg"] = (sizeof($return["msgs"]) > $max_msgs); |
---|
| 4328 | $return["msgs"] = array_slice($return["msgs"], 0, $max_msgs); |
---|
[4560] | 4329 | $return["msgs"]['num_msgs'] = $num_msgs; |
---|
[3923] | 4330 | |
---|
[1709] | 4331 | return $return; |
---|
| 4332 | } |
---|
[1472] | 4333 | |
---|
[2] | 4334 | function delete_and_show_previous_message($params) |
---|
| 4335 | { |
---|
| 4336 | $return = $this->get_info_previous_msg($params); |
---|
[1472] | 4337 | |
---|
[2] | 4338 | $params_tmp1 = array(); |
---|
| 4339 | $params_tmp1['msgs_to_delete'] = $params['msg_number']; |
---|
| 4340 | $params_tmp1['folder'] = $params['msg_folder']; |
---|
| 4341 | $return_tmp1 = $this->delete_msg($params_tmp1); |
---|
[1472] | 4342 | |
---|
[2] | 4343 | $return['msg_number_deleted'] = $return_tmp1; |
---|
[1472] | 4344 | |
---|
[2] | 4345 | return $return; |
---|
| 4346 | } |
---|
[1472] | 4347 | |
---|
| 4348 | |
---|
[2] | 4349 | function automatic_trash_cleanness($params) |
---|
| 4350 | { |
---|
| 4351 | $before_date = date("m/d/Y", strtotime("-".$params['before_date']." day")); |
---|
| 4352 | $criteria = 'BEFORE "'.$before_date.'"'; |
---|
[325] | 4353 | $mbox_stream = $this->open_mbox('INBOX'.$this->imap_delimiter.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']); |
---|
[3018] | 4354 | // Free others requests |
---|
| 4355 | session_write_close(); |
---|
[2] | 4356 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
| 4357 | if (is_array($messages)){ |
---|
| 4358 | foreach ($messages as $msg_number){ |
---|
| 4359 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
| 4360 | } |
---|
| 4361 | } |
---|
[51] | 4362 | if($mbox_stream) |
---|
| 4363 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 4364 | return $messages; |
---|
| 4365 | } |
---|
| 4366 | // Fix the search problem with special characters!!!! |
---|
| 4367 | function remove_accents($string) { |
---|
[1472] | 4368 | return strtr($string, |
---|
| 4369 | "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ", |
---|
[2] | 4370 | "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); |
---|
| 4371 | } |
---|
| 4372 | |
---|
[4795] | 4373 | function make_search_date($date,$before = false){ |
---|
| 4374 | |
---|
[1622] | 4375 | //TODO: Adaptar a data de acordo com o locale do sistema. |
---|
| 4376 | list($day,$month,$year) = explode("/", $date); |
---|
[4795] | 4377 | $before?$day=(int)$day+1:$day=(int)$day; |
---|
| 4378 | $timestamp = mktime(0,0,0,(int)$month,$day,(int)$year); |
---|
| 4379 | $search_date = date('d-M-Y',$timestamp); |
---|
[1622] | 4380 | return $search_date; |
---|
| 4381 | |
---|
[4795] | 4382 | } |
---|
[1622] | 4383 | |
---|
[3843] | 4384 | function search_msg( $params = false ) |
---|
| 4385 | { |
---|
| 4386 | $mbox_stream = ""; |
---|
| 4387 | |
---|
| 4388 | if(strpos($params['condition'],"#")===false) |
---|
| 4389 | { //local messages |
---|
| 4390 | $search=false; |
---|
| 4391 | } |
---|
| 4392 | else |
---|
| 4393 | { |
---|
| 4394 | $search = explode(",",$params['condition']); |
---|
| 4395 | } |
---|
| 4396 | |
---|
| 4397 | $params['page'] = $params['page'] * 1; |
---|
[689] | 4398 | |
---|
[3843] | 4399 | if( is_array($search) ) |
---|
| 4400 | { |
---|
| 4401 | $search = array_unique($search); // Remove duplicated folders |
---|
| 4402 | $search_criteria = ''; |
---|
| 4403 | $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; |
---|
| 4404 | foreach($search as $tmp) |
---|
| 4405 | { |
---|
| 4406 | $tmp1 = explode("##",$tmp); |
---|
| 4407 | $sum = 0; |
---|
| 4408 | $name_box = $tmp1[0]; |
---|
| 4409 | unset($filter); |
---|
| 4410 | foreach($tmp1 as $index => $criteria) |
---|
| 4411 | { |
---|
| 4412 | if ($index != 0 && strlen($criteria) != 0) |
---|
| 4413 | { |
---|
| 4414 | $filter_array = explode("<=>",html_entity_decode(rawurldecode($criteria))); |
---|
| 4415 | $filter .= " ".$filter_array[0]; |
---|
| 4416 | if (strlen($filter_array[1]) != 0) |
---|
| 4417 | { |
---|
| 4418 | if ( trim($filter_array[0]) != 'BEFORE' && |
---|
| 4419 | trim($filter_array[0]) != 'SINCE' && |
---|
| 4420 | trim($filter_array[0]) != 'ON') |
---|
| 4421 | { |
---|
| 4422 | $filter .= '"'.$filter_array[1].'"'; |
---|
[5134] | 4423 | }else if(trim($filter_array[0]) == 'BEFORE' ){ |
---|
[4795] | 4424 | $filter .= '"'.$this->make_search_date($filter_array[1],true).'"'; |
---|
| 4425 | }else{ |
---|
| 4426 | $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; |
---|
| 4427 | } |
---|
[3843] | 4428 | } |
---|
| 4429 | } |
---|
| 4430 | } |
---|
| 4431 | |
---|
[5134] | 4432 | $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO-8859-1" ); |
---|
[3843] | 4433 | $filter = $this->remove_accents($filter); |
---|
[1472] | 4434 | |
---|
[3843] | 4435 | //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name |
---|
| 4436 | if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user') |
---|
| 4437 | { |
---|
| 4438 | $folder_name = explode($this->imap_delimiter,$name_box); |
---|
| 4439 | $this->ldap = new ldap_functions(); |
---|
| 4440 | |
---|
| 4441 | if ($cn = $this->ldap->uid2cn($folder_name[1])) |
---|
| 4442 | { |
---|
| 4443 | $folder_name[1] = $cn; |
---|
| 4444 | } |
---|
| 4445 | $folder_name = implode($this->imap_delimiter,$folder_name); |
---|
[3391] | 4446 | } |
---|
[3843] | 4447 | else |
---|
[5134] | 4448 | $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO-8859-1" ); |
---|
[3843] | 4449 | |
---|
| 4450 | if(!is_resource($mbox_stream)) |
---|
| 4451 | $mbox_stream = $this->open_mbox($name_box); |
---|
| 4452 | else |
---|
| 4453 | imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); |
---|
| 4454 | |
---|
| 4455 | if (preg_match("/^.?\bALL\b/", $filter)) |
---|
| 4456 | { |
---|
| 4457 | // Quick Search, note: this ALL isn't the same ALL from imap_search |
---|
| 4458 | $all_criterias = array ("TO","SUBJECT","FROM","CC"); |
---|
| 4459 | |
---|
| 4460 | foreach($all_criterias as $criteria_fixed) |
---|
| 4461 | { |
---|
| 4462 | $_filter = $criteria_fixed . substr($filter,4); |
---|
| 4463 | |
---|
| 4464 | $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); |
---|
| 4465 | |
---|
| 4466 | if(is_array($search_criteria)) |
---|
| 4467 | { |
---|
| 4468 | foreach($search_criteria as $new_search) |
---|
| 4469 | { |
---|
| 4470 | $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); |
---|
[5134] | 4471 | $elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); |
---|
[4795] | 4472 | $elem['uid'] = $new_search; |
---|
| 4473 | /* compare dates in ordering */ |
---|
| 4474 | $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); |
---|
[3843] | 4475 | $retorno[] = $elem; |
---|
| 4476 | } |
---|
| 4477 | } |
---|
| 4478 | } |
---|
| 4479 | } |
---|
[4068] | 4480 | else{ |
---|
[5134] | 4481 | $search_criteria = imap_search($mbox_stream, $filter, SE_UID); |
---|
[4941] | 4482 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) |
---|
| 4483 | { |
---|
| 4484 | if((!strpos($filter,"FLAGGED") === false) || (!strpos($filter,"UNFLAGGED") === false)) |
---|
| 4485 | { |
---|
| 4486 | $num_msgs = imap_num_msg($mbox_stream); |
---|
| 4487 | $flagged_msgs = array(); |
---|
| 4488 | for ($i=$num_msgs; $i>0; $i--) |
---|
[4068] | 4489 | { |
---|
[4941] | 4490 | $iuid = @imap_uid($this->mbox,$i); |
---|
| 4491 | $header = $this->get_header($iuid); |
---|
| 4492 | if(trim($header->Flagged)) |
---|
| 4493 | { |
---|
| 4494 | $flagged_msgs[$i] = $iuid; |
---|
| 4495 | } |
---|
[4068] | 4496 | } |
---|
[5134] | 4497 | if((count($flagged_msgs) >0) && (strpos($filter,"UNFLAGGED") === false)) |
---|
[4941] | 4498 | { |
---|
[5134] | 4499 | $arry_diff = is_array($search_criteria) ? array_diff($flagged_msgs,$search_criteria):$flagged_msgs; |
---|
| 4500 | foreach($arry_diff as $msg) |
---|
[4941] | 4501 | { |
---|
[5134] | 4502 | $search_criteria[] = $msg; |
---|
[4941] | 4503 | } |
---|
| 4504 | } |
---|
[5134] | 4505 | else if((count($flagged_msgs) >0) && (is_array($search_criteria)) && (!strpos($filter,"UNFLAGGED") === false)) |
---|
[4941] | 4506 | { |
---|
[5134] | 4507 | $search_criteria = array_diff($search_criteria,$flagged_msgs); |
---|
[4941] | 4508 | } |
---|
| 4509 | } |
---|
| 4510 | } |
---|
| 4511 | |
---|
| 4512 | if( is_array( $search_criteria) ) |
---|
| 4513 | { |
---|
| 4514 | foreach($search_criteria as $new_search) |
---|
| 4515 | { |
---|
| 4516 | $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); |
---|
[5134] | 4517 | $elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); |
---|
[4941] | 4518 | $elem['uid'] = $new_search; |
---|
| 4519 | /* compare dates in ordering */ |
---|
| 4520 | $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); |
---|
| 4521 | $retorno[] = $elem; |
---|
| 4522 | } |
---|
| 4523 | } |
---|
[3843] | 4524 | } |
---|
| 4525 | } |
---|
| 4526 | } |
---|
| 4527 | |
---|
| 4528 | if($mbox_stream) |
---|
| 4529 | { |
---|
| 4530 | imap_close($mbox_stream); |
---|
[3803] | 4531 | } |
---|
[3843] | 4532 | |
---|
[3803] | 4533 | $num_msgs = count($retorno); |
---|
[3223] | 4534 | |
---|
[3803] | 4535 | /* Comparison functions, descendent is ascendent with parms inverted */ |
---|
[4515] | 4536 | function SORTDATE($a, $b){ return ($a['udatecomp'] < $b['udatecomp']); } |
---|
[3803] | 4537 | function SORTDATE_REVERSE($b, $a) { return SORTDATE($a,$b); } |
---|
[3391] | 4538 | |
---|
[3803] | 4539 | function SORTWHO($a, $b) { return (strtoupper($a['from']) > strtoupper($b['from'])); } |
---|
| 4540 | function SORTWHO_REVERSE($b, $a) { return SORTWHO($a,$b); } |
---|
| 4541 | |
---|
| 4542 | function SORTSUBJECT($a, $b) { return (strtoupper($a['subject']) > strtoupper($b['subject'])); } |
---|
| 4543 | function SORTSUBJECT_REVERSE($b, $a) { return SORTSUBJECT($a,$b); } |
---|
| 4544 | |
---|
| 4545 | function SORTBOX($a, $b) { return ($a['boxname'] > $b['boxname']); } |
---|
| 4546 | function SORTBOX_REVERSE($b, $a) { return SORTBOX($a,$b); } |
---|
| 4547 | |
---|
| 4548 | function SORTSIZE($a, $b) { return ($a['size'] > $b['size']); } |
---|
| 4549 | function SORTSIZE_REVERSE($b, $a) { return SORTSIZE($a,$b); } |
---|
| 4550 | |
---|
[3843] | 4551 | usort( $retorno, $params['sort_type']); |
---|
| 4552 | $pageret = array_slice( $retorno, $params['page'] * $this->prefs['max_email_per_page'], $this->prefs['max_email_per_page']); |
---|
| 4553 | |
---|
| 4554 | $arrayRetorno['num_msgs'] = $num_msgs; |
---|
| 4555 | $arrayRetorno['data'] = $pageret; |
---|
[4158] | 4556 | $arrayRetorno['currentTab'] = $params['current_tab']; |
---|
[3803] | 4557 | |
---|
[3843] | 4558 | if ($pageret) |
---|
| 4559 | { |
---|
| 4560 | return $arrayRetorno; |
---|
| 4561 | } |
---|
| 4562 | else |
---|
| 4563 | { |
---|
| 4564 | return 'none'; |
---|
| 4565 | } |
---|
[2] | 4566 | } |
---|
[1472] | 4567 | |
---|
[3803] | 4568 | function get_msg_detail($uid_msg,$name_box, $mbox_stream ) |
---|
[271] | 4569 | { |
---|
[828] | 4570 | $header = $this->get_header($uid_msg); |
---|
[3803] | 4571 | require_once("class.imap_attachment.inc.php"); |
---|
[828] | 4572 | $imap_attachment = new imap_attachment(); |
---|
| 4573 | $attachments = $imap_attachment->get_attachment_headerinfo($mbox_stream, $uid_msg); |
---|
| 4574 | $attachments = $attachments['number_attachments'] > 0?"T".$attachments['number_attachments']:""; |
---|
| 4575 | $flag = $header->Unseen |
---|
| 4576 | .$header->Recent |
---|
| 4577 | .$header->Flagged |
---|
| 4578 | .$header->Draft |
---|
| 4579 | .$header->Answered |
---|
| 4580 | .$header->Deleted |
---|
| 4581 | .$attachments; |
---|
| 4582 | |
---|
| 4583 | |
---|
[163] | 4584 | $subject = $this->decode_string($header->fetchsubject); |
---|
| 4585 | $from = $header->from[0]->mailbox; |
---|
[2] | 4586 | if($header->from[0]->personal != "") |
---|
| 4587 | $from = $header->from[0]->personal; |
---|
[3843] | 4588 | $ret_msg['from'] = $this->decode_string($from); |
---|
| 4589 | $ret_msg['subject'] = $subject; |
---|
| 4590 | $ret_msg['udate'] = gmdate("d/m/Y",$header->udate + $this->functions->CalculateDateOffset()); |
---|
| 4591 | $ret_msg['size'] = $header->Size; |
---|
| 4592 | $ret_msg['flag'] = $flag; |
---|
[1472] | 4593 | return $ret_msg; |
---|
| 4594 | } |
---|
[3391] | 4595 | |
---|
| 4596 | |
---|
| 4597 | function size_msg($size){ |
---|
| 4598 | $var = floor($size/1024); |
---|
| 4599 | if($var >= 1){ |
---|
| 4600 | return $var." kb"; |
---|
| 4601 | }else{ |
---|
| 4602 | return $size ." b"; |
---|
| 4603 | } |
---|
| 4604 | } |
---|
| 4605 | |
---|
[2] | 4606 | function ob_array($the_object) |
---|
| 4607 | { |
---|
| 4608 | $the_array=array(); |
---|
| 4609 | if(!is_scalar($the_object)) |
---|
| 4610 | { |
---|
| 4611 | foreach($the_object as $id => $object) |
---|
| 4612 | { |
---|
| 4613 | if(is_scalar($object)) |
---|
| 4614 | { |
---|
| 4615 | $the_array[$id]=$object; |
---|
| 4616 | } |
---|
| 4617 | else |
---|
| 4618 | { |
---|
| 4619 | $the_array[$id]=$this->ob_array($object); |
---|
| 4620 | } |
---|
| 4621 | } |
---|
| 4622 | return $the_array; |
---|
| 4623 | } |
---|
| 4624 | else |
---|
| 4625 | { |
---|
| 4626 | return $the_object; |
---|
| 4627 | } |
---|
| 4628 | } |
---|
[1472] | 4629 | |
---|
[2] | 4630 | function getacl() |
---|
| 4631 | { |
---|
| 4632 | $this->ldap = new ldap_functions(); |
---|
[1472] | 4633 | |
---|
[2] | 4634 | $return = array(); |
---|
[1472] | 4635 | $mbox_stream = $this->open_mbox(); |
---|
[2] | 4636 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
[1472] | 4637 | |
---|
[2] | 4638 | $i = 0; |
---|
| 4639 | foreach ($mbox_acl as $user => $acl) |
---|
| 4640 | { |
---|
| 4641 | if ($user != $this->username) |
---|
| 4642 | { |
---|
| 4643 | $return[$i]['uid'] = $user; |
---|
| 4644 | $return[$i]['cn'] = $this->ldap->uid2cn($user); |
---|
| 4645 | } |
---|
| 4646 | $i++; |
---|
| 4647 | } |
---|
| 4648 | return $return; |
---|
| 4649 | } |
---|
[1472] | 4650 | |
---|
[2] | 4651 | function setacl($params) |
---|
| 4652 | { |
---|
| 4653 | $old_users = $this->getacl(); |
---|
| 4654 | if (!count($old_users)) |
---|
| 4655 | $old_users = array(); |
---|
[1472] | 4656 | |
---|
[2] | 4657 | $tmp_array = array(); |
---|
| 4658 | foreach ($old_users as $index => $user_info) |
---|
| 4659 | { |
---|
| 4660 | $tmp_array[$index] = $user_info['uid']; |
---|
| 4661 | } |
---|
| 4662 | $old_users = $tmp_array; |
---|
[1472] | 4663 | |
---|
[2] | 4664 | $users = unserialize($params['users']); |
---|
| 4665 | if (!count($users)) |
---|
| 4666 | $users = array(); |
---|
[1472] | 4667 | |
---|
[2] | 4668 | //$add_share = array_diff($users, $old_users); |
---|
| 4669 | $remove_share = array_diff($old_users, $users); |
---|
| 4670 | |
---|
| 4671 | $mbox_stream = $this->open_mbox(); |
---|
| 4672 | |
---|
| 4673 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 4674 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
| 4675 | |
---|
| 4676 | /*if (count($add_share)) |
---|
| 4677 | { |
---|
| 4678 | foreach ($add_share as $index=>$uid) |
---|
| 4679 | { |
---|
| 4680 | if (is_array($mailboxes_list)) |
---|
| 4681 | { |
---|
| 4682 | foreach ($mailboxes_list as $key => $val) |
---|
| 4683 | { |
---|
| 4684 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
| 4685 | imap_setacl ($mbox_stream, $folder, "$uid", "lrswipcda"); |
---|
| 4686 | } |
---|
| 4687 | } |
---|
| 4688 | } |
---|
| 4689 | }*/ |
---|
[1472] | 4690 | |
---|
[2] | 4691 | if (count($remove_share)) |
---|
| 4692 | { |
---|
| 4693 | foreach ($remove_share as $index=>$uid) |
---|
| 4694 | { |
---|
[4741] | 4695 | if (is_array($mailboxes_list)) |
---|
| 4696 | { |
---|
| 4697 | foreach ($mailboxes_list as $key => $val) |
---|
| 4698 | { |
---|
| 4699 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
| 4700 | $folder = str_replace("&-", "&", $folder); |
---|
| 4701 | imap_setacl ($mbox_stream, $folder, "$uid", ""); |
---|
| 4702 | } |
---|
| 4703 | } |
---|
[1472] | 4704 | } |
---|
[2] | 4705 | } |
---|
[1472] | 4706 | |
---|
[2] | 4707 | return true; |
---|
| 4708 | } |
---|
[1472] | 4709 | |
---|
[2] | 4710 | function getaclfromuser($params) |
---|
| 4711 | { |
---|
| 4712 | $useracl = $params['user']; |
---|
[1472] | 4713 | |
---|
[2] | 4714 | $return = array(); |
---|
| 4715 | $return[$useracl] = 'false'; |
---|
[1472] | 4716 | $mbox_stream = $this->open_mbox(); |
---|
[2] | 4717 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
[1472] | 4718 | |
---|
[2] | 4719 | foreach ($mbox_acl as $user => $acl) |
---|
| 4720 | { |
---|
| 4721 | if (($user != $this->username) && ($user == $useracl)) |
---|
| 4722 | { |
---|
| 4723 | $return[$user] = $acl; |
---|
| 4724 | } |
---|
| 4725 | } |
---|
| 4726 | return $return; |
---|
| 4727 | } |
---|
| 4728 | |
---|
| 4729 | function getacltouser($user) |
---|
| 4730 | { |
---|
| 4731 | $return = array(); |
---|
| 4732 | $mbox_stream = $this->open_mbox(); |
---|
[325] | 4733 | //Alterado, antes era 'imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); |
---|
| 4734 | //Afim de tratar as pastas compartilhadas, verificandos as permissoes de operacao sobre as mesmas |
---|
| 4735 | //No caso de se tratar da caixa do proprio usuario logado, utiliza a sintaxe abaixo |
---|
| 4736 | if(substr($user,0,4) != 'user') |
---|
[449] | 4737 | $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); |
---|
[325] | 4738 | else |
---|
[5134] | 4739 | $mbox_acl = @imap_getacl($mbox_stream, $user); |
---|
| 4740 | if(isset($mbox_acl[$this->username])) |
---|
[2] | 4741 | return $mbox_acl[$this->username]; |
---|
[5134] | 4742 | else |
---|
| 4743 | return ''; |
---|
[2] | 4744 | } |
---|
| 4745 | |
---|
[1472] | 4746 | |
---|
[2] | 4747 | function setaclfromuser($params) |
---|
| 4748 | { |
---|
| 4749 | $user = $params['user']; |
---|
| 4750 | $acl = $params['acl']; |
---|
[1472] | 4751 | |
---|
[2] | 4752 | $mbox_stream = $this->open_mbox(); |
---|
| 4753 | |
---|
| 4754 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 4755 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
| 4756 | |
---|
| 4757 | if (is_array($mailboxes_list)) |
---|
| 4758 | { |
---|
| 4759 | foreach ($mailboxes_list as $key => $val) |
---|
| 4760 | { |
---|
[449] | 4761 | $folder = str_replace($serverString, "", imap_utf7_encode($val->name)); |
---|
| 4762 | $folder = str_replace("&-", "&", $folder); |
---|
[2] | 4763 | if (!imap_setacl ($mbox_stream, $folder, $user, $acl)) |
---|
| 4764 | { |
---|
[449] | 4765 | $return = imap_last_error(); |
---|
[2] | 4766 | } |
---|
| 4767 | } |
---|
| 4768 | } |
---|
[449] | 4769 | if (isset($return)) |
---|
| 4770 | return $return; |
---|
| 4771 | else |
---|
| 4772 | return true; |
---|
[2] | 4773 | } |
---|
[1472] | 4774 | |
---|
[51] | 4775 | function download_attachment($msg,$msgno) |
---|
| 4776 | { |
---|
[1472] | 4777 | $array_parts_attachments = array(); |
---|
[3289] | 4778 | //$array_parts_attachments['names'] = ''; |
---|
[689] | 4779 | include_once("class.imap_attachment.inc.php"); |
---|
[1472] | 4780 | $imap_attachment = new imap_attachment(); |
---|
| 4781 | |
---|
[51] | 4782 | if (count($msg->fname[$msgno]) > 0) |
---|
| 4783 | { |
---|
| 4784 | $i = 0; |
---|
| 4785 | foreach ($msg->fname[$msgno] as $index=>$fname) |
---|
| 4786 | { |
---|
| 4787 | $array_parts_attachments[$i]['pid'] = $msg->pid[$msgno][$index]; |
---|
[1397] | 4788 | $array_parts_attachments[$i]['name'] = $imap_attachment->flat_mime_decode($this->decode_string($fname)); |
---|
[51] | 4789 | $array_parts_attachments[$i]['name'] = $array_parts_attachments[$i]['name'] ? $array_parts_attachments[$i]['name'] : "attachment.bin"; |
---|
| 4790 | $array_parts_attachments[$i]['encoding'] = $msg->encoding[$msgno][$index]; |
---|
[3289] | 4791 | //$array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', '; |
---|
[51] | 4792 | $array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index]; |
---|
| 4793 | $i++; |
---|
| 4794 | } |
---|
| 4795 | } |
---|
[3289] | 4796 | //$array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); |
---|
[51] | 4797 | return $array_parts_attachments; |
---|
[1472] | 4798 | } |
---|
[69] | 4799 | |
---|
[4436] | 4800 | |
---|
| 4801 | /** |
---|
| 4802 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 4803 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 4804 | * @param $params |
---|
| 4805 | */ |
---|
| 4806 | function spam($params) |
---|
[69] | 4807 | { |
---|
[4416] | 4808 | |
---|
| 4809 | $mbox_stream = $this->open_mbox($params['folder']); |
---|
[69] | 4810 | $msgs_number = explode(',',$params['msgs_number']); |
---|
| 4811 | |
---|
[4416] | 4812 | $user = Array(); |
---|
| 4813 | |
---|
| 4814 | if(substr($params['folder'], 0, 4) == 'user') |
---|
| 4815 | { |
---|
| 4816 | $ldapObject = new ldap_functions(); |
---|
| 4817 | |
---|
| 4818 | $folderArray = Array(); |
---|
| 4819 | $folderArray = explode($this->imap_delimiter, $params['folder']); |
---|
| 4820 | |
---|
| 4821 | $user['name'] = $folderArray[1]; |
---|
| 4822 | $user['email'] = $ldapObject->getMailByUid($user['name']); |
---|
| 4823 | |
---|
| 4824 | } |
---|
| 4825 | else |
---|
| 4826 | { |
---|
| 4827 | $user['name'] = $this->username; |
---|
| 4828 | $user['email'] = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 4829 | } |
---|
| 4830 | |
---|
| 4831 | foreach($msgs_number as $msg_number) |
---|
| 4832 | { |
---|
[877] | 4833 | $imap_msg_number = imap_msgno($mbox_stream, $msg_number); |
---|
| 4834 | $header = imap_fetchheader($mbox_stream, $imap_msg_number); |
---|
| 4835 | $body = imap_body($mbox_stream, $imap_msg_number); |
---|
[69] | 4836 | $msg = $header . $body; |
---|
[4416] | 4837 | strtok($user['email'], '@'); |
---|
[69] | 4838 | $domain = strtok('@'); |
---|
| 4839 | |
---|
[4416] | 4840 | |
---|
| 4841 | |
---|
[449] | 4842 | //Encontrar a assinatura do dspam no cabecalho |
---|
| 4843 | $v = explode("\r\n", $header); |
---|
| 4844 | foreach ($v as $linha){ |
---|
[877] | 4845 | if (eregi("^Message-ID", $linha)) { |
---|
| 4846 | $args = explode(" ", $linha); |
---|
| 4847 | $msg_id = "'$args[1]'"; |
---|
| 4848 | } elseif (eregi("^X-DSPAM-Signature", $linha)) { |
---|
[449] | 4849 | $args = explode(" ",$linha); |
---|
| 4850 | $signature = $args[1]; |
---|
| 4851 | } |
---|
| 4852 | } |
---|
| 4853 | |
---|
[877] | 4854 | // Seleciona qual comando a ser executado |
---|
[4416] | 4855 | switch($params['spam']){ |
---|
[449] | 4856 | case 'true': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam']; break; |
---|
| 4857 | case 'false': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham']; break; |
---|
| 4858 | } |
---|
[877] | 4859 | |
---|
[4416] | 4860 | |
---|
[877] | 4861 | $tags = array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##', '##MSGID##'); |
---|
[4416] | 4862 | $cmd = str_replace($tags, array($user['email'], $user['name'], $domain, $signature, $msg_id), $cmd); |
---|
| 4863 | |
---|
[78] | 4864 | system($cmd); |
---|
[69] | 4865 | } |
---|
[4416] | 4866 | |
---|
[69] | 4867 | imap_close($mbox_stream); |
---|
| 4868 | return false; |
---|
| 4869 | } |
---|
[4436] | 4870 | |
---|
| 4871 | |
---|
[5134] | 4872 | /** |
---|
| 4873 | * Descrição do método |
---|
| 4874 | * |
---|
| 4875 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 4876 | * @author |
---|
| 4877 | * @sponsor Caixa Econômica Federal |
---|
| 4878 | * @author |
---|
| 4879 | * @param <tipo> <$msg_number> <Número da mensagem> |
---|
| 4880 | * @return <cabeçalho da mensagem> |
---|
| 4881 | * @access <public> |
---|
| 4882 | */ |
---|
[4436] | 4883 | function get_header($msg_number) |
---|
| 4884 | { |
---|
[4795] | 4885 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); |
---|
[535] | 4886 | if (!is_object($header)) |
---|
| 4887 | return false; |
---|
[1472] | 4888 | |
---|
[5134] | 4889 | if($header->Flagged != "F" ) { |
---|
[659] | 4890 | $flag = preg_match('/importance *: *(.*)\r/i', |
---|
| 4891 | imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) |
---|
[1472] | 4892 | ,$importance); |
---|
[659] | 4893 | $header->Flagged = $flag==0?false:strtolower($importance[1])=="high"?"F":false; |
---|
| 4894 | } |
---|
[1472] | 4895 | |
---|
[535] | 4896 | return $header; |
---|
| 4897 | } |
---|
[1000] | 4898 | |
---|
| 4899 | //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 |
---|
| 4900 | ///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. |
---|
| 4901 | |
---|
[5191] | 4902 | |
---|
[3911] | 4903 | function insert_email($source,$folder,$timestamp,$flags){ |
---|
[5191] | 4904 | |
---|
[1000] | 4905 | $username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 4906 | $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
| 4907 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 4908 | $imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
| 4909 | $imap_options = '/notls/novalidate-cert'; |
---|
[5134] | 4910 | |
---|
| 4911 | |
---|
| 4912 | $folder = mb_convert_encoding( $folder, "UTF7-IMAP","ISO-8859-1"); |
---|
| 4913 | |
---|
[1000] | 4914 | $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); |
---|
[5134] | 4915 | |
---|
| 4916 | if(imap_last_error() === 'Mailbox already exists') |
---|
[1000] | 4917 | imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}".$folder)); |
---|
| 4918 | if($timestamp){ |
---|
[4436] | 4919 | $pdate = date_parse(date('r')); // pega a data atual do servidor (TODO: pegar a data da mensagem local) |
---|
| 4920 | $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] | 4921 | /* TODO: o diretorio /tmp deve ser substituido pelo diretorio temporario configurado no setup */ |
---|
| 4922 | $file = "/tmp/sess_".$_SESSION[ 'phpgw_session' ][ 'session_id' ]; |
---|
| 4923 | |
---|
[1000] | 4924 | $f = fopen($file,"w"); |
---|
| 4925 | fputs($f,base64_encode($source)); |
---|
[4795] | 4926 | fclose($f); |
---|
[5134] | 4927 | $command = "python ".$_SESSION['rootPath']."/expressoMail1_2/imap.py \"$imap_server\" \"$imap_port\" \"$username\" \"$password\" \"$timestamp\" \"$folder\" \"$file\""; |
---|
| 4928 | $return['command']= exec($command); |
---|
[1000] | 4929 | }else{ |
---|
| 4930 | $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $source, "\\Seen"); |
---|
| 4931 | } |
---|
| 4932 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); |
---|
[3872] | 4933 | |
---|
[1000] | 4934 | $return['msg_no'] = $status->uidnext - 1; |
---|
[3911] | 4935 | $return['error'] = imap_last_error(); |
---|
| 4936 | if(!$return['error'] && $flags != '' ){ |
---|
[3872] | 4937 | |
---|
[3911] | 4938 | $flags_array=explode(':',$flags); |
---|
| 4939 | //"Answered","Draft","Flagged","Unseen" |
---|
| 4940 | $flags_fixed = ""; |
---|
| 4941 | if($flags_array[0] == 'A') |
---|
| 4942 | $flags_fixed.="\\Answered "; |
---|
| 4943 | if($flags_array[1] == 'X') |
---|
| 4944 | $flags_fixed.="\\Draft "; |
---|
| 4945 | if($flags_array[2] == 'F') |
---|
| 4946 | $flags_fixed.="\\Flagged "; |
---|
| 4947 | if($flags_array[3] != 'U') |
---|
| 4948 | $flags_fixed.="\\Seen "; |
---|
[5184] | 4949 | if($flags_array[4] == 'F') |
---|
| 4950 | $flags_fixed.="\\Answered \\Draft "; |
---|
[3911] | 4951 | imap_setflag_full($mbox_stream, $return['msg_no'], $flags_fixed, ST_UID); |
---|
| 4952 | } |
---|
[5134] | 4953 | |
---|
| 4954 | //Ignorando erro de AUTH=Plain |
---|
| 4955 | if($return['error'] === 'SECURITY PROBLEM: insecure server advertised AUTH=PLAIN') |
---|
| 4956 | $return['error'] = false; |
---|
| 4957 | |
---|
[1000] | 4958 | if($mbox_stream) |
---|
[3911] | 4959 | imap_close($mbox_stream); |
---|
[1000] | 4960 | return $return; |
---|
| 4961 | } |
---|
| 4962 | |
---|
[5134] | 4963 | function show_decript($params,$dec=0){ |
---|
[1035] | 4964 | $source = $params['source']; |
---|
[5083] | 4965 | |
---|
[5134] | 4966 | //error_log("source: $source\nversao: " . PHP_VERSION); |
---|
| 4967 | if ($dec == 0) |
---|
| 4968 | { |
---|
| 4969 | $source = str_replace(" ", "+", $source,$i); |
---|
[5083] | 4970 | if (version_compare(PHP_VERSION, '5.2.0', '>=')){ |
---|
| 4971 | if(!$source = base64_decode($source,true)) |
---|
[5134] | 4972 | return "error ".$source."Espaï¿?os ".$i; |
---|
[5083] | 4973 | |
---|
| 4974 | } |
---|
| 4975 | else { |
---|
| 4976 | if(!$source = base64_decode($source)) |
---|
[5134] | 4977 | return "error ".$source."Espaï¿?os ".$i; |
---|
| 4978 | } |
---|
[1035] | 4979 | } |
---|
[3803] | 4980 | |
---|
[1035] | 4981 | $insert = $this->insert_email($source,'INBOX'.$this->imap_delimiter.'decifradas'); |
---|
| 4982 | |
---|
| 4983 | $get['msg_number'] = $insert['msg_no']; |
---|
| 4984 | $get['msg_folder'] = 'INBOX'.$this->imap_delimiter.'decifradas'; |
---|
| 4985 | $return = $this->get_info_msg($get); |
---|
| 4986 | $get['msg_number'] = $params['ID']; |
---|
| 4987 | $get['msg_folder'] = $params['folder']; |
---|
| 4988 | $tmp = $this->get_info_msg($get); |
---|
| 4989 | if(!$tmp['status_get_msg_info']) |
---|
| 4990 | { |
---|
| 4991 | $return['msg_day']=$tmp['msg_day']; |
---|
| 4992 | $return['msg_hour']=$tmp['msg_hour']; |
---|
| 4993 | $return['fulldate']=$tmp['fulldate']; |
---|
| 4994 | $return['smalldate']=$tmp['smalldate']; |
---|
| 4995 | } |
---|
| 4996 | else |
---|
| 4997 | { |
---|
| 4998 | $return['msg_day']=''; |
---|
| 4999 | $return['msg_hour']=''; |
---|
| 5000 | $return['fulldate']=''; |
---|
| 5001 | $return['smalldate']=''; |
---|
| 5002 | } |
---|
| 5003 | $return['msg_no'] =$insert['msg_no']; |
---|
| 5004 | $return['error'] = $insert['error']; |
---|
| 5005 | $return['folder'] = $params['folder']; |
---|
| 5006 | //$return['acls'] = $insert['acls']; |
---|
| 5007 | $return['original_ID'] = $params['ID']; |
---|
| 5008 | |
---|
| 5009 | return $return; |
---|
| 5010 | |
---|
| 5011 | } |
---|
[1472] | 5012 | |
---|
[1000] | 5013 | //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 |
---|
| 5014 | //Base64 os "+" são substituidos por " " no envio e essa função arruma esse efeito. |
---|
| 5015 | |
---|
| 5016 | function treat_base64_from_post($source){ |
---|
| 5017 | $offset = 0; |
---|
| 5018 | do |
---|
| 5019 | { |
---|
| 5020 | if($inicio = strpos($source, 'Content-Transfer-Encoding: base64', $offset)) |
---|
| 5021 | { |
---|
| 5022 | $inicio = strpos($source, "\n\r", $inicio); |
---|
| 5023 | $fim = strpos($source, '--', $inicio); |
---|
| 5024 | if(!$fim) |
---|
| 5025 | $fim = strpos($source,"\n\r", $inicio); |
---|
| 5026 | $length = $fim-$inicio; |
---|
| 5027 | $parte = substr( $source,$inicio,$length-1); |
---|
| 5028 | $parte = str_replace(" ", "+", $parte); |
---|
| 5029 | $source = substr_replace($source, $parte, $inicio, $length-1); |
---|
| 5030 | } |
---|
| 5031 | if($offset > $inicio) |
---|
| 5032 | $offset=FALSE; |
---|
| 5033 | else |
---|
| 5034 | $offset = $inicio; |
---|
| 5035 | } |
---|
| 5036 | while($offset); |
---|
| 5037 | return $source; |
---|
| 5038 | } |
---|
| 5039 | |
---|
| 5040 | //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. |
---|
| 5041 | |
---|
| 5042 | function unarchive_mail($params) |
---|
[5191] | 5043 | { |
---|
[1000] | 5044 | $dest_folder = $params['folder']; |
---|
| 5045 | $sources = explode("#@#@#@",$params['source']); |
---|
[5134] | 5046 | //Add user timeszone |
---|
[5191] | 5047 | $timestamps = explode("#@#@#@",$params['timestamp']); |
---|
| 5048 | |
---|
| 5049 | |
---|
[3911] | 5050 | $flags = explode("#@#@#@",$params['flags']); |
---|
[5191] | 5051 | |
---|
[5134] | 5052 | foreach($sources as $index=>$src) { |
---|
| 5053 | if($src!=""){ |
---|
[3911] | 5054 | $source = $this->treat_base64_from_post($src); |
---|
[5191] | 5055 | $timestampsactual = $timestamps[$index] + $this->functions->CalculateDateOffset(); |
---|
| 5056 | $insert = $this->insert_email($source, mb_convert_encoding( $dest_folder,"ISO-8859-1","UTF-8"), $timestampsactual,$flags[$index]); |
---|
[3911] | 5057 | } |
---|
| 5058 | } |
---|
[1000] | 5059 | return $insert; |
---|
| 5060 | } |
---|
| 5061 | |
---|
| 5062 | function download_all_local_attachments($params) |
---|
| 5063 | { |
---|
| 5064 | $source = $params['source']; |
---|
| 5065 | $source = $this->treat_base64_from_post($source); |
---|
| 5066 | $insert = $this->insert_email($source,'INBOX'.$this->imap_delimiter.'decifradas'); |
---|
| 5067 | $exporteml = new ExportEml(); |
---|
| 5068 | $params['num_msg']=$insert['msg_no']; |
---|
| 5069 | $params['folder']='INBOX'.$this->imap_delimiter.'decifradas'; |
---|
| 5070 | return $exporteml->download_all_attachments($params); |
---|
| 5071 | } |
---|
[4830] | 5072 | |
---|
| 5073 | /** |
---|
| 5074 | * Método que envia um email reportando um erro no email do usuário |
---|
| 5075 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 5076 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
| 5077 | */ |
---|
| 5078 | function report_mail_error($params) |
---|
| 5079 | { |
---|
| 5080 | $params = $params['params']; |
---|
| 5081 | $array_params = explode(";;", $params); |
---|
| 5082 | $id_msg = $array_params[0]; |
---|
| 5083 | $msg_user = $array_params[1]; |
---|
| 5084 | |
---|
| 5085 | if($msg_user == '') |
---|
| 5086 | $msg_user = "Sem mensagem!"; |
---|
| 5087 | |
---|
| 5088 | $toname = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
| 5089 | |
---|
| 5090 | $exporteml = new ExportEml(); |
---|
| 5091 | $mail_content = $exporteml->export_msg_data($id_msg, $msg_folder); |
---|
| 5092 | $this->open_mbox($msg_folder); |
---|
| 5093 | $title = "Erro de email reportado"; |
---|
| 5094 | $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>" . |
---|
| 5095 | "$msg_user</body><br><br><hr>"; |
---|
| 5096 | |
---|
[5134] | 5097 | require_once $_SESSION['rootPath'] . '/API/class.servicelocator.php'; |
---|
[4830] | 5098 | $mailService = ServiceLocator::getService('mail'); |
---|
[5134] | 5099 | $mailService->addStringAttachment($mail_content, 'report.eml', 'application/text'); |
---|
| 5100 | $mailService->sendMail($_SESSION['phpgw_info']['expressomail']['server']['sugestoes_email_to'], $GLOBALS['phpgw_info']['user']['email'], $title, $body); |
---|
[4830] | 5101 | } |
---|
| 5102 | |
---|
[5134] | 5103 | function array_msort($array, $cols) |
---|
| 5104 | { |
---|
| 5105 | $colarr = array(); |
---|
| 5106 | foreach ($cols as $col => $order) { |
---|
| 5107 | $colarr[$col] = array(); |
---|
| 5108 | foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } |
---|
| 5109 | } |
---|
| 5110 | $params = array(); |
---|
| 5111 | foreach ($cols as $col => $order) { |
---|
| 5112 | $params[] =& $colarr[$col]; |
---|
| 5113 | $params = array_merge($params, (array)$order); |
---|
| 5114 | } |
---|
| 5115 | call_user_func_array('array_multisort', $params); |
---|
| 5116 | $ret = array(); |
---|
| 5117 | $keys = array(); |
---|
| 5118 | $first = true; |
---|
| 5119 | foreach ($colarr as $col => $arr) { |
---|
| 5120 | foreach ($arr as $k => $v) { |
---|
| 5121 | if ($first) { $keys[$k] = substr($k,1); } |
---|
| 5122 | $k = $keys[$k]; |
---|
| 5123 | if (!isset($ret[$k])) $ret[$k] = $array[$k]; |
---|
| 5124 | $ret[$k][$col] = $array[$k][$col]; |
---|
| 5125 | } |
---|
| 5126 | $first = false; |
---|
| 5127 | } |
---|
| 5128 | |
---|
| 5129 | return $ret; |
---|
| 5130 | |
---|
| 5131 | } |
---|
| 5132 | |
---|
| 5133 | function parseCriteriaSearchMail($search) |
---|
| 5134 | { |
---|
| 5135 | $criteria = ''; |
---|
| 5136 | $searchArray = explode(' ', $search); |
---|
| 5137 | |
---|
| 5138 | foreach ($searchArray as $v) |
---|
| 5139 | if(trim($v) !== '' ) |
---|
| 5140 | $criteria .= 'TEXT "'.$v.'" ' ; |
---|
| 5141 | |
---|
| 5142 | return $criteria; |
---|
| 5143 | } |
---|
| 5144 | |
---|
| 5145 | function quickSearchMail( $params ) |
---|
| 5146 | { |
---|
| 5147 | $return = array(); |
---|
| 5148 | $return['folder'] = $params['folder']; |
---|
| 5149 | if(!is_array($params['folder'])) |
---|
| 5150 | $params['folder'] = array( $params['folder'] ); |
---|
| 5151 | |
---|
| 5152 | if(!isset($params['sort'])) |
---|
[5172] | 5153 | $params['sort'] = 'SORTDATE_REVERSE'; |
---|
[5134] | 5154 | |
---|
| 5155 | $params['search'] = mb_convert_encoding($params['search'], 'UTF-8',mb_detect_encoding($params['search'].'x', 'UTF-8, ISO-8859-1')); |
---|
| 5156 | |
---|
| 5157 | $i = 0; |
---|
| 5158 | if(!isset($params['page'])) $params['page'] = 0; |
---|
| 5159 | $end = ($this->prefs['max_email_per_page'] * ((int)$params['page'] + 1)); |
---|
| 5160 | $ini = $end - $this->prefs['max_email_per_page'] ; |
---|
| 5161 | $count = 0; |
---|
| 5162 | |
---|
| 5163 | $search = $this->parseCriteriaSearchMail($params['search']); |
---|
| 5164 | |
---|
| 5165 | foreach ($params['folder'] as $folder) |
---|
| 5166 | { |
---|
| 5167 | $imap = $this->open_mbox( $folder ) ; |
---|
[5172] | 5168 | $msgIds = imap_sort( $imap , SORTDATE , 1 , SE_UID , $search ,'UTF-8'); |
---|
[5134] | 5169 | |
---|
| 5170 | $count += count($msgIds); |
---|
| 5171 | |
---|
| 5172 | foreach ($msgIds as $ii => $v) |
---|
| 5173 | { |
---|
| 5174 | $msg = imap_headerinfo ( $imap, imap_msgno($imap, $v) ); |
---|
| 5175 | $return['msgs'][$i]['from'] = ''; |
---|
| 5176 | |
---|
| 5177 | $from = $msg->from[0]->mailbox; |
---|
| 5178 | if($msg->from[0]->personal != "") |
---|
| 5179 | $from = $msg->from[0]->personal; |
---|
| 5180 | $return['msgs'][$i]['from'] = mb_convert_encoding($this->decode_string($from), 'UTF-8'); |
---|
| 5181 | |
---|
| 5182 | $return['msgs'][$i]['subject'] = ' '; |
---|
| 5183 | |
---|
| 5184 | $subject = imap_mime_header_decode($msg->subject); |
---|
| 5185 | foreach ($subject as $tmp) |
---|
[5189] | 5186 | $return['msgs'][$i]['subject'] .= mb_convert_encoding($tmp->text, 'UTF-8', 'UTF-8 , ISO-8859-1'); |
---|
[5134] | 5187 | |
---|
[5189] | 5188 | |
---|
[5134] | 5189 | $return['msgs'][$i]['flag'] = ' '; |
---|
| 5190 | $return['msgs'][$i]['flag'] .= $msg->Unseen ? $msg->Unseen : ''; |
---|
| 5191 | $return['msgs'][$i]['flag'] .= $msg->Recent ? $msg->Recent : ''; |
---|
| 5192 | $return['msgs'][$i]['flag'] .= $msg->Flagged ? $msg->Flagged : ''; |
---|
| 5193 | $return['msgs'][$i]['flag'] .= $msg->Draft ? $msg->Draft : ''; |
---|
| 5194 | $return['msgs'][$i]['flag'] .= $msg->Answered ? $msg->Answered : ''; |
---|
| 5195 | $return['msgs'][$i]['flag'] .= $msg->Deleted ? $msg->Deleted : ''; |
---|
| 5196 | |
---|
| 5197 | $return['msgs'][$i]['udate'] = gmdate("d/m/Y",$msg->udate + $this->functions->CalculateDateOffset()); |
---|
| 5198 | $return['msgs'][$i]['udatecomp'] = substr ($return['msgs'][$i]['udate'], -4) ."-". substr ($return['msgs'][$i]['udate'], 3, 2) ."-". substr ($return['msgs'][$i]['udate'], 0, 2); |
---|
| 5199 | $return['msgs'][$i]['date'] = $msg->udate; |
---|
| 5200 | $return['msgs'][$i]['size'] = $msg->Size; |
---|
| 5201 | $return['msgs'][$i]['boxname'] = $folder; |
---|
| 5202 | $return['msgs'][$i]['uid'] = $v; |
---|
| 5203 | $i++; |
---|
| 5204 | } |
---|
| 5205 | } |
---|
| 5206 | |
---|
| 5207 | $return['num_msgs'] = $count; |
---|
| 5208 | |
---|
| 5209 | if(!isset($return['msgs'])) |
---|
| 5210 | $return['msgs'] = array(); |
---|
| 5211 | |
---|
| 5212 | define('SORTBOX', 69); |
---|
| 5213 | define('SORTWHO', 2); |
---|
| 5214 | define('SORTBOX_REVERSE', 69); |
---|
| 5215 | define('SORTWHO_REVERSE', 2); |
---|
| 5216 | define('SORTDATE_REVERSE', 0); |
---|
| 5217 | define('SORTSUBJECT_REVERSE', 3); |
---|
| 5218 | define('SORTSIZE_REVERSE', 6); |
---|
| 5219 | |
---|
| 5220 | switch (constant( $params['sort'] )){ |
---|
| 5221 | case 0 : $sA = 'date'; break; |
---|
| 5222 | case 2 : $sA = 'from'; break; |
---|
| 5223 | case 69 : $sA = 'boxname'; break; |
---|
| 5224 | case 3 : $sA = 'subject'; break; |
---|
| 5225 | case 6 : $sA = 'size'; break; |
---|
| 5226 | } |
---|
[4830] | 5227 | |
---|
[5134] | 5228 | |
---|
[5172] | 5229 | if($params['sort'] !== 'SORTDATE_REVERSE') |
---|
[5134] | 5230 | if(strpos($params['sort'],'REVERSE') !== false) |
---|
[5172] | 5231 | $return['msgs'] = $this->array_msort($return['msgs'] , array( $sA => SORT_DESC)); |
---|
| 5232 | else |
---|
| 5233 | $return['msgs'] = $this->array_msort($return['msgs'] , array( $sA => SORT_ASC)); |
---|
[5134] | 5234 | |
---|
| 5235 | $k = -1; |
---|
| 5236 | $nMsgs = array(); |
---|
| 5237 | |
---|
| 5238 | foreach ($return['msgs'] as $v) |
---|
| 5239 | { |
---|
| 5240 | $k++; |
---|
| 5241 | if($k < $ini || $k >= $end ) continue; |
---|
| 5242 | $nMsgs[] = $v; |
---|
| 5243 | } |
---|
| 5244 | $return['msgs'] = $nMsgs; |
---|
[5189] | 5245 | |
---|
[5134] | 5246 | $return = json_encode($return); |
---|
| 5247 | $return = base64_encode($return); |
---|
[4830] | 5248 | |
---|
[5134] | 5249 | return $return; |
---|
| 5250 | } |
---|
| 5251 | |
---|
[3157] | 5252 | function get_quota_folders(){ |
---|
| 5253 | |
---|
| 5254 | // Additional Imap Class for not-implemented functions into PHP-IMAP extension. |
---|
| 5255 | include_once("class.imapfp.inc.php"); |
---|
| 5256 | $imapfp = new imapfp(); |
---|
| 5257 | |
---|
| 5258 | if(!$imapfp->open($this->imap_server,$this->imap_port)) |
---|
| 5259 | return $imapfp->get_error(); |
---|
| 5260 | if (!$imapfp->login( $this->username,$this->password )) |
---|
| 5261 | return $imapfp->get_error(); |
---|
| 5262 | |
---|
| 5263 | $response_array = $imapfp->get_mailboxes_size(); |
---|
| 5264 | if ($imapfp->error) |
---|
| 5265 | return $imapfp->get_error(); |
---|
| 5266 | |
---|
| 5267 | $data = array(); |
---|
| 5268 | $quota_root = $this->get_quota(array('folder_id' => "INBOX")); |
---|
| 5269 | $data["quota_root"] = $quota_root; |
---|
| 5270 | |
---|
| 5271 | foreach ($response_array as $idx=>$line) { |
---|
| 5272 | $line2 = str_replace('"', "", $line); |
---|
| 5273 | $line2 = str_replace(" /vendor/cmu/cyrus-imapd/size (value.shared ",";",str_replace("* ANNOTATION ","",$line2)); |
---|
| 5274 | list($folder,$size) = explode(";",$line2); |
---|
[3854] | 5275 | $quota_used = str_replace(")","",$size); |
---|
| 5276 | $quotaPercent = (($quota_used / 1024) / $data["quota_root"]["quota_limit"])*100; |
---|
[3157] | 5277 | $folder = mb_convert_encoding($folder, "ISO_8859-1", "UTF7-IMAP"); |
---|
| 5278 | if(!preg_match('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i',$folder)){ |
---|
| 5279 | $folder = $this->functions->getLang("Inbox"); |
---|
| 5280 | } |
---|
| 5281 | else |
---|
| 5282 | $folder = preg_replace('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i','', $folder); |
---|
| 5283 | |
---|
| 5284 | $data[$folder] = array("quota_percent" => sprintf("%.1f",round($quotaPercent,1)), "quota_used" => $quota_used); |
---|
| 5285 | } |
---|
| 5286 | $imapfp->close(); |
---|
| 5287 | return $data; |
---|
| 5288 | } |
---|
[5134] | 5289 | |
---|
| 5290 | function getaclfrombox($mail) |
---|
| 5291 | { |
---|
| 5292 | $mailArray = explode('@', $mail); |
---|
| 5293 | $boxacl = $mailArray[0]; |
---|
| 5294 | $return = array(); |
---|
| 5295 | |
---|
| 5296 | if(!$this->mbox) |
---|
| 5297 | $this->open_mbox(); |
---|
| 5298 | |
---|
| 5299 | $mbox_acl = imap_getacl($this->mbox, 'user' . $this->imap_delimiter . $boxacl); |
---|
| 5300 | |
---|
| 5301 | foreach ($mbox_acl as $user => $acl) |
---|
| 5302 | { |
---|
| 5303 | if ($user != $boxacl ) |
---|
| 5304 | $return[$user] = $acl; |
---|
| 5305 | } |
---|
| 5306 | return $return; |
---|
| 5307 | } |
---|
[2] | 5308 | } |
---|
[278] | 5309 | ?> |
---|