updates
This commit is contained in:
parent
58b2504e14
commit
b4fe29413b
|
|
@ -193,14 +193,27 @@ const copyLink = async (link: string | undefined) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatDate = (dateString: string) => {
|
const formatDate = (dateString: string) => {
|
||||||
|
if (!dateString) return '';
|
||||||
|
|
||||||
|
try {
|
||||||
const date = new Date(dateString);
|
const date = new Date(dateString);
|
||||||
return date.toLocaleString('en-US', {
|
// Check if date is valid
|
||||||
month: 'short',
|
if (isNaN(date.getTime())) {
|
||||||
day: 'numeric',
|
return dateString; // Return original if parsing fails
|
||||||
|
}
|
||||||
|
|
||||||
|
return date.toLocaleString('en-GB', {
|
||||||
|
day: '2-digit',
|
||||||
|
month: '2-digit',
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
hour: '2-digit',
|
hour: '2-digit',
|
||||||
minute: '2-digit'
|
minute: '2-digit',
|
||||||
|
hour12: false
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Date formatting error:', error);
|
||||||
|
return dateString;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStatusColor = (status: string) => {
|
const getStatusColor = (status: string) => {
|
||||||
|
|
|
||||||
|
|
@ -210,14 +210,9 @@ async function fetchImapEmails(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchCriteria = [
|
// Use ALL to get all messages, then filter manually
|
||||||
'OR',
|
// This avoids the complex search criteria issues
|
||||||
['FROM', clientEmail],
|
imap.search(['ALL'], (err, results) => {
|
||||||
['TO', clientEmail],
|
|
||||||
['CC', clientEmail]
|
|
||||||
];
|
|
||||||
|
|
||||||
imap.search(searchCriteria, (err, results) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(`Search error in ${folderName}:`, err);
|
console.error(`Search error in ${folderName}:`, err);
|
||||||
searchNextFolder();
|
searchNextFolder();
|
||||||
|
|
@ -252,17 +247,38 @@ async function fetchImapEmails(
|
||||||
return;
|
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 = {
|
const email: EmailMessage = {
|
||||||
id: parsed.messageId || `${Date.now()}-${seqno}`,
|
id: parsed.messageId || `${Date.now()}-${seqno}`,
|
||||||
from: parsed.from?.text || '',
|
from: fromEmail,
|
||||||
to: Array.isArray(parsed.to)
|
to: toEmails,
|
||||||
? parsed.to.map((addr: any) => addr.text).join(', ')
|
|
||||||
: parsed.to?.text || '',
|
|
||||||
subject: parsed.subject || '',
|
subject: parsed.subject || '',
|
||||||
body: parsed.text || '',
|
body: parsed.text || '',
|
||||||
html: parsed.html || undefined,
|
html: parsed.html || undefined,
|
||||||
timestamp: parsed.date?.toISOString() || new Date().toISOString(),
|
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')) {
|
if (parsed.headers.has('in-reply-to')) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue