Skip to content

Email for professionals and teams

improve import emails from file/imap

Hieu Nguyen (Jack)d74923c90aaf
diff --git a/src/app/(settings)/settings/import/page.tsx b/src/app/(settings)/settings/import/page.tsx
index 80e71d1..bae1767 100644
--- a/src/app/(settings)/settings/import/page.tsx
+++ b/src/app/(settings)/settings/import/page.tsx
@@ -122,7 +122,7 @@ export default function SettingsImportPage() {
const discoveredFolders = await fetchImapFolders(imapForm);
const expandedSources: ImportSourceItem[] = [];
for (const source of selectedSources) {
- if (source.id === "system:folders") {
+ if (source.id === "system:others") {
expandedSources.push(
...filterCustomImapFolders(discoveredFolders, selectedSources).map(
getFolderImportSource,
@@ -244,10 +244,10 @@ export default function SettingsImportPage() {
imported once into {fileImportSource.label}
</p>
</div>
- {selectedSections.includes("folders") && (
- <p className="rounded-lg border border-amber-100 bg-amber-50 px-4 py-3 text-sm text-amber-700">
- Folders can be imported automatically from IMAP. File import
- cannot discover source folders.
+ {selectedSections.includes("others") && (
+ <p className="rounded-lg border border-amber-100 bg-amber-50 px-4 py-3 text-sm text-amber-700">
+ Other folders can be imported automatically from IMAP. File import
+ cannot discover which section a message belongs to.
</p>
)}
<Button
diff --git a/src/app/(settings)/settings/import/types.d.ts b/src/app/(settings)/settings/import/types.d.ts
index 75abef6..1ce8020 100644
--- a/src/app/(settings)/settings/import/types.d.ts
+++ b/src/app/(settings)/settings/import/types.d.ts
@@ -15,7 +15,7 @@ export type ImapFormState = {
limit: string;
};
-export type ImportSourceSection = "inbox" | "sent" | "drafts" | "archived" | "spam" | "trash" | "folders";
+export type ImportSourceSection = "inbox" | "sent" | "drafts" | "archived" | "spam" | "trash" | "others";
export type ImportSourceOption = {
value: ImportSourceSection;
diff --git a/src/app/(settings)/settings/import/utils.ts b/src/app/(settings)/settings/import/utils.ts
index 2653b75..7c9c21a 100644
--- a/src/app/(settings)/settings/import/utils.ts
+++ b/src/app/(settings)/settings/import/utils.ts
@@ -15,7 +15,7 @@ export const importSourceOptions: ImportSourceOption[] = [
{ value: "archived", label: "Archived", imapFolder: "Archive", destination: "system:archived", system: true },
{ value: "spam", label: "Spam", imapFolder: "Spam", destination: "system:spam", system: true },
{ value: "trash", label: "Trash", imapFolder: "Trash", destination: "system:trash", system: true },
- { value: "folders", label: "Folders", imapFolder: "", destination: "" },
+ { value: "others", label: "Others", imapFolder: "", destination: "system:inbox" },
];
export function getImportSourceOption(section: ImportSourceSection): ImportSourceOption {
@@ -46,7 +46,7 @@ export function getFolderImportSource(folderName: string): ImportSourceItem {
}
export function resolveImapSourceFolder(source: ImportSourceItem, folders: string[]): string {
- if (!source.sourceSection || source.sourceSection === "folders") return source.imapFolder;
+ if (!source.sourceSection || source.sourceSection === "others") return source.imapFolder;
const match = findFolderMatch(folders, getFolderAliases(source.sourceSection));
return match ?? source.imapFolder;
}
@@ -65,7 +65,7 @@ export function filterCustomImapFolders(folders: string[], selectedSources: Impo
}
export function getFileImportSource(sources: ImportSourceItem[]): ImportSourceItem {
- return sources.find((source) => source.id !== "system:folders") ?? getSelectedImportSources(["inbox"])[0];
+ return sources.find((source) => source.id !== "system:others") ?? getSelectedImportSources(["inbox"])[0];
}
export async function ensureImportDestination(
diff --git a/src/lib/backups/export.ts b/src/lib/backups/export.ts
index 30c4f6d..c6f537a 100644
--- a/src/lib/backups/export.ts
+++ b/src/lib/backups/export.ts
@@ -47,16 +47,15 @@ function createInsertStatement(db: D1Database, table: DatabaseBackupTable, row:
const columns = Object.keys(row);
if (columns.length === 0) throw new Error(`Backup contains an invalid ${table} record`);
const placeholders = columns.map(() => "?").join(", ");
- return db.prepare(`INSERT INTO ${table} (${columns.join(", ")}) VALUES (${placeholders})`).bind(...columns.map((column) => row[column]));
+ const identifiers = columns.map((column) => `\`${column.replaceAll("`", "``")}\``).join(", ");
+ return db.prepare(`INSERT INTO ${table} (${identifiers}) VALUES (${placeholders})`).bind(...columns.map((column) => row[column]));
}
function validateDatabaseBackup(document: DatabaseBackupDocument): void {
for (const table of BACKUP_TABLES) {
for (const row of document.tables[table]) {
- for (const [column, value] of Object.entries(row)) {
- if (!/^[a-z_]+$/.test(column) || (value !== null && typeof value !== "string" && typeof value !== "number")) {
- throw new Error(`Backup contains an invalid ${table} record`);
- }
+ if (!row || typeof row !== "object" || Array.isArray(row)) {
+ throw new Error(`Backup contains an invalid ${table} record`);
}
}
}