Search Gmail for mail with attachments - search

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.

Related

GMail IMAP API limited to first 1000

I've bee experimenting with GMail IMAP API using the gmail ruby gem and was unable to pull search results for old emails. More specifically, if I would search for emails about a year ago they would not show up in the search result. This seems consistent with the Mail app on iPhone which also uses IMAP and seems likes its impossible to retrieve old emails.
It seems like this might be related to some limit that Gmail is putting on the IMAP interface which limits it only to the first 1000 emails.
Anybody else can confirm this?
Is there a way around this?
That's settable in gmail. I don't remember whether it's a per-account of per-mailbox setting.

How to scan ALL mail via Gmail API?

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.

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

IMAP SEARCH of Gmail not finding all messages

When I try to search Gmail via IMAP using X-GM-THRID it does not always find the related message. What could be the problem?

Link to individual mails in gmail

I want to download all emails in a gmail account and also want to get the unique url which will open the exact mail in gmail, off course with authentication. I tried using javax.mail imap library but Imap probably doesn't supports anything like it.
I can use "https://mail.google.com/mail/feed/atom" gmail feeds. but won't give me entire email and it only gives unread email and I don't want to miss any email
You can do this if you are using Google Apps for Business/Education. If you are, you can access the Gmail inbox feed (Atom) by using OAuth. OAuth can also be used to access Gmail via IMAP - you can then have complete access to the IMAP server programmatically, see Gmail IMAP and SMTP using OAuth.
Google has extended IMAP to allow developers to provide a more Gmail-like experience via IMAP, see: (Gmail IMAP Extensions, X-GM-EXT-1).
The unique message (X-GM-MSGID) and unique thread (X-GM-THRID) ids can be used to produce links to Gmail messages directly - you just have to hex encode the id long (e.g. Long.toHexString(x_gm_msgId)). Your link will then need need to be in the form of:
http://mail.google.com/mail?account_id=ACCOUNT_ID_HERE&message_id=MESSAGE_ID_HERE&view=conv&extsrc=atom
supplying ACCOUNT_ID_HERE (something like user#someplace.com) and MESSAGE_ID_HERE as appropriate.
I have been working in this area and think you might find my project useful, see: java-gmail-imap.
[NB: URLs formatted as above do not work on Gmail's mobile site (at least on iPhone/Safari).]
https://mail.google.com/mail/#all/HexEncodeMessageID
replace the HexEncodeMessageID part with the ID. You get it, when you open the email in a new window (use the pop out icon in the upper right corner.
The id looks like this: search=inbox&th=1426b8f59e003aa0
I'm fairly confident this is not possible - that there is no reliable way to get the unique URL that'll lead to a single email in Gmail. I'd love to hear otherwise!
I do believe it is possible to get a URL that will lead to the Gmail thread containing the message - but you have no control over which message(s) are "expanded" in this threaded display.

Resources