if ($compose_new_win) { $location = set_url_var($location, 'composenew', 1, false); } else { $location = str_replace('search.php', 'compose.php', $location); $location = str_replace('right_main.php', 'compose.php', $location); } } } else { $exception = true; } } else { // Move messages if (count($id)) { // move messages only when target mailbox is not the same as source mailbox if ($mailbox != $targetMailbox) { sqimap_msgs_list_move($imapConnection, $id, $targetMailbox); if ($auto_expunge) { $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); } else { $cnt = 0; } if ($startMessage + $cnt - 1 >= $mbx_response['EXISTS']) { if ($startMessage > $show_num) { $location = set_url_var($location, 'startMessage', $startMessage - $show_num, false); } else { $location = set_url_var($location, 'startMessage', 1, false); } } } } else { $exception = true;
/** * 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'); } }
?> " /> <?php if ($account) { $imapConnection = sqimap_login($account['username'], $GO_CRYPTO->decrypt($account['password']), $account['host'], $account['port'], true); $aMailboxPref = array(MBX_PREF_SORT => 0, MBX_PREF_LIMIT => (int) $show_num, MBX_PREF_AUTO_EXPUNGE => (bool) $auto_expunge, MBX_PREF_INTERNALDATE => (bool) getPref($data_dir, $username, 'internal_date_sort')); $aConfig = array('allow_thread_sort' => $allow_thread_sort, 'allow_server_sort' => $allow_server_sort, 'user' => $username, 'offset' => $startMessage); $aMailbox = sqm_api_mailbox_select($imapConnection, $mailbox, $aConfig, $aMailboxPref); if ($aMailbox) { //block email to spam folder if (isset($_REQUEST['spam_uid']) && $_REQUEST['spam_uid'] > 0) { $spam_folder = $account['spam']; if ($_REQUEST['spam_address'] != '' && $spam_folder != '') { $email->add_filter($account['id'], "sender", smart_addslashes($_REQUEST['spam_address']), addslashes($spam_folder)); $messages[] = $_REQUEST['spam_uid']; sqimap_msgs_list_move($imapConnection, $messages, $spam_folder); } } } else { echo '<p class="Error">' . $ml_connect_failed . ' \'' . $account['host'] . '\' ' . $ml_at_port . ': ' . $account['port'] . '</p>'; echo '<p class="Error">' . imap_last_error() . '</p>'; require $GO_THEME->theme_path . 'footer.inc'; exit; } require "navigation.inc"; } else { echo '<br /><h3>' . $ml_no_accounts . '</h3><p class="normal">' . $ml_text . '</p>'; } echo '</form>'; sqimap_logout($imapConnection); require $GO_THEME->theme_path . "footer.inc";
/** * 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; }
/** * 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 * @param string $targetMailbox fake the target mailbox for move operations * @param boolean $bypass_trash fake the bypass trash checkbox for delete operations * @return string $sError error string in case of an error * @since 1.5.1 * @author Marc Groot Koerkamp */ function handleMessageListForm($imapConnection, &$aMailbox, $sButton = '', $aUid = array(), $targetMailbox = '', $bypass_trash = NULL) { /* incoming formdata */ $sButton = sqgetGlobalVar('moveButton', $sTmp, SQ_FORM) ? 'move' : $sButton; $sButton = sqgetGlobalVar('copyButton', $sTmp, SQ_FORM) ? 'copy' : $sButton; $sButton = sqgetGlobalVar('expungeButton', $sTmp, SQ_FORM) ? 'expunge' : $sButton; $sButton = sqgetGlobalVar('forward', $sTmp, SQ_FORM) ? 'forward' : $sButton; $sButton = sqgetGlobalVar('delete', $sTmp, SQ_FORM) ? 'setDeleted' : $sButton; $sButton = sqgetGlobalVar('undeleteButton', $sTmp, SQ_FORM) ? 'unsetDeleted' : $sButton; $sButton = sqgetGlobalVar('markRead', $sTmp, SQ_FORM) ? 'setSeen' : $sButton; $sButton = sqgetGlobalVar('markUnread', $sTmp, SQ_FORM) ? 'unsetSeen' : $sButton; $sButton = sqgetGlobalVar('markFlagged', $sTmp, SQ_FORM) ? 'setFlagged' : $sButton; $sButton = sqgetGlobalVar('markUnflagged', $sTmp, SQ_FORM) ? 'unsetFlagged' : $sButton; if (empty($targetMailbox)) { sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_FORM); } if (is_null($bypass_trash)) { sqgetGlobalVar('bypass_trash', $bypass_trash, SQ_FORM); } sqgetGlobalVar('msg', $msg, SQ_FORM); if (sqgetGlobalVar('account', $iAccount, SQ_FORM) === false) { $iAccount = 0; } $sError = ''; $mailbox = $aMailbox['NAME']; /* retrieve the check boxes */ $aUid = isset($msg) && is_array($msg) ? array_values($msg) : $aUid; if (count($aUid) && $sButton != 'expunge') { // don't do anything to any messages until we have done security check // FIXME: not sure this code really belongs here, but there's nowhere else to put it with this architecture sqgetGlobalVar('smtoken', $submitted_token, SQ_FORM, ''); sm_validate_security_token($submitted_token, -1, TRUE); // make sure message UIDs are sanitized (BIGINT) foreach ($aUid as $i => $uid) { $aUid[$i] = preg_match('/^[0-9]+$/', $uid) ? $uid : '0'; } $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, true, $mailbox); sqsession_register($targetMailbox, 'lastTargetMailbox'); $bExpunge = true; break; case 'copy': // sqimap_msgs_list_copy returns true or false. // If error happens - fourth argument handles it inside function. sqimap_msgs_list_copy($imapConnection, $aUid, $targetMailbox, true); sqsession_register($targetMailbox, 'lastTargetMailbox'); break; case 'forward': $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']['SESSION_NUMBER'] = $composesession; $aMailbox['FORWARD_SESSION']['UIDS'] = $aUid; } break; default: // Hook for plugin buttons $temp = array(&$sButton, &$aMailbox, $iAccount, $aMailbox['NAME'], &$aUid); do_hook('mailbox_display_button_action', $temp); break; } /** * $aUpdatedMsgs 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 an 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']; } /** * Also update flags in message object */ //FIXME: WHY are we keeping flags in TWO places?!? This is error-prone and some core code uses the is_xxxx message object values while other code uses the flags array above. That's a mess. if (isset($aMailbox['MSG_HEADERS'][$iUid]['MESSAGE_OBJECT'])) { $message = $aMailbox['MSG_HEADERS'][$iUid]['MESSAGE_OBJECT']; $message->is_seen = false; $message->is_answered = false; $message->is_forwarded = false; $message->is_deleted = false; $message->is_flagged = false; $message->is_mdnsent = false; foreach ($aMsg['FLAGS'] as $flag => $value) { if (strtolower($flag) == '\\seen' && $value) { $message->is_seen = true; } else { if (strtolower($flag) == '\\answered' && $value) { $message->is_answered = true; } else { if (strtolower($flag) == '$forwarded' && $value) { $message->is_forwarded = true; } else { if (strtolower($flag) == '\\deleted' && $value) { $message->is_deleted = true; } else { if (strtolower($flag) == '\\flagged' && $value) { $message->is_flagged = true; } else { if (strtolower($flag) == '$mdnsent' && $value) { $message->is_mdnsent = true; } } } } } } } $aMailbox['MSG_HEADERS'][$iUid]['MESSAGE_OBJECT'] = $message; } /** * 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; $aMailbox['TOTAL'][$aMailbox['SETINDEX']] -= (int) $iExpungedMessages; } 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); $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $aMailbox['NAME'], array(), array()); } else { // this is the same hook as above, but here it is called in the // context of not having had any messages selected and if any // plugin handles the situation, it should return TRUE so we // know this was not an erroneous user action // global $null; $temp = array(&$sButton, &$aMailbox, $iAccount, $aMailbox['NAME'], $null); if (!boolean_hook_function('mailbox_display_button_action', $temp, 1) && $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']); } }
function delete_move_next_move() { global $imapConnection, $mailbox, $auto_expunge, $lastTargetMailbox; sqgetGlobalVar('move_id', $move_id, SQ_POST); sqgetGlobalVar('mailbox', $mailbox, SQ_FORM); sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST); // Move message sqimap_msgs_list_move($imapConnection, $move_id, $targetMailbox); if ($auto_expunge) { delete_move_expunge_from_all($move_id); // sqimap_mailbox_expunge($imapConnection, $mailbox, true); } if ($targetMailbox != $lastTargetMailbox) { $lastTargetMailbox = $targetMailbox; sqsession_register($lastTargetMailbox, 'lastTargetMailbox'); } }
} // && $mail->open($account['host'], $account['type'], $account['port'],$account['username'], $GO_CRYPTO->decrypt($account['password']),$mailbox, 0, $account['use_ssl'], $account['novalidate_cert'])) $imapConnection = sqimap_login($account['username'], $GO_CRYPTO->decrypt($account['password']), $account['host'], $account['port'], true); if (!$imapConnection) { email_error(); } $aMailboxPref = array(MBX_PREF_SORT => 0, MBX_PREF_LIMIT => (int) $show_num, MBX_PREF_AUTO_EXPUNGE => (bool) $auto_expunge, MBX_PREF_INTERNALDATE => (bool) getPref($data_dir, $username, 'internal_date_sort')); $aConfig = array('allow_thread_sort' => $allow_thread_sort, 'allow_server_sort' => $allow_server_sort, 'user' => $username, 'offset' => $startMessage); $aMailbox = sqm_api_mailbox_select($imapConnection, $mailbox, $aConfig, $aMailboxPref); if (!$aMailbox) { email_error(); } if ($task == 'move_mail') { $messages = array($uid); $move_to_mailbox = smartstrip($_REQUEST['move_to_mailbox']); if (sqimap_msgs_list_move($imapConnection, $messages, $move_to_mailbox)) { header('Location: ' . $GO_MODULES->url . 'index.php?account_id=' . $account_id . '&mailbox=' . $mailbox); sqimap_logout($imapConnection); exit; } } $aMailbox['SORT'] = $sort_order ? $sort_field + 1 : $sort_field; fetchMessageHeaders($imapConnection, $aMailbox); if (isset($aMailbox['MSG_HEADERS'][$uid]['MESSAGE_OBJECT'])) { $message = $aMailbox['MSG_HEADERS'][$uid]['MESSAGE_OBJECT']; $FirstTimeSee = !$message->is_seen; } else { $message = sqimap_get_message($imapConnection, $uid, $mailbox); $FirstTimeSee = !$message->is_seen; $message->is_seen = true; $aMailbox['MSG_HEADERS'][$uid]['MESSAGE_OBJECT'] = $message;
/** * Loops through all the Received Headers to find IP Addresses * @param stream imap_stream the stream to read from * @access private */ function spam_filters($imap_stream) { global $data_dir, $username; global $SpamFilters_YourHop; global $SpamFilters_DNScache; global $SpamFilters_SharedCache; global $SpamFilters_BulkQuery; global $SpamFilters_CacheTTL; $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 $Value) { if ($Value['enabled']) { $run = true; break; } } // short-circuit if (!$run) { return; } // Ask for a big list of all "Received" headers in the inbox with // flags for each message. Kinda big. if ($filters_spam_scan == 'new') { $search_array = array(); $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, TRUE); 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)) { $headers = sqimap_get_small_header_list($imap_stream, $search_array, array('Received'), array()); } else { if ($filters_spam_scan != 'new') { $headers = sqimap_get_small_header_list($imap_stream, null, array('Received'), array()); } else { return; } } if (!count($headers)) { return; } $bulkquery = strlen($SpamFilters_BulkQuery) > 0 ? true : false; $IPs = array(); $aSpamIds = array(); foreach ($headers as $id => $aValue) { if (isset($aValue['UID'])) { $MsgNum = $aValue['UID']; } else { $MsgNum = $id; } // Look through all of the Received headers for IP addresses if (isset($aValue['RECEIVED'])) { foreach ($aValue['RECEIVED'] as $received) { // Check to see if this line is the right "Received from" line // to check // $aValue['Received'] is an array with all the received lines. // We should check them from bottom to top and only check the first 2. // Currently we check only the header where $SpamFilters_YourHop in occures 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, $aMatch)) { $isspam = false; if (filters_spam_check_site($aMatch[1], $aMatch[2], $aMatch[3], $aMatch[4], $filters)) { $aSpamIds[] = $MsgNum; $isspam = true; } if ($bulkquery) { array_shift($aMatch); $IP = explode('.', $aMatch); 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 we've checked one IP and YourHop is // just a space if ($SpamFilters_YourHop == ' ' || $isspam) { break; // don't check any more } } } } } } // Lookie! It's spam! Yum! if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) { if (!sqimap_msgs_list_move($imap_stream, $aSpamIds, $filters_spam_folder)) { // if errors occurred, don't try to filter again during this session sqsession_register(TRUE, 'filters_error'); global $color; error_box(_("A problem occurred filtering messages. Check filter settings and account quota if applicable. Filtering is disabled for the remainder of this login session."), $color); } // expunge even in the case of errors, in case some // messages were filtered before the error happened sqimap_mailbox_expunge($imap_stream, 'INBOX'); } if ($bulkquery && count($IPs)) { filters_bulkquery($filters, $IPs); } if ($SpamFilters_SharedCache) { filters_SaveCache(); } else { sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache'); } }