From 30c8c2f2b05bab8b962b51c0faeb282980324a5c Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 9 Jul 2021 15:12:50 +0200 Subject: Splits UI into steps and enhances log messages --- app/imap.js | 49 +++++++++++---- app/index.html | 4 +- app/src/components/Folders.vue | 7 +++ app/src/components/Panel.vue | 55 +++++++++++++++- app/src/components/Select.vue | 81 ++++++++++++++++++++++++ app/src/pages/Home.vue | 129 -------------------------------------- app/src/pages/Steps/1-From.vue | 32 ++++++++++ app/src/pages/Steps/2-To.vue | 51 +++++++++++++++ app/src/pages/Steps/3-Migrate.vue | 111 ++++++++++++++++++++++++++++++++ app/src/router.js | 18 +++++- 10 files changed, 388 insertions(+), 149 deletions(-) create mode 100644 app/src/components/Select.vue delete mode 100644 app/src/pages/Home.vue create mode 100644 app/src/pages/Steps/1-From.vue create mode 100644 app/src/pages/Steps/2-To.vue create mode 100644 app/src/pages/Steps/3-Migrate.vue (limited to 'app') diff --git a/app/imap.js b/app/imap.js index 4041089..d8caa0e 100644 --- a/app/imap.js +++ b/app/imap.js @@ -1,9 +1,10 @@ const { ipcMain } = require('electron'); const { ImapFlow } = require('imapflow'); -ipcMain.on('imap:listTree:from', listTreeFrom); -ipcMain.on('imap:listTree:to', listTreeTo); -ipcMain.on('imap:migrate', migrate); +ipcMain.on('imap:connect', apiConnect); +ipcMain.on('imap:listTree:from', apiListTreeFrom); +ipcMain.on('imap:listTree:to', apiListTreeTo); +ipcMain.on('imap:migrate', apiMigrate); /** * Connect to server @@ -51,7 +52,22 @@ ImapFlow.prototype.fetchArray = async function (range, query, options = {}) { * @param {IpcMainEvent} event * @param {object} options */ -async function listTreeFrom (event, options) { +async function apiConnect (event, options) { + try { + const client = await connect(options); + + event.reply('imap:connect:reply', true); + await client.logout(); + } catch (e) { + event.reply('imap:connect:error', e); + } +} + +/** + * @param {IpcMainEvent} event + * @param {object} options + */ +async function apiListTreeFrom (event, options) { try { const client = await connect(options); @@ -66,7 +82,7 @@ async function listTreeFrom (event, options) { * @param {IpcMainEvent} event * @param {object} options */ -async function listTreeTo (event, options) { +async function apiListTreeTo (event, options) { try { const client = await connect(options); @@ -82,7 +98,7 @@ async function listTreeTo (event, options) { * @param {object} from * @param {object} to */ -async function migrate (event, { from, to }) { +async function apiMigrate (event, { from, to }) { const fromClient = await connect(from); const toClient = await connect(to); @@ -108,17 +124,24 @@ async function migrate (event, { from, to }) { event.reply('imap:migrate:progress', '- Comparing messages'); const msgs = fromMsgs.filter((fromMsg) => !toMsgs.some((toMsg) => Buffer.compare(toMsg.source, fromMsg.source) === 0)); - event.reply('imap:migrate:progress', `- Message status: Found ${fromMsgs.length} messages total and ${msgs.length} new messages to migrate`); + event.reply('imap:migrate:progress', `- Found ${fromMsgs.length} messages total and ${msgs.length} new messages to migrate`); - await toClient.noop(); - for (const msg of msgs) { - appendCommands.push(toClient.append(fromFolder.path, msg.source, Array.from(msg.flags), msg.envelope.date)); + if (msgs.length > 0) { + event.reply('imap:migrate:progress', '- Starting migration'); + + await toClient.noop(); + for (const msg of msgs) { + appendCommands.push(toClient.append(fromFolder.path, msg.source, Array.from(msg.flags), msg.envelope.date)); + } + + await Promise.all(appendCommands); + event.reply('imap:migrate:progress', '- Done'); } - } finally { - await Promise.all(appendCommands); - event.reply('imap:migrate:progress', '- Done'); + fromMailbox.release(); toMailbox.release(); + } catch (e) { + event.reply('imap:migrate:error', e); } } diff --git a/app/index.html b/app/index.html index 8b7ddc9..df22432 100644 --- a/app/index.html +++ b/app/index.html @@ -2,8 +2,8 @@ - - Hello World! + + Mail Migrator diff --git a/app/src/components/Folders.vue b/app/src/components/Folders.vue index b801c1a..5c5c388 100644 --- a/app/src/components/Folders.vue +++ b/app/src/components/Folders.vue @@ -19,3 +19,10 @@ export default { }, }; + + diff --git a/app/src/components/Panel.vue b/app/src/components/Panel.vue index 527a8a9..eb92af7 100644 --- a/app/src/components/Panel.vue +++ b/app/src/components/Panel.vue @@ -1,5 +1,9 @@ diff --git a/app/src/components/Select.vue b/app/src/components/Select.vue new file mode 100644 index 0000000..f2d1187 --- /dev/null +++ b/app/src/components/Select.vue @@ -0,0 +1,81 @@ + + + + + diff --git a/app/src/pages/Home.vue b/app/src/pages/Home.vue deleted file mode 100644 index 8385a46..0000000 --- a/app/src/pages/Home.vue +++ /dev/null @@ -1,129 +0,0 @@ - - - - - diff --git a/app/src/pages/Steps/1-From.vue b/app/src/pages/Steps/1-From.vue new file mode 100644 index 0000000..e1bd82e --- /dev/null +++ b/app/src/pages/Steps/1-From.vue @@ -0,0 +1,32 @@ + + + diff --git a/app/src/pages/Steps/2-To.vue b/app/src/pages/Steps/2-To.vue new file mode 100644 index 0000000..1cce01d --- /dev/null +++ b/app/src/pages/Steps/2-To.vue @@ -0,0 +1,51 @@ + + + diff --git a/app/src/pages/Steps/3-Migrate.vue b/app/src/pages/Steps/3-Migrate.vue new file mode 100644 index 0000000..c8d2e39 --- /dev/null +++ b/app/src/pages/Steps/3-Migrate.vue @@ -0,0 +1,111 @@ + + + diff --git a/app/src/router.js b/app/src/router.js index 7676449..93ca201 100644 --- a/app/src/router.js +++ b/app/src/router.js @@ -1,12 +1,26 @@ import { createRouter, createWebHashHistory } from 'vue-router'; -import Home from './pages/Home'; +import Step1 from './pages/Steps/1-From'; +import Step2 from './pages/Steps/2-To'; +import Step3 from './pages/Steps/3-Migrate'; export default createRouter({ history: createWebHashHistory(), routes: [ { path: '/', - component: Home, + redirect: '/steps/1', + }, + { + path: '/steps/1', + component: Step1, + }, + { + path: '/steps/2', + component: Step2, + }, + { + path: '/steps/3', + component: Step3, }, ], }); -- cgit v1.2.3