We are running courier currently which enables us to set different SQL userdb queries for IMAP and POP3. We need this because we do not want to give all users IMAP access, a boolean column in the userdb allows IMAP access if set.

For performance and stability reasons we are currently migrating to dovecot. I found no way yet to either set different SQL queries based on POP3 or IMAP access - or to pass the access method as variable to the SQL query. Both ways would work.

Here's the relevant mysql config from courier:

    IF(isimap=1 OR '$(service)'='webmail','disableimap=0,','disableimap=1,'),\
  FROM mail_users WHERE username = '$(local_part)@$(domain)'

The service variable comes from the daemon config file. Is there something similar in dovecot?


You can use the %s variable to check what service is being requested. See http://wiki2.dovecot.org/Variables .

Something like this could work for you as the SQL query:

  '%u' AS username, '%d' AS domain,
  password, uid, gid, homedir AS home
FROM mail_users
  CONCAT('%u', '@', '%d') = username'' AND
  (isimap=1 OR '%s' <> 'imap')


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.