Message order in Gmail boxes - gmail-imap

I wrote a simple script in python using imaplib to download gmail messages from a given box (or a label which behaves like a box). Since some boxes contain very large number of messages, my script allows to download only those numered within an interval like 100-200, so that I can resume downloading as some later time.
My question is whether it is guaranteed that the message order within the box as provided by IMAP is always the same (chronological order). My tests seem to support this conclusion by I would like to be sure.
-- tsf

The IMAP RFC states:
Unique identifiers are assigned in a strictly ascending fashion in the
mailbox; as each message is added to the mailbox it is assigned a
higher UID than the message(s) which were added previously.

Related

AIP Sensitivity Labels added via Power Automate

I am interested to know if its possible to apply a sensitivity label to a document received via an email and then save the document to a specific directory in one drive.
For example, lets say company xyz sends a mail with files attached that we must process, I would like the files to be removed from the mail, marked with a custom sensitivity label like xzy_secret and then store the file in a OneDrive folder called xyz_company
So all the files in that folder eventually are labelled as per the customer.
Does anyone know if this is possible? The idea is that we can then apply DLP to our customers files and ensure we can track them within the business.
Anyone have any ideas? Is there an API for doing this or a power automate method?
As far as I know, Send an email action (with power automate) does not support applying the sensitivity label to the email currently. Being said that, you may need to implement your needs through the Rest API, please check this article and see if it helps:
https://joannecklein.com/2019/05/06/setting-a-retention-label-in-sharepoint-from-microsoft-flow/

Retrieve Email Sequence Number from UID Message Fetch MailCore2

Looking at Mailcore docs, I see a method to retrieve the sequence number of an email or emails by executing a fetch using the email UID. However, when looking at the Mailcore2 docs, I don't see any way to accomplish this. Is there a method for this in Mailcore2 that I am somehow not seeing, or a way to bubble up this information? I know it is possible in the command line, but I'd like to be able access it from inside my iOS app.
EDIT:
Here is why I am looking for this functionality:
We have a native iOS client that fetches the 10 newest emails at a time and saves them. Additionally, the client will fetch the next 10 older emails at a time and save them, as well as the lowest UID it has seen (minUID).
So we need to be able to continually fetch the next 10 older emails that exist on the server that the client has not yet stored or seen. (Therein lies the challenge).
Initially, we did this by fetching emails by UID in groups of 10, using our saved minUID minus 1 as the starting point for each fetch, and updating our minUID at the end of each fetch. However, as UIDs are not necessarily contiguous, the number of emails that was returned was inconsistent, and sometimes zero. To solve this problem, we thought it would be helpful to (before each fetch for the next 10 older emails), fetch the email with our stored minUID, check its current sequence number, and then fetch the next 10 older emails based on that sequence number.
To fetch messages based on a sequence number, you can use the following function syncMessagesWithFolder:folderName:requestKind:uids:modSeq:
The below example will fetch you all the new/modified messages for the folder folder above sequence number highestModSeq.
MCOIMAPFetchMessagesOperation * op = [self.imapSession syncMessagesWithFolder:folderName
requestKind:requestKind
uids:[MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)]
modSeq:highestModSeq];
The documentation is not exactly the best place to find examples, but our wiki is increasingly becoming an excellent repository for that kind of information. What you're looking for is -[MCOIMAPSession fetchMessagesByUIDOperationWithFolder:requestKind:uids:], an example of which can be found under the IMAP examples wiki page.

How to mark IMAP message as fetched?

I am working on PHP project that should fetch emails from IMAP server, and store them in local database.
Same IMAP server can be used by other email clients, like outbox and so on.
The problem is how to know which messages I already fetched, and which I didn't? I am thinking to use search by datetime, but is it reliable(I would have cronjob, that would access user mail box every minute, and check for emails, but not sure if datetime can cause some issues, for example in case when at almost same time arrive short message and message with big attachment).
I was thinking about system tags, but user can modify them via email client, so I can rely on them, and don't want to modify them and confuse client.
Next I was thinking about custom tags, but not all IMAP servers support them(and our software need to be flexible as much as possible).
Any good idea how I could solve this problem?
Keep track of the currently highest synced UID of the folder you are syncing, and verify that the UIDVALIDITY value of the folder match.
Unique identifiers are assigned in a strictly ascending fashion in the mailbox; as each message is added to the mailbox it is assigned a higher UID than the message(s) which were added previously. Unlike message sequence numbers, unique identifiers are not necessarily contiguous.

Can an email be printed as soon as it enters the Inbox?

We are working on an online food ordering application. When the user orders something from any restaurant, an email is sent to the restaurant's email address mentioning the order details. However, our client wants that an order print out should be generated automatically as soon as a new order is received.
Is it feasible using ROR? If not, any alternate solution to the problem?
When my group wrote something like this we went a little lower tech, and had the system generate a fax and send it to a fax machine at the restaurant. Of course, that's mainly because this was a system working across many restaurants, with disparate IT infrastructures, and the one thing they had in common was each had a fax machine.
I would figure this could be done in 1 of two ways:
1- Outlook event-- Outlook has the ability to set up 'rules', one of which I think allows printing.
2- Create a script that runs every few minutes, checks the email (either through IMAP, or POP, depending on the account), and prints all of them out.
See this: http://ruby.about.com/od/tasks/a/pop3.htm for info on how to check POP3 mail with ruby on rails.
For printing, the links mentioned here seem useful: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/504a616bf3e28057/ff6cb91462dfe961?pli=1
Ensure that you have 'from' or 'subject' filters setup, otherwise there will be a lot of spam printing.
You can use software to print your order automatically when email is received, it supports also print attachment like pdf, word, etc...
It is used by a lot of restaurant to print online order:
http://www.automatic-email-manager.com/

RoR + SMS: Rails web app architecture to send/receive SMS?

What web app architecture works well receiving/sending SMS text messages? By "architecture, I mean specific architecture, not generally, such as MVC.
Background: I'm building a web app that receives queries from/sends answers to cell phones. The app design (and business model) expects to communicate with cell devices via SMS text messages. IOW: There is no MVC web page "view". The cell phone screen is effectively the "view".
I would question whether this is really a web application. If the view layer is SMS, you don't have to use the internet as a transport, you could use hardware to connect to the cell phone network.
If you are thinking of using a commercial http/sms gateway, there is a good article on using the Ruby Clicktell gem from a Rails application. Seems like a good route to try.
This depends on how you will be receiving and sending the SMS messages.
There is a specific Short message protocol (SMPP - http://en.wikipedia.org/wiki/SMPP).
For that you will need an SMPP server.
If you are using a one of the various SMS over HTTP providers (such as Clickatell - http://www.clickatell.com), then a web framework such as RoR is fine as both the sending and receiving of SMS messages are actually web requests.
In this case your system view is the HTTP response to the gateway, not the cellphone screen. There are actually quite a few steps involved:
Cellphone -> Cellular Network -> Gateway -> Your Service and the reply: Cellphone <- Cellular Network <- Gateway <- Your Service
I've made one of these before using rails. I created a budget tracker I could send commands to with my cell phone. I used it to create a list of items i needed to buy/take care of on the upcoming paycheck. When the check came in, I would send commands to mark each item off the list. I included commands to query a list as well. The commands looked something like "lc mar4" to create the fourth paycheck in march's budget list. Once a list was created, I could send commands without specifying the list and I made the script just apply the command to the last list if no list was specified and crunch down the other arguments. "la court 50 p" would add too the mar4 list an item named "court" with a value of 50 and a tag "p" which I called pending. When I took care of court that friday, I could send "lu court 50 d" which would update the court item with the same value with the tag "d" for done. I had a command called "lp" which would print the current list. "lp d" would print all the "d" tagged items on the current list. "lsum p" would print all the pending items on the current list.
I made an empty rails app. Made my database schema and my models but had no controllers. I had a script in scripts that included a pop/ssl library i found somewhere to download email from a gmail account i had setup for this. From then on it was pretty easy, just check the new messages for each message make sure it came from my cell phone and parse the message and optionally send back a response. (I had programmed that email address into my cellphone, and sent text commands to that email address). I added a cron job and set it to run every minute.
I don't know what that architecture is, but its basically a service that queries a 3rd party and does different things dependent on the response. If you did true SMS with shortcodes, I'll let you know now that I think there is a sizeable investment necessary to do those for real. Might be easier to start develop with email text messaging through sms gateways.
I'm not saying this is the best way to do it by far, It would have been cooler to have had the messages "pushed" to me instead of checking every minute, but hey I just wanted to balance my budget with my phone.

Resources