Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

week 6 & 7& 8 #5

Merged
merged 3 commits into from
Aug 23, 2022
Merged

week 6 & 7& 8 #5

merged 3 commits into from
Aug 23, 2022

Conversation

bishoy-magdy
Copy link
Collaborator

What has been done

  • Added the feature of fetching the message data from imap.
  • Installed the email parser.
  • Added the feature of parsing the HTML message and extracting the body using DOMParser.
  • Added the feature of marking the converted message in the plugin without editing the message or adding flags.
  • Added the feature to save the last change on the screen (main screen) when the plugin is closed.
  • Created email parser class and added the unit test for the email parser class.
  • Added the ability to convert email notes to text.
  • Created the class responsible for posting notes to Joplin.
  • Added inline attachments to note.
  • Added the feature of converting emails to notes without logging in.

Demo

A demo example of the latest feature that was added

offline2.mp4

@bishoy-magdy bishoy-magdy requested a review from roman-r-m August 16, 2022 09:24
src/core/imap.ts Outdated
}

try {
const value = await joplin.settings.value(CONVERTED_MESSAGES);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setting will grow over time, could become a performance bottleneck at some point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came up with a better solution: get the converted message and store it in a variable, then query that variable to see if there is a new message, and when there is, the values are updated. This means that the converted message in Joplin is not only updated until there is a new message(If you have another solution please tell me).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by variable here? You need to persists this information between restarts somehow.

It seems to me that the easiest way to store this information is to use the email account itself - you either delete messages you've converted, mark them read, or move to another folder.
Or you could only store the date of the last seen email and only process newer. This way you store it on the client but at least it's just one number per mailbox.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, the thought came to my mind to store this information by using the email account itself, but there is no standard way to mark the message. To be more clear, some email providers allow you to mark messages while others don't.

But I found a solution One of the flags that are standard for all email providers is the 'SEEN' flag. Every message is flagged as 'UNSEEN' if the message is new or the user marks it as 'UNSEEN'.

So I will add an additional condition in the search, which is to search for the messages that are "from" a specific email and marked as "UNSEEN" and then mark the messages as "SEEN" after fetching them.

I think this solution is better than deleting. and the user can mark as an "unread" message any number of messages in their email provider.

Sorry for the delay in suggesting this solution. It took me a lot of time to test this solution across different email providers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example:

git2.mp4

],
);

attachmentsProp.push({contentId: contentId, id: resource.id});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth cleaning up the temp file afterwards

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried deleting folders in this place, but it will slow down when there are a lot of messages that you want to convert because it will create and delete and so on. What I did is every time the plugin starts, it deletes the old attachments and starts creating a new temporary folder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could potentially be a security risk, say, if you run the plugin in Joplin portable from a USB drive, your emails will be left on the computer.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't the delete job be a self-running/isolated background job?
The "old" temp folder could be renamed, a new one created, old, now renamed, deleted in the background

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could potentially be a security risk, say, if you run the plugin in Joplin portable from a USB drive, your emails will be left on the computer.

Okay, I refacted the function to this mechanism.

  • Create a temp folder
    • Post all emails including attachments to Joplin.
  • Remove a temp folder

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't the delete job be a self-running/isolated background job?
The "old" temp folder could be renamed, a new one created, old, now renamed, deleted in the background

It's a sync function, which means I can't go to the next line after finishing this function(delete a temp folder).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could in theory use a web worker (or whatever the equivalent of threads in the JS world is called) but this looks like an overkill.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could in theory use a web worker (or whatever the equivalent of threads in the JS world is called) but this looks like an overkill.

This looks very good since we can add all the notes and attachments posting functions in the other JS thread.
I will read more about web worker. and I will definitely add it if I notice its presence will be important.

@bishoy-magdy bishoy-magdy requested a review from roman-r-m August 17, 2022 22:11
const emailFolders = joplinFolders.items.filter((e)=>{
return this.folders.includes(e.title);
});

const emailTags = joplinTags.items.filter((e)=>{
return this.tags.includes(e.title);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find how these tags are set right now, but I think this will stop working if a tag is renamed. Best to use IDs as you did with folder.

I guess it's not a concern for manual one-time import but for monitoring mailbox it is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this code to the 'addTags' function and fixed it so that if 'has_more' in Joplin tags is true, this function now takes a set of tags and creates all tags that are not inside Joplin tags, and it returns all mentioned tags with all properties. 

If something is not clear, please tell me.

removed the feature of local marking messages, added the feature of marking messages using the email providers, fixed If 'has_more' is true in Joplin tags or folders, refacted TempFolder mechanism

setupTempFolder = new SetupTempFolder();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor thing but there is no reason to create a new instance on every iteration.
In fact, you don't need to create any instances of this class at all - all method can be made static

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, it will be changed in the next PR.

await this.updateConvertedMessages(newMessages);
this.uids.push(...newMessages);

setupTempFolder.removeTempFolder();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it will be any faster but you don't need to delete the whole folder, only specific files corresponding to already processed emails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting an entire file is a little faster than looping through each file and deleting it.

only specific files corresponding to already processed emails.

This is actually only what will be in the file, which means that the whole file will be deleted, and I also want to leave no trace after doing what is required.

I tested it by converting more than 100 eml files. Some of them contain large files containing videos and images, and the conversion process works fine.

@roman-r-m
Copy link
Contributor

Overall looks good, I'm going to merge despite a couple of small comments. Feel free to ignore those or address in subsequent PRs.

@roman-r-m roman-r-m merged commit 53b1faa into main Aug 23, 2022
@bishoy-magdy
Copy link
Collaborator Author

Overall looks good, I'm going to merge despite a couple of small comments. Feel free to ignore those or address in subsequent PRs.

Big thanks for this code review. In parallel, I made some changes for the purpose of improvement for some code that will be in the next PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants