Exemplo n.º 1
0
$mail_id = CValue::get("mail_id");
$part = CValue::get("part");
$log_pop = new CSourcePOP();
$log_pop->name = "user-pop-" . $user->_id;
$log_pop->loadMatchingObject();
if (!$log_pop) {
    CAppUI::stepAjax("Source POP indisponible", UI_MSG_ERROR);
}
if (!$mail_id) {
    CAppUI::stepAjax("CSourcePOP-error-mail_id", UI_MSG_ERROR);
}
$mail = new CUserMail();
$mail->load($mail_id);
if ($mail->_id) {
    $pop = new CPop($log_pop);
    $pop->open();
    $attach = new CMailAttachments();
    $struct = $pop->structure($mail->uid);
    $parts = explode(".", $part);
    //recursive parts
    foreach ($parts as $key => $value) {
        $struct = $struct->parts[$value];
    }
    $attach->loadFromHeader($struct);
    $attach->part = $part;
    $attach->loadContentFromPop($pop->openPart($mail->uid, $attach->getpartDL()));
    $smarty = new CSmartyDP();
    $smarty->assign("_attachment", $attach);
    $smarty->display("inc_show_attachments.tpl");
    $pop->close();
}
Exemplo n.º 2
0
 /**
  * Get the attachments of a mail_id
  *
  * @param int  $mail_id     id of the mail (warning, UID and not ID)
  * @param bool $structure   structure
  * @param bool $part_number part number
  * @param bool $part_temp   part for get the part later
  *
  * @return CMailAttachments[]
  */
 function getListAttachments($mail_id, $structure = false, $part_number = false, $part_temp = false)
 {
     if (!$structure) {
         $structure = $this->structure($mail_id);
     }
     if ($structure) {
         if (!isset($structure->parts) && !$part_number) {
             //plain text only, no recursive
             $part_number = "1";
         }
         if (!$part_number) {
             $part_number = "0";
         }
         switch ($structure->type) {
             //multipart, alternatived
             case 1:
                 while (list($index, $sub_structure) = each($structure->parts)) {
                     if ($part_number !== false) {
                         $prefix = $part_number . '.';
                     } else {
                         $prefix = null;
                     }
                     if ($part_temp !== false) {
                         $prefix_temp = $part_temp . '.';
                     } else {
                         $prefix_temp = null;
                     }
                     self::getListAttachments($mail_id, $sub_structure, $prefix . ($index + 1), $prefix_temp . $index);
                 }
                 break;
                 // text
             // text
             case 0:
             case 2:
                 //message
             //message
             case 3:
                 //application
             //application
             case 4:
                 //audio
             //audio
             case 5:
                 //images
             //images
             case 6:
                 //video
                 $attach = new CMailAttachments();
                 $attach->loadFromHeader($structure);
                 if ($attach->name) {
                     $attach->part = $part_temp;
                     //inline attachments
                     $this->content["attachments"][] = $attach;
                 }
                 break;
             default:
                 //other
         }
     }
     return $this->content["attachments"];
 }