How to scan ALL mail via Gmail API? - gmail

After I OAuth my google account I can connect to it via the IMAP protocol. Listing folders lists all the "labels" plus "[Gmail]" which isn't selectable.
Is there any way to list ALL mail and/or at least get into the trash? Also what about archived - those don't show up in the INBOX folder
I did some digging around and tried this:
var_dump($storage->getFolders('[Gmail]'));
which doesn't list anything... but this does:
var_dump($storage->getFolders('[Gmail]/Trash'));
How can I list all those folders

[Gmail]/All Mail contains all of your messages in Gmail, including your sent and archived messages. Any messages that you see in your inbox will also appear in the [Gmail]/All Mail folder.

Related

Why attachments from Gmail drafts copied to Trash?

I use this Gmail API request for fetching Gmail messages in user mailbox. I need to list messages from Trash as well. But in some cases message list got by list messages request is different from actual content of Trash folder content.
To reproduce the problem next steps can be performed:
Ensure that my Trash folder is empty - no messages visible in Gmail web client and API list messages request returns 0 messages in Trash.
Start creating message by pushing "COMPOSE" button in Gmail web client.
Attach file to this draft message.
Get messages list in Trash using Gmail API list messages request.
The request returns 1 new message in user Trash folder (with the file attached to draft mentioned above) however it`s not visible in Gmail web client.
Is it normal or kind of bug? Is this a problem of Gmail web client or Gmail API?
Based from this thread, when you upload a file to Gmail as an attachment, Gmail creates a temporary file to hold the data and is then sent to Trash.
So, to get a more precise search, try adding q parameter using the advanced search syntax.
See Searching for Messages to learn more.

Search Gmail for mail with attachments

I have connected and logged in to gmail's imap server using openssl. I intend to search for all mails that have an attachment with them. How can I do that?
IMAP itself does not have a search term for that, but Gmail's extended search support should allow you to search for messages with attachments. You'll have to select the folder you're interested in:
a SELECT INBOX
Then use the GMail specific search command:
b UID SEARCH X-GM-RAW "has:attachment"
That should give you a list of UIDs of messages that have attachments.

Outlook REST API - getFolders not returning all folders

I'm just getting started with the Outlook REST API. My baseline is the tutorial that uses node-outlook.
First order of business is to retrieve all of the folders in my mail account.
So I issue this REST request:
GET https://outlook.office.com/api/v2.0/Me/MailFolders
Instead of returning all of my folders, it only returns the "well known" folders:
Clutter
Deleted Items
Drafts
Inbox
Junk Email
Outbox
Sent Items
Trash
Am I missing a query parameter or something that says, "no, really, all of them please"?
UPDATE
I tried a different email account, and I also don't get all of my actual folders, but I get a different subset (some of which are well-known, others aren't).
I am implementing the paging protocol (using the #nextLink parameter) so it's not a matter of page sizes. I am getting these 8 folders on one account, and 18 folders on another.
So there must be something that decides what folders will be returned.
UPDATE 2
I changed to doing a folder sync instead using the "beta" API. In this case, I also get an unnamed folder in the list, which is the parent of the other folders. It comes along with a ChildFolderCount which is accurate. However, when I do a child folder request on that folder id I get the same list.
UPDATE 3
Here's the request url I'm using when I attempt to read the child folders of the one folder that comes back with a non-zero ChildFolderCount.
GET https://outlook.office.com/api/beta/Me/MailFolders/AAMkADRmMzFmNjZmLWU3MjctNGZiNi1iZTg4LTRmNGQwYTVhMDgxYgAuAAAAAAB8IxaZ5KGbQom4EPywGCSdAQDVy0eYwAzLS63k5pohzykCAAAAAAEJAAA=/childfolders
Here's what appears to define what folders are returned by this API and what are not:
If I create a folder in office365 directly on outlook webmail, it shows up in this query.
If I create a folder in Mac Mail, it does not.
Mac Mail accesses the service using EWS, so I would expect a folder created by it would be like any other folder.
So there is something about folders created on Mac Mail that prevents them from being returned by this API.
Folders created in Mac Mail DO show up in web mail and vice versa.
Folders created on an iPhone DO show up, so in my limited testing it looks like Mac Mail may be the only app suffering from this problem. The problem I have is most of my folders were created in Mac Mail and I have no easy way of rebuilding them.
I'm thinking this is just a BUG in the API. At any rate, this answers my original question and should help anyone out there trying to use the new API.
If I find a workaround I'll post it here.

Getting [Gmail] All Mail from different languages

I'm using python imaplib to read Gmail messages from the [Gmail] All Mail folder.
For most accounts, the all mail folder is named "[Gmail] All Mail". However, a couple accounts have it as: "[Gmail]/&BBIEQQRP- &BD8EPgRHBEIEMA-"
It seems to be related to an account in a foreign language.
Does anyone recognize the encoding?
Is there a way to figure out which folder is the "All Mail" folder?
Alternatively, is there a systematic way of getting all the possible names of the All Mail folder so I can search for it?
GMail supports an XLIST function to get the localized name of the folder.
See Gmail IMAP Extensions

How to move message to Trash in gmail imap?

I am creating an application in which I need to delete mail using IMAP in gmail. But when I set the flag to delete the message moves to spam folder instead of trash or directly deletion. Is there any way to move message to trash?
UPDATE
Now my messages are moving from inbox to important folder. I'm sending message to my self( in web browser) and it's marked as important by default.
There is a Google support site that says "Do NOT save deleted messages to your [Gmail]/Trash folder because this will delete a message in all folders." - so you might want to do exactly that :)
Adding onto flob's answer
the following folder paths works too
it seems like it's depending on when the user sign up for gmail
"[Gmail]/Trash"
"[Google Mail]/Bin"
"[Gmail]/Bin"

Resources