Are there some command line tools (or libraries) out there to access a gmail account, e.g. to read unread messages, download messages, etc.?
If you like Vim there is a gem called Vmail. The cool thing about Vmail is that its keybindings are similar to Gmail's keyboard shortcuts. So for instance, to archive a message in Gmail you type
e. In Vmail you type
The Google Command Line Tool might provide such support in the future. Right now it is limited to Blogger, Calendar, Contacts, Docs, Picasa and Youtube.
You can do this using Postfix and Fetchmail. See here: http://souptonuts.sourceforge.net/postfix_tutorial.html
You've got two questions here.
Are there libraries? Yup - but you'll want to mention a programming language of choice. All of them have some library associated for interacting with the google suite.
Are there command line tools? Yup. You can use good old Mutt or Pine. I've also heard good things about Sup and it seems to be oriented towards gmail style usage.