How do you get a list of users for a dovecot email server that connect via IMAP (as opposed to POP)?

Our server is setup to authenticate via LDAP/PAM. Is there an easy way to get a list of the users who are accessing their mail via IMAP, rather than POP? I am about to migrate our server to Google Apps and want to migrate all of the mail for my IMAP users only (couple hundred out of several hundred total users). POP mail will be migrated separately from the client end obviously.

I would much rather migrate only the IMAP users rather than the whole domain which would include migrating a bunch of POP mail left in the server that has already been read/sorted/deleted in the client's email program. Migrating all of that extra useless leftover POP mail could waste weeks of migration time.

I suppose parsing some logs to see who has connected on an IMAP port (995 or 993) would give me a list would work if someone could help me do that. I know I have the raw dovecot logs, but am hoping for a cleaner solution.


To get a list of logins:

cat /var/log/mail.log | grep imap-login 

Now we need to cut it down to something a little more useable -- filter out the username, and eliminate duplicates:

cat /var/log/mail.log | grep imap-login:\ Login | sed -e 's/.*Login: user=<\(.*\)>, method=.*/\1/g' | sort | uniq

This gets the imap logins that complete (supply a name), uses sed with a regex to cut out the name, sorts it and then takes the unique names.

| improve this answer | |
  • Thank you! So much cleaner than the PHP script I wrote to do it. I REALLY need to learn how to use regex without just googling ten million different things until something works. – Colt McCormack Sep 30 '12 at 3:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.