Example #1
0
function forwardGetAttachs($smarty, $module_name, $local_templates_dir, $arrConf, &$pImap)
{
    $jsonObject = new PaloSantoJSON();
    $mailbox = getParameter('current_folder');
    $pImap->setMailbox($mailbox);
    $uid = getParameter("uid");
    if (is_null($uid) || $uid == '' || $uid === false || $uid == 'undefined') {
        $jsonObject->set_error('Invalid Email Message');
        return $jsonObject->createJSON();
    }
    $result = $pImap->login($_SESSION['elastix_user'], $_SESSION['elastix_pass2']);
    if ($result === false) {
        $jsonObject->set_error($pImap->errMsg);
    } else {
        $pMessage = new paloImapMessage($pImap->getConnection(), $uid, $pImap->getMailbox());
        $attachments = $pMessage->createAttachmentsToForward();
        if ($attachments === false) {
            $jsonObject->set_error($pMessage->errMsg);
        } else {
            $jsonObject->set_message($attachments);
        }
    }
    cleanAlertsImap();
    $pImap->close_mail_connection();
    return $jsonObject->createJSON();
}
 function readEmailMsg($uid)
 {
     $message = array();
     //obtenemos el message number dado su id
     $msg_num = @imap_msgno($this->connection, $uid);
     //$msg_num no puede ser igual a 0
     if (empty($msg_num)) {
         $this->errMsg = _tr('Messages does not exist');
         return false;
     }
     //leemos la cabecera del mensaje
     try {
         $header = @imap_headerinfo($this->connection, $msg_num);
     } catch (Exception $e) {
         //no exist un mensaje con dicho uid
         $this->errMsg = "imap_headerinfo failed: " . @imap_last_error();
         return false;
     }
     //TODO: parsear el arreglo de las etiquetas to, from, cc , bcc y replay_to
     // y reemplazar con ese valor las etiquetas toaddress, fromaddress, ccaddress, bccaddress, reply_toaddress
     if (!empty($header)) {
         //$message['header']['to']=$header->to;
         $message['header']['to']['tag'] = _tr('To');
         $message['header']['to']['content'] = trim(htmlentities($header->toaddress, ENT_COMPAT, 'UTF-8'));
         //$message['header']['from']=$header->from;
         $message['header']['from']['tag'] = _tr('From');
         $message['header']['from']['content'] = trim(htmlentities($header->fromaddress, ENT_COMPAT, 'UTF-8'));
         $message['header']['subject'] = isset($header->subject) ? trim(htmlentities($header->subject, ENT_COMPAT, 'UTF-8')) : _tr('No Subject');
         if ($message['header']['subject'] === '') {
             $message['header']['subject'] = _tr('No Subject');
         }
         if (isset($header->date)) {
             $message['header']['date']['tag'] = _tr('Date');
             $message['header']['date']['content'] = $header->date;
         }
         if (isset($header->cc)) {
             //$message['header']['cc']=$header->cc;
             $message['header']['cc']['tag'] = _tr('CC');
             $message['header']['cc']['content'] = trim(htmlentities($header->ccaddress, ENT_COMPAT, 'UTF-8'));
         }
         if (isset($header->bcc)) {
             //$message['header']['bcc']=$header->bcc;
             $message['header']['bcc']['tag'] = _tr('BCC');
             $message['header']['bcc']['content'] = trim(htmlentities($header->bccaddress, ENT_COMPAT, 'UTF-8'));
         }
         if (isset($header->reply_to)) {
             $message['header']['reply_to'] = $header->reply_toaddress;
         }
     } else {
         //no exist un mensaje con dicho uid
         $this->errMsg = _tr('Messages does not exist');
         return false;
     }
     //leemos el mensaje en si
     $pMessage = new paloImapMessage($this->connection, $uid, $this->mailbox);
     $pMessage->imapReadMesg();
     $message['attachment'] = $pMessage->getAttachments();
     $message['body'] = $pMessage->getBody();
     return $message;
 }