updates
This commit is contained in:
@@ -210,14 +210,9 @@ async function fetchImapEmails(
|
||||
return;
|
||||
}
|
||||
|
||||
const searchCriteria = [
|
||||
'OR',
|
||||
['FROM', clientEmail],
|
||||
['TO', clientEmail],
|
||||
['CC', clientEmail]
|
||||
];
|
||||
|
||||
imap.search(searchCriteria, (err, results) => {
|
||||
// Use ALL to get all messages, then filter manually
|
||||
// This avoids the complex search criteria issues
|
||||
imap.search(['ALL'], (err, results) => {
|
||||
if (err) {
|
||||
console.error(`Search error in ${folderName}:`, err);
|
||||
searchNextFolder();
|
||||
@@ -252,17 +247,38 @@ async function fetchImapEmails(
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this email involves the client
|
||||
const fromEmail = parsed.from?.text || '';
|
||||
const toEmails = Array.isArray(parsed.to)
|
||||
? parsed.to.map((addr: any) => addr.text).join(', ')
|
||||
: parsed.to?.text || '';
|
||||
const ccEmails = Array.isArray(parsed.cc)
|
||||
? parsed.cc.map((addr: any) => addr.text).join(', ')
|
||||
: parsed.cc?.text || '';
|
||||
|
||||
// Filter to only include emails to/from the client
|
||||
const involvesClient =
|
||||
fromEmail.toLowerCase().includes(clientEmail.toLowerCase()) ||
|
||||
toEmails.toLowerCase().includes(clientEmail.toLowerCase()) ||
|
||||
ccEmails.toLowerCase().includes(clientEmail.toLowerCase());
|
||||
|
||||
if (!involvesClient) {
|
||||
messagesProcessed++;
|
||||
if (messagesProcessed === messagesToFetch.length) {
|
||||
searchNextFolder();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const email: EmailMessage = {
|
||||
id: parsed.messageId || `${Date.now()}-${seqno}`,
|
||||
from: parsed.from?.text || '',
|
||||
to: Array.isArray(parsed.to)
|
||||
? parsed.to.map((addr: any) => addr.text).join(', ')
|
||||
: parsed.to?.text || '',
|
||||
from: fromEmail,
|
||||
to: toEmails,
|
||||
subject: parsed.subject || '',
|
||||
body: parsed.text || '',
|
||||
html: parsed.html || undefined,
|
||||
timestamp: parsed.date?.toISOString() || new Date().toISOString(),
|
||||
direction: parsed.from?.text.toLowerCase().includes(userEmail.toLowerCase()) ? 'sent' : 'received'
|
||||
direction: fromEmail.toLowerCase().includes(userEmail.toLowerCase()) ? 'sent' : 'received'
|
||||
};
|
||||
|
||||
if (parsed.headers.has('in-reply-to')) {
|
||||
|
||||
Reference in New Issue
Block a user