예제 #1
0
/**
 * This returns a parsed string called $body. That string can then
 * be displayed as the actual message in the HTML. It contains
 * everything needed, including HTML Tags, Attachments at the
 * bottom, etc.
 */
function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $mailbox = 'INBOX', $clean = false)
{
    /* This if statement checks for the entity to show as the
     * primary message. To add more of them, just put them in the
     * order that is their priority.
     */
    global $startMessage, $languages, $squirrelmail_language, $show_html_default, $sort, $has_unsafe_images, $passed_ent_id, $username, $key, $imapServerAddress, $imapPort, $download_and_unsafe_link;
    if (!sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET)) {
        $view_unsafe_images = false;
    }
    $body = '';
    $urlmailbox = urlencode($mailbox);
    $body_message = getEntity($message, $ent_num);
    if ($body_message->header->type0 == 'text' || $body_message->header->type0 == 'rfc822') {
        $body = mime_fetch_body($imap_stream, $id, $ent_num);
        $body = decodeBody($body, $body_message->header->encoding);
        if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
            if (mb_detect_encoding($body) != 'ASCII') {
                $body = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $body);
            }
        }
        $hookResults = do_hook("message_body", $body);
        $body = $hookResults[1];
        /* If there are other types that shouldn't be formatted, add
         * them here.
         */
        if ($body_message->header->type1 == 'html') {
            if ($show_html_default != 1) {
                $entity_conv = array('&nbsp;' => ' ', '<p>' => "\n", '<P>' => "\n", '<br>' => "\n", '<BR>' => "\n", '<br />' => "\n", '<BR />' => "\n", '&gt;' => '>', '&lt;' => '<');
                $body = strtr($body, $entity_conv);
                $body = strip_tags($body);
                $body = trim($body);
                translateText($body, $wrap_at, $body_message->header->getParameter('charset'));
            } else {
                $charset = $body_message->header->getParameter('charset');
                if (!empty($charset)) {
                    $body = charset_decode($charset, $body, false, true);
                }
                $body = magicHTML($body, $id, $message, $mailbox);
            }
        } else {
            translateText($body, $wrap_at, $body_message->header->getParameter('charset'));
        }
        // if this is the clean display (i.e. printer friendly), stop here.
        if ($clean) {
            return $body;
        }
        $download_and_unsafe_link = '';
        $link = 'passed_id=' . $id . '&amp;ent_id=' . $ent_num . '&amp;mailbox=' . $urlmailbox . '&amp;sort=' . $sort . '&amp;startMessage=' . $startMessage . '&amp;show_more=0';
        if (isset($passed_ent_id)) {
            $link .= '&amp;passed_ent_id=' . $passed_ent_id;
        }
        $download_and_unsafe_link .= '&nbsp;|&nbsp;<a href="download.php?absolute_dl=true&amp;' . $link . '">' . _("Download this as a file") . '</a>';
        if ($view_unsafe_images) {
            $text = _("Hide Unsafe Images");
        } else {
            if (isset($has_unsafe_images) && $has_unsafe_images) {
                $link .= '&amp;view_unsafe_images=1';
                $text = _("View Unsafe Images");
            } else {
                $text = '';
            }
        }
        if ($text != '') {
            $download_and_unsafe_link .= '&nbsp;|&nbsp;<a href="read_body.php?' . $link . '">' . $text . '</a>';
        }
    }
    return $body;
}
예제 #2
0
$message =& $messages[$mbx_response['UIDVALIDITY']][$passed_id];
$message_ent = $message->getEntity($ent_id);
if ($passed_ent_id) {
    $message =& $message->getEntity($passed_ent_id);
}
$header = $message_ent->header;
$type0 = $header->type0;
$type1 = $header->type1;
$charset = $header->getParameter('charset');
$encoding = strtolower($header->encoding);
$msg_url = 'read_body.php?' . $QUERY_STRING;
$msg_url = set_url_var($msg_url, 'ent_id', 0);
$dwnld_url = '../src/download.php?' . $QUERY_STRING . '&amp;absolute_dl=true';
$unsafe_url = 'view_text.php?' . $QUERY_STRING;
$unsafe_url = set_url_var($unsafe_url, 'view_unsafe_images', 1);
$body = mime_fetch_body($imapConnection, $passed_id, $ent_id);
$body = decodeBody($body, $encoding);
if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
    if (mb_detect_encoding($body) != 'ASCII') {
        $body = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $body);
    }
}
if ($type1 == 'html' || isset($override_type1) && $override_type1 == 'html') {
    $ishtml = TRUE;
    // html attachment with character set information
    if (!empty($charset)) {
        $body = charset_decode($charset, $body, false, true);
    }
    $body = magicHTML($body, $passed_id, $message, $mailbox);
} else {
    $ishtml = FALSE;
예제 #3
0
function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection)
{
    global $attachment_dir, $username, $data_dir, $squirrelmail_language;
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    if (!count($message->entities) || $message->type0 == 'message' && $message->type1 == 'rfc822') {
        if (!in_array($message->entity_id, $entities) && $message->entity_id) {
            switch ($message->type0) {
                case 'message':
                    if ($message->type1 == 'rfc822') {
                        $filename = $message->rfc822_header->subject;
                        if ($filename == "") {
                            $filename = "untitled-" . $message->entity_id;
                        }
                        $filename .= '.msg';
                    } else {
                        $filename = $message->getFilename();
                    }
                    break;
                default:
                    if (!$message->mime_header) {
                        /* temporary hack */
                        $message->mime_header = $message->header;
                    }
                    $filename = $message->getFilename();
                    break;
            }
            $filename = str_replace('&#32;', ' ', decodeHeader($filename));
            if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) {
                $filename = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $filename);
            }
            $localfilename = GenerateRandomString(32, '', 7);
            $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
            while (file_exists($full_localfilename)) {
                $localfilename = GenerateRandomString(32, '', 7);
                $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
            }
            $message->att_local_name = $full_localfilename;
            $composeMessage->initAttachment($message->type0 . '/' . $message->type1, $filename, $full_localfilename);
            /* Write Attachment to file */
            $fp = fopen("{$hashed_attachment_dir}/{$localfilename}", 'wb');
            fputs($fp, decodeBody(mime_fetch_body($imapConnection, $passed_id, $message->entity_id), $message->header->encoding));
            fclose($fp);
        }
    } else {
        for ($i = 0, $entCount = count($message->entities); $i < $entCount; $i++) {
            $composeMessage = getAttachments($message->entities[$i], $composeMessage, $passed_id, $entities, $imapConnection);
        }
    }
    return $composeMessage;
}
예제 #4
0
파일: spamcop.php 프로젝트: jprice/EHCP
    ?>
" />
  <input type="hidden" name="send_to" value="<?php 
    echo htmlspecialchars($report_email);
    ?>
" />
  <input type="hidden" name="subject" value="reply anyway" />
  <input type="hidden" name="identity" value="0" />
  <input type="hidden" name="session" value="<?php 
    echo $session;
    ?>
" />
<?php 
    echo '<input type="submit" name="send" value="' . _("Send Spam Report") . "\" />\n";
} else {
    $spam_message = mime_fetch_body($imap_stream, $passed_id, $passed_ent_id, 50000);
    if (strlen($spam_message) == 50000) {
        $Warning = "\n[truncated by SpamCop]\n";
        $spam_message = substr($spam_message, 0, 50000 - strlen($Warning)) . $Warning;
    }
    if (isset($js_web) && $js_web) {
        ?>
  <form method="post" action="http://members.spamcop.net/sc" name="submitspam"
    enctype="multipart/form-data"><?php 
    } else {
        ?>
  <form method="post" action="http://members.spamcop.net/sc" name="submitspam"
    enctype="multipart/form-data" target="_top"><?php 
    }
    ?>
  <input type="hidden" name="action" value="submit" />
예제 #5
0
echo $color[0];
?>
">
   <b><center>
<?php 
echo _("Viewing a Business Card") . " - ";
if (isset($where) && isset($what)) {
    // from a search
    echo "<a href=\"../../src/read_body.php?mailbox=" . urlencode($mailbox) . "&passed_id={$passed_id}&where=" . urlencode($where) . "&what=" . urlencode($what) . "\">" . _("View message") . "</a>";
} else {
    echo "<a href=\"../../src/read_body.php?mailbox=" . urlencode($mailbox) . "&passed_id={$passed_id}&startMessage={$startMessage}&show_more=0\">" . _("View message") . "</a>";
}
echo "</center></b></td></tr>";
$message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
$entity_vcard = getEntity($message, $passed_ent_id);
$vcard = mime_fetch_body($imapConnection, $passed_id, $passed_ent_id);
$vcard = decodeBody($vcard, $entity_vcard->header->encoding);
$vcard = explode("\n", $vcard);
foreach ($vcard as $l) {
    $k = substr($l, 0, strpos($l, ':'));
    $v = substr($l, strpos($l, ':') + 1);
    $attributes = explode(';', $k);
    $k = strtolower(array_shift($attributes));
    foreach ($attributes as $attr) {
        if ($attr == "quoted-printable") {
            $v = quoted_printable_decode($v);
        } else {
            $k .= ';' . $attr;
        }
    }
    $v = ereg_replace(';', "\n", $v);
예제 #6
0
$imap_stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
$mbx_response = sqimap_mailbox_select($imap_stream, $mailbox);
$message =& $messages[$mbx_response['UIDVALIDITY']][$passed_id];
if (!is_object($message)) {
    $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
}
$message_ent = $message->getEntity($ent_id);
if ($passed_ent_id) {
    $message = $message->getEntity($passed_ent_id);
}
$header = $message_ent->header;
$type0 = $header->type0;
$type1 = $header->type1;
$charset = $header->getParameter('charset');
$encoding = strtolower($header->encoding);
$body = mime_fetch_body($imap_stream, $passed_id, $ent_id);
$body = decodeBody($body, $encoding);
do_hook('message_body', $body);
/**
 * TODO: check if xtra_code is needed.
if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
    function_exists($languages[$squirrelmail_language]['XTRA_CODE'].'_decode')) {
    if (mb_detect_encoding($body) != 'ASCII') {
        $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $body);
    }
}
*/
/** TODO: provide reduced version of MagicHTML() */
$body = MagicHTML($body, $passed_id, $message, $mailbox);
/** TODO: charset might be part of html code. */
header('Content-Type: text/html; charset=' . $charset);
예제 #7
0
function newMail($mailbox = '', $passed_id = '', $passed_ent_id = '', $action = '', $session = '')
{
    global $editor_size, $default_use_priority, $body, $idents, $use_signature, $data_dir, $username, $key, $imapServerAddress, $imapPort, $imap_stream_options, $composeMessage, $body_quote, $request_mdn, $request_dr, $mdn_user_support, $languages, $squirrelmail_language, $default_charset, $do_not_reply_to_self;
    /*
     * Set $default_charset to correspond with the user's selection
     * of language interface. $default_charset global is not correct,
     * if message is composed in new window.
     */
    set_my_charset();
    $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
    $mailprio = 3;
    if ($passed_id) {
        $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
        sqimap_mailbox_select($imapConnection, $mailbox);
        $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
        $body = '';
        if ($passed_ent_id) {
            /* redefine the messsage in case of message/rfc822 */
            $message = $message->getEntity($passed_ent_id);
            /* message is an entity which contains the envelope and type0=message
             * and type1=rfc822. The actual entities are childs from
             * $message->entities[0]. That's where the encoding and is located
             */
            $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain'));
            if (!count($entities)) {
                $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain', 'text/html'));
            }
            $orig_header = $message->rfc822_header;
            /* here is the envelope located */
            /* redefine the message for picking up the attachments */
            $message = $message->entities[0];
        } else {
            $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain'));
            if (!count($entities)) {
                $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain', 'text/html'));
            }
            $orig_header = $message->rfc822_header;
        }
        $type0 = $message->type0;
        $type1 = $message->type1;
        foreach ($entities as $ent) {
            $msg = $message->getEntity($ent);
            $type0 = $msg->type0;
            $type1 = $msg->type1;
            $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
            $body_part_entity = $message->getEntity($ent);
            $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding);
            if ($type1 == 'html') {
                $bodypart = str_replace("\n", ' ', $bodypart);
                $bodypart = preg_replace(array('/<\\/?p>/i', '/<div><\\/div>/i', '/<br\\s*(\\/)*>/i', '/<\\/?div>/i'), "\n", $bodypart);
                $bodypart = str_replace(array('&nbsp;', '&gt;', '&lt;'), array(' ', '>', '<'), $bodypart);
                $bodypart = strip_tags($bodypart);
            }
            if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
                if (mb_detect_encoding($bodypart) != 'ASCII') {
                    $bodypart = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $bodypart);
                }
            }
            // charset encoding in compose form stuff
            if (isset($body_part_entity->header->parameters['charset'])) {
                $actual = $body_part_entity->header->parameters['charset'];
            } else {
                $actual = 'us-ascii';
            }
            if ($actual && is_conversion_safe($actual) && $actual != $default_charset) {
                $bodypart = charset_convert($actual, $bodypart, $default_charset, false);
            }
            // end of charset encoding in compose
            $body .= $bodypart;
        }
        if ($default_use_priority) {
            $mailprio = substr($orig_header->priority, 0, 1);
            if (!$mailprio) {
                $mailprio = 3;
            }
        } else {
            $mailprio = '';
        }
        $from_o = $orig_header->from;
        if (is_array($from_o)) {
            if (isset($from_o[0])) {
                $from_o = $from_o[0];
            }
        }
        if (is_object($from_o)) {
            $orig_from = $from_o->getAddress();
        } else {
            $orig_from = '';
        }
        $identities = array();
        if (count($idents) > 1) {
            foreach ($idents as $nr => $data) {
                $enc_from_name = '"' . $data['full_name'] . '" <' . $data['email_address'] . '>';
                $identities[] = $enc_from_name;
            }
            $identity_match = $orig_header->findAddress($identities);
            if ($identity_match !== FALSE) {
                $identity = $identity_match;
            }
        }
        switch ($action) {
            case 'draft':
                $use_signature = FALSE;
                $composeMessage->rfc822_header = $orig_header;
                $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true);
                $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true);
                $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true);
                $send_from = $orig_header->getAddr_s('from');
                $send_from_parts = new AddressStructure();
                $send_from_parts = $orig_header->parseAddress($send_from);
                $send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host;
                $identity = find_identity(array($send_from_add));
                $subject = decodeHeader($orig_header->subject, false, false, true);
                // Remember the receipt settings
                $request_mdn = $mdn_user_support && !empty($orig_header->dnt) ? '1' : '0';
                $request_dr = $mdn_user_support && !empty($orig_header->drnt) ? '1' : '0';
                /* remember the references and in-reply-to headers in case of an reply */
                //FIXME: it would be better to fiddle with headers inside of the message object or possibly when delivering the message to its destination (drafts folder?); is this possible?
                $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references;
                $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to;
                // rewrap the body to clean up quotations and line lengths
                sqBodyWrap($body, $editor_size);
                $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
                break;
            case 'edit_as_new':
                $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true);
                $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true);
                $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true);
                $subject = decodeHeader($orig_header->subject, false, false, true);
                $mailprio = $orig_header->priority;
                $orig_from = '';
                $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
                // rewrap the body to clean up quotations and line lengths
                sqBodyWrap($body, $editor_size);
                break;
            case 'forward':
                $send_to = '';
                $subject = getforwardSubject(decodeHeader($orig_header->subject, false, false, true));
                $body = getforwardHeader($orig_header) . $body;
                // the logic for calling sqUnWordWrap here would be to allow the browser to wrap the lines
                // forwarded message text should be as undisturbed as possible, so commenting out this call
                // sqUnWordWrap($body);
                $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
                //add a blank line after the forward headers
                $body = "\n" . $body;
                break;
            case 'forward_as_attachment':
                $subject = getforwardSubject(decodeHeader($orig_header->subject, false, false, true));
                $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
                $subject = decodeHeader($orig_header->subject, false, false, true);
                $subject = str_replace('"', "'", $subject);
                $subject = trim($subject);
                if (substr(strtolower($subject), 0, 4) != 'fwd:') {
                    $subject = 'Fwd: ' . $subject;
                }
                $body = '';
                break;
            case 'reply_all':
                if (isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) {
                    $send_to = $orig_header->getAddr_s('mail_followup_to');
                } else {
                    $send_to_cc = replyAllString($orig_header);
                    $send_to_cc = decodeHeader($send_to_cc, false, false, true);
                    $send_to_cc = str_replace('""', '"', $send_to_cc);
                }
            case 'reply':
                // skip this if send_to was already set right above here
                if (!$send_to) {
                    $send_to = $orig_header->reply_to;
                    if (is_array($send_to) && count($send_to)) {
                        $send_to = $orig_header->getAddr_s('reply_to', ',', FALSE, TRUE);
                    } else {
                        if (is_object($send_to)) {
                            /* unneccesarry, just for failsafe purpose */
                            $send_to = $orig_header->getAddr_s('reply_to', ',', FALSE, TRUE);
                        } else {
                            $send_to = $orig_header->getAddr_s('from', ',', FALSE, TRUE);
                        }
                    }
                }
                $send_to = decodeHeader($send_to, false, false, true);
                $send_to = str_replace('""', '"', $send_to);
                // If user doesn't want replies to her own messages
                // going back to herself (instead send again to the
                // original recipient of the message being replied to),
                // then iterate through identities, checking if the TO
                // field is one of them (if the reply is to ourselves)
                //
                // Note we don't bother if the original message doesn't
                // have anything in the TO field itself (because that's
                // what we use if we change the recipient to be that of
                // the previous message)
                //
                if ($do_not_reply_to_self && !empty($orig_header->to)) {
                    $orig_to = '';
                    foreach ($idents as $id) {
                        if (!empty($id['email_address']) && strpos($send_to, $id['email_address']) !== FALSE) {
                            // if this is a reply-all, the original recipient
                            // is already in the CC field, so we can just blank
                            // the recipient (TO field) (as long as the CC field
                            // isn't empty that is)... but then move the CC into
                            // the TO, so TO isn't empty
                            //
                            if ($action == 'reply_all' && !empty($send_to_cc)) {
                                $orig_to = $send_to_cc;
                                $send_to_cc = '';
                                break;
                            }
                            $orig_to = $orig_header->to;
                            if (is_array($orig_to) && count($orig_to)) {
                                $orig_to = $orig_header->getAddr_s('to', ',', FALSE, TRUE);
                            } else {
                                if (is_object($orig_to)) {
                                    /* unneccesarry, just for failsafe purpose */
                                    $orig_to = $orig_header->getAddr_s('to', ',', FALSE, TRUE);
                                } else {
                                    $orig_to = '';
                                }
                            }
                            $orig_to = decodeHeader($orig_to, false, false, true);
                            $orig_to = str_replace('""', '"', $orig_to);
                            break;
                        }
                    }
                    // if the reply was addressed back to ourselves,
                    // we will send it to the TO of the previous message
                    //
                    if (!empty($orig_to)) {
                        $send_to = $orig_to;
                        // in this case, we also want to reset the FROM
                        // identity as well (it should match the original
                        // *FROM* header instead of TO or CC)
                        //
                        if (count($idents) > 1) {
                            $identity = '';
                            foreach ($idents as $i => $id) {
                                if (!empty($id['email_address']) && strpos($orig_from, $id['email_address']) !== FALSE) {
                                    $identity = $i;
                                    break;
                                }
                            }
                        }
                    }
                }
                $subject = decodeHeader($orig_header->subject, false, false, true);
                $subject = str_replace('"', "'", $subject);
                $subject = trim($subject);
                if (substr(strtolower($subject), 0, 3) != 're:') {
                    $subject = 'Re: ' . $subject;
                }
                /* this corrects some wrapping/quoting problems on replies */
                $rewrap_body = explode("\n", $body);
                $from = is_array($orig_header->from) && !empty($orig_header->from) ? $orig_header->from[0] : $orig_header->from;
                $body = '';
                $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
                foreach ($rewrap_body as $line) {
                    if ($strip_sigs && rtrim($line, "\r\n") == '-- ') {
                        break;
                    }
                    if (preg_match("/^(>+)/", $line, $matches)) {
                        $gt = $matches[1];
                        $body .= $body_quote . str_replace("\n", "\n{$body_quote}{$gt} ", rtrim($line)) . "\n";
                    } else {
                        $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n{$body_quote}" . (!empty($body_quote) ? ' ' : ''), rtrim($line)) . "\n";
                    }
                }
                //rewrap the body to clean up quotations and line lengths
                $body = sqBodyWrap($body, $editor_size);
                $body = getReplyCitation($from, $orig_header->date) . $body;
                $composeMessage->reply_rfc822_header = $orig_header;
                break;
            default:
                break;
        }
        //FIXME: we used to register $compose_messages in the session here, but not any more - so do we still need the session_write_close() and sqimap_logout() here?  We probably need the IMAP logout, but what about the session closure?
        session_write_close();
        sqimap_logout($imapConnection);
    }
    $ret = array('send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity);
    return $ret;
}
예제 #8
0
function newMail($mailbox = '', $passed_id = '', $passed_ent_id = '', $action = '', $session = '')
{
    global $editor_size, $default_use_priority, $body, $idents, $use_signature, $composesession, $data_dir, $username, $username, $key, $imapServerAddress, $imapPort, $compose_messages, $composeMessage, $body_quote;
    global $languages, $squirrelmail_language, $default_charset;
    /*
     * Set $default_charset to correspond with the user's selection
     * of language interface. $default_charset global is not correct,
     * if message is composed in new window.
     */
    set_my_charset();
    $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
    $mailprio = 3;
    if ($passed_id) {
        $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
        sqimap_mailbox_select($imapConnection, $mailbox);
        $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
        $body = '';
        if ($passed_ent_id) {
            /* redefine the messsage in case of message/rfc822 */
            $message = $message->getEntity($passed_ent_id);
            /* message is an entity which contains the envelope and type0=message
             * and type1=rfc822. The actual entities are childs from
             * $message->entities[0]. That's where the encoding and is located
             */
            $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain'));
            if (!count($entities)) {
                $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain', 'html/plain'));
            }
            $orig_header = $message->rfc822_header;
            /* here is the envelope located */
            /* redefine the message for picking up the attachments */
            $message = $message->entities[0];
        } else {
            $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain'));
            if (!count($entities)) {
                $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain', 'html/plain'));
            }
            $orig_header = $message->rfc822_header;
        }
        $encoding = $message->header->encoding;
        $type0 = $message->type0;
        $type1 = $message->type1;
        foreach ($entities as $ent) {
            $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
            $body_part_entity = $message->getEntity($ent);
            $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding);
            if ($type1 == 'html') {
                $bodypart = str_replace("\n", ' ', $bodypart);
                $bodypart = preg_replace(array('/<p>/i', '/<br\\s*(\\/)*>/i'), "\n", $bodypart);
                $bodypart = str_replace(array('&nbsp;', '&gt;', '&lt;'), array(' ', '>', '<'), $bodypart);
                $bodypart = strip_tags($bodypart);
            }
            if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
                if (mb_detect_encoding($bodypart) != 'ASCII') {
                    $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
                }
            }
            // charset encoding in compose form stuff
            if (isset($body_part_entity->header->parameters['charset'])) {
                $actual = $body_part_entity->header->parameters['charset'];
            } else {
                $actual = 'us-ascii';
            }
            if ($actual && is_conversion_safe($actual) && $actual != $default_charset) {
                $bodypart = charset_convert($actual, $bodypart, $default_charset, false);
            }
            // end of charset encoding in compose
            $body .= $bodypart;
        }
        if ($default_use_priority) {
            $mailprio = substr($orig_header->priority, 0, 1);
            if (!$mailprio) {
                $mailprio = 3;
            }
        } else {
            $mailprio = '';
        }
        $identity = '';
        $from_o = $orig_header->from;
        if (is_array($from_o)) {
            if (isset($from_o[0])) {
                $from_o = $from_o[0];
            }
        }
        if (is_object($from_o)) {
            $orig_from = $from_o->getAddress();
        } else {
            $orig_from = '';
        }
        $identities = array();
        if (count($idents) > 1) {
            foreach ($idents as $nr => $data) {
                $enc_from_name = '"' . $data['full_name'] . '" <' . $data['email_address'] . '>';
                if ($enc_from_name == $orig_from) {
                    $identity = $nr;
                    break;
                }
                $identities[] = $enc_from_name;
            }
            $identity_match = $orig_header->findAddress($identities);
            if ($identity_match) {
                $identity = $identity_match;
            }
        }
        switch ($action) {
            case 'draft':
                $use_signature = FALSE;
                $composeMessage->rfc822_header = $orig_header;
                $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true);
                $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true);
                $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true);
                // FIXME: ident support?
                $subject = decodeHeader($orig_header->subject, false, false, true);
                /* remember the references and in-reply-to headers in case of an reply */
                $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references;
                $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to;
                $body_ary = explode("\n", $body);
                $cnt = count($body_ary);
                $body = '';
                for ($i = 0; $i < $cnt; $i++) {
                    if (!ereg("^[>\\s]*\$", $body_ary[$i]) || !$body_ary[$i]) {
                        sqWordWrap($body_ary[$i], $editor_size, $default_charset);
                        $body .= $body_ary[$i] . "\n";
                    }
                    unset($body_ary[$i]);
                }
                sqUnWordWrap($body);
                $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
                break;
            case 'edit_as_new':
                $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true);
                $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true);
                $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true);
                $subject = decodeHeader($orig_header->subject, false, false, true);
                $mailprio = $orig_header->priority;
                $orig_from = '';
                $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
                sqUnWordWrap($body);
                break;
            case 'forward':
                $send_to = '';
                $subject = decodeHeader($orig_header->subject, false, false, true);
                if (substr(strtolower($subject), 0, 4) != 'fwd:' && substr(strtolower($subject), 0, 5) != '[fwd:' && substr(strtolower($subject), 0, 6) != '[ fwd:') {
                    $subject = '[Fwd: ' . $subject . ']';
                }
                $body = getforwardHeader($orig_header) . $body;
                $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
                $body = "\n" . $body;
                break;
            case 'forward_as_attachment':
                $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
                $body = '';
                break;
            case 'reply_all':
                if (isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) {
                    $send_to = $orig_header->getAddr_s('mail_followup_to');
                } else {
                    $send_to_cc = replyAllString($orig_header);
                    $send_to_cc = decodeHeader($send_to_cc, false, false, true);
                }
            case 'reply':
                if (!$send_to) {
                    $send_to = $orig_header->reply_to;
                    if (is_array($send_to) && count($send_to)) {
                        $send_to = $orig_header->getAddr_s('reply_to');
                    } else {
                        if (is_object($send_to)) {
                            /* unneccesarry, just for failsafe purpose */
                            $send_to = $orig_header->getAddr_s('reply_to');
                        } else {
                            $send_to = $orig_header->getAddr_s('from');
                        }
                    }
                }
                $send_to = decodeHeader($send_to, false, false, true);
                $subject = decodeHeader($orig_header->subject, false, false, true);
                $subject = trim($subject);
                if (substr(strtolower($subject), 0, 3) != 're:') {
                    $subject = 'Re: ' . $subject;
                }
                /* this corrects some wrapping/quoting problems on replies */
                $rewrap_body = explode("\n", $body);
                $from = is_array($orig_header->from) && !empty($orig_header->from) ? $orig_header->from[0] : $orig_header->from;
                sqUnWordWrap($body);
                $body = '';
                $cnt = count($rewrap_body);
                for ($i = 0; $i < $cnt; $i++) {
                    sqWordWrap($rewrap_body[$i], $editor_size, $default_charset);
                    if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
                        $gt = $matches[1];
                        $body .= $body_quote . str_replace("\n", "\n" . $body_quote . "{$gt} ", rtrim($rewrap_body[$i])) . "\n";
                    } else {
                        $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n" . $body_quote . (!empty($body_quote) ? ' ' : ''), rtrim($rewrap_body[$i])) . "\n";
                    }
                    unset($rewrap_body[$i]);
                }
                $body = getReplyCitation($from, $orig_header->date) . $body;
                $composeMessage->reply_rfc822_header = $orig_header;
                break;
            default:
                break;
        }
        $compose_messages[$session] = $composeMessage;
        sqsession_register($compose_messages, 'compose_messages');
        session_write_close();
        sqimap_logout($imapConnection);
    }
    $ret = array('send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity);
    return $ret;
}
예제 #9
0
/**
 * This returns a parsed string called $body. That string can then
 * be displayed as the actual message in the HTML. It contains
 * everything needed, including HTML Tags, Attachments at the
 * bottom, etc.
 *
 * Since 1.2.0 function uses message_body hook.
 * Till 1.3.0 function included output of formatAttachments().
 *
 * @param resource $imap_stream imap connection resource
 * @param object $message squirrelmail message object
 * @param array $color squirrelmail color theme array
 * @param integer $wrap_at number of characters per line
 * @param string $ent_num (since 1.3.0) message part id
 * @param integer $id (since 1.3.0) message id
 * @param string $mailbox (since 1.3.0) imap folder name
 * @return string html formated message text
 */
function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $mailbox = 'INBOX')
{
    /* This if statement checks for the entity to show as the
     * primary message. To add more of them, just put them in the
     * order that is their priority.
     */
    global $startMessage, $languages, $squirrelmail_language, $show_html_default, $sort, $has_unsafe_images, $passed_ent_id, $use_iframe, $iframe_height, $download_and_unsafe_link, $download_href, $unsafe_image_toggle_href, $unsafe_image_toggle_text, $oTemplate, $nbsp;
    // workaround for not updated config.php
    if (!isset($use_iframe)) {
        $use_iframe = false;
    }
    // If there's no "view_unsafe_images" variable in the URL, turn unsafe
    // images off by default.
    sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET, FALSE);
    $body = '';
    $urlmailbox = urlencode($mailbox);
    $body_message = getEntity($message, $ent_num);
    if ($body_message->header->type0 == 'text' || $body_message->header->type0 == 'rfc822') {
        $body = mime_fetch_body($imap_stream, $id, $ent_num);
        $body = decodeBody($body, $body_message->header->encoding);
        if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
            if (mb_detect_encoding($body) != 'ASCII') {
                $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $body);
            }
        }
        /* As of 1.5.2, $body is passed (and modified) by reference */
        do_hook('message_body', $body);
        /* If there are other types that shouldn't be formatted, add
         * them here.
         */
        if ($body_message->header->type1 == 'html') {
            if ($show_html_default != 1) {
                $entity_conv = array('&nbsp;' => ' ', '<p>' => "\n", '<P>' => "\n", '<br>' => "\n", '<BR>' => "\n", '<br />' => "\n", '<BR />' => "\n", '&gt;' => '>', '&lt;' => '<');
                $body = strtr($body, $entity_conv);
                $body = strip_tags($body);
                $body = trim($body);
                translateText($body, $wrap_at, $body_message->header->getParameter('charset'));
            } elseif ($use_iframe) {
                /**
                 * If we don't add html message between iframe tags,
                 * we must detect unsafe images and modify $has_unsafe_images.
                 */
                $html_body = magicHTML($body, $id, $message, $mailbox);
                // Convert character set in order to display html mails in different character set
                $html_body = charset_decode($body_message->header->getParameter('charset'), $html_body, false, true);
                // creating iframe url
                $iframeurl = sqm_baseuri() . 'src/view_html.php?' . 'mailbox=' . $urlmailbox . '&amp;passed_id=' . $id . '&amp;ent_id=' . $ent_num . '&amp;view_unsafe_images=' . (int) $view_unsafe_images;
                global $oTemplate;
                $oTemplate->assign('iframe_url', $iframeurl);
                $oTemplate->assign('iframe_height', $iframe_height);
                $oTemplate->assign('html_body', $html_body);
                $body = $oTemplate->fetch('read_html_iframe.tpl');
            } else {
                // old way of html rendering
                /**
                 * convert character set. charset_decode does not remove html special chars
                 * applied by magicHTML functions and does not sanitize them second time if
                 * fourth argument is true.
                 */
                $charset = $body_message->header->getParameter('charset');
                if (!empty($charset)) {
                    $body = charset_decode($charset, $body, false, true);
                }
                $body = magicHTML($body, $id, $message, $mailbox);
            }
        } else {
            translateText($body, $wrap_at, $body_message->header->getParameter('charset'));
        }
        /*
         * Previously the links for downloading and unsafe images were printed
         * under the mail. By putting the links in a global variable we can
         * print it in the toolbar where it belongs. Since the original code was
         * in this place it's left here. It might be possible to move it to some
         * other place if that makes sense. The possibility to do so has not
         * been evaluated yet.
         */
        // Initialize the global variable to an empty string.
        // FIXME: To have $download_and_unsafe_link as a global variable might not be needed since the use of separate variables ($download_href, $unsafe_image_toggle_href, and $unsafe_image_toggle_text) for the templates was introduced.
        $download_and_unsafe_link = '';
        // Prepare and build a link for downloading the mail.
        $link = 'passed_id=' . $id . '&amp;ent_id=' . $ent_num . '&amp;mailbox=' . $urlmailbox . '&amp;sort=' . $sort . '&amp;startMessage=' . $startMessage . '&amp;show_more=0';
        if (isset($passed_ent_id)) {
            $link .= '&amp;passed_ent_id=' . $passed_ent_id;
        }
        $download_href = SM_PATH . 'src/download.php?absolute_dl=true&amp;' . $link;
        // Always add the link for downloading the mail as a file to the global
        // variable.
        $download_and_unsafe_link .= "{$nbsp}|{$nbsp}" . create_hyperlink($download_href, _("Download this as a file"));
        // Find out the right text to use in the link depending on the
        // circumstances. If the unsafe images are displayed the link should
        // hide them, if they aren't displayed the link should only appear if
        // the mail really contains unsafe images.
        if ($view_unsafe_images) {
            $text = _("Hide Unsafe Images");
        } else {
            if (isset($has_unsafe_images) && $has_unsafe_images) {
                $link .= '&amp;view_unsafe_images=1';
                $text = _("View Unsafe Images");
            } else {
                $text = '';
            }
        }
        // Only create a link for unsafe images if there's need for one. If so:
        // add it to the global variable.
        if ($text != '') {
            $unsafe_image_toggle_href = SM_PATH . 'src/read_body.php?' . $link;
            $unsafe_image_toggle_text = $text;
            $download_and_unsafe_link .= "{$nbsp}|{$nbsp}" . create_hyperlink($unsafe_image_toggle_href, $text);
        }
    }
    return $body;
}
예제 #10
0
파일: mime.php 프로젝트: jprice/EHCP
/**
 * This returns a parsed string called $body. That string can then
 * be displayed as the actual message in the HTML. It contains
 * everything needed, including HTML Tags, Attachments at the
 * bottom, etc.
 */
function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $mailbox = 'INBOX', $clean = false)
{
    /* This if statement checks for the entity to show as the
     * primary message. To add more of them, just put them in the
     * order that is their priority.
     */
    global $startMessage, $languages, $squirrelmail_language, $show_html_default, $sort, $has_unsafe_images, $passed_ent_id, $username, $key, $imapServerAddress, $imapPort, $download_and_unsafe_link;
    // If there's no "view_unsafe_images" variable in the URL, turn unsafe
    // images off by default.
    if (!sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET)) {
        $view_unsafe_images = false;
    }
    $body = '';
    $urlmailbox = urlencode($mailbox);
    $body_message = getEntity($message, $ent_num);
    if ($body_message->header->type0 == 'text' || $body_message->header->type0 == 'rfc822') {
        $body = mime_fetch_body($imap_stream, $id, $ent_num);
        $body = decodeBody($body, $body_message->header->encoding);
        if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
            if (mb_detect_encoding($body) != 'ASCII') {
                $body = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $body);
            }
        }
        $hookResults = do_hook("message_body", $body);
        $body = $hookResults[1];
        /* If there are other types that shouldn't be formatted, add
         * them here.
         */
        if ($body_message->header->type1 == 'html') {
            if ($show_html_default != 1) {
                $entity_conv = array('&nbsp;' => ' ', '<p>' => "\n", '<P>' => "\n", '<br>' => "\n", '<BR>' => "\n", '<br />' => "\n", '<BR />' => "\n", '&gt;' => '>', '&lt;' => '<');
                $body = strtr($body, $entity_conv);
                $body = strip_tags($body);
                $body = trim($body);
                translateText($body, $wrap_at, $body_message->header->getParameter('charset'));
            } else {
                $charset = $body_message->header->getParameter('charset');
                if (!empty($charset)) {
                    $body = charset_decode($charset, $body, false, true);
                }
                $body = magicHTML($body, $id, $message, $mailbox);
            }
        } else {
            translateText($body, $wrap_at, $body_message->header->getParameter('charset'));
        }
        // if this is the clean display (i.e. printer friendly), stop here.
        if ($clean) {
            return $body;
        }
        /*
         * Previously the links for downloading and unsafe images were printed
         * under the mail. By putting the links in a global variable we can
         * print it in the toolbar where it belongs. Since the original code was
         * in this place it's left here. It might be possible to move it to some
         * other place if that makes sense. The possibility to do so has not
         * been evaluated yet.
         */
        // Initialize the global variable to an empty string.
        $download_and_unsafe_link = '';
        // Prepare and build a link for downloading the mail.
        $link = 'passed_id=' . $id . '&amp;ent_id=' . $ent_num . '&amp;mailbox=' . $urlmailbox . '&amp;sort=' . $sort . '&amp;startMessage=' . $startMessage . '&amp;show_more=0';
        if (isset($passed_ent_id)) {
            $link .= '&amp;passed_ent_id=' . $passed_ent_id;
        }
        // Always add the link for downloading the mail as a file to the global
        // variable.
        $download_and_unsafe_link .= '&nbsp;|&nbsp;<a href="download.php?absolute_dl=true&amp;' . $link . '">' . _("Download this as a file") . '</a>';
        // Find out the right text to use in the link depending on the
        // circumstances. If the unsafe images are displayed the link should
        // hide them, if they aren't displayed the link should only appear if
        // the mail really contains unsafe images.
        if ($view_unsafe_images) {
            $text = _("Hide Unsafe Images");
        } else {
            if (isset($has_unsafe_images) && $has_unsafe_images) {
                $link .= '&amp;view_unsafe_images=1';
                $text = _("View Unsafe Images");
            } else {
                $text = '';
            }
        }
        // Only create a link for unsafe images if there's need for one. If so:
        // add it to the global variable.
        if ($text != '') {
            $download_and_unsafe_link .= '&nbsp;|&nbsp;<a href="read_body.php?' . $link . '">' . $text . '</a>';
        }
    }
    return $body;
}
예제 #11
0
/**
 * Shows translation box in message display window
 * @access private
 */
function translate_read_form_function()
{
    global $color, $translate_server;
    global $message, $translate_dir;
    global $translate_show_read;
    global $imapConnection, $wrap_at, $passed_id, $mailbox;
    global $translate_gpltrans_url;
    global $translate_babelfish_enabled, $translate_go_enabled, $translate_dictionary_enabled, $translate_google_enabled, $translate_gpltrans_enabled, $translate_intertran_enabled, $translate_promt_enabled, $translate_otenet_enabled;
    global $translate_custom_enabled;
    if (!$translate_show_read) {
        return;
    }
    $translate_server_option = 'translate_' . $translate_server . '_enabled';
    if ($translate_server == 'gpltrans' && $translate_gpltrans_url == '' || !${$translate_server_option} || !function_exists('translate_form_' . $translate_server)) {
        error_box(_("Selected translation engine is disabled. Please update your translation preferences."));
        return;
    }
    $translate_dir = 'to';
    $trans_ar = $message->findDisplayEntity(array(), array('text/plain'));
    $body = '';
    $final_body = '';
    if (!empty($trans_ar[0])) {
        for ($i = 0; $i < count($trans_ar); $i++) {
            /* reduced version of formatBody and translateText functions */
            // get message entity information
            $body_message = getEntity($message, $trans_ar[$i]);
            // get message body
            $body = mime_fetch_body($imapConnection, $passed_id, $trans_ar[$i]);
            // convert encoded messages
            $body = decodeBody($body, $body_message->header->encoding);
            /*
             * if message part is html formated - convert spaces, html line feeds,
             * less than and greater than html entities and remove tags
             */
            if ($body_message->header->type1 == 'html') {
                $entity_conv = array('&nbsp;' => ' ', '<p>' => "\n", '<P>' => "\n", '<br>' => "\n", '<BR>' => "\n", '<br />' => "\n", '<BR />' => "\n", '&gt;' => '>', '&lt;' => '<');
                $body = strtr($body, $entity_conv);
                $body = strip_tags($body);
            }
            // remove whitespace
            $body = trim($body);
            // save processed text and parse other entity
            $final_body .= charset_decode($body_message->header->getParameter('charset'), $body);
        }
        // add form if message is not empty
        if (!empty($final_body)) {
            $function = 'translate_form_' . $translate_server;
            $function($final_body);
        }
    }
}