linux:exim-sql.conf

local_scan_path = /usr/lib/exim4/local_scan/sa-exim.so

hide pgsql_servers = localhost::5433/authdb/poczta/poczta1

primary_hostname = czarny06.aklin

domainlist local_domains = @ : czarny06.aklin : poczta.czarny06.aklin
domainlist relay_to_domains = czarny02.aklin : czarny04.aklin
hostlist   relay_from_hosts = 127.0.0.1 : 10.0.3.67
domainlist exdomains = fiw.local 

acl_smtp_rcpt = acl_check_rcpt
acl_smtp_data = acl_check_data
acl_not_smtp  = wiadomosci_z_sendmaila

av_scanner = clamd:/var/run/clamav/clamd.ctl

tls_advertise_hosts = *

tls_certificate = /etc/exim4/mail.crt
tls_privatekey = /etc/exim4/mail.key

daemon_smtp_ports = 25 : 465 : 587
tls_on_connect_ports = 465

never_users = root

host_lookup = *

rfc1413_hosts = !10.0.2.0/24
rfc1413_query_timeout = 5s

ignore_bounce_errors_after = 2d

timeout_frozen_after = 7d

begin acl

wiadomosci_z_sendmaila:

  accept  add_header    = X-SA-Nie-Uruchamiaj-Mnie: 9787be32e0cb6ae2b4e06f57c6461893

acl_check_rcpt:

	
  warn	local_parts = pracownicy
  	domains = +local_domains
  	add_header = Reply-To: pracownicy@czarny06.aklin

  warn  hosts = czarny02.aklin : czarny04.aklin
  	add_header    = X-SA-Nie-Uruchamiaj-Mnie: 9787be32e0cb6ae2b4e06f57c6461893

  accept  hosts = :
  	  add_header    = X-SA-Nie-Uruchamiaj-Mnie: 9787be32e0cb6ae2b4e06f57c6461893

  deny    message       = Restricted characters in address
          domains       = +local_domains
          local_parts   = ^[.] : ^.*[@%!/|]

  deny    message       = Restricted characters in address
          domains       = !+local_domains
          local_parts   = ^[./|] : ^.*[@%!] : ^.*/\\.\\./

  accept  local_parts   = postmaster
          domains       = +local_domains

  require verify        = sender

  accept  hosts         = +relay_from_hosts
  	  add_header    = X-SA-Nie-Uruchamiaj-Mnie: 9787be32e0cb6ae2b4e06f57c6461893
          control       = submission

  accept  authenticated = *
	  add_header	= X-SA-Nie-Uruchamiaj-Mnie: 9787be32e0cb6ae2b4e06f57c6461893
          control       = submission

  require message = relay not permitted
          domains = +local_domains : +relay_to_domains : +exdomains

  require verify = recipient

  accept

acl_check_data:

  deny    malware    = *
          message    = This message contains a virus ($malware_name).

  accept

begin routers

dnslookup:
  driver = dnslookup
  domains = ! +local_domains : ! +exdomains
  transport = remote_smtp
  ignore_target_hosts = 0.0.0.0 : 127.0.0.0/8
  no_more

aliases_poczta_czarny_06_aklin:
  driver = redirect
  allow_fail
  allow_defer
  domains = poczta.czarny06.aklin
  data = ${lookup{$local_part}lsearch{/etc/aliases-poczta}}
  file_transport = address_file
  pipe_transport = address_pipe

system_aliases:
  driver = redirect
  allow_fail
  allow_defer
  data = ${lookup pgsql{select goto from alias where address = '${local_part}'}{$value}}
  file_transport = address_file
  pipe_transport = address_pipe

userforward:
  driver = redirect
  check_local_user
  file = $home/.forward
  no_verify
  no_expn
  check_ancestor
  file_transport = address_file
  pipe_transport = address_pipe
  reply_transport = address_reply

localuser_spam_flag:
  driver = accept
  condition = ${lookup pgsql{select count(account_id) from account where username = '${local_part}'}{$value}}
  condition = ${if eq {$h_X-Spam-Flag}{YES} {1}{0}}
  transport = local_delivery_spam

localuser:
  driver = accept
  condition = ${lookup pgsql{select count(account_id) from account where username = '${local_part}'}{$value}}
  transport = local_delivery
  cannot_route_message = Unknown user

begin transports

remote_smtp:
  driver = smtp
  headers_remove = X-SA-Nie-Uruchamiaj-Mnie : X-SA-Exim-Connect-IP : X-SA-Exim-Rcpt-To : X-SA-Exim-Mail-From

remote_smtp_ex:
  driver = smtp
  headers_remove = X-SA-Nie-Uruchamiaj-Mnie : X-SA-Exim-Connect-IP : X-SA-Exim-Rcpt-To : X-SA-Exim-Mail-From
  hosts_avoid_tls = *

local_delivery:
  driver = appendfile
  maildir_format
  directory = ${lookup pgsql{SELECT maildir FROM account WHERE username = '$local_part'}{$value}}
 # file = /var/mail/$local_part
  delivery_date_add
  envelope_to_add
  return_path_add
  group = mail
  mode = 0660
  headers_remove = X-SA-Nie-Uruchamiaj-Mnie : X-SA-Exim-Connect-IP : X-SA-Exim-Rcpt-To : X-SA-Exim-Mail-From
  user = dovecot

local_delivery_spam:
  driver = appendfile
  maildir_format
  directory = ${lookup pgsql{SELECT maildir FROM account WHERE username = '$local_part'}{$value}}/.spam
 # file = /var/mail/$local_part
  delivery_date_add
  envelope_to_add
  return_path_add
  group = mail
  mode = 0660
  headers_remove = X-SA-Nie-Uruchamiaj-Mnie : X-SA-Exim-Connect-IP : X-SA-Exim-Rcpt-To : X-SA-Exim-Mail-From
  user = dovecot

address_pipe:
  driver = pipe
  return_output

address_file:
  driver = appendfile
  delivery_date_add
  envelope_to_add
  return_path_add

address_reply:
  driver = autoreply

begin retry

*                      *           F,2h,15m; G,16h,1h,1.5; F,4d,6h

begin rewrite

begin authenticators

PLAIN:
  driver                     = plaintext
  server_set_id              = $auth2
  server_prompts             = :
  server_condition           = ${lookup pgsql{select count(account_id) from account where username = '$2' and password = '$3'}{$value}}
  server_advertise_condition = ${if def:tls_cipher }

LOGIN:
  driver                     = plaintext
  server_set_id              = $auth1
  server_prompts             = <| Username: | Password:
  server_condition           = ${lookup pgsql{select count(account_id) from account where username = '$1' and password = '$2'}{$value}}
  server_advertise_condition = ${if def:tls_cipher }