How can I do this, I tried using IMAP but sometimes google blocks the account for unusual activity.
what I am trying to do is a web app to organize your mail semantically.
messages.get() is the basic way to get an individual message given the id. you can retrieve the message.id by using messages.list(), which takes familiar parameters like "q" (the query string, can accept anything the search box in gmail accepts).
https://developers.google.com/gmail/api/ has quickstarts in a few languages and guides for common tasks you want to do (see the "Search for Messages" guide).