courrier multi account restore compose
This commit is contained in:
parent
4e7bdb1631
commit
1a380f973c
@ -642,7 +642,7 @@ export default function CourrierPage() {
|
|||||||
|
|
||||||
// Extract the base folder name if it already has an account prefix
|
// Extract the base folder name if it already has an account prefix
|
||||||
let baseFolder = folder;
|
let baseFolder = folder;
|
||||||
let folderAccountId = accountId;
|
let folderAccountId = null;
|
||||||
|
|
||||||
if (folder.includes(':')) {
|
if (folder.includes(':')) {
|
||||||
const parts = folder.split(':');
|
const parts = folder.split(':');
|
||||||
@ -651,71 +651,46 @@ export default function CourrierPage() {
|
|||||||
|
|
||||||
logEmailOp('MAILBOX-CHANGE', `Parsed folder: accountId=${folderAccountId}, baseFolder=${baseFolder}`);
|
logEmailOp('MAILBOX-CHANGE', `Parsed folder: accountId=${folderAccountId}, baseFolder=${baseFolder}`);
|
||||||
|
|
||||||
// If the prefixed account doesn't match our account, log a warning
|
// CRITICAL FIX: If the folder has an account prefix that doesn't match the requested account,
|
||||||
|
// log a warning and ALWAYS use the requested accountId
|
||||||
if (folderAccountId !== accountId.toString()) {
|
if (folderAccountId !== accountId.toString()) {
|
||||||
logEmailOp('MAILBOX-CHANGE', `WARNING: Folder prefix mismatch`, {
|
logEmailOp('MAILBOX-CHANGE', `WARNING: Folder prefix mismatch - FIXING`, {
|
||||||
folderAccount: folderAccountId,
|
folderAccount: folderAccountId,
|
||||||
targetAccount: accountId,
|
requestedAccount: accountId,
|
||||||
originalFolder: folder
|
originalFolder: folder,
|
||||||
|
baseFolder: baseFolder
|
||||||
});
|
});
|
||||||
|
// Force the correct account ID to be used
|
||||||
|
folderAccountId = accountId.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always create a consistent folder name with current account prefix
|
// ALWAYS create a consistent folder name with REQUESTED account prefix
|
||||||
const prefixedFolder = `${accountId}:${baseFolder}`;
|
const prefixedFolder = `${accountId}:${baseFolder}`;
|
||||||
logEmailOp('MAILBOX-CHANGE', `Normalized folder name: ${prefixedFolder}`);
|
logEmailOp('MAILBOX-CHANGE', `Normalized folder name: ${prefixedFolder}`);
|
||||||
|
|
||||||
// Find exact folder match in account's folders
|
|
||||||
const exactMatch = account.folders?.find(f =>
|
|
||||||
f === prefixedFolder ||
|
|
||||||
f === baseFolder ||
|
|
||||||
(f.includes(':') && f.split(':')[1] === baseFolder)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (exactMatch) {
|
|
||||||
logEmailOp('MAILBOX-CHANGE', `Found exact folder match: ${exactMatch}`);
|
|
||||||
} else {
|
|
||||||
logEmailOp('MAILBOX-CHANGE', `No exact folder match found for ${baseFolder}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no match and not INBOX, show error
|
|
||||||
if (!exactMatch && !baseFolder.toLowerCase().includes('inbox')) {
|
|
||||||
logEmailOp('MAILBOX-CHANGE', `ERROR: Folder not found: ${baseFolder}`);
|
|
||||||
toast({
|
|
||||||
title: "Folder not found",
|
|
||||||
description: `The folder "${baseFolder}" does not exist for this account.`,
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the exact match if found, otherwise use our constructed prefixedFolder
|
|
||||||
const folderToUse = exactMatch || prefixedFolder;
|
|
||||||
logEmailOp('MAILBOX-CHANGE', `Proceeding with folder: ${folderToUse}`);
|
|
||||||
|
|
||||||
// CRITICAL FIX: Lock in the selected folder BEFORE changing it in the system
|
// CRITICAL FIX: Lock in the selected folder BEFORE changing it in the system
|
||||||
// This prevents any race conditions where the folder gets reset to INBOX
|
// This prevents any race conditions where the folder gets reset to INBOX
|
||||||
setSelectedFolders(prev => {
|
setSelectedFolders(prev => {
|
||||||
const updated = {
|
const updated = {
|
||||||
...prev,
|
...prev,
|
||||||
[accountId]: folderToUse
|
[accountId]: prefixedFolder
|
||||||
};
|
};
|
||||||
logEmailOp('MAILBOX-CHANGE', `Updated selected folders map`, updated);
|
logEmailOp('MAILBOX-CHANGE', `Updated selected folders map`, updated);
|
||||||
return updated;
|
return updated;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Use the correct changeFolder method to handle the folder change properly
|
// Call changeFolder with the prefixed folder name and explicit accountId
|
||||||
// This ensures that the account ID is properly passed along
|
// This ensures that both the folder name and accountId parameter are consistent
|
||||||
changeFolder(folderToUse, accountId)
|
changeFolder(prefixedFolder, accountId)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
logEmailOp('MAILBOX-CHANGE', `Successfully changed to folder ${folderToUse}`);
|
logEmailOp('MAILBOX-CHANGE', `Successfully changed to folder ${prefixedFolder}`);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
logEmailOp('MAILBOX-CHANGE', `ERROR: Failed to change to folder ${folderToUse}`, { error });
|
logEmailOp('MAILBOX-CHANGE', `ERROR: Failed to change to folder ${prefixedFolder}`, { error });
|
||||||
toast({
|
toast({
|
||||||
title: "Error changing folders",
|
title: "Error changing folders",
|
||||||
description: `Failed to change to folder ${baseFolder}. ${error?.message || ''}`,
|
description: `Failed to change to folder ${baseFolder}. ${error instanceof Error ? error.message : String(error)}`,
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@ -822,37 +797,10 @@ export default function CourrierPage() {
|
|||||||
setSelectedAccount(account);
|
setSelectedAccount(account);
|
||||||
logEmailOp('ACCOUNT-SELECT', `Selected account set to: ${account.email}`);
|
logEmailOp('ACCOUNT-SELECT', `Selected account set to: ${account.email}`);
|
||||||
|
|
||||||
// Find an INBOX folder in this account's folders
|
// SIMPLIFIED APPROACH: Instead of trying to find an existing INBOX folder,
|
||||||
// Look for exact INBOX or accountId:INBOX pattern
|
// just create a properly formatted one with the current account ID
|
||||||
const inboxPatterns = ['INBOX', ':INBOX', 'inbox', 'Inbox'];
|
const inboxFolder = `${account.id}:INBOX`;
|
||||||
|
logEmailOp('ACCOUNT-SELECT', `Using standardized INBOX folder: ${inboxFolder}`);
|
||||||
let inboxFolder = account.folders.find(f =>
|
|
||||||
inboxPatterns.some(pattern => {
|
|
||||||
const hasPattern = f.includes(pattern);
|
|
||||||
// For prefixed folders, make sure it's for the current account
|
|
||||||
if (f.includes(':')) {
|
|
||||||
const [folderId] = f.split(':');
|
|
||||||
return hasPattern && folderId === account.id;
|
|
||||||
}
|
|
||||||
return hasPattern;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
// If no inbox found, use the first folder or create a default inbox path
|
|
||||||
if (!inboxFolder) {
|
|
||||||
inboxFolder = account.folders.length > 0
|
|
||||||
? account.folders[0]
|
|
||||||
: `${account.id}:INBOX`;
|
|
||||||
logEmailOp('ACCOUNT-SELECT', `No INBOX found, using folder: ${inboxFolder}`);
|
|
||||||
} else {
|
|
||||||
logEmailOp('ACCOUNT-SELECT', `Found INBOX folder: ${inboxFolder}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the folder has the account prefix
|
|
||||||
if (!inboxFolder.includes(':')) {
|
|
||||||
inboxFolder = `${account.id}:${inboxFolder}`;
|
|
||||||
logEmailOp('ACCOUNT-SELECT', `Added account prefix to folder: ${inboxFolder}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the selected folders map with the proper account ID and folder
|
// Update the selected folders map with the proper account ID and folder
|
||||||
setSelectedFolders(prev => {
|
setSelectedFolders(prev => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user