Are there some command line tools (or libraries) out there to access a gmail account, e.g. to read unread messages, download messages, etc.? 
Command line tools to access Gmail?
gmail
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 ,e.