Ejemplo n.º 1
0
function aff_mail($servr, $user, $passwd, $folder, $mail, $verbose, $lang, $sort, $sortdir)
{
    $mailhost = $servr;
    require 'conf.php';
    require 'check_lang.php';
    global $attach_tab;
    //	GLOBAL $PHP_SELF;
    $glob_body = '';
    $subject = $from = $to = $cc = '';
    if (setlocale(LC_TIME, $lang_locale) != $lang_locale) {
        $default_date_format = $no_locale_date_format;
    }
    $current_date = strftime($default_date_format, time());
    $pop = @imap_open('{' . $mailhost . '}' . $folder, $user, $passwd);
    // Finding the next and previous message number
    $sorted = imap_sort($pop, $sort, $sortdir);
    for ($i = 0; $i < sizeof($sorted); $i++) {
        if ($mail == $sorted[$i]) {
            $prev_msg = $sorted[$i - 1];
            $next_msg = $sorted[$i + 1];
            break;
        }
    }
    // END finding the next and previous message number
    $num_messages = @imap_num_msg($pop);
    $ref_contenu_message = @imap_header($pop, $mail);
    $struct_msg = @imap_fetchstructure($pop, $mail);
    if (sizeof($struct_msg->parts) > 0) {
        GetPart($struct_msg, NULL, $display_rfc822);
    } else {
        GetSinglePart($struct_msg, htmlspecialchars(imap_fetchheader($pop, $mail)), @imap_body($pop, $mail));
    }
    if ($verbose == 1 && $use_verbose == 1) {
        $header = htmlspecialchars(imap_fetchheader($pop, $mail));
    } else {
        $header = '';
    }
    $tmp = array_pop($attach_tab);
    if (preg_match('/text/html/i', $tmp['mime']) || preg_match('/text/plain/i', $tmp['mime'])) {
        if ($tmp['transfer'] == 'QUOTED-PRINTABLE') {
            $glob_body = imap_qprint(imap_fetchbody($pop, $mail, $tmp['number']));
        } elseif ($tmp['transfer'] == 'BASE64') {
            $glob_body = base64_decode(imap_fetchbody($pop, $mail, $tmp['number']));
        } else {
            $glob_body = imap_fetchbody($pop, $mail, $tmp['number']);
        }
        $glob_body = remove_stuff($glob_body, $lang, $tmp['mime']);
    } else {
        array_push($attach_tab, $tmp);
    }
    @imap_close($pop);
    if ($struct_msg->subtype != 'ALTERNATIVE' && $struct_msg->subtype != 'RELATED') {
        switch (sizeof($attach_tab)) {
            case 0:
                $link_att = '';
                break;
            case 1:
                $link_att = '<tr><td align="right" valign="top" class="mail">' . $html_att . '</td><td bgcolor="' . $glob_theme->mail_properties . '" class="mail">' . link_att($mailhost, $mail, $attach_tab, $display_part_no) . '</td></tr>';
                break;
            default:
                $link_att = '<tr><td align="right" valign="top" class="mail">' . $html_atts . '</td><td bgcolor="' . $glob_theme->mail_properties . '" class="mail">' . link_att($mailhost, $mail, $attach_tab, $display_part_no) . '</td></tr>';
                break;
        }
    }
    $subject_array = imap_mime_header_decode($ref_contenu_message->subject);
    for ($j = 0; $j < count($subject_array); $j++) {
        $subject .= $subject_array[$j]->text;
    }
    $from_array = imap_mime_header_decode($ref_contenu_message->fromaddress);
    for ($j = 0; $j < count($from_array); $j++) {
        $from .= $from_array[$j]->text;
    }
    $to_array = imap_mime_header_decode($ref_contenu_message->toaddress);
    for ($j = 0; $j < count($to_array); $j++) {
        $to .= $to_array[$j]->text;
    }
    $cc_array = imap_mime_header_decode($ref_contenu_message->ccaddress);
    for ($j = 0; $j < count($cc_array); $j++) {
        $cc .= $cc_array[$j]->text;
    }
    $content = array('from' => htmlspecialchars($from), 'to' => htmlspecialchars($to), 'cc' => htmlspecialchars($cc), 'subject' => htmlspecialchars($subject), 'date' => change_date(chop($ref_contenu_message->udate), $lang), 'att' => $link_att, 'body' => $glob_body, 'body_mime' => $tmp['mime'], 'body_transfer' => $tmp['transfer'], 'header' => $header, 'verbose' => $verbose, 'prev' => $prev_msg, 'next' => $next_msg);
    return $content;
}
Ejemplo n.º 2
0
 function load_mail($attach_tab)
 {
     // parse the message
     global $default_charset;
     $ref_contenu_message = @imap_headerinfo($this->mbox, $this->mailid);
     $struct_msg = @imap_fetchstructure($this->mbox, $this->mailid);
     $mail = $this->mbox;
     $ev = $this->mailid;
     $conf->display_rfc822 = true;
     if ($struct_msg->type == 3 || isset($struct_msg->parts) && sizeof($struct_msg->parts) > 0) {
         $this->GetPart($attach_tab, $struct_msg, NULL, $conf->display_rfc822);
     } else {
         $pop_fetchheader_mail_ev = @imap_fetchheader($mail, $ev);
         $pop_body_mail_ev = @imap_body($mail, $ev);
         GetSinglePart($attach_tab, $struct_msg, $pop_fetchheader_mail_ev, $pop_body_mail_ev);
     }
     $conf->use_verbose = true;
     $header = "";
     if ($verbose == 1 && $conf->use_verbose == true) {
         $header = imap_fetchheader($mail, $ev);
     }
     $tmpvar = array_pop($attach_tab);
     if ($struct_msg->type == 3) {
         $body = '';
     } else {
         $body = @imap_fetchbody($mail, $ev, $tmpvar['number']);
     }
     if (eregi('text/html', $tmpvar['mime']) || eregi('text/plain', $tmpvar['mime'])) {
         if ($tmpvar['transfer'] == 'QUOTED-PRINTABLE') {
             $body = imap_qprint($body);
         }
         if ($tmpvar['transfer'] == 'BASE64') {
             $body = base64_decode($body);
         }
         $body = remove_stuff($body, $tmpvar['mime']);
         $body_charset = $tmpvar['charset'] == "default" ? $this->detect_charset($body) : $tmpvar['charset'];
         if (strtolower($body_charset) == "us-ascii") {
             $body_charset = "UTF-8";
         }
         if ($body_charset == "" || $body_charset == null) {
             if (isset($conf->default_charset) && $conf->default_charset != "") {
                 $body_charset = $conf->default_charset;
             } else {
                 $body_charset = "UTF-8";
             }
         }
         if (isset($_REQUEST['user_charset']) && $_REQUEST['user_charset'] != '') {
             $body_charset = $_REQUEST['user_charset'];
         }
         $this->charsets = $body_charset;
         if (empty($GLOBALS['charset'])) {
             $GLOBALS['charset'] = $default_charset;
         }
         $body_converted = function_exists(iconv) ? @iconv($body_charset, $GLOBALS['charset'], $body) : $body;
         $body = $body_converted === FALSE ? $body : $body_converted;
         $tmpvar['charset'] = $body_converted === FALSE ? $body_charset : $GLOBALS['charset'];
     } else {
         array_push($attach_tab, $tmpvar);
     }
     $link_att = '';
     $att_links = '';
     //variable added to display the attachments in full email view
     $conf->display_part_no = true;
     if ($struct_msg->subtype != 'ALTERNATIVE' || $struct_msg->subtype != 'RELATED') {
         switch (sizeof($attach_tab)) {
             case 0:
                 $link_att = '<span id="webmail_cont" style="display:none;"><tr><th class="mailHeaderLabel right"></th><td class="mailHeaderData"></td></tr></span>';
                 break;
             case 1:
                 $link_att = '<span id="webmail_cont" style="display:none;"><tr><th class="mailHeaderLabel right">' . $html_att . ':</th><td class="mailHeaderData">' . $this->link_att($mail, $attach_tab, $conf->display_part_no, $ev) . '</td></tr></span>';
                 $this->att_links .= $this->link_att($mail, $attach_tab, $conf->display_part_no, $ev) . "</br>";
                 break;
             default:
                 $link_att = '<span id="webmail_cont" style="display:none;"><tr><th class="mailHeaderLabel right">' . $html_atts . ':</th><td class="mailHeaderData">' . $this->link_att($mail, $attach_tab, $conf->display_part_no, $ev) . '</td></tr></span>';
                 $this->att_links .= $this->link_att($mail, $attach_tab, $conf->display_part_no, $ev) . "</br>";
                 break;
         }
     } else {
         $link_att = '<span id="webmail_cont" style="display:none;"><tr><th class="mailHeaderLabel right"></th><td class="mailHeaderData"></td></tr></span>';
     }
     $struct_msg = @imap_fetchstructure($mail, $ev);
     $msg_charset = '';
     if ($struct_msg->ifparameters) {
         while ($obj = array_pop($struct_msg->parameters)) {
             if (strtolower($obj->attribute) == 'charset') {
                 $msg_charset = $obj->value;
                 break;
             }
         }
     }
     if ($msg_charset == '') {
         $msg_charset = 'UTF-8';
     }
     $subject_header = str_replace('x-unknown', $msg_charset, $ref_contenu_message->subject);
     $subject_array = $this->mime_header_decode($subject_header);
     for ($j = 0; $j < count($subject_array); $j++) {
         $subject .= $subject_array[$j]->text;
     }
     $from_header = str_replace('x-unknown', $msg_charset, $ref_contenu_message->fromaddress);
     $from_array = $this->mime_header_decode($from_header);
     for ($j = 0; $j < count($from_array); $j++) {
         $from .= $from_array[$j]->text;
     }
     //fixed the issue #3235
     $toheader = @imap_fetchheader($this->mbox, $this->mailid);
     $to_arr = explode("To:", $toheader);
     if (!stripos($to_arr[1], 'mime')) {
         $to_add = stripos($to_arr[1], "CC:") ? explode("CC:", $to_arr[1]) : explode("Subject:", $to_arr[1]);
         $to_header = trim($to_add[0]);
     } else {
         $to_header = str_replace('x-unknown', $msg_charset, $ref_contenu_message->toaddress);
     }
     $to_array = $this->mime_header_decode($to_header);
     for ($j = 0; $j < count($to_array); $j++) {
         $to .= $to_array[$j]->text;
     }
     $to = str_replace(',', ', ', $to);
     $this->to_header = $to_header;
     $cc_header = isset($ref_contenu_message->ccaddress) ? $ref_contenu_message->ccaddress : '';
     $cc_header = str_replace('x-unknown', $msg_charset, $cc_header);
     $cc_array = isset($ref_contenu_message->ccaddress) ? imap_mime_header_decode($cc_header) : 0;
     if ($cc_array != 0) {
         for ($j = 0; $j < count($cc_array); $j++) {
             $cc .= $cc_array[$j]->text;
         }
     }
     $cc = str_replace(',', ', ', $cc);
     $this->cc_header = $cc_header;
     $reply_to_header = isset($ref_contenu_message->reply_toaddress) ? $ref_contenu_message->reply_toaddress : '';
     $reply_to_header = str_replace('x-unknown', $msg_charset, $reply_to_header);
     $reply_to_array = isset($ref_contenu_message->reply_toaddress) ? imap_mime_header_decode($reply_to_header) : 0;
     if ($reply_to_array != 0) {
         for ($j = 0; $j < count($reply_to_array); $j++) {
             $reply_to .= $reply_to_array[$j]->text;
         }
     }
     $timestamp = chop($ref_contenu_message->udate);
     $date = format_date($timestamp, $lang);
     $time = format_time($timestamp, $lang);
     $content = array('from' => $from, 'to' => $to, 'cc' => $cc, 'reply_to' => $reply_to, 'subject' => $subject, 'date' => $date, 'time' => $time, 'complete_date' => $date, 'att' => $link_att, 'body' => $this->graphicalsmilies($body), 'body_mime' => $this->convertLang2Html($tmpvar['mime']), 'body_transfer' => $this->convertLang2Html($tmpvar['transfer']), 'header' => $header, 'verbose' => $verbose, 'prev' => $prev_msg, 'next' => $next_msg, 'msgnum' => $mail, 'attachtab' => $attach_tab, 'charset' => $body_charset);
     return $content;
 }