I am working on application that can determine which Gmail Tab an email is placed under (ie Social
, Promotions
, etc). Is there any way of determining which Gmail Tab an email is placed into with the Javamail API? Or are there some other applications that can determine this?
Thanks in advance.
It is not possible to determine the category/tab with the Javamail API because Google do not integrate the information with the IMAP protocol. The category/tab is only available via Google's proprietary GMail APIs.
In the GMail settings under labels, I was able to get categories to show up as folders in the GMail web client by clicking on 'show' next to categories, however they did not come down in the IMAP request. It must be by design because there is no "Show in IMAP" option provided for the categories.
In the existing answer it is mentioned that the GMail IMAP extensions can be used to access X-GM-THRID and X-GM-LABELS
These extensions are explained in Google's GMail IMAP docs: https://developers.google.com/gmail/imap/imap-extensions
X-GM-LABELS -> "Gmail treats labels as folders for the purposes of IMAP."
a010 FETCH 1:4 (X-GM-LABELS)
X-GM-THRID -> "Gmail provides a thread ID to associate groups of messages in the same manner as in the Gmail web interface."
a008 FETCH 1:4 (X-GM-THRID)
But neither of these extensions specifies the category to which an email belongs.
There are however two alternative solutions that will allow Javamail to work with categories indirectly:
Procedure for changing categories into labels/IMAP-folders:
Screenshots for the procedure:
The procedure for skipping the inbox
The list of possible categories to filter on:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With