I've got several POP3 accounts that need to be collected and handed to an IMAP server.
This must be safe, so anything racey or non-atomic won't work. How should I do this?
Can clarify what you mean by "handed" to an IMAP server?
Are you trying to consolidate messages stored in several POP email accounts into one IMAP account? Is this a one time deal or ongoing?
One-time deal: Use a desktop client like Thunderbird. Add each pop3 account in turn (you can give each one their own "inbox"), as well as the imap account. Download all your pop3 messages. Then highlight all of a pop3's account messages and drag them to a folder on your imap account.
If you are running an email server with IMAP and you want it to fetch from POP3 accounts on an ongoing basis, or you don't mind using SMTP to get the messages to the IMAP server, then you should look into fetchmail.