Judging from the title (i.e. ignoring the "windows" tag and the "port 25" you want to connect to), I'd recommend either Archivemail or offlineimap.
You can read about Archivemail in it's man page. From the synopsis:
archivemail is a tool for archiving and compressing old email in
mailboxes. By default it will read the mailbox MAILBOX, moving
messages that are older that the specified number of days (180 by
default) to a mbox(5)-format mailbox in the same directory that is
compressed with gzip(1). It can also just delete old email rather than
archivemail supports reading IMAP, Maildir, MH and mbox-format
mailboxes, but always writes mbox-format archives.
I am tempted to say that offlineimap (man page) is a bit more powerful, but that depends on your needs.
OfflineImap operates on a REMOTE and a LOCAL repository and
synchronizes emails between them, so that you can read the same
mailbox from multiple computers. The REMOTE repository is some IMAP
server, while LOCAL can be either a local Maildir or another IMAP
I don't think any of those can save every mail with a filename pattern you desire, but with maildir every email is a file and you could open every file, extract the desired information and rename the file. That sounds like a hundred lines of Python.