foxcpp / maddy

✉️ Composable all-in-one mail server.
https://maddy.email
GNU General Public License v3.0
5.11k stars 246 forks source link

Setup $(local_domains) from table instead of maddy.conf #340

Open fgma opened 3 years ago

fgma commented 3 years ago

Use case

I'd like to load $(local_domains) from a table like sqlite. Right now I need to specify domains in maddy.conf but my accounts and aliases are all setup inside sqlite.

Your idea for a solution

foxcpp commented 3 years ago

0.5 will introduce table.chain that can be used to combine multiple table modules.

What you want would be possible by pulling together table.regexp and table.sql_query/sql_table.

For example, this "table" will define all possible addresses:

table.chain possible_addrs {
  step regexp ".+@(.+)" "$1"
  step sql_table {
    driver sqlite3
    dsn credentials.db
    table_name domains
  }
}

(Basically, first step extracts domain from the address and second looks that domain up in a DB table)

Then relevant destination directives could be replaced with destination_in:

E.g.

destination_in &possible_addrs {
  deliver_to &local_routing
}
fgma commented 3 years ago

Would it also be possible to have a generic configuration for a catch-all which fetches an optional catch-all target address for addresses that don't exist from a table?

foxcpp commented 3 years ago

Rewritting all addresses to an internal address like catchall@maddy.invalid and then looking it up in the table should be the way to go:

table.chain catch_all {
  step regexp ".*" "catchall@maddy.invalid"
  step sql_table {
    driver sqlite3
    dsn catchalldb
    table_name catchall
  }
}