Some time ago I ve written a Python script, using poplib library, which retrieves messages from my pop3 email account. Now I would like to use it to retrieve emails from different mail server which works with IMAP. It works well, but only to retrieve messages from Inbox. Is there any way to also get emails from other folders like Spam, Sent etc? I know I could use imaplib and rewrite the script, but my questions is if it's possible to obtain that with poplib.
No.
POP is a single folder protocol.  It is very simple and was not designed for multiple folders.
You will need to use IMAP or other advanced protocols to access additional folders.
Checking folders different than inbox using poplib in Python