Ubuntu - Dovecot - Configuration

dovecot.conf
protocols = imap imaps pop3 pop3s
 
disable_plaintext_auth = no
 
log_timestamp = "%Y-%m-%d %H:%M:%S "
 
ssl_cert_file = /etc/dovecot/mail.crt
ssl_key_file = /etc/dovecot/mail.key
 
login_user = dovecot
 
mail_location = maildir:%h
 
mail_privileged_group = mail
 
first_valid_uid = 109
 
protocol imap {
 
}
 
 
protocol pop3 {
 
  pop3_uidl_format = %08Xu%08Xv
 
}
 
auth default {
  mechanisms = plain
 
  passdb sql {
    args = /etc/dovecot/dovecot-sql.conf
  }
 
  userdb sql {
    args = /etc/dovecot/dovecot-sql.conf
  }
 
  user = root
 
}
 
dict {
}
 
plugin {
 
}
dovecot-sql.conf
driver = pgsql
 
connect = host=localhost port=5433 dbname=authdb user=poczta password=poczta1
 
default_pass_scheme = PLAIN
 
password_query = select password from account where username = '%u'
 
user_query = select 109 as uid, 110 as gid, maildir as home from account where username = '%u'
core.sql
-- core tables
 
CREATE TABLE alias (
  alias_id serial PRIMARY KEY,
  address text NOT NULL,
  goto text NOT NULL
);
CREATE TABLE account (
  account_id serial primary key,
  username text NOT NULL,
  password text NOT NULL,
  maildir text NOT NULL default '/mail/new'
);
INSERT INTO alias (address,goto) VALUES ('john','johns@example.com');
INSERT INTO alias (address,goto) VALUES ('john','johns@example2.com');
INSERT INTO alias (address,goto) VALUES ('john','johns@example3.com');
 
INSERT INTO account (username,password,maildir) VALUES ('john','john','/mail/john');
INSERT INTO account (username,password,maildir) VALUES ('test','test','/mail/test');
INSERT INTO account (username,password,maildir) VALUES ('test1','test1','/mail/test1');