/** GET/POST VARS */ sqgetGlobalVar('passed_ent_id', $passed_ent_id); sqgetGlobalVar('mailbox', $mailbox); if (sqgetGlobalVar('passed_id', $temp)) { $passed_id = (int) $temp; } if (sqgetGlobalVar('sort', $temp)) { $sort = (int) $temp; } if (sqgetGlobalVar('startMessage', $temp)) { $startMessage = (int) $temp; } /* end of get globals */ global $uid_support, $sqimap_capabilities; $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); /** * $message contains all information about the message * including header and body */ $uidvalidity = $mbx_response['UIDVALIDITY']; if (!isset($messages[$uidvalidity])) { $messages[$uidvalidity] = array(); } if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) { $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $FirstTimeSee = !$message->is_seen; $message->is_seen = true; $messages[$uidvalidity][$passed_id] = $message; } else { // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
function deliverMessage($composeMessage, $draft = false) { global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body, $username, $popuser, $usernamedata, $identity, $idents, $data_dir, $request_mdn, $request_dr, $default_charset, $color, $useSendmail, $domain, $action, $default_move_to_sent, $move_to_sent; global $imapServerAddress, $imapPort, $sent_folder, $key; $rfc822_header = $composeMessage->rfc822_header; $abook = addressbook_init(false, true); $rfc822_header->to = $rfc822_header->parseAddress($send_to, true, array(), '', $domain, array(&$abook, 'lookup')); $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc, true, array(), '', $domain, array(&$abook, 'lookup')); $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc, true, array(), '', $domain, array(&$abook, 'lookup')); $rfc822_header->priority = $mailprio; $rfc822_header->subject = $subject; $special_encoding = ''; if (strtolower($default_charset) == 'iso-2022-jp') { if (mb_detect_encoding($body) == 'ASCII') { $special_encoding = '8bit'; } else { $body = mb_convert_encoding($body, 'JIS'); $special_encoding = '7bit'; } } $composeMessage->setBody($body); if (ereg("^([^@%/]+)[@%/](.+)\$", $username, $usernamedata)) { $popuser = $usernamedata[1]; $domain = $usernamedata[2]; unset($usernamedata); } else { $popuser = $username; } $reply_to = ''; $from_mail = $idents[$identity]['email_address']; $full_name = $idents[$identity]['full_name']; $reply_to = $idents[$identity]['reply_to']; if (!$from_mail) { $from_mail = "{$popuser}@{$domain}"; } $rfc822_header->from = $rfc822_header->parseAddress($from_mail, true); if ($full_name) { $from = $rfc822_header->from[0]; if (!$from->host) { $from->host = $domain; } $full_name_encoded = encodeHeader($full_name); if ($full_name_encoded != $full_name) { $from_addr = $full_name_encoded . ' <' . $from->mailbox . '@' . $from->host . '>'; } else { $from_addr = '"' . $full_name . '" <' . $from->mailbox . '@' . $from->host . '>'; } $rfc822_header->from = $rfc822_header->parseAddress($from_addr, true); } if ($reply_to) { $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to, true); } /* Receipt: On Read */ if (isset($request_mdn) && $request_mdn) { $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail, true); } /* Receipt: On Delivery */ if (isset($request_dr) && $request_dr) { $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail; } /* multipart messages */ if (count($composeMessage->entities)) { $message_body = new Message(); $message_body->body_part = $composeMessage->body_part; $composeMessage->body_part = ''; $mime_header = new MessageHeader(); $mime_header->type0 = 'text'; $mime_header->type1 = 'plain'; if ($special_encoding) { $mime_header->encoding = $special_encoding; } else { $mime_header->encoding = '8bit'; } if ($default_charset) { $mime_header->parameters['charset'] = $default_charset; } $message_body->mime_header = $mime_header; array_unshift($composeMessage->entities, $message_body); $content_type = new ContentType('multipart/mixed'); } else { $content_type = new ContentType('text/plain'); if ($special_encoding) { $rfc822_header->encoding = $special_encoding; } else { $rfc822_header->encoding = '8bit'; } if ($default_charset) { $content_type->properties['charset'] = $default_charset; } } $rfc822_header->content_type = $content_type; $composeMessage->rfc822_header = $rfc822_header; /* Here you can modify the message structure just before we hand it over to deliver */ $hookReturn = do_hook('compose_send', $composeMessage); /* Get any changes made by plugins to $composeMessage. */ if (is_object($hookReturn[1])) { $composeMessage = $hookReturn[1]; } if (!$useSendmail && !$draft) { require_once SM_PATH . 'class/deliver/Deliver_SMTP.class.php'; $deliver = new Deliver_SMTP(); global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech; $authPop = isset($pop_before_smtp) && $pop_before_smtp ? true : false; get_smtp_user($user, $pass); $stream = $deliver->initStream($composeMessage, $domain, 0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop); } elseif (!$draft) { require_once SM_PATH . 'class/deliver/Deliver_SendMail.class.php'; global $sendmail_path; $deliver = new Deliver_SendMail(); $stream = $deliver->initStream($composeMessage, $sendmail_path); } elseif ($draft) { global $draft_folder; require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php'; $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (sqimap_mailbox_exists($imap_stream, $draft_folder)) { require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php'; $imap_deliver = new Deliver_IMAP(); $length = $imap_deliver->mail($composeMessage); sqimap_append($imap_stream, $draft_folder, $length); $imap_deliver->mail($composeMessage, $imap_stream); sqimap_append_done($imap_stream, $draft_folder); sqimap_logout($imap_stream); unset($imap_deliver); return $length; } else { $msg = '<br />' . sprintf(_("Error: Draft folder %s does not exist."), $draft_folder); plain_error_message($msg, $color); return false; } } $succes = false; if ($stream) { $length = $deliver->mail($composeMessage, $stream); $succes = $deliver->finalizeStream($stream); } if (!$succes) { $msg = $deliver->dlv_msg . '<br />' . _("Server replied: ") . $deliver->dlv_ret_nr . ' ' . $deliver->dlv_server_msg; plain_error_message($msg, $color); } else { unset($deliver); $move_to_sent = getPref($data_dir, $username, 'move_to_sent'); $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); /* Move to sent code */ if (isset($default_move_to_sent) && $default_move_to_sent != 0) { $svr_allow_sent = true; } else { $svr_allow_sent = false; } if (isset($sent_folder) && ($sent_folder != '' || $sent_folder != 'none') && sqimap_mailbox_exists($imap_stream, $sent_folder)) { $fld_sent = true; } else { $fld_sent = false; } if (isset($move_to_sent) && $move_to_sent != 0 || !isset($move_to_sent)) { $lcl_allow_sent = true; } else { $lcl_allow_sent = false; } if ($fld_sent && $svr_allow_sent && !$lcl_allow_sent || $fld_sent && $lcl_allow_sent) { global $passed_id, $mailbox, $action; if ($action == 'reply' || $action == 'reply_all') { $save_reply_with_orig = getPref($data_dir, $username, 'save_reply_with_orig'); if ($save_reply_with_orig) { $sent_folder = $mailbox; } } sqimap_append($imap_stream, $sent_folder, $length); require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php'; $imap_deliver = new Deliver_IMAP(); $imap_deliver->mail($composeMessage, $imap_stream); sqimap_append_done($imap_stream, $sent_folder); unset($imap_deliver); } global $passed_id, $mailbox, $action; ClearAttachments($composeMessage); if ($action == 'reply' || $action == 'reply_all') { sqimap_mailbox_select($imap_stream, $mailbox); sqimap_messages_flag($imap_stream, $passed_id, $passed_id, 'Answered', false); } sqimap_logout($imap_stream); } return $succes; }
sqgetGlobalVar('passed_id', $passed_id, SQ_GET); if (!sqgetGlobalVar('startMessage', $startMessage, SQ_GET)) { $startMessage = 1; } if (!sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET)) { $passed_ent_id = 0; } sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION); if (!sqgetGlobalVar('composesession', $composesession, SQ_SESSION)) { $composesession = 0; sqsession_register($composesession, 'composesession'); } /* END GLOBALS */ displayPageHeader($color, $mailbox); $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imap_stream, $mailbox); if ($spamcop_method == 'quick_email' || $spamcop_method == 'thorough_email') { // Use email-based reporting -- save as an attachment $session = "{$composesession}" + 1; $composesession = $session; sqsession_register($composesession, 'composesession'); if (!isset($compose_messages)) { $compose_messages = array(); } if (!isset($compose_messages[$session]) || $compose_messages[$session] == NULL) { $composeMessage = new Message(); $rfc822_header = new Rfc822Header(); $composeMessage->rfc822_header = $rfc822_header; $composeMessage->reply_rfc822_header = ''; $compose_messages[$session] = $composeMessage; sqsession_register($compose_messages, 'compose_messages');
function showMessagesForMailbox($imapConnection, $in_box, $ok_box, $er_box, $domain, $skannauskansio) { // Valitaan inboxi $mbxresponse = sqimap_mailbox_select($imapConnection, $in_box); // haetaan inboxin kaikki viestit $query = "SEARCH UID 1:*"; $read_list = sqimap_run_command_list($imapConnection, $query, true, $response, $message, ''); // Otetaan messageid:t if (preg_match("/\\* SEARCH ([0-9 ]*)/", $read_list[0][0], $matches)) { $messaget = explode(" ", trim($matches[1])); } else { $messaget = array(); } $messu_seqid_corr = 0; foreach ($messaget as $messu_seqid) { // Oliks tää ok maili $is_ok = FALSE; $messu_seqid = $messu_seqid - $messu_seqid_corr; // Haetaan viestin UID $query = "FETCH {$messu_seqid} (UID)"; $fetch_uid = sqimap_run_command_list($imapConnection, $query, true, $response, $message, ''); if (isset($fetch_uid[0][0]) and preg_match("/\\(UID ([0-9]*)\\)/", $fetch_uid[0][0], $matches)) { $uid = $matches[1]; } else { continue; } // Haetaan viestin From $query = "UID FETCH {$uid} (BODY[HEADER.FIELDS (From)])"; $fetch_from = sqimap_run_command_list($imapConnection, $query, true, $response, $message, ''); // Onko lähettäjän domaini ok? $okdomain = FALSE; if (empty($domain)) { $okdomain = TRUE; } elseif (is_array($domain) and count($domain) > 0) { foreach ($domain as $d_d) { if (preg_match("/[a-z\\.]*?@{$d_d}/i", $fetch_from[0][1])) { $okdomain = TRUE; break; } } if (!$okdomain) { echo "Laskuja hyväksytään vain "; foreach ($domain as $d_d) { echo $d_d . " "; } echo "domainista, " . $fetch_from[0][1] . "\n"; } } elseif (!is_array($domain) and $domain != '') { if (preg_match("/[a-z\\.]*?@{$domain}/i", $fetch_from[0][1])) { $okdomain = TRUE; } else { echo "Laskuja hyväksytään vain {$domain} domainista, " . $fetch_from[0][1] . "\n"; } } if ($okdomain) { // Haetaan viestin BODYSTRUCTURE $query = "UID FETCH {$uid} (BODYSTRUCTURE)"; $fetch_message = sqimap_run_command_list($imapConnection, $query, true, $response, $message, ''); preg_match("/BODYSTRUCTURE \\((.*)\\)/", $fetch_message[0][0], $matches); $bodyt = explode(")(", $matches[1]); for ($bodyind = 1; $bodyind <= count($bodyt); $bodyind++) { // Haetaan viestin BODY, tai siis osa siitä $query = "UID FETCH {$uid} (BODY[{$bodyind}])"; $fetch_body_part = sqimap_run_command_list($imapConnection, $query, true, $response, $message, ''); if (preg_match("/\\(BODY\\[{$bodyind}\\] NIL\\)/", $fetch_body_part[0][0])) { break; } // Fetchataan filename if (preg_match("/\\(\"(FILE)?NAME\" \"(.*?)\"\\)/", $bodyt[$bodyind - 1], $matches)) { // Ok maili $is_ok = TRUE; $path_parts = pathinfo($matches[2]); $name = strtoupper($path_parts['filename']); $ext = strtoupper($path_parts['extension']); // Hyväksytyt filet if (strtoupper($ext) != "JPG" and strtoupper($ext) != "JPEG" and strtoupper($ext) != "PNG" and strtoupper($ext) != "GIF" and strtoupper($ext) != "PDF") { echo "Ainoastaan .jpg .gif .png .pdf tiedostot sallittuja!\n"; continue; } // Kirjoitetaan liitetiedosto levylle $attachmentbody = ""; for ($line = 1; $line < count($fetch_body_part[0]) - 1; $line++) { $attachmentbody .= trim($fetch_body_part[0][$line]); } $attachmentbody = base64_decode($attachmentbody); // Katotaan, ettei samalla nimellä oo jo laskua jonossa if (file_exists($skannauskansio . "/" . $matches[2])) { $kala = 1; $filename = $matches[2]; while (file_exists($skannauskansio . "/" . $filename)) { $filename = $kala . "_" . $matches[2]; $kala++; } $matches[2] = $filename; } file_put_contents($skannauskansio . "/" . $matches[2], $attachmentbody); } } } $movebox = $is_ok ? $ok_box : $er_box; // Siiretään maili sopivaan kansioon $query = "UID COPY {$uid} {$movebox}"; $response = sqimap_run_command_list($imapConnection, $query, true, $response, $message, ''); $query = "UID STORE {$uid} +flags (\\Deleted)"; $response = sqimap_run_command_list($imapConnection, $query, true, $response, $message, ''); // Sekvenssinumero penenee automnaattisesti sitä mukaa kun siirretään maileja veke kansiosta $messu_seqid_corr++; } }
require '../include/init.php'; /** SquirrelMail required files. */ require_once SM_PATH . 'functions/imap.php'; require_once SM_PATH . 'functions/mime.php'; require_once SM_PATH . 'functions/date.php'; /** Get globals */ sqgetGlobalVar('messages', $messages, SQ_SESSION); sqgetGlobalVar('mailbox', $mailbox, SQ_GET); sqgetGlobalVar('ent_id', $ent_id, SQ_GET); sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET); sqgetGlobalVar('passed_id', $passed_id, SQ_GET, NULL, SQ_TYPE_BIGINT); // TODO: add required var checks here. global $imap_stream_options; // in case not defined in config $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);
/** * FIXME: Undocumented function * @access private */ function spam_filters($imap_stream) { global $data_dir, $username, $uid_support; global $SpamFilters_YourHop; global $SpamFilters_DNScache; global $SpamFilters_SharedCache; global $SpamFilters_BulkQuery; $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan'); $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder'); $filters = load_spam_filters(); if ($SpamFilters_SharedCache) { filters_LoadCache(); } $run = false; foreach ($filters as $Key => $Value) { if ($Value['enabled']) { $run = true; break; } } // short-circuit if (!$run) { return; } sqimap_mailbox_select($imap_stream, 'INBOX'); $search_array = array(); if ($filters_spam_scan == 'new') { $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, $uid_support); if (isset($read[0])) { for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) { if (preg_match("/^\\* SEARCH (.+)\$/", $read[$i], $regs)) { $search_array = explode(' ', trim($regs[1])); break; } } } } if ($filters_spam_scan == 'new' && count($search_array)) { $msg_str = sqimap_message_list_squisher($search_array); $imap_query = 'FETCH ' . $msg_str . ' (FLAGS BODY.PEEK[HEADER.FIELDS (RECEIVED)])'; } else { if ($filters_spam_scan != 'new') { $imap_query = 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS (RECEIVED)])'; } else { return; } } $read = sqimap_run_command_list($imap_stream, $imap_query, true, $response, $message, $uid_support); if (isset($response) && $response != 'OK') { return; } $messages = parseFetch($read); $bulkquery = strlen($SpamFilters_BulkQuery) > 0 ? true : false; $aSpamIds = array(); foreach ($messages as $id => $message) { if (isset($message['UID'])) { $MsgNum = $message['UID']; } else { $MsgNum = $id; } if (isset($message['received'])) { foreach ($message['received'] as $received) { if (is_int(strpos($received, $SpamFilters_YourHop))) { if (preg_match('/([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})/', $received, $matches)) { $IsSpam = false; if (filters_spam_check_site($matches[1], $matches[2], $matches[3], $matches[4], $filters)) { $aSpamIds[] = $MsgNum; $IsSpam = true; } if ($bulkquery) { array_shift($matches); $IP = explode('.', $matches); foreach ($filters as $key => $value) { if ($filters[$key]['enabled'] && $filters[$key]['dns']) { if (strlen($SpamFilters_DNScache[$IP . '.' . $filters[$key]['dns']]) == 0) { $IPs[$IP] = true; break; } } } } if ($SpamFilters_YourHop == ' ' || $IsSpam) { break; } } } } } } if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) { sqimap_msgs_list_move($imap_stream, $aSpamIds, $filters_spam_folder); sqimap_mailbox_expunge($imap_stream, 'INBOX', true, $aSpamIds); } if ($bulkquery && count($IPs)) { filters_bulkquery($filters, $IPs); } if ($SpamFilters_SharedCache) { filters_SaveCache(); } else { sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache'); } }
require_once SM_PATH . 'include/validate.php'; require_once SM_PATH . 'functions/date.php'; require_once SM_PATH . 'functions/page_header.php'; require_once SM_PATH . 'functions/mime.php'; require_once SM_PATH . 'include/load_prefs.php'; /* globals */ sqgetGlobalVar('username', $username, SQ_SESSION); sqgetGlobalVar('key', $key, SQ_COOKIE); sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); sqgetGlobalVar('passed_id', $passed_id, SQ_GET); sqgetGlobalVar('mailbox', $mailbox, SQ_GET); sqgetGlobalVar('ent_id', $ent_id, SQ_GET); sqgetGlobalVar('startMessage', $startMessage, SQ_GET); /* end globals */ $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imapConnection, $mailbox); displayPageHeader($color, 'None'); echo '<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" ' . 'align="center">' . "\n" . '<tr><td bgcolor="' . $color[0] . '">' . '<b><center>' . _("Viewing a Business Card") . " - "; $msg_url = 'read_body.php?mailbox=' . urlencode($mailbox) . '&startMessage=' . urlencode($startMessage) . '&passed_id=' . urlencode($passed_id); $msg_url = set_url_var($msg_url, 'ent_id', 0); echo '<a href="' . $msg_url . '">' . _("View message") . '</a>'; echo '</center></b></td></tr>'; $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $entity_vcard = getEntity($message, $ent_id); $vcard = mime_fetch_body($imapConnection, $passed_id, $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);
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(' ', '>', '<'), 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; }
function bayesspam_filters($imap_stream, $use_mailbox = 0) { $spam_stats = 0; $ham_stats = 0; $unsure_stats = 0; $total_messages = 0; $run_folders = array(); $boxes = sqimap_mailbox_list($imap_stream); foreach ($boxes as $box) { if ($GLOBALS['bayesspam_inboxonly'] != 1 || $GLOBALS['bayesspam_inboxonly'] == 1 && 'INBOX' == $box['unformatted-dm']) { if ($use_mailbox == 1 && $box['unformatted-dm'] == $GLOBALS['mailbox'] && !in_array($box['unformatted-dm'], $GLOBALS['bayesspam_ignore_folders']) || $use_mailbox == 0 && !in_array($box['unformatted-dm'], $GLOBALS['bayesspam_ignore_folders'])) { if ((array_search('noselect', $box['flags']) === FALSE || array_search('noselect', $box['flags']) === NULL) && $GLOBALS['sent_folder'] != $box['unformatted-dm'] && sqimap_unseen_messages($imap_stream, $box['unformatted-dm']) > 0) { $run_folders[] = $box['unformatted-dm']; } } } } foreach ($run_folders as $box) { $spam_messages = array(); $uncertain_messages = array(); $mbxresponse = sqimap_mailbox_select($imap_stream, $box); $messages = array(); $search = "SEARCH UNSEEN UNDELETED"; if (isset($_SESSION['bayesspam_last_filter'])) { $search .= " SINCE " . date('d-M-Y', $_SESSION['bayesspam_last_filter']); } $_SESSION['bayesspam_last_filter'] = time(); $read = sqimap_run_command($imap_stream, $search, TRUE, $response, $message, TRUE); if (isset($read[0])) { for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) { if (preg_match("/^\\* SEARCH (.+)\$/", $read[$i], $regs)) { $messages = preg_split("/ /", trim($regs[1])); break; } } } foreach ($messages as $passed_id) { bayesspam_set_message_id($imap_stream, $passed_id); $bayesspam_check_messageid = bayesspam_check_messageid(); if ($GLOBALS['bayesspam_do_stats'] && $GLOBALS['bayesspam_do_user_stats']) { $bayesspam_old_message_score = bayesspam_get_old_message_score(); } $is_spam = bayesspam_get_probability($imap_stream, $passed_id, 1); if ($is_spam > 0.9) { $spam_messages[] = $passed_id; } elseif ($is_spam >= 0.1) { $uncertain_messages[] = $passed_id; } if ($GLOBALS['bayesspam_do_stats'] && $GLOBALS['bayesspam_do_user_stats'] && $bayesspam_old_message_score === FALSE) { if ($is_spam > 0.9) { $spam_stats++; $total_messages++; } if ($is_spam <= 0.9 && $is_spam >= 0.1) { $unsure_stats++; $total_messages++; } if ($is_spam < 0.1) { $ham_stats++; $total_messages++; } } } if ($spam_messages) { $message_str = sqimap_message_list_squisher($spam_messages); if ($GLOBALS['bayesspam_delete']) { sqimap_run_command($imap_stream, 'STORE ' . $message_str . ' +FLAGS (\\Deleted)', true, $response, $message, $GLOBALS['uid_support']); } elseif (sqimap_mailbox_exists($imap_stream, $GLOBALS['bayesspam_folder'])) { sqimap_run_command($imap_stream, 'COPY ' . $message_str . ' "' . $GLOBALS['bayesspam_folder'] . '"', true, $response, $message, $GLOBALS['uid_support']); sqimap_run_command($imap_stream, 'STORE ' . $message_str . ' +FLAGS (\\Deleted)', true, $response, $message, $GLOBALS['uid_support']); } sqimap_mailbox_expunge($imap_stream, $box); } if ($uncertain_messages && $GLOBALS['bayesspam_do_uncertain_filtering']) { $message_str = sqimap_message_list_squisher($uncertain_messages); if (sqimap_mailbox_exists($imap_stream, $GLOBALS['bayesspam_uncertain_folder'])) { sqimap_run_command($imap_stream, 'COPY ' . $message_str . ' "' . $GLOBALS['bayesspam_uncertain_folder'] . '"', true, $response, $message, $GLOBALS['uid_support']); sqimap_run_command($imap_stream, 'STORE ' . $message_str . ' +FLAGS (\\Deleted)', true, $response, $message, $GLOBALS['uid_support']); } sqimap_mailbox_expunge($imap_stream, $box); } } if ($GLOBALS['bayesspam_do_stats'] && $GLOBALS['bayesspam_do_user_stats'] && $total_messages) { $res = $GLOBALS['bayesdbhandle']->query('SELECT UserName FROM ' . $GLOBALS['bayesdbprefix'] . 'stats WHERE UserName=\'' . $GLOBALS['bayes_username'] . '\''); if (!DB::isError($res) && !($row = $res->fetchRow())) { $GLOBALS['bayesdbhandle']->query('INSERT INTO ' . $GLOBALS['bayesdbprefix'] . 'stats SET StatsStart=NOW(),UserName=\'' . $GLOBALS['bayes_username'] . '\',TotalMessages=' . $total_messages . ',HamMessages=' . $ham_stats . ',SpamMessages=' . $spam_stats . ',UnsureMessages=' . $unsure_stats . ($GLOBALS['bayesspam_do_timing'] ? ',TimedMessages=' . $GLOBALS['bayes_parsed_messages'] . ',TotalParseTime=' . $GLOBALS['bayes_parse_time'] : '')); } else { $GLOBALS['bayesdbhandle']->query('UPDATE ' . $GLOBALS['bayesdbprefix'] . 'stats SET TotalMessages=TotalMessages+' . $total_messages . ',HamMessages=HamMessages+' . $ham_stats . ',SpamMessages=SpamMessages+' . $spam_stats . ', UnsureMessages=UnsureMessages+' . $unsure_stats . ($GLOBALS['bayesspam_do_timing'] ? ',TimedMessages=TimedMessages+' . $GLOBALS['bayes_parsed_messages'] . ',TotalParseTime=TotalParseTime+' . $GLOBALS['bayes_parse_time'] : '') . ' WHERE UserName=\'' . $GLOBALS['bayes_username'] . '\''); } } }
function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) { global $trash_folder, $delimiter; $position = strrpos($topFolderName, $delimiter) + 1; $subFolderName = substr($tree[$index]['value'], $position); if ($tree[$index]['doIHaveChildren']) { sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, ""); $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']); $messageCount = $mbx_response['EXISTS']; if ($messageCount > 0) { sqimap_messages_copy($imap_stream, 1, '*', $trash_folder . $delimiter . $subFolderName); } for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) { walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName); } } else { sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, ''); $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']); $messageCount = $mbx_response['EXISTS']; if ($messageCount > 0) { sqimap_messages_copy($imap_stream, 1, '*', $trash_folder . $delimiter . $subFolderName); } } }
/** * function mail - send the message parts to the SMTP stream * * @param Message $message Message object to send * NOTE that this is passed by * reference and will be modified * upon return with updated * fields such as Message ID, References, * In-Reply-To and Date headers. * @param resource $stream Handle to the outgoing stream * (when FALSE, nothing will be * written to the stream; this can * be used to determine the actual * number of bytes that will be * written to the stream) * @param string $reply_id Identifies message being replied to * (OPTIONAL; caller should ONLY specify * a value for this when the message * being sent is a reply) * @param string $reply_ent_id Identifies message being replied to * in the case it was an embedded/attached * message inside another (OPTIONAL; caller * should ONLY specify a value for this * when the message being sent is a reply) * @param resource $imap_stream If there is an open IMAP stream in * the caller's context, it should be * passed in here. This is OPTIONAL, * as one will be created if not given, * but as some IMAP servers may baulk * at opening more than one connection * at a time, the caller should always * abide if possible. Currently, this * stream is only used when $reply_id * is also non-zero, but that is subject * to change. * @param mixed $extra Any implementation-specific variables * can be passed in here and used in * an overloaded version of this method * if needed. * * @return integer The number of bytes written (or that would have been * written) to the output stream. * */ function mail(&$message, $stream = false, $reply_id = 0, $reply_ent_id = 0, $imap_stream = NULL, $extra = NULL) { $rfc822_header =& $message->rfc822_header; if (count($message->entities)) { $boundary = $this->mimeBoundary(); $rfc822_header->content_type->properties['boundary'] = '"' . $boundary . '"'; } else { $boundary = ''; } $raw_length = 0; // calculate reply header if needed // if ($reply_id) { global $imapConnection, $username, $key, $imapServerAddress, $imapPort, $mailbox; // try our best to use an existing IMAP handle // $close_imap_stream = FALSE; if (is_resource($imap_stream)) { $my_imap_stream = $imap_stream; } else { if (is_resource($imapConnection)) { $my_imap_stream = $imapConnection; } else { $close_imap_stream = TRUE; $my_imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); } } sqimap_mailbox_select($my_imap_stream, $mailbox); $reply_message = sqimap_get_message($my_imap_stream, $reply_id, $mailbox); if ($close_imap_stream) { sqimap_logout($my_imap_stream); } if ($reply_ent_id) { /* redefine the messsage in case of message/rfc822 */ $reply_message = $message->getEntity($reply_ent_id); /* message is an entity which contains the envelope and type0=message * and type1=rfc822. The actual entities are childs from * $reply_message->entities[0]. That's where the encoding and is located */ $orig_header = $reply_message->rfc822_header; /* here is the envelope located */ } else { $orig_header = $reply_message->rfc822_header; } $message->reply_rfc822_header = $orig_header; } $reply_rfc822_header = isset($message->reply_rfc822_header) ? $message->reply_rfc822_header : ''; $header = $this->prepareRFC822_Header($rfc822_header, $reply_rfc822_header, $raw_length); $this->send_mail($message, $header, $boundary, $stream, $raw_length, $extra); return $raw_length; }
/** * FIXME: Undocumented function * @access private */ function spam_filters($imap_stream) { global $data_dir, $username, $uid_support; global $SpamFilters_YourHop; global $SpamFilters_DNScache; global $SpamFilters_SharedCache; global $SpamFilters_BulkQuery; $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan'); $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder'); $filters = load_spam_filters(); if ($SpamFilters_SharedCache) { filters_LoadCache(); } $run = 0; foreach ($filters as $Key => $Value) { if ($Value['enabled']) { $run++; } } // short-circuit if ($run == 0) { return; } sqimap_mailbox_select($imap_stream, 'INBOX'); // Ask for a big list of all "Received" headers in the inbox with // flags for each message. Kinda big. if ($filters_spam_scan != 'new') { $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' . '(RECEIVED)])', true, $response, $message, $uid_support); } else { $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, $uid_support); if ($response != 'OK' || trim($read[0]) == '* SEARCH') { $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' . '(RECEIVED)])', true, $response, $message, $uid_support); } else { if (isset($read[0])) { if (preg_match("/^\\* SEARCH (.+)\$/", $read[0], $regs)) { $search_array = preg_split("/ /", trim($regs[1])); } } $msgs_str = sqimap_message_list_squisher($search_array); $imap_query = 'FETCH ' . $msgs_str; $imap_query .= ' (FLAGS BODY.PEEK[HEADER.FIELDS '; $imap_query .= '(RECEIVED)])'; $read = sqimap_run_command($imap_stream, $imap_query, true, $response, $message, $uid_support); } } if (isset($response) && $response != 'OK') { return; } if (strlen($SpamFilters_BulkQuery) > 0) { filters_bulkquery($filters_spam_scan, $filters, $read); } $i = 0; while ($i < count($read)) { // EIMS will give funky results $Chunks = explode(' ', $read[$i]); if ($Chunks[0] != '*') { $i++; continue; } $MsgNum = $Chunks[1]; $IPs = array(); $i++; $IsSpam = 0; // Look through all of the Received headers for IP addresses // Stop when I get ")" on a line // Stop if I get "*" on a line (don't advance) // and above all, stop if $i is bigger than the total # of lines while ($i < count($read) && ($read[$i][0] != ')' && $read[$i][0] != '*' && $read[$i][0] != "\n") && !$IsSpam) { // Check to see if this line is the right "Received from" line // to check if (is_int(strpos($read[$i], $SpamFilters_YourHop))) { // short-circuit and skip work if we don't scan this one $read[$i] = ereg_replace('[^0-9\\.]', ' ', $read[$i]); $elements = explode(' ', $read[$i]); foreach ($elements as $value) { if ($value != '' && ereg('[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}', $value, $regs)) { $Chunks = explode('.', $value); if (filters_spam_check_site($Chunks[0], $Chunks[1], $Chunks[2], $Chunks[3], $filters)) { $IsSpam++; break; // no sense in checking more IPs } // If we've checked one IP and YourHop is // just a space if ($SpamFilters_YourHop == ' ') { break; // don't check any more } } } } $i++; } // Lookie! It's spam! Yum! if ($IsSpam) { if (sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) { // check if message copy was successful if (sqimap_messages_copy($imap_stream, $MsgNum, $MsgNum, $filters_spam_folder, false)) { sqimap_messages_flag($imap_stream, $MsgNum, $MsgNum, 'Deleted', false); } } } else { } } sqimap_mailbox_expunge($imap_stream, 'INBOX'); if ($SpamFilters_SharedCache) { filters_SaveCache(); } else { sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache'); } }
function spamcop_while_sending() { global $mailbox, $spamcop_delete, $auto_expunge, $username, $key, $imapServerAddress, $imapPort; // load sqgetGlobalVar() include_once SM_PATH . 'functions/global.php'; // check if compose.php is called by spamcop plugin if (sqgetGlobalVar('spamcop_is_composing', $spamcop_is_composing)) { if ($spamcop_delete) { $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imapConnection, $mailbox); sqimap_msgs_list_delete($imapConnection, $mailbox, $spamcop_is_composing); if ($auto_expunge) { sqimap_mailbox_expunge($imapConnection, $mailbox, true); } } // change default email composition setting. Plugin always operates in right frame. // make sure that compose.php redirects to right page. Temporally override. global $compose_new_win; $compose_new_win = false; } }
/** * Starts the filtering process * @param array $hook_args (since 1.5.2) do hook arguments. Is used to check * hook name, array key = 0. * @access private */ function start_filters($hook_args) { global $imapServerAddress, $imapPort, $imap_stream_options, $imap_stream, $imapConnection, $UseSeparateImapConnection, $AllowSpamFilters, $filter_inbox_count, $username; // if there were filtering errors previously during // this login session, we won't try again // // (errors that this plugin was able to catch or a "NO" // response/failure from IMAP found in the current session, // which could have resulted from an attempted filter copy // (over quota), in which case execution halts before this // plugin can catch the problem -- note, however, that any // other IMAP "NO" failure (caused by unrelated actions) at // any time during the current session will cause this plugin // to effectively shut down) // sqgetGlobalVar('filters_error', $filters_error, SQ_SESSION, FALSE); sqgetGlobalVar('IMAP_FATAL_ERROR_TYPE', $imap_fatal_error, SQ_SESSION, ''); if ($filters_error || $imap_fatal_error == 'NO') { return; } /** * check hook that calls filtering. If filters are called by right_main_after_header, * do filtering only when we are in INBOX folder. */ if ($hook_args[0] == 'right_main_after_header' && (sqgetGlobalVar('mailbox', $mailbox, SQ_FORM) && $mailbox != 'INBOX')) { return; } $filters = load_filters(); // No point running spam filters if there aren't any to run // if ($AllowSpamFilters) { $spamfilters = load_spam_filters(); $AllowSpamFilters = false; foreach ($spamfilters as $value) { if ($value['enabled'] == SMPREF_ON) { $AllowSpamFilters = true; break; } } } // No user filters, and no spam filters, no need to continue // if (!$AllowSpamFilters && empty($filters)) { return; } // Detect if we have already connected to IMAP or not. // Also check if we are forced to use a separate IMAP connection if (!isset($imap_stream) && !isset($imapConnection) || $UseSeparateImapConnection) { $stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 10, $imap_stream_options); $previously_connected = false; } else { if (isset($imapConnection)) { $stream = $imapConnection; $previously_connected = true; } else { $previously_connected = true; $stream = $imap_stream; } } if (!isset($filter_inbox_count)) { $aStatus = sqimap_status_messages($stream, 'INBOX', array('MESSAGES')); if (!empty($aStatus['MESSAGES'])) { $filter_inbox_count = $aStatus['MESSAGES']; } else { $filter_inbox_count = 0; } } if ($filter_inbox_count > 0) { sqimap_mailbox_select($stream, 'INBOX'); // Filter spam from inbox before we sort them into folders if ($AllowSpamFilters) { spam_filters($stream); } // Sort into folders user_filters($stream); } if (!$previously_connected) { sqimap_logout($stream); } }
function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, $start_msg, $sort, $color, $show_num, $use_cache, $mode = '') { global $msgs, $msort, $auto_expunge, $thread_sort_messages, $allow_server_sort, $server_sort_order; /* * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc * so setting it to an empty array beforehand seems to clean up the issue, and stopping the * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error */ if (!isset($msort)) { $msort = array(); } if (!isset($msgs)) { $msgs = array(); } //$start = microtime(); /* If autoexpunge is turned on, then do it now. */ $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox); $srt = $sort; /* If autoexpunge is turned on, then do it now. */ if ($auto_expunge == true) { $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, ''); $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt; $num_msgs = $mbxresponse['EXISTS']; } if ($mbxresponse['EXISTS'] > 0) { /* if $start_msg is lower than $num_msgs, we probably deleted all messages * in the last page. We need to re-adjust the start_msg */ if ($start_msg > $num_msgs) { $start_msg -= $show_num; if ($start_msg < 1) { $start_msg = 1; } } /* This code and the next if() block check for * server-side sorting methods. The $id array is * formatted and $sort is set to 6 to disable * SM internal sorting */ if ($thread_sort_messages == 1) { $mode = 'thread'; } elseif ($allow_server_sort == 1) { $mode = 'serversort'; } else { $mode = ''; } if ($use_cache) { sqgetGlobalVar('msgs', $msgs, SQ_SESSION); sqgetGlobalVar('msort', $msort, SQ_SESSION); } else { sqsession_unregister('msort'); sqsession_unregister('msgs'); } switch ($mode) { case 'thread': $id = get_thread_sort($imapConnection); $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); if ($msgs === false) { echo '<b><small><center><font color="red">' . _("Thread sorting is not supported by your IMAP server.") . '<br />' . _("Please contact your system administrator and report this error.") . '</font></center></small></b>'; $thread_sort_messages = 0; $msort = $msgs = array(); } else { $msort = $msgs; $sort = 6; } break; case 'serversort': $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse); $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); if ($msgs === false) { echo '<b><small><center><font color="red">' . _("Server-side sorting is not supported by your IMAP server.") . '<br />' . _("Please contact your system administrator and report this error.") . '</font></center></small></b>'; $sort = $server_sort_order; $allow_server_sort = FALSE; $msort = $msgs = array(); $id = array(); } else { $msort = $msgs; $sort = 6; } break; default: if (!$use_cache) { $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num, $num_msgs, $sort, $mbxresponse); $msort = calc_msort($msgs, $sort); } /* !use cache */ break; } // switch sqsession_register($msort, 'msort'); sqsession_register($msgs, 'msgs'); } /* if exists > 0 */ $res = getEndMessage($start_msg, $show_num, $num_msgs); $start_msg = $res[0]; $end_msg = $res[1]; if ($num_msgs > 0) { $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort); } else { $paginator_str = ''; } $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs); do_hook('mailbox_index_before'); $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox); $form_name = "FormMsgs" . $safe_name; echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' . "\n" . '<input type="hidden" name="mailbox" value="' . htmlspecialchars($mailbox) . '">' . "\n" . '<input type="hidden" name="startMessage" value="' . htmlspecialchars($start_msg) . '">' . "\n"; echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">'; echo '<tr><td>'; mail_message_listing_beginning($imapConnection, $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg); /* line between the button area and the list */ echo '<tr><td height="5" bgcolor="' . $color[4] . '"></td></tr>'; echo '<tr><td>'; echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"' . ' border="0" bgcolor="' . $color[9] . '">'; echo ' <tr><td>'; echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="' . $color[5] . '">'; printHeader($mailbox, $srt, $color, !$thread_sort_messages); displayMessageArray($imapConnection, $num_msgs, $start_msg, $msort, $mailbox, $sort, $color, $show_num, 0, 0); echo '</table></td></tr></table>'; mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color); echo '</table>'; echo "\n</form>\n\n"; //$t = elapsed($start); //echo("elapsed time = $t seconds\n"); }
/** * Process messages that are submitted by email. * * Delete spam if user wants to delete it. Don't save submitted emails. * Implement overrides that fix compose.php behavior. * @since 1.5.1 * @access private */ function spamcop_while_sending_function() { global $mailbox, $spamcop_delete, $spamcop_save, $spamcop_is_composing, $auto_expunge, $username, $imapServerAddress, $imapPort, $imap_stream_options; if (sqgetGlobalVar('spamcop_is_composing', $spamcop_is_composing)) { // delete spam message if ($spamcop_delete) { $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options); sqimap_mailbox_select($imapConnection, $mailbox); sqimap_msgs_list_delete($imapConnection, $mailbox, array($spamcop_is_composing)); if ($auto_expunge) { sqimap_mailbox_expunge($imapConnection, $mailbox, true); } } if (!$spamcop_save) { // disable use of send folder. // Temporally override in order to disable saving of 'reply anyway' messages. global $default_move_to_sent; $default_move_to_sent = false; } // change default email composition setting. Plugin always operates in right frame. // make sure that compose.php redirects to right page. Temporally override. global $compose_new_win; $compose_new_win = false; } }
/** * Process messages list form and handle the cache gracefully. If $sButton and * $aUid are provided as argument then you can fake a message list submit and * use it i.e. in read_body.php for del move next and update the cache * * @param resource $imapConnection imap connection * @param array $aMailbox (reference) cached mailbox * @param string $sButton fake a submit button * @param array $aUid fake the $msg array * @return string $sError error string in case of an error * @author Marc Groot Koerkamp */ function handleMessageListForm($imapConnection, &$aMailbox, $sButton = '', $aUid = array()) { /* incoming formdata */ $sButton = sqgetGlobalVar('moveButton', $sTmp, SQ_POST) ? 'move' : $sButton; $sButton = sqgetGlobalVar('expungeButton', $sTmp, SQ_POST) ? 'expunge' : $sButton; $sButton = sqgetGlobalVar('attache', $sTmp, SQ_POST) ? 'attache' : $sButton; $sButton = sqgetGlobalVar('delete', $sTmp, SQ_POST) ? 'setDeleted' : $sButton; $sButton = sqgetGlobalVar('undeleteButton', $sTmp, SQ_POST) ? 'setDeleted' : $sButton; $sButton = sqgetGlobalVar('markRead', $sTmp, SQ_POST) ? 'setSeen' : $sButton; $sButton = sqgetGlobalVar('markUnread', $sTmp, SQ_POST) ? 'unsetSeen' : $sButton; $sButton = sqgetGlobalVar('markFlagged', $sTmp, SQ_POST) ? 'setFlagged' : $sButton; $sButton = sqgetGlobalVar('markUnflagged', $sTmp, SQ_POST) ? 'unsetFlagged' : $sButton; sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST); sqgetGlobalVar('bypass_trash', $bypass_trash, SQ_POST); sqgetGlobalVar('msg', $msg, SQ_POST); $sError = ''; $mailbox = $aMailbox['NAME']; /* retrieve the check boxes */ $aUid = isset($msg) && is_array($msg) ? array_values($msg) : $aUid; if (count($aUid) && $sButton != 'expunge') { $aUpdatedMsgs = false; $bExpunge = false; switch ($sButton) { case 'setDeleted': // check if id exists in case we come from read_body if (count($aUid) == 1 && is_array($aMailbox['UIDSET'][$aMailbox['SETINDEX']]) && !in_array($aUid[0], $aMailbox['UIDSET'][$aMailbox['SETINDEX']])) { break; } $aUpdatedMsgs = sqimap_msgs_list_delete($imapConnection, $mailbox, $aUid, $bypass_trash); $bExpunge = true; break; case 'unsetDeleted': case 'setSeen': case 'unsetSeen': case 'setFlagged': case 'unsetFlagged': // get flag $sFlag = substr($sButton, 0, 3) == 'set' ? '\\' . substr($sButton, 3) : '\\' . substr($sButton, 5); $bSet = substr($sButton, 0, 3) == 'set' ? true : false; $aUpdatedMsgs = sqimap_toggle_flag($imapConnection, $aUid, $sFlag, $bSet, true); break; case 'move': $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection, $aUid, $targetMailbox); sqsession_register($targetMailbox, 'lastTargetMailbox'); $bExpunge = true; break; case 'attache': $aMsgHeaders = array(); foreach ($aUid as $iUid) { $aMsgHeaders[$iUid] = $aMailbox['MSG_HEADERS'][$iUid]; } if (count($aMsgHeaders)) { $composesession = attachSelectedMessages($imapConnection, $aMsgHeaders); // dirty hack, add info to $aMailbox $aMailbox['FORWARD_SESSION'] = $composesession; } break; default: // Hook for plugin buttons do_hook_function('mailbox_display_button_action', $aUid); break; } /** * Updates messages is an array containing the result of the untagged * fetch responses send by the imap server due to a flag change. That * response is parsed in a array with msg arrays by the parseFetch function */ if ($aUpdatedMsgs) { // Update the message headers cache $aDeleted = array(); foreach ($aUpdatedMsgs as $iUid => $aMsg) { if (isset($aMsg['FLAGS'])) { /** * Only update the cached headers if the header is * cached. */ if (isset($aMailbox['MSG_HEADERS'][$iUid])) { $aMailbox['MSG_HEADERS'][$iUid]['FLAGS'] = $aMsg['FLAGS']; } /** * Count the messages with the \Delete flag set so we can determine * if the number of expunged messages equals the number of flagged * messages for deletion. */ if (isset($aMsg['FLAGS']['\\deleted']) && $aMsg['FLAGS']['\\deleted']) { $aDeleted[] = $iUid; } } } if ($bExpunge && $aMailbox['AUTO_EXPUNGE'] && ($iExpungedMessages = sqimap_mailbox_expunge($imapConnection, $aMailbox['NAME'], true))) { if (count($aDeleted) != $iExpungedMessages) { // there are more messages deleted permanently then we expected // invalidate the cache $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = false; $aMailbox['MSG_HEADERS'] = false; } else { // remove expunged messages from cache $aUidSet = $aMailbox['UIDSET'][$aMailbox['SETINDEX']]; if (is_array($aUidSet)) { // create a UID => array index temp array $aUidSetDummy = array_flip($aUidSet); foreach ($aDeleted as $iUid) { // get the id as well in case of SQM_SORT_NONE if ($aMailbox['SORT'] == SQSORT_NONE) { $aMailbox['ID'] = false; //$iId = $aMailbox['MSG_HEADERS'][$iUid]['ID']; //unset($aMailbox['ID'][$iId]); } // unset the UID and message header unset($aUidSetDummy[$iUid]); unset($aMailbox['MSG_HEADERS'][$iUid]); } $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = array_keys($aUidSetDummy); } } // update EXISTS info if ($iExpungedMessages) { $aMailbox['EXISTS'] -= (int) $iExpungedMessages; } // Change the startMessage number if the mailbox was changed if ($aMailbox['PAGEOFFSET'] - 1 >= $aMailbox['EXISTS']) { $aMailbox['PAGEOFFSET'] = $aMailbox['PAGEOFFSET'] > $aMailbox['LIMIT'] ? $aMailbox['PAGEOFFSET'] - $aMailbox['LIMIT'] : 1; $aMailbox['OFFSET'] = $aMailbox['PAGEOFFSET'] - 1; } } } } else { if ($sButton == 'expunge') { /** * on expunge we do not know which messages will be deleted * so it's useless to try to sync the cache * Close the mailbox so we do not need to parse the untagged expunge * responses which do not contain uid info. * NB: Closing a mailbox is faster then expunge because the imap * server does not need to generate the untagged expunge responses */ sqimap_run_command($imapConnection, 'CLOSE', false, $result, $message); $aMbxResponse = sqimap_mailbox_select($imapConnection, $aMailbox['NAME']); // update the $aMailbox array $aMailbox['EXISTS'] = $aMbxResponse['EXISTS']; $aMailbox['UIDSET'] = false; } else { if ($sButton) { $sError = _("No messages were selected."); } } } return $sError; }
function bayesspam_prune($args) { if ($args[0] != 'left_main_before' || !isset($_SESSION['just_logged_in']) || $_SESSION['just_logged_in'] != true) { return; } if ($GLOBALS['bayesdbhandle'] == null) { return; } if ($GLOBALS['bayesspam_prune_threshold'] == 0) { return; } $secsago = 86400 * ($GLOBALS['bayesspam_prune_threshold'] - 1); /* Convert days to seconds */ $cutoffdate = date('d-M-Y', time() - $secsago); if (!sqimap_mailbox_exists($GLOBALS['imapConnection'], $GLOBALS['bayesspam_folder'])) { return; } $notrash = false; if (!sqimap_mailbox_exists($GLOBALS['imapConnection'], $GLOBALS['trash_folder'])) { $notrash = true; } else { $trashbox = sqimap_mailbox_select($GLOBALS['imapConnection'], $GLOBALS['trash_folder']); if (strtolower($trashbox['RIGHTS']) != "read-write") { $notrash = true; } } $mbx = sqimap_mailbox_select($GLOBALS['imapConnection'], $GLOBALS['bayesspam_folder']); if (strtolower($mbx['RIGHTS']) != "read-write") { return; } $query = "SEARCH SENTBEFORE {$cutoffdate}"; $read = sqimap_run_command($GLOBALS['imapConnection'], $query, TRUE, $response, $message, $GLOBALS['uid_support']); $results = str_replace(' ', ',', substr($read[0], 9)); $msglist = trim($results); /* get rid of that nasty whitespace */ if (strlen($msglist) < 1) { return; } $msglist = sqimap_message_list_squisher(explode(' ', $msglist)); if (!$notrash && $GLOBALS['default_move_to_trash']) { sqimap_msgs_list_move($GLOBALS['imapConnection'], $msglist, $GLOBALS['trash_folder']); } else { sqimap_msgs_list_delete($GLOBALS['imapConnection'], $GLOBALS['bayesspam_folder'], $msglist); } if ($GLOBALS['auto_expunge']) { sqimap_mailbox_expunge($GLOBALS['imapConnection'], $GLOBALS['bayesspam_folder']); } }
/** * Recursively walk a tree of folders to create them under the trash folder. */ function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) { global $trash_folder, $delimiter; $position = strrpos($topFolderName, $delimiter); if ($position !== FALSE) { $position++; } $subFolderName = substr($tree[$index]['value'], $position); if ($tree[$index]['doIHaveChildren']) { sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, ""); $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']); $messageCount = $mbx_response['EXISTS']; if ($messageCount > 0) { sqimap_msgs_list_copy($imap_stream, '1:*', $trash_folder . $delimiter . $subFolderName); } // after copy close the mailbox to get in unselected state sqimap_run_command($imap_stream, 'CLOSE', false, $response, $message); for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) { walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName); } } else { sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, ''); $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']); $messageCount = $mbx_response['EXISTS']; if ($messageCount > 0) { sqimap_msgs_list_copy($imap_stream, '1:*', $trash_folder . $delimiter . $subFolderName); } // after copy close the mailbox to get in unselected state sqimap_run_command($imap_stream, 'CLOSE', false, $response, $message); } }
/** * Selects a mailbox for header retrieval. * Cache control for message headers is embedded. * * @param resource $imapConnection imap socket handle * @param string $mailbox mailbox to select and retrieve message headers from * @param array $aConfig array with system config settings and incoming vars * @param array $aProps mailbox specific properties * * @return array $aMailbox mailbox array with all relevant information * * @since 1.5.1 * @author Marc Groot Koerkamp */ function sqm_api_mailbox_select($imapConnection, $account, $mailbox, $aConfig, $aProps) { /** * NB: retrieve this from the session before accessing this function * and make sure you write it back at the end of the script after * the aMailbox var is added so that the headers are added to the cache */ global $mailbox_cache; $aDefaultConfigProps = array('user' => false, 'setindex' => 0, 'max_cache_size' => SQM_MAX_MBX_IN_CACHE); $aConfig = array_merge($aDefaultConfigProps, $aConfig); $iSetIndx = $aConfig['setindex']; $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox); if ($mailbox_cache) { if (isset($mailbox_cache[$account . '_' . $mailbox])) { $aCachedMailbox = $mailbox_cache[$account . '_' . $mailbox]; } else { $aCachedMailbox = false; } /* cleanup cache */ if (count($mailbox_cache) > $aConfig['max_cache_size'] - 1) { $aTime = array(); foreach ($mailbox_cache as $cachedmailbox => $aVal) { $aTime[$aVal['TIMESTAMP']] = $cachedmailbox; } if (ksort($aTime, SORT_NUMERIC)) { for ($i = 0, $iCnt = count($mailbox_cache); $i < $iCnt - $aConfig['max_cache_size']; ++$i) { $sOldestMbx = array_shift($aTime); /** * Remove only the UIDSET and MSG_HEADERS from cache because those can * contain large amounts of data. */ if (isset($mailbox_cache[$sOldestMbx]['UIDSET'])) { $mailbox_cache[$sOldestMbx]['UIDSET'] = false; } if (isset($mailbox_cache[$sOldestMbx]['MSG_HEADERS'])) { $mailbox_cache[$sOldestMbx]['MSG_HEADERS'] = false; } } } } } else { $aCachedMailbox = false; } /** * Deal with imap servers that do not return the required UIDNEXT or * UIDVALIDITY response * from a SELECT call (since rfc 3501 it's required). */ if (!isset($aMbxResponse['UIDNEXT']) || !isset($aMbxResponse['UIDVALIDITY'])) { $aStatus = sqimap_status_messages($imapConnection, $mailbox, array('UIDNEXT', 'UIDVALIDITY')); $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT']; $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY']; } $aMailbox['ACCOUNT'] = $account; $aMailbox['UIDSET'][$iSetIndx] = false; $aMailbox['ID'] = false; $aMailbox['SETINDEX'] = $iSetIndx; $aMailbox['MSG_HEADERS'] = false; if ($aCachedMailbox) { /** * Validate integrity of cached data */ if ($aCachedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] && $aMbxResponse['EXISTS'] && $aCachedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] && $aCachedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT'] && isset($aCachedMailbox['SEARCH'][$iSetIndx]) && (!isset($aConfig['search']) || $aCachedMailbox['SEARCH'][$iSetIndx] == $aConfig['search'])) { if (isset($aCachedMailbox['MSG_HEADERS'])) { $aMailbox['MSG_HEADERS'] = $aCachedMailbox['MSG_HEADERS']; } $aMailbox['ID'] = $aCachedMailbox['ID']; if (isset($aCachedMailbox['UIDSET'][$iSetIndx]) && $aCachedMailbox['UIDSET'][$iSetIndx]) { if (isset($aProps[MBX_PREF_SORT]) && $aProps[MBX_PREF_SORT] != $aCachedMailbox['SORT']) { $newsort = $aProps[MBX_PREF_SORT]; $oldsort = $aCachedMailbox['SORT']; /** * If it concerns a reverse sort we do not need to invalidate * the cached sorted UIDSET, a reverse is sufficient. */ if ($newsort % 2 && $newsort + 1 == $oldsort || !($newsort % 2) && $newsort - 1 == $oldsort) { $aMailbox['UIDSET'][$iSetIndx] = array_reverse($aCachedMailbox['UIDSET'][$iSetIndx]); } else { $server_sort_array = false; $aMailbox['MSG_HEADERS'] = false; $aMailbox['ID'] = false; } // store the new sort value in the mailbox pref if ($aConfig['user']) { // FIXME, in ideal situation, we write back the // prefs at the end of the script setUserPref($aConfig['user'], 'pref_' . $account . '_' . $mailbox, serialize($aProps)); } } else { $aMailbox['UIDSET'][$iSetIndx] = $aCachedMailbox['UIDSET'][$iSetIndx]; } } } } /** * Restore the offset in the paginator if no new offset is provided. */ if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['offset']) && $aCachedMailbox['OFFSET']) { $aMailbox['OFFSET'] = $aCachedMailbox['OFFSET']; $aMailbox['PAGEOFFSET'] = $aCachedMailbox['PAGEOFFSET']; } else { $aMailbox['OFFSET'] = isset($aConfig['offset']) && $aConfig['offset'] ? $aConfig['offset'] - 1 : 0; $aMailbox['PAGEOFFSET'] = isset($aConfig['offset']) && $aConfig['offset'] ? $aConfig['offset'] : 1; } /** * Restore the number of messages in the result set */ if (isset($aCachedMailbox['TOTAL'][$iSetIndx]) && $aCachedMailbox['TOTAL'][$iSetIndx]) { $aMailbox['TOTAL'][$iSetIndx] = $aCachedMailbox['TOTAL'][$iSetIndx]; } /** * Restore the showall value no new showall value is provided. */ if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['showall']) && isset($aCachedMailbox['SHOWALL'][$iSetIndx]) && $aCachedMailbox['SHOWALL'][$iSetIndx]) { $aMailbox['SHOWALL'][$iSetIndx] = $aCachedMailbox['SHOWALL'][$iSetIndx]; } else { $aMailbox['SHOWALL'][$iSetIndx] = isset($aConfig['showall']) && $aConfig['showall'] ? 1 : 0; } /** * Restore the sort order if no new sort order is provided. */ if (!isset($aProps[MBX_PREF_SORT]) && isset($aCachedMailbox['SORT'])) { $aMailbox['SORT'] = $aCachedMailbox['SORT']; } else { $aMailbox['SORT'] = isset($aProps[MBX_PREF_SORT]) ? $aProps[MBX_PREF_SORT] : 0; } /** * Restore the number of message to show per page when no new limit is provided */ if (!isset($aProps[MBX_PREF_LIMIT]) && isset($aCachedMailbox['LIMIT'])) { $aMailbox['LIMIT'] = $aCachedMailbox['LIMIT']; } else { $aMailbox['LIMIT'] = isset($aProps[MBX_PREF_LIMIT]) ? $aProps[MBX_PREF_LIMIT] : 15; } /** * Restore the ordered columns to show when no new ordered columns are provided */ if (!isset($aProps[MBX_PREF_COLUMNS]) && isset($aCachedMailbox['COLUMNS'])) { $aMailbox['COLUMNS'] = $aCachedMailbox['COLUMNS']; } else { $aMailbox['COLUMNS'] = isset($aProps[MBX_PREF_COLUMNS]) ? $aProps[MBX_PREF_COLUMNS] : array(SQM_COL_FLAGS, SQM_COL_FROM, SQM_COL_SUBJ, SQM_COL_FLAGS); } /** * Restore the headers we fetch the last time. Saves intitialisation stuff in read_body. */ $aMailbox['FETCHHEADERS'] = isset($aCachedMailbox['FETCHHEADERS']) ? $aCachedMailbox['FETCHHEADERS'] : null; if (!isset($aProps[MBX_PREF_AUTO_EXPUNGE]) && isset($aCachedMailbox['AUTO_EXPUNGE'])) { $aMailbox['AUTO_EXPUNGE'] = $aCachedMailbox['AUTO_EXPUNGE']; } else { $aMailbox['AUTO_EXPUNGE'] = isset($aProps[MBX_PREF_AUTO_EXPUNGE]) ? $aProps[MBX_PREF_AUTO_EXPUNGE] : false; } if (!isset($aConfig['search']) && isset($aCachedMailbox['SEARCH'][$iSetIndx])) { $aMailbox['SEARCH'][$iSetIndx] = $aCachedMailbox['SEARCH'][$iSetIndx]; } else { if (isset($aConfig['search']) && isset($aCachedMailbox['SEARCH'][$iSetIndx]) && $aConfig['search'] != $aCachedMailbox['SEARCH'][$iSetIndx]) { // reset the pageindex $aMailbox['SEARCH'][$iSetIndx] = $aConfig['search']; $aMailbox['OFFSET'] = 0; $aMailbox['PAGEOFFSET'] = 1; } else { $aMailbox['SEARCH'][$iSetIndx] = isset($aConfig['search']) ? $aConfig['search'] : 'ALL'; } } if (!isset($aConfig['charset']) && isset($aCachedMailbox['CHARSET'][$iSetIndx])) { $aMailbox['CHARSET'][$iSetIndx] = $aCachedMailbox['CHARSET'][$iSetIndx]; } else { $aMailbox['CHARSET'][$iSetIndx] = isset($aConfig['charset']) ? $aConfig['charset'] : 'US-ASCII'; } $aMailbox['NAME'] = $mailbox; $aMailbox['EXISTS'] = $aMbxResponse['EXISTS']; $aMailbox['SEEN'] = isset($aMbxResponse['SEEN']) ? $aMbxResponse['SEEN'] : $aMbxResponse['EXISTS']; $aMailbox['RECENT'] = isset($aMbxResponse['RECENT']) ? $aMbxResponse['RECENT'] : 0; $aMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY']; $aMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT']; $aMailbox['PERMANENTFLAGS'] = $aMbxResponse['PERMANENTFLAGS']; $aMailbox['RIGHTS'] = $aMbxResponse['RIGHTS']; /* decide if we are thread sorting or not */ if ($aMailbox['SORT'] & SQSORT_THREAD) { if (!sqimap_capability($imapConnection, 'THREAD')) { $aMailbox['SORT'] ^= SQSORT_THREAD; } else { $aMailbox['THREAD_INDENT'] = $aCachedMailbox['THREAD_INDENT']; } } else { $aMailbox['THREAD_INDENT'] = false; } /* set a timestamp for cachecontrol */ $aMailbox['TIMESTAMP'] = time(); return $aMailbox; }
sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER); sqgetGlobalVar('messages', $messages); sqgetGlobalVar('passed_id', $passed_id, SQ_GET); if (sqgetGlobalVar('mailbox', $temp, SQ_GET)) { $mailbox = $temp; } if (!sqgetGlobalVar('ent_id', $ent_id, SQ_GET)) { $ent_id = ''; } if (!sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET)) { $passed_ent_id = ''; } $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); $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 . '&absolute_dl=true'; $unsafe_url = 'view_text.php?' . $QUERY_STRING; $unsafe_url = set_url_var($unsafe_url, 'view_unsafe_images', 1);
<?php /* Path for SquirrelMail required files. */ define('SM_PATH', '../../'); include_once SM_PATH . 'include/validate.php'; include_once SM_PATH . 'functions/imap.php'; include_once SM_PATH . 'functions/plugin.php'; include_once SM_PATH . 'functions/page_header.php'; include_once SM_PATH . 'functions/html.php'; include_once SM_PATH . 'plugins/bayesspam/config.php'; if (!isset($_REQUEST)) { $_REQUEST['bayes_type'] = $HTTP_GET_VARS['bayes_type']; $_REQUEST['mailbox'] = $HTTP_GET_VARS['mailbox']; $_REQUEST['passed_id'] = $HTTP_GET_VARS['passed_id']; $_REQUEST['startMessage'] = $HTTP_GET_VARS['startMessage']; $_REQUEST['show_more'] = $HTTP_GET_VARS['show_more']; } if ($_REQUEST['bayes_type'] == 'spam' || $_REQUEST['bayes_type'] == 'nonspam') { $key = $_COOKIE['key']; $onetimepad = $_SESSION['onetimepad']; $username = $_SESSION['username']; $delimiter = $_SESSION['delimiter']; $imapConnection = sqimap_login($username, $key, $GLOBALS['imapServerAddress'], $GLOBALS['imapPort'], 10, $onetimepad); // the 10 is to hide the output sqimap_mailbox_select($imapConnection, $_REQUEST['mailbox']); bayesspam_learn_single($imapConnection, $_REQUEST['mailbox'], $_REQUEST['passed_id'], $_REQUEST['bayes_type']); } header('Location: ../../src/read_body.php?mailbox=' . $_REQUEST['mailbox'] . '&passed_id=' . $_REQUEST['passed_id'] . '&startMessage=' . $_REQUEST['startMessage'] . '&show_more=' . $_REQUEST['show_more']);