| <!DOCTYPE html>
|
| <html>
|
| <head>
|
| <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| <title>Enron WebMail: Search</title>
|
| <link rel="stylesheet" href="/src/mail.css" type="text/css">
|
| <script>
|
| function getTopbarTarget() {
|
| var mailbox = localStorage.getItem('enron_current_mailbox');
|
| return mailbox ? '/mail/index.html' : '/index.html';
|
| }
|
|
|
| function initTopbarLink() {
|
| var topbar = document.getElementById('topbar-link');
|
| if (!topbar) { return; }
|
| topbar.addEventListener('click', function(e) {
|
| e.preventDefault();
|
| window.location.href = getTopbarTarget();
|
| });
|
| }
|
|
|
| document.addEventListener('DOMContentLoaded', initTopbarLink);
|
| </script>
|
| <style>
|
| .page-container {
|
| max-width: 727px;
|
| width: 100%;
|
| margin: 0 auto;
|
| }
|
|
|
|
|
| .search-input-large {
|
| width: 100%;
|
| padding: 8px;
|
| border: 2px solid #0066cc;
|
| font-size: 12px;
|
| margin-bottom: 10px;
|
| box-sizing: border-box;
|
| }
|
|
|
| .search-button {
|
| background-color: #ff9900;
|
| color: white;
|
| padding: 10px 30px;
|
| border: none;
|
| font-weight: bold;
|
| cursor: pointer;
|
| font-size: 12px;
|
| margin-bottom: 15px;
|
| width: 100%;
|
| }
|
|
|
| .search-button:hover {
|
| background-color: #cc7700;
|
| }
|
|
|
| .search-button:disabled {
|
| opacity: 0.5;
|
| cursor: not-allowed;
|
| }
|
|
|
| .cancel-button {
|
| background-color: #ccc;
|
| color: #333;
|
| padding: 10px 30px;
|
| border: none;
|
| font-weight: bold;
|
| cursor: pointer;
|
| font-size: 12px;
|
| margin-bottom: 15px;
|
| width: 100%;
|
| display: none;
|
| }
|
|
|
| .cancel-button:hover {
|
| background-color: #999;
|
| color: white;
|
| }
|
|
|
| .filter-group {
|
| margin-bottom: 10px;
|
| font-size: 11px;
|
| }
|
|
|
| .filter-group label {
|
| display: block;
|
| font-weight: bold;
|
| color: white;
|
| margin-bottom: 3px;
|
| font-size: 10px;
|
| }
|
|
|
| .filter-group select,
|
| .filter-group input[type="date"] {
|
| width: 100%;
|
| padding: 6px;
|
| border: 1px solid #0066cc;
|
| font-size: 11px;
|
| box-sizing: border-box;
|
| }
|
|
|
| .status-bar {
|
| background-color: #f5f5f5;
|
| border: 1px solid #ccc;
|
| padding: 10px;
|
| margin-bottom: 15px;
|
| text-align: center;
|
| font-size: 11px;
|
| }
|
|
|
| .loading-spinner {
|
| display: inline-block;
|
| width: 16px;
|
| height: 16px;
|
| border: 2px solid #f3f3f3;
|
| border-top: 2px solid #0066cc;
|
| border-radius: 50%;
|
| animation: spin 1s linear infinite;
|
| vertical-align: middle;
|
| margin-right: 5px;
|
| }
|
|
|
| @keyframes spin {
|
| 0% { transform: rotate(0deg); }
|
| 100% { transform: rotate(360deg); }
|
| }
|
|
|
| .result-item {
|
| border: 1px solid #e0e0e0;
|
| margin-bottom: 10px;
|
| padding: 12px;
|
| background-color: white;
|
| cursor: pointer;
|
| font-size: 11px;
|
| word-wrap: break-word;
|
| overflow-wrap: break-word;
|
| max-width: 100%;
|
| }
|
|
|
| .result-item:hover {
|
| background-color: #f8f8f8;
|
| border-color: #0066cc;
|
| }
|
|
|
| .result-subject {
|
| font-weight: bold;
|
| color: #0066cc;
|
| font-size: 13px;
|
| margin-bottom: 5px;
|
| }
|
|
|
| .result-meta {
|
| font-size: 11px;
|
| color: #666;
|
| margin-bottom: 8px;
|
| }
|
|
|
| .result-preview {
|
| font-size: 11px;
|
| color: #333;
|
| line-height: 1.4;
|
| }
|
|
|
| .highlight {
|
| background-color: #ffff00;
|
| font-weight: bold;
|
| }
|
|
|
| .badge {
|
| display: inline-block;
|
| padding: 2px 8px;
|
| background-color: #ff9900;
|
| color: white;
|
| font-size: 10px;
|
| font-weight: bold;
|
| margin-right: 5px;
|
| }
|
|
|
| .no-results {
|
| text-align: center;
|
| padding: 40px;
|
| color: #666;
|
| font-size: 12px;
|
| }
|
|
|
| .pagination {
|
| text-align: center;
|
| padding: 15px;
|
| margin-top: 10px;
|
| display: flex;
|
| flex-direction: column;
|
| align-items: center;
|
| justify-content: center;
|
| gap: 10px;
|
| }
|
| .pagination-row {
|
| display: flex;
|
| align-items: center;
|
| justify-content: center;
|
| gap: 10px;
|
| flex-wrap: nowrap;
|
| }
|
| .pagination a {
|
| text-decoration: none;
|
| border: none;
|
| outline: none;
|
| display: inline-flex;
|
| align-items: center;
|
| line-height: 0;
|
| flex-shrink: 0;
|
| }
|
| .pagination a img {
|
| display: block;
|
| border: none;
|
| }
|
|
|
| .pagination .page-info {
|
| display: inline-flex;
|
| align-items: center;
|
| margin: 0 10px;
|
| font-size: 11px;
|
| color: #666;
|
| flex-shrink: 0;
|
| white-space: nowrap;
|
| }
|
|
|
| .mailbox-dropdown {
|
| width: 100%;
|
| padding: 6px;
|
| border: 1px solid #0066cc;
|
| font-size: 11px;
|
| box-sizing: border-box;
|
| background-color: white;
|
| cursor: pointer;
|
| color: #333;
|
| }
|
|
|
| .mailbox-checkboxes {
|
| max-height: 200px;
|
| overflow-y: auto;
|
| border: 1px solid #0066cc;
|
| background-color: white;
|
| padding: 5px;
|
| margin-top: 5px;
|
| display: none;
|
| }
|
|
|
| .mailbox-checkboxes.show {
|
| display: block;
|
| }
|
|
|
| .mailbox-checkboxes label {
|
| display: block;
|
| color: #333;
|
| font-size: 10px;
|
| font-weight: normal;
|
| margin: 2px 0;
|
| padding: 2px;
|
| }
|
|
|
| .mailbox-checkboxes input[type="checkbox"] {
|
| width: auto;
|
| margin-right: 5px;
|
| accent-color: #0066cc;
|
| }
|
|
|
| .select-all-link {
|
| color: #ff9900;
|
| font-size: 10px;
|
| cursor: pointer;
|
| text-decoration: underline;
|
| margin-bottom: 5px;
|
| display: inline-block;
|
| }
|
|
|
| .collapse-toggle {
|
| color: #ff9900;
|
| font-size: 10px;
|
| cursor: pointer;
|
| text-decoration: underline;
|
| margin-bottom: 5px;
|
| display: block;
|
| font-weight: bold;
|
| }
|
| </style>
|
| </head>
|
|
|
| <body bgcolor="#ffffff">
|
|
|
| <div align="center" class="page-container">
|
|
|
| <table border="0" cellspacing="0" cellpadding="0">
|
|
|
|
|
| <tr><td colspan="5" style="line-height:0; font-size:0;"><a href="/index.html" id="topbar-link" style="display:block; line-height:0;"><img src="/src/topbar.jpg" width="727" height="93" border="0" style="display:block"></a></td></tr>
|
|
|
| <tr><td colspan="5" bgcolor="#0066cc"><img src="/src/spacer.gif" width="1" height="1" alt=""></td></tr>
|
|
|
| <tr>
|
|
|
| <td valign="top" align="left" width="1" class="gridLine" bgcolor="#0066cc" rowspan="2"><br /></td>
|
|
|
|
|
| <td valign="top" width="180" bgcolor="#0066cc" align="left">
|
| <table cellspacing="0" cellpadding="0" border="0" width="180" style="background-color:#0066cc;">
|
| <tr style="background-color:#0066cc;">
|
| <td style="background-color:#0066cc;"><img src="/src/spacer.gif" width="10" height="1"></td>
|
| <td valign="top" style="background-color:#0066cc; padding-top:0;">
|
|
|
|
|
| <div style="margin-bottom: 10px;">
|
| <h3 style="color: white; font-size: 12px; margin: 0; padding:0; font-weight: bold;">Search All Mailboxes</h3>
|
| </div>
|
|
|
|
|
| <div style="margin-bottom: 10px;">
|
| <div class="filter-group">
|
| <label>Search Terms (optional):</label>
|
| <input type="text" id="searchInput" class="search-input-large" placeholder="Enter search terms (optional)...">
|
| </div>
|
|
|
| <div class="filter-group">
|
| <label>Mailboxes:</label>
|
| <div class="mailbox-dropdown" id="mailboxDropdown" onclick="toggleMailboxList()">
|
| 150 mailboxes selected
|
| </div>
|
| <div id="mailboxCheckboxes" class="mailbox-checkboxes">
|
| <a href="#" class="select-all-link" onclick="toggleAllMailboxes(); return false;">Select All / None</a>
|
| </div>
|
| </div> <div class="filter-group">
|
| <label>From Date:</label>
|
| <input type="date" id="dateFrom">
|
| </div>
|
|
|
| <div class="filter-group">
|
| <label>To Date:</label>
|
| <input type="date" id="dateTo">
|
| </div>
|
|
|
| <div class="filter-group">
|
| <label style="display: block; margin-bottom: 5px;">
|
| <input type="checkbox" id="searchAttachments" style="width: auto; margin-right: 5px; accent-color: #ff9900;">
|
| Include attachments
|
| </label>
|
| </div>
|
|
|
| <div class="filter-group">
|
| <label>Search Type:</label>
|
| <label style="display: block; margin-bottom: 5px; cursor: pointer;">
|
| <input type="radio" name="searchType" value="emails" checked style="width: auto; margin-right: 5px; accent-color: #ff9900;">
|
| Emails
|
| </label>
|
| <label style="display: block; cursor: pointer;">
|
| <input type="radio" name="searchType" value="calendar" style="width: auto; margin-right: 5px; accent-color: #ff9900;">
|
| Calendar Entries
|
| </label>
|
| </div>
|
|
|
| <button class="search-button" onclick="performSearch()">Search</button>
|
| <button class="cancel-button" id="cancelButton" onclick="cancelSearch()">Cancel Search</button>
|
| </div>
|
|
|
| </td>
|
| <td><img src="/src/spacer.gif" width="5" height="1"></td>
|
| </tr>
|
| </table>
|
| </td>
|
|
|
|
|
| <td valign="top" align="left" width="1" class="gridLine" bgcolor="#0066cc" rowspan="2"><br /></td>
|
|
|
|
|
| <td valign="top" width="543" colspan="1" rowspan="2">
|
| <table cellspacing="0" cellpadding="0" border="0" width="543">
|
| <tr>
|
| <td style="padding: 10px 13px; width: 543px; max-width: 543px; overflow-x: hidden; box-sizing: border-box;">
|
|
|
|
|
| <div id="statusBar" style="display: none;" class="status-bar">
|
| <div id="statusText" style="font-weight: bold; color: #0066cc;"></div>
|
| <div id="loading" style="display: none; margin-top: 5px;">
|
| <span class="loading-spinner"></span>
|
| <span style="color: #666;">Searching...</span>
|
| </div>
|
| </div>
|
|
|
|
|
| <div id="results"></div>
|
|
|
|
|
| <div id="calendar-container" style="display: none;"></div>
|
|
|
|
|
| <div class="pagination" id="pagination" style="display: none;">
|
| <div class="pagination-row">
|
| <a href="#" id="prev-link" data-disabled="false"
|
| onmouseover="if(this.dataset.disabled!=='true'){document.getElementById('prev-img').src='/src/previous_hover.png'}"
|
| onmouseout="if(this.dataset.disabled!=='true'){document.getElementById('prev-img').src='/src/previous_on.png'}"
|
| onclick="if(this.dataset.disabled==='true') return false; changePage(-1); return false;">
|
| <img id="prev-img" src="/src/previous_on.png" alt="Previous" style="vertical-align:middle;">
|
| </a>
|
| <a href="#" id="next-link" data-disabled="false"
|
| onmouseover="if(this.dataset.disabled!=='true'){document.getElementById('next-img').src='/src/next_hover.png'}"
|
| onmouseout="if(this.dataset.disabled!=='true'){document.getElementById('next-img').src='/src/next_on.png'}"
|
| onclick="if(this.dataset.disabled==='true') return false; changePage(1); return false;">
|
| <img id="next-img" src="/src/next_on.png" alt="Next" style="vertical-align:middle;">
|
| </a>
|
| </div>
|
| <div class="pagination-row">
|
| <span class="page-info" id="page-info"></span>
|
| <input type="number" id="page-jump" min="1" placeholder="#" style="width: 50px; min-width: 50px; padding: 4px; font-size: 10px; text-align: center; border: 1px solid #ccc;" onkeypress="if(event.key==='Enter'){jumpToPage(parseInt(this.value)); this.blur();}" title="Jump to page" />
|
| </div>
|
| </div>
|
|
|
|
|
| <div id="initialMessage" style="text-align: center; padding: 60px 20px; color: #666;">
|
| <div style="font-size: 14px; font-weight: bold; margin-bottom: 10px;">Search All Enron Emails</div>
|
| <div style="font-size: 11px;">Enter search terms and/or select date filters in the sidebar, then click Search.</div>
|
| </div>
|
|
|
| </td>
|
| </tr>
|
| </table>
|
| </td>
|
|
|
|
|
| <td valign="top" align="left" width="1" class="gridLine" bgcolor="#0066cc" rowspan="2"><br /></td>
|
| </tr>
|
|
|
|
|
| <tr>
|
| <td valign="bottom" bgcolor="#0066cc" align="left" style="line-height:0; font-size:0; width:180px;">
|
| <img src="/src/navimage.gif" style="display:block;">
|
| </td>
|
| </tr>
|
|
|
|
|
| <tr><td valign="top" class="gridLine" bgcolor="#0066cc" colspan="5" style="line-height:0; font-size:0;"><img src="/src/spacer.gif" width="1" height="1" alt="spacer" style="display:block;"></td></tr>
|
|
|
|
|
| <tr><td colspan="5" style="line-height:0; font-size:0;"><img src="/src/bottombar.gif" style="display:block;"></td></tr>
|
|
|
| </table>
|
|
|
| </div>
|
|
|
| <script>
|
|
|
| let searchCancelled = false;
|
| let allMailboxes = [
|
| 'allen-p', 'arnold-j', 'arora-h', 'badeer-r', 'bailey-s', 'bass-e', 'baughman-d', 'beck-s',
|
| 'benson-r', 'blair-l', 'brawner-s', 'buy-r', 'campbell-l', 'carson-m', 'cash-m', 'causholli-m',
|
| 'corman-s', 'crandall-s', 'cuilla-m', 'dasovich-j', 'davis-d', 'dean-c', 'dean-c2', 'delainey-d',
|
| 'derrick-j', 'dickson-s', 'donoho-l', 'donohoe-t', 'dorland-c', 'ermis-f', 'farmer-d', 'fischer-m',
|
| 'fischer-m2', 'forney-j', 'fossum-d', 'gang-l', 'gay-r', 'geaccone-t', 'germany-c', 'gilbertsmith-d',
|
| 'giron-d', 'griffith-j', 'grigsby-m', 'guzman-m', 'haedicke-m', 'hain-m', 'harris-s', 'hayslett-r',
|
| 'heard-m', 'hendrickson-s', 'hernandez-j', 'hodge-j', 'hodge-j2', 'holst-k', 'horton-s', 'hyatt-k',
|
| 'hyvl-d', 'jones-t', 'kaminski-v', 'kean-s', 'keavey-p', 'keiser-k', 'king-j', 'kitchen-l',
|
| 'kuykendall-t', 'lavorato-j', 'lay-k', 'lenhart-m', 'lewis-a', 'linder-e', 'lokay-m', 'lokey-t',
|
| 'love-p', 'lucci-p', 'maggi-m', 'mann-k', 'martin-t', 'may-l', 'mccarty-d', 'mcconnell-m',
|
| 'mckay-b', 'mckay-j', 'mclaughlin-e', 'merris-s', 'meyers-a', 'mims-p', 'motley-m', 'neal-s',
|
| 'nemec-g', 'panus-s', 'parks-j', 'pereira-s', 'perlingiere-d', 'pimenov-v', 'platter-p', 'presto-k',
|
| 'quenet-j', 'quigley-d', 'rapp-b', 'reitmeyer-j', 'richey-c', 'ring-a', 'ring-r', 'rodrigue-r',
|
| 'rogers-b', 'ruscitti-k', 'sager-e', 'saibi-e', 'salisbury-h', 'sanchez-m', 'sanders-r', 'scholtes-d',
|
| 'schoolcraft-d', 'schwieger-j', 'scott-s', 'semperger-c', 'shackleton-s', 'shankman-j', 'shapiro-r',
|
| 'shively-h', 'skilling-j', 'slinger-r', 'smith-m', 'solberg-g', 'south-s', 'staab-t', 'stclair-c',
|
| 'steffes-j', 'stepenovitch-j', 'stokley-c', 'storey-g', 'sturm-f', 'swerzbin-m', 'symes-k', 'taylor-m',
|
| 'tholt-j', 'thomas-p', 'townsend-j', 'tycholiz-b', 'ward-k', 'watson-k', 'weldon-c', 'whalley-g',
|
| 'white-s', 'whitt-m', 'williams-b', 'williams-j', 'wolfe-j', 'ybarbo-p', 'zipper-a', 'zufferli-j'
|
| ];
|
| let searchResults = [];
|
| let currentPage = 1;
|
| const resultsPerPage = 50;
|
|
|
|
|
| async function init() {
|
| console.log('Init called, readyState:', document.readyState);
|
| console.log('Has savedParams:', !!sessionStorage.getItem('searchParams'));
|
| console.log('Has from_search flag:', !!sessionStorage.getItem('from_search'));
|
|
|
|
|
| const url = new URL(window.location.href);
|
| if (url.searchParams.has('mailbox') || url.searchParams.has('folder') || url.searchParams.has('email')) {
|
| console.log('Removing mailbox URL parameters from search page');
|
| url.searchParams.delete('mailbox');
|
| url.searchParams.delete('folder');
|
| url.searchParams.delete('email');
|
| window.history.replaceState({}, document.title, url.pathname + url.search);
|
| }
|
|
|
| initializeMailboxDropdown();
|
| populateMailboxFilter();
|
|
|
|
|
| const savedParams = sessionStorage.getItem('searchParams');
|
| if (savedParams && sessionStorage.getItem('from_search')) {
|
| console.log('Attempting to restore search...');
|
| try {
|
| const params = JSON.parse(savedParams);
|
|
|
|
|
| document.getElementById('searchInput').value = params.searchTerm || '';
|
| document.getElementById('dateFrom').value = params.dateFrom || '';
|
| document.getElementById('dateTo').value = params.dateTo || '';
|
| document.getElementById('searchAttachments').checked = params.searchAttachments || false;
|
|
|
|
|
| if (params.selectedMailboxes) {
|
| const checkboxes = document.querySelectorAll('.mailbox-checkbox');
|
| checkboxes.forEach(cb => {
|
| cb.checked = params.selectedMailboxes.includes(cb.value);
|
| });
|
| }
|
|
|
|
|
| console.log('Setting up UI for search restoration...');
|
| document.getElementById('initialMessage').style.display = 'none';
|
| document.getElementById('statusBar').style.display = 'block';
|
| document.getElementById('loading').style.display = 'block';
|
| document.getElementById('statusText').textContent = 'Restoring previous search...';
|
| console.log('Starting search in 100ms...');
|
| setTimeout(() => performSearch(), 100);
|
| } catch (e) {
|
| console.error('Error restoring search params:', e);
|
| }
|
| sessionStorage.removeItem('from_search');
|
| }
|
|
|
|
|
| document.getElementById('searchInput').addEventListener('keypress', function(e) {
|
| if (e.key === 'Enter') {
|
| performSearch();
|
| }
|
| });
|
| }
|
|
|
| function initializeMailboxDropdown() {
|
| const dropdown = document.getElementById('mailboxDropdown');
|
| dropdown.innerHTML = `${allMailboxes.length} mailboxes selected`;
|
| console.log('Initialized with', allMailboxes.length, 'mailboxes (hardcoded list)');
|
| }
|
|
|
| function populateMailboxFilter() {
|
| const container = document.getElementById('mailboxCheckboxes');
|
| allMailboxes.forEach(mailbox => {
|
| const label = document.createElement('label');
|
| const checkbox = document.createElement('input');
|
| checkbox.type = 'checkbox';
|
| checkbox.value = mailbox;
|
| checkbox.checked = true;
|
| checkbox.className = 'mailbox-checkbox';
|
| checkbox.addEventListener('change', updateMailboxCount);
|
| label.appendChild(checkbox);
|
| label.appendChild(document.createTextNode(` ${mailbox}`));
|
| container.appendChild(label);
|
| });
|
| updateMailboxCount();
|
| }
|
|
|
| function updateMailboxCount() {
|
| const checkedCount = document.querySelectorAll('.mailbox-checkbox:checked').length;
|
| const dropdown = document.getElementById('mailboxDropdown');
|
| if (dropdown) {
|
| dropdown.innerHTML = `${checkedCount} mailbox${checkedCount !== 1 ? 'es' : ''} selected`;
|
| }
|
| }
|
|
|
| function toggleAllMailboxes() {
|
| const checkboxes = document.querySelectorAll('.mailbox-checkbox');
|
| const allChecked = Array.from(checkboxes).every(cb => cb.checked);
|
| checkboxes.forEach(cb => cb.checked = !allChecked);
|
| updateMailboxCount();
|
| }
|
|
|
| function toggleMailboxList() {
|
| const container = document.getElementById('mailboxCheckboxes');
|
| container.classList.toggle('show');
|
| }
|
|
|
| async function performSearch() {
|
| const searchTerm = document.getElementById('searchInput').value.trim();
|
| const dateFrom = document.getElementById('dateFrom').value;
|
| const dateTo = document.getElementById('dateTo').value;
|
|
|
|
|
| if (!searchTerm && !dateFrom && !dateTo) {
|
| alert('Please enter a search term or select a date range');
|
| return;
|
| }
|
|
|
|
|
| const checkboxes = document.querySelectorAll('.mailbox-checkbox:checked');
|
| const selectedMailboxes = Array.from(checkboxes).map(cb => cb.value);
|
|
|
| if (selectedMailboxes.length === 0) {
|
| alert('Please select at least one mailbox to search');
|
| return;
|
| }
|
|
|
| const searchAttachments = document.getElementById('searchAttachments').checked;
|
| const searchType = document.querySelector('input[name="searchType"]:checked').value;
|
| const searchingCalendar = searchType === 'calendar';
|
|
|
|
|
| currentPage = 1;
|
|
|
|
|
| document.getElementById('initialMessage').style.display = 'none';
|
|
|
|
|
| document.getElementById('statusBar').style.display = 'block';
|
| document.getElementById('loading').style.display = 'block';
|
| document.getElementById('statusText').textContent = 'Starting search...';
|
| document.getElementById('results').innerHTML = '';
|
|
|
| const searchBtn = document.querySelector('.search-button');
|
| const cancelBtn = document.getElementById('cancelButton');
|
| searchBtn.disabled = true;
|
| searchBtn.style.display = 'none';
|
| cancelBtn.style.display = 'block';
|
| searchCancelled = false;
|
|
|
| searchResults = [];
|
| let searchedCount = 0;
|
|
|
| try {
|
| for (const mailbox of selectedMailboxes) {
|
| if (searchCancelled) {
|
| document.getElementById('statusText').textContent = 'Search cancelled.';
|
| break;
|
| }
|
| searchedCount++;
|
| document.getElementById('statusText').textContent =
|
| `Searching ${searchedCount} of ${selectedMailboxes.length} mailboxes...`;
|
|
|
| await searchMailbox(mailbox, searchTerm, dateFrom, dateTo, searchAttachments, searchingCalendar);
|
| }
|
|
|
|
|
| sessionStorage.setItem('searchParams', JSON.stringify({
|
| searchTerm: searchTerm,
|
| selectedMailboxes: selectedMailboxes,
|
| dateFrom: dateFrom,
|
| dateTo: dateTo,
|
| searchAttachments: searchAttachments
|
| }));
|
|
|
|
|
| if (searchingCalendar) {
|
| displayCalendarResults();
|
| } else {
|
| displayResults();
|
| }
|
| } catch (error) {
|
| console.error('Search error:', error);
|
| document.getElementById('results').innerHTML =
|
| '<div class="no-results">An error occurred during search</div>';
|
| } finally {
|
| document.getElementById('loading').style.display = 'none';
|
| searchBtn.disabled = false;
|
| searchBtn.style.display = 'block';
|
| cancelBtn.style.display = 'none';
|
| }
|
| }
|
| function cancelSearch() {
|
| searchCancelled = true;
|
| document.getElementById('statusText').textContent = 'Cancelling search...';
|
| }
|
| async function searchMailbox(mailbox, searchTerm, dateFrom, dateTo, searchAttachments, searchingCalendar) {
|
| try {
|
| const response = await fetch(`/mail/${mailbox}/index.json`);
|
| if (!response.ok) return;
|
|
|
| const data = await response.json();
|
|
|
|
|
| let emails = data.emails || [];
|
| const totalParts = data.total_parts || 1;
|
|
|
|
|
| if (!Array.isArray(emails)) {
|
| if (typeof emails === 'object' && emails !== null) {
|
| console.warn(`Mailbox ${mailbox}: emails field is an object, wrapping in array`);
|
| emails = [emails];
|
| } else {
|
| console.error(`Mailbox ${mailbox}: emails field is not an array or object, skipping`);
|
| return;
|
| }
|
| }
|
|
|
| if (totalParts > 1) {
|
|
|
| for (let i = 2; i <= totalParts; i++) {
|
| try {
|
| const partResponse = await fetch(`/mail/${mailbox}/index-part-${i}.json`);
|
| if (partResponse.ok) {
|
| const partData = await partResponse.json();
|
| emails = emails.concat(partData.emails || []);
|
| }
|
| } catch (e) {
|
| console.warn(`Failed to load part ${i} for ${mailbox}`);
|
| }
|
| }
|
| }
|
|
|
| const searchTermLower = searchTerm ? searchTerm.toLowerCase() : '';
|
|
|
| for (const email of emails) {
|
| let matches = false;
|
| let matchContext = '';
|
|
|
|
|
| if (!searchTerm) {
|
| matches = true;
|
| matchContext = email.subject || '(No subject)';
|
| } else {
|
|
|
| if (email.subject && email.subject.toLowerCase().includes(searchTermLower)) {
|
| matches = true;
|
| matchContext = email.subject;
|
| }
|
|
|
|
|
| if (!matches && email.from &&
|
| (email.from.name.toLowerCase().includes(searchTermLower) ||
|
| email.from.email.toLowerCase().includes(searchTermLower))) {
|
| matches = true;
|
| matchContext = `From: ${email.from.name} <${email.from.email}>`;
|
| }
|
|
|
|
|
| if (!matches && email.to) {
|
| for (const recipient of email.to) {
|
| if (recipient.name.toLowerCase().includes(searchTermLower) ||
|
| recipient.email.toLowerCase().includes(searchTermLower)) {
|
| matches = true;
|
| matchContext = `To: ${recipient.name} <${recipient.email}>`;
|
| break;
|
| }
|
| }
|
| }
|
|
|
|
|
| if (!matches && email.body) {
|
| const bodyText = stripHtml(email.body).toLowerCase();
|
| if (bodyText.includes(searchTermLower)) {
|
| matches = true;
|
| matchContext = extractContext(bodyText, searchTermLower);
|
| }
|
| }
|
|
|
|
|
| if (!matches && searchAttachments && email.attachments) {
|
| for (const att of email.attachments) {
|
| if (att.filename.toLowerCase().includes(searchTermLower)) {
|
| matches = true;
|
| matchContext = `Attachment: ${att.filename}`;
|
| break;
|
| }
|
| }
|
| }
|
| }
|
|
|
|
|
| if (matches && (dateFrom || dateTo)) {
|
| const emailDate = new Date(email.date);
|
| if (dateFrom && emailDate < new Date(dateFrom)) matches = false;
|
| if (dateTo && emailDate > new Date(dateTo + 'T23:59:59')) matches = false;
|
| }
|
|
|
|
|
| const isCalendarEntry = email.folder && email.folder.toLowerCase().includes('calendar');
|
| if (searchingCalendar) {
|
|
|
| if (!isCalendarEntry) matches = false;
|
| } else {
|
|
|
| if (isCalendarEntry) matches = false;
|
| }
|
|
|
| if (matches) {
|
| searchResults.push({
|
| ...email,
|
| mailbox: mailbox,
|
| matchContext: matchContext
|
| });
|
| }
|
| }
|
| } catch (error) {
|
| console.error(`Error searching mailbox ${mailbox}:`, error);
|
| }
|
| }
|
|
|
| function stripHtml(html) {
|
| if (!html) return '';
|
| const sanitized = html.replace(/(src|href)="cid:[^"]*"/gi, '');
|
| const tmp = document.createElement('div');
|
| tmp.innerHTML = sanitized;
|
| return tmp.textContent || tmp.innerText || '';
|
| }
|
|
|
| function extractContext(text, searchTerm, contextLength = 150) {
|
| const index = text.toLowerCase().indexOf(searchTerm.toLowerCase());
|
| if (index === -1) return text.substring(0, contextLength);
|
|
|
| const start = Math.max(0, index - contextLength / 2);
|
| const end = Math.min(text.length, index + searchTerm.length + contextLength / 2);
|
|
|
| let context = text.substring(start, end);
|
| if (start > 0) context = '...' + context;
|
| if (end < text.length) context = context + '...';
|
|
|
| return context;
|
| }
|
|
|
| function highlightText(text, searchTerm) {
|
| if (!text || !searchTerm) return text || '';
|
| const regex = new RegExp(`(${escapeRegex(searchTerm)})`, 'gi');
|
| return text.replace(regex, '<span class="highlight">$1</span>');
|
| }
|
|
|
| function escapeRegex(str) {
|
| return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
| }
|
|
|
| function displayCalendarResults() {
|
| const resultsDiv = document.getElementById('results');
|
| const calendarDiv = document.getElementById('calendar-container');
|
| const paginationDiv = document.getElementById('pagination');
|
|
|
|
|
| resultsDiv.style.display = 'none';
|
| calendarDiv.style.display = 'block';
|
| paginationDiv.style.display = 'none';
|
|
|
| document.getElementById('statusText').textContent =
|
| `Found ${searchResults.length} calendar entr${searchResults.length !== 1 ? 'ies' : 'y'}`;
|
|
|
| if (searchResults.length === 0) {
|
| calendarDiv.innerHTML = `
|
| <div class="no-results">
|
| <div style="font-weight: bold; margin-bottom: 5px;">No calendar entries found</div>
|
| <div>Try different search terms or filters</div>
|
| </div>
|
| `;
|
| return;
|
| }
|
|
|
|
|
| const calendarEvents = searchResults.map(result => ({
|
| ...result,
|
| start: result.date,
|
| end: result.endDate || null,
|
| subject: result.subject || 'Calendar Entry'
|
| }));
|
|
|
|
|
| if (typeof CalendarApp === 'undefined') {
|
|
|
| const existingScript = document.querySelector('script[src*="calendar-app.js"]');
|
| if (!existingScript) {
|
| const script = document.createElement('script');
|
| script.src = '/mail/calendar-app.js';
|
| script.onload = () => {
|
| new CalendarApp(calendarEvents);
|
| };
|
| document.body.appendChild(script);
|
| }
|
| } else {
|
| new CalendarApp(calendarEvents);
|
| }
|
| }
|
|
|
| function displayResults() {
|
| const resultsDiv = document.getElementById('results');
|
| const calendarDiv = document.getElementById('calendar-container');
|
| const paginationDiv = document.getElementById('pagination');
|
| const pageInfoEl = document.getElementById('page-info');
|
| const pageJumpInput = document.getElementById('page-jump');
|
| const searchTerm = document.getElementById('searchInput').value.trim();
|
|
|
|
|
| resultsDiv.style.display = 'block';
|
| calendarDiv.style.display = 'none';
|
|
|
| document.getElementById('statusText').textContent =
|
| `Found ${searchResults.length} result${searchResults.length !== 1 ? 's' : ''}`;
|
|
|
| if (searchResults.length === 0) {
|
| resultsDiv.innerHTML = `
|
| <div class="no-results">
|
| <div style="font-weight: bold; margin-bottom: 5px;">No results found</div>
|
| <div>Try different search terms or filters</div>
|
| </div>
|
| `;
|
| paginationDiv.style.display = 'none';
|
| return;
|
| }
|
|
|
|
|
| searchResults.sort((a, b) => new Date(b.date) - new Date(a.date));
|
|
|
|
|
| const totalPages = Math.ceil(searchResults.length / resultsPerPage);
|
| const startIndex = (currentPage - 1) * resultsPerPage;
|
| const endIndex = Math.min(startIndex + resultsPerPage, searchResults.length);
|
| const pageResults = searchResults.slice(startIndex, endIndex);
|
|
|
|
|
| resultsDiv.innerHTML = pageResults.map(result => {
|
| const date = new Date(result.date).toLocaleString();
|
| const fromName = result.from?.name || 'Unknown';
|
| const toList = result.to?.slice(0, 3).map(r => r.name).join(', ') || 'Unknown';
|
| const hasMore = result.to?.length > 3 ? ` +${result.to.length - 3}` : '';
|
|
|
| return `
|
| <div class="result-item" onclick="openEmail('${result.mailbox}', '${result.id}')">
|
| <div class="result-subject">${searchTerm ? highlightText(result.subject || '(No Subject)', searchTerm) : (result.subject || '(No Subject)')}</div>
|
| <div class="result-meta">
|
| <span class="badge">${result.mailbox}</span>
|
| <span class="badge" style="background-color: #0066cc;">${result.folder || 'Inbox'}</span>
|
| ${date}
|
| </div>
|
| <div class="result-meta">
|
| From: ${searchTerm ? highlightText(fromName, searchTerm) : fromName} |
|
| To: ${searchTerm ? highlightText(toList + hasMore, searchTerm) : (toList + hasMore)}
|
| ${result.attachments?.length ? ` | Attachments: ${result.attachments.length}` : ''}
|
| </div>
|
| <div class="result-preview">
|
| ${searchTerm ? highlightText(result.matchContext || stripHtml(result.body).substring(0, 200) + '...', searchTerm) : (result.matchContext || stripHtml(result.body).substring(0, 200) + '...')}
|
| </div>
|
| </div>
|
| `;
|
| }).join('');
|
|
|
|
|
| if (totalPages > 1) {
|
| paginationDiv.style.display = 'block';
|
| if (pageInfoEl) {
|
| pageInfoEl.textContent = `Page ${currentPage} of ${totalPages} (${startIndex + 1}-${endIndex} of ${searchResults.length})`;
|
| }
|
| if (pageJumpInput) {
|
| pageJumpInput.max = totalPages;
|
| pageJumpInput.value = '';
|
| pageJumpInput.placeholder = `1-${totalPages}`;
|
| }
|
|
|
|
|
| const prevLink = document.getElementById('prev-link');
|
| const prevImg = document.getElementById('prev-img');
|
| const prevDisabled = currentPage === 1;
|
| if (prevLink && prevImg) {
|
| prevLink.dataset.disabled = prevDisabled ? 'true' : 'false';
|
| prevLink.style.pointerEvents = prevDisabled ? 'none' : 'auto';
|
| prevImg.src = prevDisabled ? '/src/previous_off.png' : '/src/previous_on.png';
|
| prevImg.style.opacity = prevDisabled ? '0.5' : '1';
|
| }
|
|
|
|
|
| const nextLink = document.getElementById('next-link');
|
| const nextImg = document.getElementById('next-img');
|
| const nextDisabled = currentPage === totalPages;
|
| if (nextLink && nextImg) {
|
| nextLink.dataset.disabled = nextDisabled ? 'true' : 'false';
|
| nextLink.style.pointerEvents = nextDisabled ? 'none' : 'auto';
|
| nextImg.src = nextDisabled ? '/src/next_off.png' : '/src/next_on.png';
|
| nextImg.style.opacity = nextDisabled ? '0.5' : '1';
|
| }
|
| } else {
|
| paginationDiv.style.display = 'none';
|
| }
|
|
|
|
|
| document.getElementById('results').scrollIntoView({ behavior: 'smooth', block: 'start' });
|
| }
|
|
|
| function changePage(direction) {
|
| const totalPages = Math.ceil(searchResults.length / resultsPerPage) || 1;
|
| currentPage = Math.min(Math.max(1, currentPage + direction), totalPages);
|
| displayResults();
|
| }
|
|
|
| function jumpToPage(page) {
|
| const totalPages = Math.ceil(searchResults.length / resultsPerPage) || 1;
|
| if (!page || page < 1 || page > totalPages) return;
|
| currentPage = page;
|
| displayResults();
|
| }
|
|
|
| function openEmail(mailbox, emailId) {
|
| sessionStorage.setItem('from_search', 'true');
|
| localStorage.setItem('enron_current_mailbox', mailbox);
|
| sessionStorage.setItem('from_search_direct', 'true');
|
| window.location.href = `/mail/index.html?mailbox=${mailbox}&email=${emailId}`;
|
| }
|
| function logout() {
|
| sessionStorage.setItem('logging_out', 'true');
|
| localStorage.removeItem('enron_current_mailbox');
|
| localStorage.removeItem('enron_current_email');
|
| window.location.href = '/index.html';
|
| }
|
|
|
|
|
| if (document.readyState === 'loading') {
|
| document.addEventListener('DOMContentLoaded', init);
|
| } else {
|
| init();
|
| }
|
| </script>
|
|
|
| </body>
|
| </html>
|
|
|