2 |
3 | This plugin adds the ability to fetch email messages (including attachments) and converts them to Joplin notes in various formats, either by monitoring any `new` or `unread` messages from a specific email address or a specific mailbox, or by uploading downloaded email messages to the plugin without having to be logged in.
4 |
5 | ***
6 |
7 | ## Installing Plugin
8 |
9 | - Open Joplin
10 | - Go to Tools > Options > Plugins
11 | - Search for `Email Plugin`
12 | - Click Install plugin
13 | - Restart Joplin to enable the plugin
14 |
15 | ***
16 |
17 | ## Features
18 |
19 | - Monitoring and fetching any `new` or `unread` messages from a specific email address.
20 |
21 | - Monitoring and fetching any `new` or `unread` messages from a specific mailbox.
22 |
23 | - Send the converted message to specific notebooks and add tags to the note by using `@` or `#` in the email subject or first line of email content and then forward the email to yourself.
24 |
25 | - Convert emails (including attachments) to notes without having to be logged into the plugin.
26 |
27 | - Convert email messages to notes in different formats (`HTML`, `Markdown`, `Text`).
28 |
29 | - Show attachments in different styles, whether they are in the form of a `Table` or `Links`.
30 |
31 | ***
32 |
33 | ## How to use
34 |
35 | - ### Monitoring and fetching from a specific email address
36 |
37 | - Open Email Plugin.
38 |
39 | - Login to the plugin with your email address and password.
40 |
41 | - Enter the email account you want to start fetching and monitoring `new` or `unread` messages from and click on the `Fetching & Monitoring` toggle.
42 |
43 | - If you enter your email address in the `from` field, simply forward the email message to yourself after adding some easy syntax to the end of the email subject, or add this syntax in a new line at the beginning of the message content, and the plugin will handle the rest.
44 |
45 | - **Set a note title** : Change note title by changing the subject of the email.
46 | - **Add to a notebook** : Add `@notebook` to send it to a specific notebook.
47 | - **Add tags** : Add `#tag` to organize the note with a tag.
48 |
49 | > **For example**: Say you want this email located in the **joplin** and **gmail** folders and also want to add **gmail** and **email** as tags to the note. Just edit the email subject or add a new line at the beginning of the message content like this:
50 | >>Email subject: My message @**joplin** @**email** #**gmail** #**email**
51 |
52 | https://user-images.githubusercontent.com/58605547/188909511-479bff3b-bb9c-42da-9d48-a29d8b22fd4b.mp4
53 |
54 | - Otherwise the email messages will be in the `email messages` folder.
55 |
56 | ***
57 |
58 | - ### Monitoring and fetching from a specific mailbox
59 |
60 | - Open Email Plugin.
61 |
62 | - Login to the plugin with your email address and password.
63 |
64 | - Select a specific mailbox and notebook in which you want the email messages to be located and click on the `Fetching & Monitoring Mailbox` toggle.
65 |
66 | ***
67 |
68 | - ### Upload downloaded email messages
69 |
70 | - Open Email Plugin.
71 |
72 | - Click on the `convert saved messages` button.
73 |
74 | - Upload `.eml` format files of email messages that you want to convert to notes.
75 |
76 | - Select a notebook, enter the tags, select the export options, and click on the `convert` button.
77 |
78 | ## Important Notes
79 |
80 | - ⚠️ Make sure the email provider allows login using the original password; otherwise, use the [app password](https://support.google.com/accounts/answer/185833?hl=en#:~:text=Create%20%26%20use%20App%20Passwords).
81 |
82 | - If you want to change the note format, remove attachments from the note, or change the attachments style while monitoring, go to `Tools` > `Email Plugin`.
83 |
84 | - If you mention folders or tags that don't exist in Joplin, they will be created automatically.
85 |
86 | - If you open the email message, the message is no longer `new` or `unread`, but you can easily mark it as unread again.
87 |
88 | ## Building the plugin
89 |
90 | The plugin is built using Webpack, which creates the compiled code in `/dist`. A JPL archive will also be created at the root, which can use to distribute the plugin.
91 |
92 | To build the plugin, simply run `npm run dist`.
93 |
94 | The project is setup to use TypeScript, although you can change the configuration to use plain JavaScript.
95 |
96 | ## Testing
97 |
98 | To test the plugin, simply run `npm test`. The testing library used is [Jest](https://jestjs.io/).
99 |
--------------------------------------------------------------------------------
/api/Global.d.ts:
--------------------------------------------------------------------------------
1 | import Plugin from '../Plugin';
2 | import Joplin from './Joplin';
3 | /**
4 | * @ignore
5 | */
6 | /**
7 | * @ignore
8 | */
9 | export default class Global {
10 | private joplin_;
11 | constructor(implementation: any, plugin: Plugin, store: any);
12 | get joplin(): Joplin;
13 | get process(): any;
14 | }
15 |
--------------------------------------------------------------------------------
/api/Joplin.d.ts:
--------------------------------------------------------------------------------
1 | import Plugin from '../Plugin';
2 | import JoplinData from './JoplinData';
3 | import JoplinPlugins from './JoplinPlugins';
4 | import JoplinWorkspace from './JoplinWorkspace';
5 | import JoplinFilters from './JoplinFilters';
6 | import JoplinCommands from './JoplinCommands';
7 | import JoplinViews from './JoplinViews';
8 | import JoplinInterop from './JoplinInterop';
9 | import JoplinSettings from './JoplinSettings';
10 | import JoplinContentScripts from './JoplinContentScripts';
11 | import JoplinClipboard from './JoplinClipboard';
12 | import JoplinWindow from './JoplinWindow';
13 | /**
14 | * This is the main entry point to the Joplin API. You can access various services using the provided accessors.
15 | *
16 | * The API is now relatively stable and in general maintaining backward compatibility is a top priority, so you shouldn't except much breakages.
17 | *
18 | * If a breaking change ever becomes needed, best effort will be done to:
19 | *
20 | * - Deprecate features instead of removing them, so as to give you time to fix the issue;
21 | * - Document breaking changes in the changelog;
22 | *
23 | * So if you are developing a plugin, please keep an eye on the changelog as everything will be in there with information about how to update your code.
24 | */
25 | export default class Joplin {
26 | private data_;
27 | private plugins_;
28 | private workspace_;
29 | private filters_;
30 | private commands_;
31 | private views_;
32 | private interop_;
33 | private settings_;
34 | private contentScripts_;
35 | private clipboard_;
36 | private window_;
37 | constructor(implementation: any, plugin: Plugin, store: any);
38 | get data(): JoplinData;
39 | get clipboard(): JoplinClipboard;
40 | get window(): JoplinWindow;
41 | get plugins(): JoplinPlugins;
42 | get workspace(): JoplinWorkspace;
43 | get contentScripts(): JoplinContentScripts;
44 | /**
45 | * @ignore
46 | *
47 | * Not sure if it's the best way to hook into the app
48 | * so for now disable filters.
49 | */
50 | get filters(): JoplinFilters;
51 | get commands(): JoplinCommands;
52 | get views(): JoplinViews;
53 | get interop(): JoplinInterop;
54 | get settings(): JoplinSettings;
55 | /**
56 | * It is not possible to bundle native packages with a plugin, because they
57 | * need to work cross-platforms. Instead access to certain useful native
58 | * packages is provided using this function.
59 | *
60 | * Currently these packages are available:
61 | *
62 | * - [sqlite3](https://www.npmjs.com/package/sqlite3)
63 | * - [fs-extra](https://www.npmjs.com/package/fs-extra)
64 | *
65 | * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/nativeModule)
66 | */
67 | require(_path: string): any;
68 | }
69 |
--------------------------------------------------------------------------------
/api/JoplinClipboard.d.ts:
--------------------------------------------------------------------------------
1 | export default class JoplinClipboard {
2 | private electronClipboard_;
3 | private electronNativeImage_;
4 | constructor(electronClipboard: any, electronNativeImage: any);
5 | readText(): Promise;
6 | writeText(text: string): Promise;
7 | readHtml(): Promise;
8 | writeHtml(html: string): Promise;
9 | /**
10 | * Returns the image in [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format.
11 | */
12 | readImage(): Promise;
13 | /**
14 | * Takes an image in [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format.
15 | */
16 | writeImage(dataUrl: string): Promise;
17 | /**
18 | * Returns the list available formats (mime types).
19 | *
20 | * For example [ 'text/plain', 'text/html' ]
21 | */
22 | availableFormats(): Promise;
23 | }
24 |
--------------------------------------------------------------------------------
/api/JoplinCommands.d.ts:
--------------------------------------------------------------------------------
1 | import { Command } from './types';
2 | /**
3 | * This class allows executing or registering new Joplin commands. Commands
4 | * can be executed or associated with
5 | * {@link JoplinViewsToolbarButtons | toolbar buttons} or
6 | * {@link JoplinViewsMenuItems | menu items}.
7 | *
8 | * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/register_command)
9 | *
10 | * ## Executing Joplin's internal commands
11 | *
12 | * It is also possible to execute internal Joplin's commands which, as of
13 | * now, are not well documented. You can find the list directly on GitHub
14 | * though at the following locations:
15 | *
16 | * * [Main screen commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/gui/MainScreen/commands)
17 | * * [Global commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/commands)
18 | * * [Editor commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/gui/NoteEditor/commands/editorCommandDeclarations.ts)
19 | *
20 | * To view what arguments are supported, you can open any of these files
21 | * and look at the `execute()` command.
22 | *
23 | * ## Executing editor commands
24 | *
25 | * There might be a situation where you want to invoke editor commands
26 | * without using a {@link JoplinContentScripts | contentScript}. For this
27 | * reason Joplin provides the built in `editor.execCommand` command.
28 | *
29 | * `editor.execCommand` should work with any core command in both the
30 | * [CodeMirror](https://codemirror.net/doc/manual.html#execCommand) and
31 | * [TinyMCE](https://www.tiny.cloud/docs/api/tinymce/tinymce.editorcommands/#execcommand) editors,
32 | * as well as most functions calls directly on a CodeMirror editor object (extensions).
33 | *
34 | * * [CodeMirror commands](https://codemirror.net/doc/manual.html#commands)
35 | * * [TinyMCE core editor commands](https://www.tiny.cloud/docs/advanced/editor-command-identifiers/#coreeditorcommands)
36 | *
37 | * `editor.execCommand` supports adding arguments for the commands.
38 | *
39 | * ```typescript
40 | * await joplin.commands.execute('editor.execCommand', {
41 | * name: 'madeUpCommand', // CodeMirror and TinyMCE
42 | * args: [], // CodeMirror and TinyMCE
43 | * ui: false, // TinyMCE only
44 | * value: '', // TinyMCE only
45 | * });
46 | * ```
47 | *
48 | * [View the example using the CodeMirror editor](https://github.com/laurent22/joplin/blob/dev/packages/app-cli/tests/support/plugins/codemirror_content_script/src/index.ts)
49 | *
50 | */
51 | export default class JoplinCommands {
52 | /**
53 | * desktop Executes the given
54 | * command.
55 | *
56 | * The command can take any number of arguments, and the supported
57 | * arguments will vary based on the command. For custom commands, this
58 | * is the `args` passed to the `execute()` function. For built-in
59 | * commands, you can find the supported arguments by checking the links
60 | * above.
61 | *
62 | * ```typescript
63 | * // Create a new note in the current notebook:
64 | * await joplin.commands.execute('newNote');
65 | *
66 | * // Create a new sub-notebook under the provided notebook
67 | * // Note: internally, notebooks are called "folders".
68 | * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
69 | * ```
70 | */
71 | execute(commandName: string, ...args: any[]): Promise;
72 | /**
73 | * desktop Registers a new command.
74 | *
75 | * ```typescript
76 | * // Register a new commmand called "testCommand1"
77 | *
78 | * await joplin.commands.register({
79 | * name: 'testCommand1',
80 | * label: 'My Test Command 1',
81 | * iconName: 'fas fa-music',
82 | * execute: () => {
83 | * alert('Testing plugin command 1');
84 | * },
85 | * });
86 | * ```
87 | */
88 | register(command: Command): Promise;
89 | }
90 |
--------------------------------------------------------------------------------
/api/JoplinContentScripts.d.ts:
--------------------------------------------------------------------------------
1 | import Plugin from '../Plugin';
2 | import { ContentScriptType } from './types';
3 | export default class JoplinContentScripts {
4 | private plugin;
5 | constructor(plugin: Plugin);
6 | /**
7 | * Registers a new content script. Unlike regular plugin code, which runs in
8 | * a separate process, content scripts run within the main process code and
9 | * thus allow improved performances and more customisations in specific
10 | * cases. It can be used for example to load a Markdown or editor plugin.
11 | *
12 | * Note that registering a content script in itself will do nothing - it
13 | * will only be loaded in specific cases by the relevant app modules (eg.
14 | * the Markdown renderer or the code editor). So it is not a way to inject
15 | * and run arbitrary code in the app, which for safety and performance
16 | * reasons is not supported.
17 | *
18 | * The plugin generator provides a way to build any content script you might
19 | * want to package as well as its dependencies. See the [Plugin Generator
20 | * doc](https://github.com/laurent22/joplin/blob/dev/packages/generator-joplin/README.md)
21 | * for more information.
22 | *
23 | * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
24 | * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
25 | *
26 | * See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
27 | *
28 | * @param type Defines how the script will be used. See the type definition for more information about each supported type.
29 | * @param id A unique ID for the content script.
30 | * @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
31 | */
32 | register(type: ContentScriptType, id: string, scriptPath: string): Promise;
33 | /**
34 | * Listens to a messages sent from the content script using postMessage().
35 | * See {@link ContentScriptType} for more information as well as the
36 | * [postMessage
37 | * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
38 | */
39 | onMessage(contentScriptId: string, callback: any): Promise;
40 | }
41 |
--------------------------------------------------------------------------------
/api/JoplinData.d.ts:
--------------------------------------------------------------------------------
1 | import { ModelType } from '../../../BaseModel';
2 | import { Path } from './types';
3 | /**
4 | * This module provides access to the Joplin data API: https://joplinapp.org/api/references/rest_api/
5 | * This is the main way to retrieve data, such as notes, notebooks, tags, etc.
6 | * or to update them or delete them.
7 | *
8 | * This is also what you would use to search notes, via the `search` endpoint.
9 | *
10 | * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/simple)
11 | *
12 | * In general you would use the methods in this class as if you were using a REST API. There are four methods that map to GET, POST, PUT and DELETE calls.
13 | * And each method takes these parameters:
14 | *
15 | * * `path`: This is an array that represents the path to the resource in the form `["resouceName", "resourceId", "resourceLink"]` (eg. ["tags", ":id", "notes"]). The "resources" segment is the name of the resources you want to access (eg. "notes", "folders", etc.). If not followed by anything, it will refer to all the resources in that collection. The optional "resourceId" points to a particular resources within the collection. Finally, an optional "link" can be present, which links the resource to a collection of resources. This can be used in the API for example to retrieve all the notes associated with a tag.
16 | * * `query`: (Optional) The query parameters. In a URL, this is the part after the question mark "?". In this case, it should be an object with key/value pairs.
17 | * * `data`: (Optional) Applies to PUT and POST calls only. The request body contains the data you want to create or modify, for example the content of a note or folder.
18 | * * `files`: (Optional) Used to create new resources and associate them with files.
19 | *
20 | * Please refer to the [Joplin API documentation](https://joplinapp.org/api/references/rest_api/) for complete details about each call. As the plugin runs within the Joplin application **you do not need an authorisation token** to use this API.
21 | *
22 | * For example:
23 | *
24 | * ```typescript
25 | * // Get a note ID, title and body
26 | * const noteId = 'some_note_id';
27 | * const note = await joplin.data.get(['notes', noteId], { fields: ['id', 'title', 'body'] });
28 | *
29 | * // Get all folders
30 | * const folders = await joplin.data.get(['folders']);
31 | *
32 | * // Set the note body
33 | * await joplin.data.put(['notes', noteId], null, { body: "New note body" });
34 | *
35 | * // Create a new note under one of the folders
36 | * await joplin.data.post(['notes'], null, { body: "my new note", title: "some title", parent_id: folders[0].id });
37 | * ```
38 | */
39 | export default class JoplinData {
40 | private api_;
41 | private pathSegmentRegex_;
42 | private serializeApiBody;
43 | private pathToString;
44 | get(path: Path, query?: any): Promise;
45 | post(path: Path, query?: any, body?: any, files?: any[]): Promise;
46 | put(path: Path, query?: any, body?: any, files?: any[]): Promise;
47 | delete(path: Path, query?: any): Promise;
48 | itemType(itemId: string): Promise;
49 | resourcePath(resourceId: string): Promise;
50 | }
51 |
--------------------------------------------------------------------------------
/api/JoplinFilters.d.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * @ignore
3 | *
4 | * Not sure if it's the best way to hook into the app
5 | * so for now disable filters.
6 | */
7 | export default class JoplinFilters {
8 | on(name: string, callback: Function): Promise;
9 | off(name: string, callback: Function): Promise;
10 | }
11 |
--------------------------------------------------------------------------------
/api/JoplinInterop.d.ts:
--------------------------------------------------------------------------------
1 | import { ExportModule, ImportModule } from './types';
2 | /**
3 | * Provides a way to create modules to import external data into Joplin or to export notes into any arbitrary format.
4 | *
5 | * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/json_export)
6 | *
7 | * To implement an import or export module, you would simply define an object with various event handlers that are called
8 | * by the application during the import/export process.
9 | *
10 | * See the documentation of the [[ExportModule]] and [[ImportModule]] for more information.
11 | *
12 | * You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/
13 | */
14 | export default class JoplinInterop {
15 | registerExportModule(module: ExportModule): Promise;
16 | registerImportModule(module: ImportModule): Promise;
17 | }
18 |
--------------------------------------------------------------------------------
/api/JoplinPlugins.d.ts:
--------------------------------------------------------------------------------
1 | import Plugin from '../Plugin';
2 | import { ContentScriptType, Script } from './types';
3 | /**
4 | * This class provides access to plugin-related features.
5 | */
6 | export default class JoplinPlugins {
7 | private plugin;
8 | constructor(plugin: Plugin);
9 | /**
10 | * Registers a new plugin. This is the entry point when creating a plugin. You should pass a simple object with an `onStart` method to it.
11 | * That `onStart` method will be executed as soon as the plugin is loaded.
12 | *
13 | * ```typescript
14 | * joplin.plugins.register({
15 | * onStart: async function() {
16 | * // Run your plugin code here
17 | * }
18 | * });
19 | * ```
20 | */
21 | register(script: Script): Promise;
22 | /**
23 | * @deprecated Use joplin.contentScripts.register()
24 | */
25 | registerContentScript(type: ContentScriptType, id: string, scriptPath: string): Promise;
26 | /**
27 | * Gets the plugin own data directory path. Use this to store any
28 | * plugin-related data. Unlike [[installationDir]], any data stored here
29 | * will be persisted.
30 | */
31 | dataDir(): Promise;
32 | /**
33 | * Gets the plugin installation directory. This can be used to access any
34 | * asset that was packaged with the plugin. This directory should be
35 | * considered read-only because any data you store here might be deleted or
36 | * re-created at any time. To store new persistent data, use [[dataDir]].
37 | */
38 | installationDir(): Promise;
39 | /**
40 | * @deprecated Use joplin.require()
41 | */
42 | require(_path: string): any;
43 | }
44 |
--------------------------------------------------------------------------------
/api/JoplinSettings.d.ts:
--------------------------------------------------------------------------------
1 | import Plugin from '../Plugin';
2 | import { SettingItem, SettingSection } from './types';
3 | export interface ChangeEvent {
4 | /**
5 | * Setting keys that have been changed
6 | */
7 | keys: string[];
8 | }
9 | export declare type ChangeHandler = (event: ChangeEvent) => void;
10 | /**
11 | * This API allows registering new settings and setting sections, as well as getting and setting settings. Once a setting has been registered it will appear in the config screen and be editable by the user.
12 | *
13 | * Settings are essentially key/value pairs.
14 | *
15 | * Note: Currently this API does **not** provide access to Joplin's built-in settings. This is by design as plugins that modify user settings could give unexpected results
16 | *
17 | * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/settings)
18 | */
19 | export default class JoplinSettings {
20 | private plugin_;
21 | constructor(plugin: Plugin);
22 | private get keyPrefix();
23 | private namespacedKey;
24 | /**
25 | * Registers new settings.
26 | * Note that registering a setting item is dynamic and will be gone next time Joplin starts.
27 | * What it means is that you need to register the setting every time the plugin starts (for example in the onStart event).
28 | * The setting value however will be preserved from one launch to the next so there is no risk that it will be lost even if for some
29 | * reason the plugin fails to start at some point.
30 | */
31 | registerSettings(settings: Record): Promise;
32 | /**
33 | * @deprecated Use joplin.settings.registerSettings()
34 | *
35 | * Registers a new setting.
36 | */
37 | registerSetting(key: string, settingItem: SettingItem): Promise;
38 | /**
39 | * Registers a new setting section. Like for registerSetting, it is dynamic and needs to be done every time the plugin starts.
40 | */
41 | registerSection(name: string, section: SettingSection): Promise;
42 | /**
43 | * Gets a setting value (only applies to setting you registered from your plugin)
44 | */
45 | value(key: string): Promise;
46 | /**
47 | * Sets a setting value (only applies to setting you registered from your plugin)
48 | */
49 | setValue(key: string, value: any): Promise;
50 | /**
51 | * Gets a global setting value, including app-specific settings and those set by other plugins.
52 | *
53 | * The list of available settings is not documented yet, but can be found by looking at the source code:
54 | *
55 | * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142
56 | */
57 | globalValue(key: string): Promise;
58 | /**
59 | * Called when one or multiple settings of your plugin have been changed.
60 | * - For performance reasons, this event is triggered with a delay.
61 | * - You will only get events for your own plugin settings.
62 | */
63 | onChange(handler: ChangeHandler): Promise;
64 | }
65 |
--------------------------------------------------------------------------------
/api/JoplinViews.d.ts:
--------------------------------------------------------------------------------
1 | import Plugin from '../Plugin';
2 | import JoplinViewsDialogs from './JoplinViewsDialogs';
3 | import JoplinViewsMenuItems from './JoplinViewsMenuItems';
4 | import JoplinViewsMenus from './JoplinViewsMenus';
5 | import JoplinViewsToolbarButtons from './JoplinViewsToolbarButtons';
6 | import JoplinViewsPanels from './JoplinViewsPanels';
7 | /**
8 | * This namespace provides access to view-related services.
9 | *
10 | * All view services provide a `create()` method which you would use to create the view object, whether it's a dialog, a toolbar button or a menu item.
11 | * In some cases, the `create()` method will return a [[ViewHandle]], which you would use to act on the view, for example to set certain properties or call some methods.
12 | */
13 | export default class JoplinViews {
14 | private store;
15 | private plugin;
16 | private dialogs_;
17 | private panels_;
18 | private menuItems_;
19 | private menus_;
20 | private toolbarButtons_;
21 | private implementation_;
22 | constructor(implementation: any, plugin: Plugin, store: any);
23 | get dialogs(): JoplinViewsDialogs;
24 | get panels(): JoplinViewsPanels;
25 | get menuItems(): JoplinViewsMenuItems;
26 | get menus(): JoplinViewsMenus;
27 | get toolbarButtons(): JoplinViewsToolbarButtons;
28 | }
29 |
--------------------------------------------------------------------------------
/api/JoplinViewsDialogs.d.ts:
--------------------------------------------------------------------------------
1 | import Plugin from '../Plugin';
2 | import { ButtonSpec, ViewHandle, DialogResult } from './types';
3 | /**
4 | * Allows creating and managing dialogs. A dialog is modal window that
5 | * contains a webview and a row of buttons. You can update the
6 | * webview using the `setHtml` method. Dialogs are hidden by default and
7 | * you need to call `open()` to open them. Once the user clicks on a
8 | * button, the `open` call will return an object indicating what button was
9 | * clicked on.
10 | *
11 | * ## Retrieving form values
12 | *
13 | * If your HTML content included one or more forms, a `formData` object
14 | * will also be included with the key/value for each form.
15 | *
16 | * ## Special button IDs
17 | *
18 | * The following buttons IDs have a special meaning:
19 | *
20 | * - `ok`, `yes`, `submit`, `confirm`: They are considered "submit" buttons
21 | * - `cancel`, `no`, `reject`: They are considered "dismiss" buttons
22 | *
23 | * This information is used by the application to determine what action
24 | * should be done when the user presses "Enter" or "Escape" within the
25 | * dialog. If they press "Enter", the first "submit" button will be
26 | * automatically clicked. If they press "Escape" the first "dismiss" button
27 | * will be automatically clicked.
28 | *
29 | * [View the demo
30 | * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/dialog)
31 | */
32 | export default class JoplinViewsDialogs {
33 | private store;
34 | private plugin;
35 | private implementation_;
36 | constructor(implementation: any, plugin: Plugin, store: any);
37 | private controller;
38 | /**
39 | * Creates a new dialog
40 | */
41 | create(id: string): Promise;
42 | /**
43 | * Displays a message box with OK/Cancel buttons. Returns the button index that was clicked - "0" for OK and "1" for "Cancel"
44 | */
45 | showMessageBox(message: string): Promise;
46 | /**
47 | * Sets the dialog HTML content
48 | */
49 | setHtml(handle: ViewHandle, html: string): Promise;
50 | /**
51 | * Adds and loads a new JS or CSS files into the dialog.
52 | */
53 | addScript(handle: ViewHandle, scriptPath: string): Promise;
54 | /**
55 | * Sets the dialog buttons.
56 | */
57 | setButtons(handle: ViewHandle, buttons: ButtonSpec[]): Promise;
58 | /**
59 | * Opens the dialog
60 | */
61 | open(handle: ViewHandle): Promise;
62 | /**
63 | * Toggle on whether to fit the dialog size to the content or not.
64 | * When set to false, the dialog is set to 90vw and 80vh
65 | * @default true
66 | */
67 | setFitToContent(handle: ViewHandle, status: boolean): Promise;
68 | }
69 |
--------------------------------------------------------------------------------
/api/JoplinViewsMenuItems.d.ts:
--------------------------------------------------------------------------------
1 | import { CreateMenuItemOptions, MenuItemLocation } from './types';
2 | import Plugin from '../Plugin';
3 | /**
4 | * Allows creating and managing menu items.
5 | *
6 | * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/register_command)
7 | */
8 | export default class JoplinViewsMenuItems {
9 | private store;
10 | private plugin;
11 | constructor(plugin: Plugin, store: any);
12 | /**
13 | * Creates a new menu item and associate it with the given command. You can specify under which menu the item should appear using the `location` parameter.
14 | */
15 | create(id: string, commandName: string, location?: MenuItemLocation, options?: CreateMenuItemOptions): Promise;
16 | }
17 |
--------------------------------------------------------------------------------
/api/JoplinViewsMenus.d.ts:
--------------------------------------------------------------------------------
1 | import { MenuItem, MenuItemLocation } from './types';
2 | import Plugin from '../Plugin';
3 | /**
4 | * Allows creating menus.
5 | *
6 | * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/menu)
7 | */
8 | export default class JoplinViewsMenus {
9 | private store;
10 | private plugin;
11 | constructor(plugin: Plugin, store: any);
12 | private registerCommandAccelerators;
13 | /**
14 | * Creates a new menu from the provided menu items and place it at the given location. As of now, it is only possible to place the
15 | * menu as a sub-menu of the application build-in menus.
16 | */
17 | create(id: string, label: string, menuItems: MenuItem[], location?: MenuItemLocation): Promise;
18 | }
19 |
--------------------------------------------------------------------------------
/api/JoplinViewsPanels.d.ts:
--------------------------------------------------------------------------------
1 | import Plugin from '../Plugin';
2 | import { ViewHandle } from './types';
3 | /**
4 | * Allows creating and managing view panels. View panels currently are
5 | * displayed at the right of the sidebar and allows displaying any HTML
6 | * content (within a webview) and update it in real-time. For example it
7 | * could be used to display a table of content for the active note, or
8 | * display various metadata or graph.
9 | *
10 | * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/toc)
11 | */
12 | export default class JoplinViewsPanels {
13 | private store;
14 | private plugin;
15 | constructor(plugin: Plugin, store: any);
16 | private controller;
17 | /**
18 | * Creates a new panel
19 | */
20 | create(id: string): Promise;
21 | /**
22 | * Sets the panel webview HTML
23 | */
24 | setHtml(handle: ViewHandle, html: string): Promise;
25 | /**
26 | * Adds and loads a new JS or CSS files into the panel.
27 | */
28 | addScript(handle: ViewHandle, scriptPath: string): Promise;
29 | /**
30 | * Called when a message is sent from the webview (using postMessage).
31 | *
32 | * To post a message from the webview to the plugin use:
33 | *
34 | * ```javascript
35 | * const response = await webviewApi.postMessage(message);
36 | * ```
37 | *
38 | * - `message` can be any JavaScript object, string or number
39 | * - `response` is whatever was returned by the `onMessage` handler
40 | *
41 | * Using this mechanism, you can have two-way communication between the
42 | * plugin and webview.
43 | *
44 | * See the [postMessage
45 | * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages) for more details.
46 | *
47 | */
48 | onMessage(handle: ViewHandle, callback: Function): Promise;
49 | /**
50 | * Sends a message to the webview.
51 | *
52 | * The webview must have registered a message handler prior, otherwise the message is ignored. Use;
53 | *
54 | * ```javascript
55 | * webviewApi.onMessage((message) => { ... });
56 | * ```
57 | *
58 | * - `message` can be any JavaScript object, string or number
59 | *
60 | * The view API may have only one onMessage handler defined.
61 | * This method is fire and forget so no response is returned.
62 | *
63 | * It is particularly useful when the webview needs to react to events emitted by the plugin or the joplin api.
64 | */
65 | postMessage(handle: ViewHandle, message: any): void;
66 | /**
67 | * Shows the panel
68 | */
69 | show(handle: ViewHandle, show?: boolean): Promise;
70 | /**
71 | * Hides the panel
72 | */
73 | hide(handle: ViewHandle): Promise;
74 | /**
75 | * Tells whether the panel is visible or not
76 | */
77 | visible(handle: ViewHandle): Promise;
78 | }
79 |
--------------------------------------------------------------------------------
/api/JoplinViewsToolbarButtons.d.ts:
--------------------------------------------------------------------------------
1 | import { ToolbarButtonLocation } from './types';
2 | import Plugin from '../Plugin';
3 | /**
4 | * Allows creating and managing toolbar buttons.
5 | *
6 | * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/register_command)
7 | */
8 | export default class JoplinViewsToolbarButtons {
9 | private store;
10 | private plugin;
11 | constructor(plugin: Plugin, store: any);
12 | /**
13 | * Creates a new toolbar button and associate it with the given command.
14 | */
15 | create(id: string, commandName: string, location: ToolbarButtonLocation): Promise;
16 | }
17 |
--------------------------------------------------------------------------------
/api/JoplinWindow.d.ts:
--------------------------------------------------------------------------------
1 | import Plugin from '../Plugin';
2 | export interface Implementation {
3 | injectCustomStyles(elementId: string, cssFilePath: string): Promise;
4 | }
5 | export default class JoplinWindow {
6 | private plugin_;
7 | private store_;
8 | private implementation_;
9 | constructor(implementation: Implementation, plugin: Plugin, store: any);
10 | /**
11 | * Loads a chrome CSS file. It will apply to the window UI elements, except
12 | * for the note viewer. It is the same as the "Custom stylesheet for
13 | * Joplin-wide app styles" setting. See the [Load CSS Demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/load_css)
14 | * for an example.
15 | */
16 | loadChromeCssFile(filePath: string): Promise;
17 | /**
18 | * Loads a note CSS file. It will apply to the note viewer, as well as any
19 | * exported or printed note. It is the same as the "Custom stylesheet for
20 | * rendered Markdown" setting. See the [Load CSS Demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/load_css)
21 | * for an example.
22 | */
23 | loadNoteCssFile(filePath: string): Promise;
24 | }
25 |
--------------------------------------------------------------------------------
/api/JoplinWorkspace.d.ts:
--------------------------------------------------------------------------------
1 | import { FolderEntity } from '../../database/types';
2 | import { Disposable, MenuItem } from './types';
3 | export interface EditContextMenuFilterObject {
4 | items: MenuItem[];
5 | }
6 | declare type FilterHandler = (object: T) => Promise;
7 | declare enum ItemChangeEventType {
8 | Create = 1,
9 | Update = 2,
10 | Delete = 3
11 | }
12 | interface ItemChangeEvent {
13 | id: string;
14 | event: ItemChangeEventType;
15 | }
16 | interface SyncStartEvent {
17 | withErrors: boolean;
18 | }
19 | declare type ItemChangeHandler = (event: ItemChangeEvent) => void;
20 | declare type SyncStartHandler = (event: SyncStartEvent) => void;
21 | /**
22 | * The workspace service provides access to all the parts of Joplin that
23 | * are being worked on - i.e. the currently selected notes or notebooks as
24 | * well as various related events, such as when a new note is selected, or
25 | * when the note content changes.
26 | *
27 | * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins)
28 | */
29 | export default class JoplinWorkspace {
30 | private store;
31 | constructor(store: any);
32 | /**
33 | * Called when a new note or notes are selected.
34 | */
35 | onNoteSelectionChange(callback: Function): Promise;
36 | /**
37 | * Called when the content of a note changes.
38 | * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes.
39 | */
40 | onNoteContentChange(callback: Function): Promise;
41 | /**
42 | * Called when the content of the current note changes.
43 | */
44 | onNoteChange(handler: ItemChangeHandler): Promise;
45 | /**
46 | * Called when an alarm associated with a to-do is triggered.
47 | */
48 | onNoteAlarmTrigger(handler: Function): Promise;
49 | /**
50 | * Called when the synchronisation process is starting.
51 | */
52 | onSyncStart(handler: SyncStartHandler): Promise;
53 | /**
54 | * Called when the synchronisation process has finished.
55 | */
56 | onSyncComplete(callback: Function): Promise;
57 | /**
58 | * Called just before the editor context menu is about to open. Allows
59 | * adding items to it.
60 | */
61 | filterEditorContextMenu(handler: FilterHandler): void;
62 | /**
63 | * Gets the currently selected note
64 | */
65 | selectedNote(): Promise;
66 | /**
67 | * Gets the currently selected folder. In some cases, for example during
68 | * search or when viewing a tag, no folder is actually selected in the user
69 | * interface. In that case, that function would return the last selected
70 | * folder.
71 | */
72 | selectedFolder(): Promise;
73 | /**
74 | * Gets the IDs of the selected notes (can be zero, one, or many). Use the data API to retrieve information about these notes.
75 | */
76 | selectedNoteIds(): Promise;
77 | }
78 | export {};
79 |
--------------------------------------------------------------------------------
/api/index.ts:
--------------------------------------------------------------------------------
1 | import type Joplin from './Joplin';
2 |
3 | declare const joplin: Joplin;
4 |
5 | export default joplin;
6 |
--------------------------------------------------------------------------------
/api/types.ts:
--------------------------------------------------------------------------------
1 | // =================================================================
2 | // Command API types
3 | // =================================================================
4 |
5 | export interface Command {
6 | /**
7 | * Name of command - must be globally unique
8 | */
9 | name: string;
10 |
11 | /**
12 | * Label to be displayed on menu items or keyboard shortcut editor for example.
13 | * If it is missing, it's assumed it's a private command, to be called programmatically only.
14 | * In that case the command will not appear in the shortcut editor or command panel, and logically
15 | * should not be used as a menu item.
16 | */
17 | label?: string;
18 |
19 | /**
20 | * Icon to be used on toolbar buttons for example
21 | */
22 | iconName?: string;
23 |
24 | /**
25 | * Code to be ran when the command is executed. It may return a result.
26 | */
27 | execute(...args: any[]): Promise;
28 |
29 | /**
30 | * Defines whether the command should be enabled or disabled, which in turns
31 | * affects the enabled state of any associated button or menu item.
32 | *
33 | * The condition should be expressed as a "when-clause" (as in Visual Studio
34 | * Code). It's a simple boolean expression that evaluates to `true` or
35 | * `false`. It supports the following operators:
36 | *
37 | * Operator | Symbol | Example
38 | * -- | -- | --
39 | * Equality | == | "editorType == markdown"
40 | * Inequality | != | "currentScreen != config"
41 | * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted"
42 | * And | && | "oneNoteSelected && !inConflictFolder"
43 | *
44 | * Joplin, unlike VSCode, also supports parenthesis, which allows creating
45 | * more complex expressions such as `cond1 || (cond2 && cond3)`. Only one
46 | * level of parenthesis is possible (nested ones aren't supported).
47 | *
48 | * Currently the supported context variables aren't documented, but you can
49 | * find the list below:
50 | *
51 | * - [Global When Clauses](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts)
52 | * - [Desktop app When Clauses](https://github.com/laurent22/joplin/blob/dev/packages/app-desktop/services/commands/stateToWhenClauseContext.ts)
53 | *
54 | * Note: Commands are enabled by default unless you use this property.
55 | */
56 | enabledCondition?: string;
57 | }
58 |
59 | // =================================================================
60 | // Interop API types
61 | // =================================================================
62 |
63 | export enum FileSystemItem {
64 | File = 'file',
65 | Directory = 'directory',
66 | }
67 |
68 | export enum ImportModuleOutputFormat {
69 | Markdown = 'md',
70 | Html = 'html',
71 | }
72 |
73 | /**
74 | * Used to implement a module to export data from Joplin. [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/json_export) for an example.
75 | *
76 | * In general, all the event handlers you'll need to implement take a `context` object as a first argument. This object will contain the export or import path as well as various optional properties, such as which notes or notebooks need to be exported.
77 | *
78 | * To get a better sense of what it will contain it can be useful to print it using `console.info(context)`.
79 | */
80 | export interface ExportModule {
81 | /**
82 | * The format to be exported, eg "enex", "jex", "json", etc.
83 | */
84 | format: string;
85 |
86 | /**
87 | * The description that will appear in the UI, for example in the menu item.
88 | */
89 | description: string;
90 |
91 | /**
92 | * Whether the module will export a single file or multiple files in a directory. It affects the open dialog that will be presented to the user when using your exporter.
93 | */
94 | target: FileSystemItem;
95 |
96 | /**
97 | * Only applies to single file exporters or importers
98 | * It tells whether the format can package multiple notes into one file.
99 | * For example JEX or ENEX can, but HTML cannot.
100 | */
101 | isNoteArchive: boolean;
102 |
103 | /**
104 | * The extensions of the files exported by your module. For example, it is `["htm", "html"]` for the HTML module, and just `["jex"]` for the JEX module.
105 | */
106 | fileExtensions?: string[];
107 |
108 | /**
109 | * Called when the export process starts.
110 | */
111 | onInit(context: ExportContext): Promise;
112 |
113 | /**
114 | * Called when an item needs to be processed. An "item" can be any Joplin object, such as a note, a folder, a notebook, etc.
115 | */
116 | onProcessItem(context: ExportContext, itemType: number, item: any): Promise;
117 |
118 | /**
119 | * Called when a resource file needs to be exported.
120 | */
121 | onProcessResource(context: ExportContext, resource: any, filePath: string): Promise;
122 |
123 | /**
124 | * Called when the export process is done.
125 | */
126 | onClose(context: ExportContext): Promise;
127 | }
128 |
129 | export interface ImportModule {
130 | /**
131 | * The format to be exported, eg "enex", "jex", "json", etc.
132 | */
133 | format: string;
134 |
135 | /**
136 | * The description that will appear in the UI, for example in the menu item.
137 | */
138 | description: string;
139 |
140 | /**
141 | * Only applies to single file exporters or importers
142 | * It tells whether the format can package multiple notes into one file.
143 | * For example JEX or ENEX can, but HTML cannot.
144 | */
145 | isNoteArchive: boolean;
146 |
147 | /**
148 | * The type of sources that are supported by the module. Tells whether the module can import files or directories or both.
149 | */
150 | sources: FileSystemItem[];
151 |
152 | /**
153 | * Tells the file extensions of the exported files.
154 | */
155 | fileExtensions?: string[];
156 |
157 | /**
158 | * Tells the type of notes that will be generated, either HTML or Markdown (default).
159 | */
160 | outputFormat?: ImportModuleOutputFormat;
161 |
162 | /**
163 | * Called when the import process starts. There is only one event handler within which you should import the complete data.
164 | */
165 | onExec(context: ImportContext): Promise;
166 | }
167 |
168 | export interface ExportOptions {
169 | format?: string;
170 | path?: string;
171 | sourceFolderIds?: string[];
172 | sourceNoteIds?: string[];
173 | // modulePath?: string;
174 | target?: FileSystemItem;
175 | }
176 |
177 | export interface ExportContext {
178 | destPath: string;
179 | options: ExportOptions;
180 |
181 | /**
182 | * You can attach your own custom data using this propery - it will then be passed to each event handler, allowing you to keep state from one event to the next.
183 | */
184 | userData?: any;
185 | }
186 |
187 | export interface ImportContext {
188 | sourcePath: string;
189 | options: any;
190 | warnings: string[];
191 | }
192 |
193 | // =================================================================
194 | // Misc types
195 | // =================================================================
196 |
197 | export interface Script {
198 | onStart?(event: any): Promise;
199 | }
200 |
201 | export interface Disposable {
202 | // dispose():void;
203 | }
204 |
205 | export enum ModelType {
206 | Note = 1,
207 | Folder = 2,
208 | Setting = 3,
209 | Resource = 4,
210 | Tag = 5,
211 | NoteTag = 6,
212 | Search = 7,
213 | Alarm = 8,
214 | MasterKey = 9,
215 | ItemChange = 10,
216 | NoteResource = 11,
217 | ResourceLocalState = 12,
218 | Revision = 13,
219 | Migration = 14,
220 | SmartFilter = 15,
221 | Command = 16,
222 | }
223 |
224 | // =================================================================
225 | // Menu types
226 | // =================================================================
227 |
228 | export interface CreateMenuItemOptions {
229 | accelerator: string;
230 | }
231 |
232 | export enum MenuItemLocation {
233 | File = 'file',
234 | Edit = 'edit',
235 | View = 'view',
236 | Note = 'note',
237 | Tools = 'tools',
238 | Help = 'help',
239 |
240 | /**
241 | * @deprecated Do not use - same as NoteListContextMenu
242 | */
243 | Context = 'context',
244 |
245 | // If adding an item here, don't forget to update isContextMenuItemLocation()
246 |
247 | /**
248 | * When a command is called from the note list context menu, the
249 | * command will receive the following arguments:
250 | *
251 | * - `noteIds:string[]`: IDs of the notes that were right-clicked on.
252 | */
253 | NoteListContextMenu = 'noteListContextMenu',
254 |
255 | EditorContextMenu = 'editorContextMenu',
256 |
257 | /**
258 | * When a command is called from a folder context menu, the
259 | * command will receive the following arguments:
260 | *
261 | * - `folderId:string`: ID of the folder that was right-clicked on
262 | */
263 | FolderContextMenu = 'folderContextMenu',
264 |
265 | /**
266 | * When a command is called from a tag context menu, the
267 | * command will receive the following arguments:
268 | *
269 | * - `tagId:string`: ID of the tag that was right-clicked on
270 | */
271 | TagContextMenu = 'tagContextMenu',
272 | }
273 |
274 | export function isContextMenuItemLocation(location: MenuItemLocation): boolean {
275 | return [
276 | MenuItemLocation.Context,
277 | MenuItemLocation.NoteListContextMenu,
278 | MenuItemLocation.EditorContextMenu,
279 | MenuItemLocation.FolderContextMenu,
280 | MenuItemLocation.TagContextMenu,
281 | ].includes(location);
282 | }
283 |
284 | export interface MenuItem {
285 | /**
286 | * Command that should be associated with the menu item. All menu item should
287 | * have a command associated with them unless they are a sub-menu.
288 | */
289 | commandName?: string;
290 |
291 | /**
292 | * Arguments that should be passed to the command. They will be as rest
293 | * parameters.
294 | */
295 | commandArgs?: any[];
296 |
297 | /**
298 | * Set to "separator" to create a divider line
299 | */
300 | type?: string;
301 |
302 | /**
303 | * Accelerator associated with the menu item
304 | */
305 | accelerator?: string;
306 |
307 | /**
308 | * Menu items that should appear below this menu item. Allows creating a menu tree.
309 | */
310 | submenu?: MenuItem[];
311 |
312 | /**
313 | * Menu item label. If not specified, the command label will be used instead.
314 | */
315 | label?: string;
316 | }
317 |
318 | // =================================================================
319 | // View API types
320 | // =================================================================
321 |
322 | export interface ButtonSpec {
323 | id: ButtonId;
324 | title?: string;
325 | onClick?(): void;
326 | }
327 |
328 | export type ButtonId = string;
329 |
330 | export enum ToolbarButtonLocation {
331 | /**
332 | * This toolbar in the top right corner of the application. It applies to the note as a whole, including its metadata.
333 | */
334 | NoteToolbar = 'noteToolbar',
335 |
336 | /**
337 | * This toolbar is right above the text editor. It applies to the note body only.
338 | */
339 | EditorToolbar = 'editorToolbar',
340 | }
341 |
342 | export type ViewHandle = string;
343 |
344 | export interface EditorCommand {
345 | name: string;
346 | value?: any;
347 | }
348 |
349 | export interface DialogResult {
350 | id: ButtonId;
351 | formData?: any;
352 | }
353 |
354 | // =================================================================
355 | // Settings types
356 | // =================================================================
357 |
358 | export enum SettingItemType {
359 | Int = 1,
360 | String = 2,
361 | Bool = 3,
362 | Array = 4,
363 | Object = 5,
364 | Button = 6,
365 | }
366 |
367 | export enum AppType {
368 | Desktop = 'desktop',
369 | Mobile = 'mobile',
370 | Cli = 'cli',
371 | }
372 |
373 | export enum SettingStorage {
374 | Database = 1,
375 | File = 2,
376 | }
377 |
378 | // Redefine a simplified interface to mask internal details
379 | // and to remove function calls as they would have to be async.
380 | export interface SettingItem {
381 | value: any;
382 | type: SettingItemType;
383 |
384 | label: string;
385 | description?: string;
386 |
387 | /**
388 | * A public setting will appear in the Configuration screen and will be
389 | * modifiable by the user. A private setting however will not appear there,
390 | * and can only be changed programmatically. You may use this to store some
391 | * values that you do not want to directly expose.
392 | */
393 | public: boolean;
394 |
395 | /**
396 | * You would usually set this to a section you would have created
397 | * specifically for the plugin.
398 | */
399 | section?: string;
400 |
401 | /**
402 | * To create a setting with multiple options, set this property to `true`.
403 | * That setting will render as a dropdown list in the configuration screen.
404 | */
405 | isEnum?: boolean;
406 |
407 | /**
408 | * This property is required when `isEnum` is `true`. In which case, it
409 | * should contain a map of value => label.
410 | */
411 | options?: Record;
412 |
413 | /**
414 | * Reserved property. Not used at the moment.
415 | */
416 | appTypes?: AppType[];
417 |
418 | /**
419 | * Set this to `true` to store secure data, such as passwords. Any such
420 | * setting will be stored in the system keychain if one is available.
421 | */
422 | secure?: boolean;
423 |
424 | /**
425 | * An advanced setting will be moved under the "Advanced" button in the
426 | * config screen.
427 | */
428 | advanced?: boolean;
429 |
430 | /**
431 | * Set the min, max and step values if you want to restrict an int setting
432 | * to a particular range.
433 | */
434 | minimum?: number;
435 | maximum?: number;
436 | step?: number;
437 |
438 | /**
439 | * Either store the setting in the database or in settings.json. Defaults to database.
440 | */
441 | storage?: SettingStorage;
442 | }
443 |
444 | export interface SettingSection {
445 | label: string;
446 | iconName?: string;
447 | description?: string;
448 | name?: string;
449 | }
450 |
451 | // =================================================================
452 | // Data API types
453 | // =================================================================
454 |
455 | /**
456 | * An array of at least one element and at most three elements.
457 | *
458 | * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.)
459 | * - **[1]**: (Optional) Resource ID.
460 | * - **[2]**: (Optional) Resource link.
461 | */
462 | export type Path = string[];
463 |
464 | // =================================================================
465 | // Content Script types
466 | // =================================================================
467 |
468 | export type PostMessageHandler = (message: any)=> Promise;
469 |
470 | /**
471 | * When a content script is initialised, it receives a `context` object.
472 | */
473 | export interface ContentScriptContext {
474 | /**
475 | * The plugin ID that registered this content script
476 | */
477 | pluginId: string;
478 |
479 | /**
480 | * The content script ID, which may be necessary to post messages
481 | */
482 | contentScriptId: string;
483 |
484 | /**
485 | * Can be used by CodeMirror content scripts to post a message to the plugin
486 | */
487 | postMessage: PostMessageHandler;
488 | }
489 |
490 | export enum ContentScriptType {
491 | /**
492 | * Registers a new Markdown-It plugin, which should follow the template
493 | * below.
494 | *
495 | * ```javascript
496 | * module.exports = {
497 | * default: function(context) {
498 | * return {
499 | * plugin: function(markdownIt, options) {
500 | * // ...
501 | * },
502 | * assets: {
503 | * // ...
504 | * },
505 | * }
506 | * }
507 | * }
508 | * ```
509 | * See [the
510 | * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
511 | * for a simple Markdown-it plugin example.
512 | *
513 | * ## Exported members
514 | *
515 | * - The `context` argument is currently unused but could be used later on
516 | * to provide access to your own plugin so that the content script and
517 | * plugin can communicate.
518 | *
519 | * - The **required** `plugin` key is the actual Markdown-It plugin - check
520 | * the [official doc](https://github.com/markdown-it/markdown-it) for more
521 | * information. The `options` parameter is of type
522 | * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts),
523 | * which contains a number of options, mostly useful for Joplin's internal
524 | * code.
525 | *
526 | * - Using the **optional** `assets` key you may specify assets such as JS
527 | * or CSS that should be loaded in the rendered HTML document. Check for
528 | * example the Joplin [Mermaid
529 | * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts)
530 | * to see how the data should be structured.
531 | *
532 | * ## Posting messages from the content script to your plugin
533 | *
534 | * The application provides the following function to allow executing
535 | * commands from the rendered HTML code:
536 | *
537 | * ```javascript
538 | * const response = await webviewApi.postMessage(contentScriptId, message);
539 | * ```
540 | *
541 | * - `contentScriptId` is the ID you've defined when you registered the
542 | * content script. You can retrieve it from the
543 | * {@link ContentScriptContext | context}.
544 | * - `message` can be any basic JavaScript type (number, string, plain
545 | * object), but it cannot be a function or class instance.
546 | *
547 | * When you post a message, the plugin can send back a `response` thus
548 | * allowing two-way communication:
549 | *
550 | * ```javascript
551 | * await joplin.contentScripts.onMessage(contentScriptId, (message) => {
552 | * // Process message
553 | * return response; // Can be any object, string or number
554 | * });
555 | * ```
556 | *
557 | * See {@link JoplinContentScripts.onMessage} for more details, as well as
558 | * the [postMessage
559 | * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
560 | *
561 | * ## Registering an existing Markdown-it plugin
562 | *
563 | * To include a regular Markdown-It plugin, that doesn't make use of any
564 | * Joplin-specific features, you would simply create a file such as this:
565 | *
566 | * ```javascript
567 | * module.exports = {
568 | * default: function(context) {
569 | * return {
570 | * plugin: require('markdown-it-toc-done-right');
571 | * }
572 | * }
573 | * }
574 | * ```
575 | */
576 | MarkdownItPlugin = 'markdownItPlugin',
577 |
578 | /**
579 | * Registers a new CodeMirror plugin, which should follow the template
580 | * below.
581 | *
582 | * ```javascript
583 | * module.exports = {
584 | * default: function(context) {
585 | * return {
586 | * plugin: function(CodeMirror) {
587 | * // ...
588 | * },
589 | * codeMirrorResources: [],
590 | * codeMirrorOptions: {
591 | * // ...
592 | * },
593 | * assets: {
594 | * // ...
595 | * },
596 | * }
597 | * }
598 | * }
599 | * ```
600 | *
601 | * - The `context` argument is currently unused but could be used later on
602 | * to provide access to your own plugin so that the content script and
603 | * plugin can communicate.
604 | *
605 | * - The `plugin` key is your CodeMirror plugin. This is where you can
606 | * register new commands with CodeMirror or interact with the CodeMirror
607 | * instance as needed.
608 | *
609 | * - The `codeMirrorResources` key is an array of CodeMirror resources that
610 | * will be loaded and attached to the CodeMirror module. These are made up
611 | * of addons, keymaps, and modes. For example, for a plugin that want's to
612 | * enable clojure highlighting in code blocks. `codeMirrorResources` would
613 | * be set to `['mode/clojure/clojure']`.
614 | *
615 | * - The `codeMirrorOptions` key contains all the
616 | * [CodeMirror](https://codemirror.net/doc/manual.html#config) options
617 | * that will be set or changed by this plugin. New options can alse be
618 | * declared via
619 | * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption),
620 | * and then have their value set here. For example, a plugin that enables
621 | * line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`.
622 | *
623 | * - Using the **optional** `assets` key you may specify **only** CSS assets
624 | * that should be loaded in the rendered HTML document. Check for example
625 | * the Joplin [Mermaid
626 | * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts)
627 | * to see how the data should be structured.
628 | *
629 | * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys
630 | * must be provided for the plugin to be valid. Having multiple or all
631 | * provided is also okay.
632 | *
633 | * See also the [demo
634 | * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
635 | * for an example of all these keys being used in one plugin.
636 | *
637 | * ## Posting messages from the content script to your plugin
638 | *
639 | * In order to post messages to the plugin, you can use the postMessage
640 | * function passed to the {@link ContentScriptContext | context}.
641 | *
642 | * ```javascript
643 | * const response = await context.postMessage('messageFromCodeMirrorContentScript');
644 | * ```
645 | *
646 | * When you post a message, the plugin can send back a `response` thus
647 | * allowing two-way communication:
648 | *
649 | * ```javascript
650 | * await joplin.contentScripts.onMessage(contentScriptId, (message) => {
651 | * // Process message
652 | * return response; // Can be any object, string or number
653 | * });
654 | * ```
655 | *
656 | * See {@link JoplinContentScripts.onMessage} for more details, as well as
657 | * the [postMessage
658 | * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
659 | *
660 | */
661 | CodeMirrorPlugin = 'codeMirrorPlugin',
662 | }
663 |
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | transform: { '^.+\\.ts?$': 'ts-jest' },
3 | testEnvironment: 'node',
4 | testRegex: '/test/.*\\.(test|spec)?\\.ts$',
5 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
6 | };
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "joplin-plugin-email",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
6 | "prepare": "npm run dist",
7 | "update": "npm install -g generator-joplin && yo joplin --update",
8 | "test": "jest"
9 | },
10 | "license": "MIT",
11 | "keywords": [
12 | "joplin-plugin"
13 | ],
14 | "devDependencies": {
15 | "@types/jest": "^26.0.23",
16 | "@types/node": "^14.0.14",
17 | "@typescript-eslint/eslint-plugin": "^5.30.7",
18 | "@typescript-eslint/parser": "^5.30.7",
19 | "chalk": "^4.1.0",
20 | "copy-webpack-plugin": "^6.1.0",
21 | "cross-blob": "^2.0.0",
22 | "eslint": "^8.20.0",
23 | "eslint-config-google": "^0.14.0",
24 | "fs-extra": "^9.0.1",
25 | "glob": "^7.1.6",
26 | "jest": "^27.0.4",
27 | "on-build-webpack": "^0.1.0",
28 | "tar": "^6.0.5",
29 | "ts-jest": "<27.0.3",
30 | "ts-loader": "^7.0.5",
31 | "typescript": "^3.9.3",
32 | "webpack": "^4.43.0",
33 | "webpack-cli": "^3.3.11",
34 | "yargs": "^16.2.0"
35 | },
36 | "dependencies": {
37 | "@types/imap": "^0.8.35",
38 | "html-to-text": "^8.2.1",
39 | "imap": "^0.8.19",
40 | "net": "^1.0.2",
41 | "postal-mime": "^1.0.16",
42 | "tls": "^0.0.1"
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/plugin.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "extraScripts": []
3 | }
--------------------------------------------------------------------------------
/src/constants.ts:
--------------------------------------------------------------------------------
1 | export const SECTION_NAME = 'Email_Plugin';
2 | export const EXPORT_TYPE = 'Export_Type';
3 | export const ATTACHMENTS = 'Attachments';
4 | export const PLUGIN_ICON = 'fa fa-envelope';
5 | export const ATTACHMENTS_STYLE = 'Attachments_Style';
6 | export const ACCOUNTS = 'Accounts';
7 | export const LAST_STATE = 'Last_State';
8 |
9 | // This regexs from https://github.com/regexhq/mentions-regex/blob/master/index.js
10 | // @folder regex Regular expression for matching @foldre mentions
11 | export const MENTIONS_REGEX = /(?:^|[^a-zA-Z0-9_@!@#$%&*])(?:(?:﹫|@|@)(?!\/))([a-zA-Z0-9/_.]{1,150})(?:\b(?!﹫|@|@|#|⋕|♯|⌗)|$)/g;
12 |
13 | // #tag regex Regular expression for matching #tag mentions
14 | export const TAGS_REGEX = /(?:^|[^a-zA-Z0-9_@!@#$%&*])(?:(?:#|⋕|♯|⌗)(?!\/))([a-zA-Z0-9/_.]{1,150})(?:\b(?!﹫|@|@|#|⋕|♯|⌗)|$)/g;
15 |
--------------------------------------------------------------------------------
/src/core/emailConfigure.ts:
--------------------------------------------------------------------------------
1 | import {Login} from '../model/message.model';
2 | import {emailProviders} from './emailProviders';
3 | import {ImapConfig} from '../model/imapConfig.model';
4 | import {EmailProvider} from 'src/model/emailProvider.model';
5 |
6 | export function emailConfigure(login: Login): ImapConfig | never {
7 | let user = login.email;
8 | const password = login.password;
9 |
10 | user = user.toLocaleLowerCase();
11 |
12 | // Remove extra spaces from an email.
13 | user = user.replace(/\s+/g, '');
14 |
15 |
16 | const config: EmailProvider = emailProviders.find(({type}) => user.includes('@' + type));
17 |
18 | // In the case that the email provider is not present in the email providers list, it will be returned as "undefined".
19 | if (!config) {
20 | throw new Error(`Sorry, an email provider couldn't be found, Please use the manual connection.`);
21 | }
22 |
23 | const imapConfig: ImapConfig = {
24 | user: user,
25 | password: password,
26 | ...config,
27 | };
28 |
29 | return imapConfig;
30 | }
31 |
--------------------------------------------------------------------------------
/src/core/emailParser.ts:
--------------------------------------------------------------------------------
1 | const postalMime = require('postal-mime/dist/node').postalMime.default;
2 | import {Email} from 'postal-mime';
3 | import StringOps from '../utils/stringOps';
4 |
5 | export default class EmailParser extends postalMime {
6 | emailContent: Email;
7 |
8 | constructor() {
9 | super();
10 | }
11 |
12 | // Email in RFC 822 format.
13 | async parse(message: string): Promise {
14 | // A message is invalid if it starts with a space.
15 | message = message.trim();
16 | this.emailContent = await super.parse(message);
17 | this.emailContent.subject = this.getSubject();
18 | this.emailContent.html = this.getHTML();
19 |
20 | return (this.emailContent);
21 | }
22 |
23 | getSubject() {
24 | return this.emailContent.subject || 'No Subject';
25 | }
26 |
27 | getHTML() {
28 | const {html, text} = this.emailContent;
29 | const {escapeHTML} = StringOps;
30 |
31 | // If HTML content does not exist, email text content (wrapping with html) will be returned if it does.
32 | if (!html && text) {
33 | const linebreaks = text.split('\n');
34 | const splitText = (line: string) => (line.trim() === '' ? '