Email Attachment Organizer

Email Attachment Organizer

Streamline your digital files by organizing email attachments with custom rules.

Organization Summary

No data configured yet. Please go to the Data Configuration tab to set up your organization rules and add attachments.

Configure Your Rules & Attachments

Organization Rules

Add Attachments

No attachments added. Please configure your data.

'; return; } const organizedFiles = {}; const fileTypeCounts = {}; const senderCounts = {}; attachmentItems.forEach(item => { const inputs = item.querySelectorAll('input'); if(inputs.length < 3) return; const fileName = inputs[0].value.trim(); const sender = inputs[1].value.trim(); const subject = inputs[2].value.trim(); if (!fileName) return; // Get file type const fileExtension = fileName.split('.').pop().toLowerCase(); fileTypeCounts[fileExtension] = (fileTypeCounts[fileExtension] || 0) + 1; // Get sender if(sender) { senderCounts[sender] = (senderCounts[sender] || 0) + 1; } // Determine category let category = 'Uncategorized'; if (categoryBy === 'file-type') { category = fileExtension.toUpperCase(); } else if (categoryBy === 'sender' && sender) { category = sender; } else if (categoryBy === 'subject') { // Simple keyword extraction (first word) for demonstration category = subject.split(' ')[0] || 'General'; } // Mock date for folder structure const date = new Date(); const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); // Build folder path let path; if (folderStructure === 'category/year/month') { path = `${category}/${year}/${month}`; } else { path = `${year}/${month}/${category}`; } if (!organizedFiles[path]) { organizedFiles[path] = []; } organizedFiles[path].push(fileName); }); // Build HTML output let html = `

Total Attachments

${attachmentItems.length}

File Types

${Object.keys(fileTypeCounts).join(', ').toUpperCase() || 'N/A'}

Organized File Structure

`; const sortedPaths = Object.keys(organizedFiles).sort(); if (sortedPaths.length === 0) { html += '

Could not generate a file structure. Please check your inputs.

'; } else { sortedPaths.forEach(path => { html += `

${path}/

    `; organizedFiles[path].forEach(file => { html += `
  • ${file}
  • `; }); html += `
`; }); } html += '
'; dashboardOutput.innerHTML = html; } /** * Handles the PDF download functionality. */ async function downloadPDF() { const { jsPDF } = window.jspdf; const content = document.getElementById('pdf-content'); if (!content) return; // Temporarily add a title for the PDF const pdfTitle = document.createElement('h1'); pdfTitle.innerText = 'Email Attachment Organization Summary'; pdfTitle.className = 'text-2xl font-bold text-center mb-6'; content.prepend(pdfTitle); try { const canvas = await html2canvas(content, { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / canvasHeight; let imgWidth = pdfWidth - 20; // with margin let imgHeight = imgWidth / ratio; // If content is too long, split into multiple pages let heightLeft = imgHeight; let position = 10; // top margin pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight); heightLeft -= (pdfHeight - 20); while (heightLeft > 0) { position = heightLeft - imgHeight + 10; // reset position for new page pdf.addPage(); pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight); heightLeft -= (pdfHeight - 20); } pdf.save('Email-Attachment-Summary.pdf'); } catch (error) { console.error("Error generating PDF:", error); // Fallback for user in case of error const errorDiv = document.createElement('div'); errorDiv.className = 'p-4 bg-red-100 text-red-700 rounded-lg my-4'; errorDiv.innerText = 'Sorry, there was an error generating the PDF. Please try again.'; dashboardOutput.prepend(errorDiv); } finally { // Clean up the added title pdfTitle.remove(); } } // --- Event Listeners --- if (addAttachmentBtn) { addAttachmentBtn.addEventListener('click', addAttachmentRow); } if (downloadPdfBtn) { downloadPdfBtn.addEventListener('click', downloadPDF); } // --- Initial Setup --- updateNavButtons(); // Set initial state of nav buttons generateDashboard(); // Generate initial dashboard view });
Scroll to Top