Ignore:
Timestamp:
03/02/12 03:48:47 (12 years ago)
Author:
cristiano
Message:

Ticket #2497 - Nova estrategia para o salvamento automatico de rascunhos

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/services/ImapServiceAdapter.php

    r5586 r5604  
    333333 
    334334    public function create( $URI, $data) 
    335     { 
     335    {                
    336336                switch( $URI['concept'] ) 
    337337                { 
     
    364364                                } 
    365365                                return array (); 
     366                        } 
     367                        case 'message': 
     368                        { 
     369                                $GLOBALS['phpgw_info']['flags'] = array( 'noheader' => true, 'nonavbar' => true,'currentapp' => 'expressoMail1_2','enable_nextmatchs_class' => True ); 
     370                                $return = array(); 
     371 
     372                                require_once dirname(__FILE__) . '/../../services/class.servicelocator.php'; 
     373                                $mailService = ServiceLocator::getService('mail'); 
     374 
     375                                $msg_uid = $data['msg_id']; 
     376                                $body = $data['body']; 
     377                                $body = str_replace("%nbsp;"," ",$body); 
     378                                $body = preg_replace("/\n/"," ",$body); 
     379                                $body = preg_replace("/\r/","" ,$body); 
     380                                $body = html_entity_decode ( $body, ENT_QUOTES , 'ISO-8859-1' );                                         
     381 
     382                                $folder = mb_convert_encoding($data['folder'], "UTF7-IMAP","ISO-8859-1, UTF-8"); 
     383                                $folder = @eregi_replace("INBOX[/.]", "INBOX".$this->imap_delimiter, $folder); 
     384 
     385                                $mailService->addTo($data['input_to']); 
     386                                $mailService->addCc( $data['input_cc']); 
     387                                $mailService->addBcc($data['input_cco']); 
     388                                $mailService->setSubject($data['input_subject']); 
     389 
     390                                if(isset($data['input_important_message'])) 
     391                                        $mailService->addHeaderField('Importance','High'); 
     392 
     393                                if(isset($data['input_return_receipt'])) 
     394                                        $mailService->addHeaderField('Disposition-Notification-To', Config::me('mail')); 
     395 
     396                                $isHTML = ( ( array_key_exists( 'type', $data ) && in_array( strtolower( $data[ 'type' ] ), array( 'html', 'plain' ) ) ) ? strtolower( $data[ 'type' ] ) != 'plain' : true ); 
     397 
     398                                if (!$body) $body = ' '; 
     399                                 
     400 
     401                                $mbox_stream = $this->open_mbox($folder); 
     402 
     403                                $attachment = json_decode($data['attachments'],TRUE); 
     404                                 
     405 
     406                                foreach ($attachment as &$value)  
     407                                { 
     408 
     409                                    if((int)$value > 0) //BD attachment 
     410                                    { 
     411                                         $att = Controller::read(array('id'=> $value , 'concept' => 'mailAttachment')); 
     412                                          
     413                                         if($att['disposition'] == 'embedded') 
     414                                         { 
     415                                             $body = str_replace('"../prototype/getArchive.php?mailAttachment='.$att['id'].'"', $att['name'], $body); 
     416                                             $mailService->addStringImage(base64_decode($att['source']), $att['type'], $att['name']); 
     417                                         } 
     418                                         else 
     419                                             $mailService->addStringAttachment(base64_decode($att['source']), $att['name'], $att['type'], 'base64', isset($att['disposition']) ? $att['disposition'] :'attachment' ); 
     420                                          
     421                                         unset($att); 
     422                                    } 
     423                                    else //message attachment 
     424                                    { 
     425                                        $value = json_decode($value, true); 
     426                                        $sub =  $value['name'] ? $value['name'].'.eml' :'no title.eml'; 
     427                                        $mbox_stream = $this->open_mbox($value['folder']); 
     428                                        $rawmsg = $this->getRawHeader($value['uid']) . "\r\n\r\n" . $this->getRawBody($value['uid']); 
     429                                        $mailService->addStringAttachment($rawmsg, $sub, 'message/rfc822', '7bit', 'attachment' ); 
     430                                        unset($rawmsg); 
     431                                    } 
     432 
     433                                } 
     434                                 
     435                                if($isHTML) $mailService->setBodyHtml($body); else $mailService->setBodyText($body); 
     436                                                          
     437                                if(imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, $mailService->getMessage(), "\\Seen \\Draft")) 
     438                                { 
     439                                    $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 
     440                                    $return['id'] = $status->uidnext - 1; 
     441                                         
     442                                    if($data['uidsSave'] ) 
     443                                        $this->delete_msgs(array('folder'=> $folder , 'msgs_number' => $data['uidsSave'])); 
     444                        
     445                                } 
     446                  
     447                                if($mbox_stream) imap_close($mbox_stream); 
     448                                 
     449                                 
     450                                 
     451                                return $return; 
    366452                        } 
    367453                } 
Note: See TracChangeset for help on using the changeset viewer.