Retrieve the list of UIDs in an Imapfolder with MailKit? - mailkit

I want to send the command 'UID FETCH ALL'. This gives me all the uids for this folder. I can't find any predefined method for this command.
I want to retrieve the headers of the emails in an imapfolder and save them to a local datastore with their UID so the next time, I can fetch all the UIDs, discard the ones smaller then the highest UID in my datastore and start retrieving those headers.
Additionally I can compare the range of UIDs in my datastore with the list retrieved by the command and check if any UIDs failed to be persisted to my local datastore en try to receive them again.
(Assume checking of the UIDs is in conjunction with UIDValidity).
I use this strategy to be sure all headers are in my local datastore (or my logging tells me which UID I can not retrieve/persist)
If there is another (possible better) strategy to accomplish this with MailKit please point me in the right direction.
Update:
Found a solution. Use 'inbox.Fetch(0, -1, MessageSummaryItems.UniqueId)'

Found a solution. Use 'inbox.Fetch(0, -1, MessageSummaryItems.UniqueId)'

Related

Clio API v4; Endpoint for getting list of documents within one folder

Problem: Getting a list of documents that exist in a specific folder
Tried solution:
endpoint /api/v4/folders/list.json seems to be working exactly the same as /api/v4/folders.json
Something similar to this - similar endpoint doesn't seem to exist
Filtering documents by parent_id, however this functionality doesn't exist
Is there some kind of example of the endpoint to perform such operation?
Reading the documentation, it appears as though /api/v4/folders/list.json returns the contents of a folder. If you are trying to get a list of all the documents within the folder 1425540709 (using your example above) then your GET would add a parameter "parent_id = 1425540709". According to the documentation, if you don't send a "parent_id" it defaults to the root folder for the account.
Your request url should look like this I believe:
https://app.goclio.com/api/v4/folders/list.json?parent_id=1425540709&limit=25
The response will be a json array of the items within that folder.
Make sure you send it a parameter for what fields you want back too because otherwise the api defaults to just id and etag.

How to get a list of documents based on an array of document ids?

What's the best way to get a list of documents based on another list of document ids?
If I have User and Profile objects.
Users have a single Profile
Users can save other users' profiles
The same profile can't be saved twice
The documents of the savedProfile sub collection are stored based on the uid of the user it belongs to. It also has an attribute of userRef which stores the uid of the user again. Given that savedProfiles is a list of uids. Is there a way to get a list of profiles based on the savedProfiles subcollection? Currently I am able to make a get request for a users saved profiles which returns a list of uids which I store in a variable. I'm just wondering how I would make the next request to get the full profiles of the savedProfiles based on that list? Saving the whole user profile in a users savedProfiles is also not an option since these profiles can be updated and changed quite frequently and it would be expensive to find and change each users saved profiles if that profile has been saved. (If there was 100,000 users with an average of around 10 saved profiles each).
Please tell me if there's a way to make this sort of query or if there's a better way to structure my data. Thanks.
Ok, so I think I managed to find a way. From my cloud function I used admin.firestore().getAll(refList). refList is an array of document references that I want. This returns a promise which gives a list of documents matching those references. The data for each document is accessible like normal with doc.data() I've either solved the problem, or I'm doing something very wrong. Feel free to comment and let me know if what I'm doing is okay. Thanks

How to securize an entitie on Sails?

I'm developing an API with Sails, and now I need to securize some variables from an entity. Those variable will be accesed only from Admin or own user.
I have an structure like this:
Employee (contains your employee records)
fullName
hourlyWage
phoneNumber
accountBank
Location (contains a record for each location you operate)
streetAddress
city
state
zipcode
...
I need to encrypt phonenumber and accountbank, to avoid anyone to see the values of this fields in the DataBase. Only the owner or the admin.
How I can do that? Thanks
You are looking for a way to encrypt data so that people with no required access right could not see it.
The solution for that is not Sails.js specific and Node actually comes with tools to encrypt data :https://nodejs.org/api/crypto.html.
The key rule here is to always keep your secret password safe.
As for integration in your Sails.js application, I would use callbacks in Models. The official documentation provides a good example here : http://sailsjs.org/documentation/concepts/models-and-orm/lifecycle-callbacks
Basically you just define a function that will be called each time the record is about to be created, fetched or updated. You can then apply your encrypt/decrypt functions there.
This will encrypt/decrypt your phone numbers and bank account numbers automatically.
Regarding access control, you can use Sails' policies along with authentication to determine if the client has the right to access the resource. If not you can always remove attributes from the response sent back to the client.

java imap, performance issues, fetching all mails

I will use java mail api to handle mails like thunderbird etc. I have to fetch mails having 1000 messages. My design will be: When user performs a synch on a folder, i will get all uids of the messages in the folder:
Message[] msgs = ufolder.getMessagesByUID(1, UIDFolder.LASTUID);
// Use a suitable FetchProfile
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.FLAGS);
I wil then compare the list of uids with the list stored in my db.
For the deleted ones, for example a message is not in the folder but in the db, i will mark it as deleted.
For the new ones, for example a message is in the folder but not in the db, i will mark as possible new. But, because messageuids are not safe (can be changed by the mail server on some cases), for the new mails, i will use additioanlly a custom hash value build from message id in the header + subject + receivedate and build a md5 hash. Only for the possible new mails i will use this hash and catch new mails.
For the moved messages, because their uids will be changed in the new folder, it will be flagged as deleted in the first and will be a new message in new folder, but the message will have same custom hash value becaue message id in the header and other properties will remain same duing the movement.
Question about performance issue: On each click on folder (folder synch) i will do the compare operation of all uids in the folder with the local uid list stored in the db to learn the deleted ones. I could not find another better way to accomplish this. As you know, thunderbird catches immediately a deleted message without relogin, even if the folder is large and the deleted message is very old (5 years). I think thunderbird also compares all message uids in that folder with a list stored locally.
How can i implement a better mechanism for the synch for a better performance? Does thunderbird apply a different approach? How can thunderbird
accomplish it so quickly?
If we were interested only for the new messages, i could have kept last stored uid and only compare the new messages later than that, but for the deleted ones, i already have to compare full folder. Additionally, UIDNEXT value is always -1 in my mail server, if it were set correctly, it will not help to get deleted ones again, a full compare is a must i think, am I wrong?
Note: I canot not use or add message listeners because the appliaction is server-client based and the mail handling task is on the server side and we do not support threads listeners etc. The events should be triggered from the client and the request is being processed on ther server and a response is returned and client handles the response on the gui.
What you want is called condstore or quick resync, RFC7162 in both cases. That's what Thunderbird uses.
That's a pair of extensions support commands like "give me all the UIDs that have changed since last time I connected", "tell me what's been deleted" and so on.
If you can't use threads to listen for these events from the mail server, your options are very limited. Probably the best thing you can do is limit the resynchronization to the messages that are visible to the client.

Facebook Messages access via imap

Does anybody know if is possible to access facebook messages via imap or pop to manage facebook messages within an email client?
No, this is not possible. Only the publicly documented APIs are available.
See especially the inbox connection of the User object
This Article propose a way to read and store facebook message:
The process is done through the following steps:
Logging in : Logging in might be one of the trickier parts. The way you login to an IMAP server is to use the following command:
LOGIN username password
Listing folders : The command you’d issue to the IMAP server is:
LIST "" *
Since we know from the Mailbox folder API description, there are only
three folders. These folders are:
Inbox (folder_id 0)
Outbox (folder_id 1)
Updates (folder_id 4)
With this in mind, we can hard code the following response to the list
command:
LIST (\HasChildren) "/" Inbox
LIST (\HasChildren) "/" Outbox
LIST (\HasChildren) "/" Updates
Selecting a folder : In IMAP, you use the following command to select a folder:
SELECT folder-name
Getting message content: The key in getting messages trough IMAP is a command named FETCH. The FETCH command comes with a lot of
different modes, but we’ll focus on the most fundamental ones. These
are (AFAIK) FLAGS, RFC822, RFC822.HEADER, RFC822.TEXT, RFC822.SIZE and
UID. Since RFC822 is just RFC822.HEADER and RFC822.TEXT combined, we
have one less variable to worry about.
FETCH UID Let’s start with UID, as this is the easiest one. You’d issue this command as follows:
FETCH 1:6 (UID)
The expected result would look something like this:
1 FETCH (UID 1029955483)
2 FETCH (UID 1029955484)
3 FETCH (UID 1029955485)
4 FETCH (UID 1029955486)
5 FETCH (UID 1029955487)
6 FETCH (UID 1029955488)
The equivalent command in Facebook’s API would be something like this
(I’m not sure if it’s possible to combine queries like this, but you
get the idea):
SELECT message_id FROM message WHERE thread_id IN (SELECT thread_id FROM thread WHERE folder_id = 0)
You would then use that output as the UID.
More operations are available in http://www.emailserviceguide.com/2010/01/making-facebooks-messaging-system-imap-compatible/