Getting new or last messages

We have already provided sample code for basic overview of a specific folder. But what if you need to get information about messages themselves rather than folder - for example, headers of last 5 mails? That can be done with the API, too: