/** * Checks if mailbox contains new messages. * * @param stream $imapConnection * @param string $mailbox FIXME: option is not used * @param string $real_box unformated mailbox name * @param string $delimeter FIXME: option is not used * @param string $unseen FIXME: option is not used * @param integer $total_new number of new messages * @return bool true, if there are new messages */ function CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter, $unseen, &$total_new) { global $folder_prefix, $trash_folder, $sent_folder, $color, $move_to_sent, $move_to_trash, $unseen_notify, $unseen_type, $newmail_allbox, $newmail_recent, $newmail_changetitle; $mailboxURL = urlencode($real_box); $unseen = $recent = 0; // Skip folders for Sent and Trash if ($real_box == $sent_folder || $real_box == $trash_folder) { return 0; } if ($unseen_notify == 2 && $real_box == 'INBOX' || $unseen_notify == 3 && ($newmail_allbox == 'on' || $real_box == 'INBOX')) { $status = sqimap_status_messages($imapConnection, $real_box); if ($newmail_recent == 'on') { $total_new += $status['RECENT']; } else { $total_new += $status['UNSEEN']; } if ($total_new) { return 1; } } return 0; }
/** * FIXME: Undocumented function * @access private */ function start_filters() { global $mailbox, $imapServerAddress, $imapPort, $imap, $imap_general, $filters, $imap_stream, $imapConnection, $UseSeparateImapConnection, $AllowSpamFilters; sqgetGlobalVar('username', $username, SQ_SESSION); sqgetGlobalVar('key', $key, SQ_COOKIE); $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 $filterkey => $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, $key, $imapServerAddress, $imapPort, 10); $previously_connected = false; } else { if (isset($imapConnection)) { $stream = $imapConnection; $previously_connected = true; } else { $previously_connected = true; $stream = $imap_stream; } } $aStatus = sqimap_status_messages($stream, 'INBOX', array('MESSAGES')); if ($aStatus['MESSAGES']) { 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); } }
/** * 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 * @author Marc Groot Koerkamp */ function sqm_api_mailbox_select($imapConnection, $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; /** * In case the properties arrays are empty set the defaults. */ $aDefaultMbxPref = array(); // MBX_PREF_SORT => 0, // MBX_PREF_LIMIT => 15, // MBX_PREF_AUTO_EXPUNGE => 0, // MBX_PREF_INTERNALDATE => 0 // ); /* array_merge doesn't work with integers as keys */ // foreach ($aDefaultMbxPref as $key => $value) { // if (!isset($aProps[$key])) { // $aProps[$key] = $value; // } // } $aDefaultConfigProps = array('allow_server_sort' => sqimap_capability($imapConnection, 'SORT'), '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[$mailbox])) { $aCachedMailbox = $mailbox_cache[$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['UIDSET'][$iSetIndx] = false; $aMailbox['ID'] = false; $aMailbox['SETINDEX'] = $iSetIndx; 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_{$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 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; } 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; } 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; } if (!isset($aProps[MBX_PREF_INTERNALDATE]) && isset($aCachedMailbox['INTERNALDATE'])) { $aMailbox['INTERNALDATE'] = $aCachedMailbox['INTERNALDATE']; } else { $aMailbox['INTERNALDATE'] = isset($aProps[MBX_PREF_INTERNALDATE]) ? $aProps[MBX_PREF_INTERNALDATE] : false; } 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['allow_thread_sort']) && isset($aCachedMailbox['ALLOW_THREAD'])) { $aMailbox['ALLOW_THREAD'] = $aCachedMailbox['ALLOW_THREAD']; } else { $aMailbox['ALLOW_THREAD'] = isset($aConfig['allow_thread_sort']) ? $aConfig['allow_thread_sort'] : false; } if (!isset($aConfig['search']) && isset($aCachedMailbox['SEARCH'][$iSetIndx])) { $aMailbox['SEARCH'][$iSetIndx] = $aCachedMailbox['SEARCH'][$iSetIndx]; } 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['ALLOW_THREAD']) { if ($aMailbox['SORT'] & SQSORT_THREAD) { $aMailbox['SORT'] -= SQSORT_THREAD; } } if ($aMailbox['SORT'] & SQSORT_THREAD) { $aMailbox['SORT_METHOD'] = 'THREAD'; $aMailbox['THREAD_INDENT'] = $aCachedMailbox['THREAD_INDENT']; } else { if (isset($aConfig['allow_server_sort']) && $aConfig['allow_server_sort']) { $aMailbox['SORT_METHOD'] = 'SERVER'; $aMailbox['THREAD_INDENT'] = false; } else { $aMailbox['SORT_METHOD'] = 'SQUIRREL'; $aMailbox['THREAD_INDENT'] = false; } } /* set a timestamp for cachecontrol */ $aMailbox['TIMESTAMP'] = time(); return $aMailbox; }
/** * create_unseen_string: * * Create unseen and total message count for both this folder and * it's subfolders. * * @param string $boxName name of the current mailbox * @param array $boxArray array for the current mailbox * @param $imapConnection current imap connection in use * @return array[0] unseen message string (for display) * @return array[1] unseen message count */ function create_unseen_string($boxName, $boxArray, $imapConnection, $unseen_type) { global $boxes, $unseen_type, $color, $unseen_cum; /* Initialize the return value. */ $result = array(0, 0); /* Initialize the counts for this folder. */ $boxUnseenCount = 0; $boxMessageCount = 0; $totalUnseenCount = 0; $totalMessageCount = 0; /* Collect the counts for this box alone. */ $status = sqimap_status_messages($imapConnection, $boxName); $boxUnseenCount = $status['UNSEEN']; if ($boxUnseenCount === false) { return false; } if ($unseen_type == 2) { $boxMessageCount = $status['MESSAGES']; } /* Initialize the total counts. */ if ($boxArray['collapse'] == SM_BOX_COLLAPSED && $unseen_cum) { /* Collect the counts for this boxes subfolders. */ $curBoxLength = strlen($boxName); $boxCount = count($boxes); for ($i = 0; $i < $boxCount; ++$i) { /* Initialize the counts for this subfolder. */ $subUnseenCount = 0; $subMessageCount = 0; /* Collect the counts for this subfolder. */ if ($boxName != $boxes[$i]['unformatted'] && substr($boxes[$i]['unformatted'], 0, $curBoxLength) == $boxName && !in_array('noselect', $boxes[$i]['flags'])) { $status = sqimap_status_messages($imapConnection, $boxes[$i]['unformatted']); $subUnseenCount = $status['UNSEEN']; if ($unseen_type == 2) { $subMessageCount = $status['MESSAGES']; } /* Add the counts for this subfolder to the total. */ $totalUnseenCount += $subUnseenCount; $totalMessageCount += $subMessageCount; } } /* Add the counts for all subfolders to that of the box. */ $boxUnseenCount += $totalUnseenCount; $boxMessageCount += $totalMessageCount; } /* And create the magic unseen count string. */ /* Really a lot more then just the unseen count. */ if ($unseen_type == 1 && $boxUnseenCount > 0) { $result[0] = "({$boxUnseenCount})"; } else { if ($unseen_type == 2) { $result[0] = "({$boxUnseenCount}/{$boxMessageCount})"; $result[0] = "<font color=\"{$color['11']}\">{$result['0']}</font>"; } } /* Set the unseen count to return to the outside world. */ $result[1] = $boxUnseenCount; /* Return our happy result. */ return $result; }
/** * 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; }
/** * Returns the number of unseen messages in this folder. * obsoleted by sqimap_status_messages ! */ function sqimap_unseen_messages($imap_stream, $mailbox) { $aStatus = sqimap_status_messages($imap_stream, $mailbox, array('UNSEEN')); return $aStatus['UNSEEN']; }
function ListBoxes($boxes, $j = 0) { global $data_dir, $username, $startmessage, $color, $unseen_notify, $unseen_type, $move_to_trash, $trash_folder, $collapse_folders, $imapConnection, $use_icons, $icon_theme, $use_special_folder_color; if (!isset($boxes) || empty($boxes)) { return; } $pre = '<nobr>'; $end = ''; $collapse = false; $unseen_found = false; $unseen = 0; $mailbox = $boxes->mailboxname_full; $leader = '<tt>'; $leader .= str_repeat(' ', $j); $mailboxURL = urlencode($mailbox); /* get unseen/total messages information */ /* Only need to display info when option is set */ if (isset($unseen_notify) && $unseen_notify > 1 && ($boxes->unseen !== false || $boxes->total !== false)) { if ($boxes->unseen !== false) { $unseen = $boxes->unseen; } /* Should only display unseen info if the folder is inbox or you set the option for all folders */ if (strtolower($mailbox) == 'inbox' || $unseen_notify == 3) { $unseen_string = $unseen; /* If users requests, display message count too */ if (isset($unseen_type) && $unseen_type == 2 && $boxes->total !== false) { $unseen_string .= '/' . $boxes->total; } $unseen_string = "<font color=\"{$color['11']}\">({$unseen_string})</font>"; /* Finally allow the script to display the values by setting a boolean. This can only occur if the unseen count is great than 0 (if you have unseen count only), or you have the message count too. */ if ($unseen > 0 || isset($unseen_type) && $unseen_type == 2) { $unseen_found = true; } } } if (isset($boxes->mbxs[0]) && $collapse_folders) { $collapse = getPref($data_dir, $username, 'collapse_folder_' . $mailbox); $collapse = $collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse; $link = '<a target="left" style="text-decoration:none" ' . 'href="left_main.php?'; if ($collapse) { if ($use_icons && $icon_theme != 'none') { $link .= "unfold={$mailboxURL}\">{$leader}<img src=\"" . SM_PATH . 'images/plus.png" border="0" height="7" width="7" /> </tt>'; } else { $link .= "unfold={$mailboxURL}\">{$leader}+ </tt>"; } } else { if ($use_icons && $icon_theme != 'none') { $link .= "fold={$mailboxURL}\">{$leader}<img src=\"" . SM_PATH . 'images/minus.png" border="0" height="7" width="7" /> </tt>'; } else { $link .= "fold={$mailboxURL}\">{$leader}- </tt>"; } } $link .= '</a>'; $pre .= $link; } else { $pre .= $leader . ' </tt>'; } /* If there are unseen message, bold the line. */ if ($move_to_trash && $mailbox == $trash_folder) { if (!isset($boxes->total)) { $boxes->total = sqimap_status_messages($imapConnection, $mailbox); } if ($unseen > 0) { $pre .= '<b>'; } $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox={$mailboxURL}\" target=\"right\" style=\"text-decoration:none\">"; if ($unseen > 0) { $end .= '</b>'; } $end .= '</a>'; if ($boxes->total > 0) { if ($unseen > 0) { $pre .= '<b>'; } $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox={$mailboxURL}\" target=\"right\" style=\"text-decoration:none\">"; if ($unseen > 0) { $end .= '</b>'; } /* Print unseen information. */ if ($unseen_found) { $end .= " <small>{$unseen_string}</small>"; } $end .= "\n<small>\n" . ' [<a href="empty_trash.php">' . _("Purge") . '</a>]' . '</small>'; } } else { if (!$boxes->is_noselect) { if ($unseen > 0) { $pre .= '<b>'; } $pre .= "<a href=\"right_main.php?PG_SHOWALL=0&startMessage=1&mailbox={$mailboxURL}\" target=\"right\" style=\"text-decoration:none\">"; if ($unseen > 0) { $end .= '</b>'; } $end .= '</a>'; } /* Print unseen information. */ if ($unseen_found) { $end .= " <small>{$unseen_string}</small>"; } } $font = ''; $fontend = ''; if ($use_special_folder_color && $boxes->is_special) { $font = "<font color=\"{$color['11']}\">"; $fontend = "</font>"; } // let plugins fiddle with end of line $end .= concat_hook_function('left_main_after_each_folder', array(isset($numMessages) ? $numMessages : '', $boxes->mailboxname_full, $imapConnection)); $end .= '</nobr>'; if (!$boxes->is_root) { echo "" . $pre . $font . str_replace(array(' ', '<', '>'), array(' ', '<', '>'), $boxes->mailboxname_sub) . $fontend . $end . '<br />' . "\n"; $j++; } if (!$collapse || $boxes->is_root) { for ($i = 0; $i < count($boxes->mbxs); $i++) { listBoxes($boxes->mbxs[$i], $j); } } }
/** * @param stream $imap_stream imap connection resource * @param object $mbx_tree * @since since 1.5.0 */ function sqimap_get_status_mbx_tree($imap_stream, &$mbx_tree) { global $unseen_notify, $unseen_type, $trash_folder, $move_to_trash; $aMbxs = $aQuery = array(); sqimap_tree_to_ref_array($mbx_tree, $aMbxs); // remove the root node array_shift($aMbxs); if ($unseen_notify == 3) { $cnt = count($aMbxs); for ($i = 0; $i < $cnt; ++$i) { $oMbx =& $aMbxs[$i]; if (!$oMbx->is_noselect) { $mbx = $oMbx->mailboxname_full; if ($unseen_type == 2 || $move_to_trash && $oMbx->mailboxname_full == $trash_folder) { $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (MESSAGES UNSEEN RECENT)'; } else { $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (UNSEEN RECENT)'; } sqimap_prepare_pipelined_query($query, $tag, $aQuery, false); } else { $oMbx->unseen = $oMbx->total = $oMbx->recent = false; $tag = false; } $oMbx->tag = $tag; $aMbxs[$i] =& $oMbx; } // execute all the queries at once $aResponse = sqimap_run_pipelined_command($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage); $cnt = count($aMbxs); for ($i = 0; $i < $cnt; ++$i) { $oMbx =& $aMbxs[$i]; $tag = $oMbx->tag; if ($tag && $aServerResponse[$tag] == 'OK') { $sResponse = implode('', $aResponse[$tag]); if (preg_match('/UNSEEN\\s+([0-9]+)/i', $sResponse, $regs)) { $oMbx->unseen = $regs[1]; } if (preg_match('/MESSAGES\\s+([0-9]+)/i', $sResponse, $regs)) { $oMbx->total = $regs[1]; } if (preg_match('/RECENT\\s+([0-9]+)/i', $sResponse, $regs)) { $oMbx->recent = $regs[1]; } } unset($oMbx->tag); } } else { if ($unseen_notify == 2) { // INBOX only $cnt = count($aMbxs); for ($i = 0; $i < $cnt; ++$i) { $oMbx =& $aMbxs[$i]; if (strtoupper($oMbx->mailboxname_full) == 'INBOX' || $move_to_trash && $oMbx->mailboxname_full == $trash_folder) { if ($unseen_type == 2 || $oMbx->mailboxname_full == $trash_folder && $move_to_trash) { $aStatus = sqimap_status_messages($imap_stream, $oMbx->mailboxname_full); $oMbx->unseen = $aStatus['UNSEEN']; $oMbx->total = $aStatus['MESSAGES']; $oMbx->recent = $aStatus['RECENT']; } else { $oMbx->unseen = sqimap_unseen_messages($imap_stream, $oMbx->mailboxname_full); } $aMbxs[$i] =& $oMbx; if (!$move_to_trash && $trash_folder) { break; } else { // trash comes after INBOX if ($oMbx->mailboxname_full == $trash_folder) { break; } } } } } } $cnt = count($aMbxs); for ($i = 0; $i < $cnt; ++$i) { $oMbx =& $aMbxs[$i]; unset($hook_status); if (!empty($oMbx->unseen)) { $hook_status['UNSEEN'] = $oMbx->unseen; } if (!empty($oMbx->total)) { $hook_status['MESSAGES'] = $oMbx->total; } if (!empty($oMbx->recent)) { $hook_status['RECENT'] = $oMbx->recent; } if (!empty($hook_status)) { $hook_status['MAILBOX'] = $oMbx->mailboxname_full; $hook_status['CALLER'] = 'sqimap_get_status_mbx_tree'; // helps w/ debugging do_hook('folder_status', $hook_status); } } }
/** * 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); } }