mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The Import page reads nine more kinds of export, each into the view it is for: mail (mbox, .eml) as cards of Board View / Email, one per conversation with the replies as comments; an .ics file's tasks by status and its events, with their dates; a Google Takeout .zip as one board with a swimlane per product (Mail, Tasks, Keep, Calendar, Google Chat); a Slack workspace export, a Mattermost bulk export, Telegram Desktop's JSON, a WhatsApp chat .txt and a DiscordChatExporter JSON as channels whose messages are comments, for Board View / Chat; and an Evernote .enex as notes with their to-dos as checklists. The Export menu writes a board as an .mbox, an .enex and a Mattermost bulk import file, each read back by the same import. MIME is decoded with mailparser and ENEX with htmlparser2 on the server, and the zips are read under the zip-bomb guards of the other zip imports. An imported message's Message-IDs pass the import sanitizer without their brackets, so a later reply to the board joins the thread. The instructions of the nine are translated into every language. TODO.md also gets the next items: grouped menus, large-file import and export, and the reports to add. Thanks to xet7 !
71 lines
5.0 KiB
JavaScript
71 lines
5.0 KiB
JavaScript
'use strict';
|
|
// Google Takeout .zip: Tasks, Keep, Mail, Calendar and Google Chat into one
|
|
// board, a swimlane per product (models/lib/googleTakeoutFormat.js, the zip
|
|
// read by server/lib/chatArchives.js readGoogleTakeout).
|
|
// Run: node --test tests/googleTakeoutFormat.test.cjs
|
|
const test = require('node:test');
|
|
const assert = require('node:assert');
|
|
const { zipSync, strToU8 } = require('fflate');
|
|
const { readGoogleTakeout } = require('../server/lib/chatArchives');
|
|
|
|
const zipOf = files => ({ zipBase64: Buffer.from(zipSync(Object.fromEntries(Object.entries(files)
|
|
.map(([name, value]) => [name, strToU8(typeof value === 'string' ? value : JSON.stringify(value))])))).toString('base64') });
|
|
|
|
// The folder names are Finnish on purpose: Takeout writes them in the
|
|
// account's language, so products are recognised by content.
|
|
const TAKEOUT = {
|
|
'Takeout/Tehtävät/Tasks.json': { kind: 'tasks#taskLists', items: [{ kind: 'tasks#taskList', title: 'Omat tehtävät', items: [
|
|
{ kind: 'tasks#task', id: 'a', title: 'Pay rent', notes: 'By transfer', status: 'needsAction', due: '2026-11-30T00:00:00.000Z' },
|
|
{ kind: 'tasks#task', id: 'b', parent: 'a', title: 'Find IBAN', status: 'completed', completed: '2026-11-10T10:00:00.000Z' },
|
|
] }] },
|
|
'Takeout/Keep/Recipe.json': { title: 'Recipe', textContent: 'Pancakes', color: 'YELLOW', isTrashed: false, isArchived: false, isPinned: true,
|
|
labels: [{ name: 'food' }], listContent: [{ text: 'Eggs', isChecked: true }], createdTimestampUsec: 1794823200000000 },
|
|
'Takeout/Keep/Old.json': { title: 'Old', textContent: 'gone', isTrashed: true, isArchived: false },
|
|
'Takeout/Keep/Recipe.html': '<html>the same note as HTML</html>',
|
|
'Takeout/Sähköposti/All mail Including Spam and Trash.mbox': [
|
|
'From 1@xxx Mon Nov 16 10:00:00 +0000 2026', 'X-Gmail-Labels: Inbox,Work', 'From: Anna <anna@example.com>',
|
|
'Subject: Hello', 'Date: Mon, 16 Nov 2026 10:00:00 +0000', 'Message-ID: <m1@example.com>', '', 'Body', ''].join('\n'),
|
|
'Takeout/Kalenteri/anna@example.com.ics': 'BEGIN:VCALENDAR\nX-WR-CALNAME:Anna\nBEGIN:VEVENT\nUID:e\nSUMMARY:Dentist\nDTSTART:20261118T080000Z\nDTEND:20261118T090000Z\nEND:VEVENT\nEND:VCALENDAR\n',
|
|
'Takeout/Google Chat/Groups/Space AAAA/group_info.json': { name: 'Project', members: [{ name: 'Anna', email: 'anna@example.com' }] },
|
|
'Takeout/Google Chat/Groups/Space AAAA/messages.json': { messages: [
|
|
{ creator: { name: 'Anna', email: 'anna@example.com' }, created_date: 'Monday, November 16, 2026 at 10:00:00 AM UTC', text: 'Kickoff' }] },
|
|
'Takeout/YouTube/history.json': [{ title: 'video' }],
|
|
'Takeout/archive_browser.html': '<html></html>',
|
|
};
|
|
|
|
let takeout;
|
|
test.before(async () => { takeout = await import('../models/lib/googleTakeoutFormat.js'); });
|
|
|
|
test('one Takeout zip is one board with a swimlane per product', async () => {
|
|
const board = takeout.parseGoogleTakeout(await readGoogleTakeout(zipOf(TAKEOUT)));
|
|
assert.deepStrictEqual(board.swimlanes.map(s => s.name), ['Mail', 'Tasks', 'Keep', 'Calendar', 'Google Chat']);
|
|
assert.strictEqual(board.columns[0].title, 'Inbox', 'the Inbox is the first list, which Board View / Email reads');
|
|
const by = lane => board.tasks.filter(t => t.swimlane_name === lane);
|
|
const [mail] = by('Mail');
|
|
assert.strictEqual(mail.email.from.address, 'anna@example.com');
|
|
assert.deepStrictEqual(mail.tags, ['Work']);
|
|
const [rent, iban] = by('Tasks');
|
|
assert.deepStrictEqual([rent.title, rent.column_name, rent.date_due], ['Pay rent', 'Omat tehtävät', '2026-11-30T00:00:00.000Z']);
|
|
assert.deepStrictEqual([iban.parent_ref, iban.tags, iban.date_end], ['a', ['done'], '2026-11-10T10:00:00.000Z']);
|
|
const keep = by('Keep');
|
|
assert.deepStrictEqual(keep.map(t => t.title), ['Recipe'], 'a trashed note is left out');
|
|
assert.deepStrictEqual([keep[0].color, keep[0].tags, keep[0].checklists[0].items],
|
|
['yellow', ['food', 'pinned'], [{ title: 'Eggs', done: true }]]);
|
|
assert.strictEqual(keep[0].date_creation, '2026-11-16T10:00:00.000Z');
|
|
assert.deepStrictEqual(by('Calendar').map(t => [t.title, t.column_name]), [['Dentist', 'Events']]);
|
|
const [space] = by('Google Chat');
|
|
assert.deepStrictEqual([space.title, space.comments[0].text], ['Project', 'Kickoff']);
|
|
// What could not be imported is said, product by product.
|
|
assert.ok(board.unsupported.some(u => u.path === '/YouTube'));
|
|
assert.ok(!board.unsupported.some(u => /archive_browser/.test(u.path)), 'a file beside the products is no product');
|
|
assert.ok(board.unsupported.some(u => /Keep trash/.test(u.reason)));
|
|
assert.ok(!board.unsupported.some(u => /Keep$|Tehtävät|Sähköposti/.test(u.path)), 'a product that was read is not reported as skipped');
|
|
});
|
|
|
|
test('negative: a Takeout with nothing for a board, and a file that is not a zip', async () => {
|
|
const empty = await readGoogleTakeout(zipOf({ 'Takeout/YouTube/history.json': [] }));
|
|
assert.throws(() => takeout.parseGoogleTakeout(empty), /no Tasks, Keep, Mail, Calendar or Google Chat/);
|
|
await assert.rejects(readGoogleTakeout({ zipBase64: 'bm90IGEgemlw' }), /not a \.zip/);
|
|
await assert.rejects(readGoogleTakeout({}), /empty/);
|
|
});
|