show multi-domain aliases everywhere

This commit is contained in:
Aine
2022-11-08 21:21:06 +02:00
parent 15d5afe90f
commit 9cfe0a6d4f
5 changed files with 35 additions and 14 deletions

View File

@@ -19,6 +19,7 @@ so you can use it to send emails from your apps and scripts as well.
- [x] Receive attachments
- [x] Catch-all mailbox
- [x] Map email threads to matrix threads
- [x] Multi-domain aliases
#### deep dive
@@ -45,15 +46,15 @@ env vars
* **POSTMOOGLE_HOMESERVER** - homeserver url, eg: `https://matrix.example.com`
* **POSTMOOGLE_LOGIN** - user login/localpart, eg: `moogle`
* **POSTMOOGLE_PASSWORD** - user password
* **POSTMOOGLE_DOMAINS** - space separated list of SMTP domains to listen for new emails. The first domain acts as actual domain, all other as aliases
* **POSTMOOGLE_DOMAINS** - space separated list of SMTP domains to listen for new emails. The first domain acts as the main (actual) domain, all other as aliases
<details>
<summary>other optional config parameters</summary>
* **POSTMOOGLE_PORT** - SMTP port to listen for new emails
* **POSTMOOGLE_TLS_PORT** - secure SMTP port to listen for new emails. Requires valid cert and key as well
* **POSTMOOGLE_TLS_CERT** - path to your SSL certificate (chain)
* **POSTMOOGLE_TLS_KEY** - path to your SSL certificate's private key
* **POSTMOOGLE_TLS_CERT** - path to the SSL certificate (chain) of your main domain
* **POSTMOOGLE_TLS_KEY** - path to the SSL certificate's private key of your main domain
* **POSTMOOGLE_TLS_REQUIRED** - require TLS connection, **even** on the non-TLS port (`POSTMOOGLE_PORT`). TLS connections are always required on the TLS port (`POSTMOOGLE_TLS_PORT`) regardless of this setting.
* **POSTMOOGLE_DATA_SECRET** - secure key (password) to encrypt account data, must be 16, 24, or 32 bytes long
* **POSTMOOGLE_NOENCRYPTION** - disable matrix encryption (libolm) support

View File

@@ -261,8 +261,8 @@ func (b *Bot) sendIntroduction(ctx context.Context, roomID id.RoomID) {
msg.WriteString(roomOptionMailbox)
msg.WriteString(" SOME_INBOX` command.\n")
msg.WriteString("You will then be able to send emails to `SOME_INBOX@")
msg.WriteString(b.domains[0])
msg.WriteString("You will then be able to send emails to ")
msg.WriteString(utils.EmailsList("SOME_INBOX", b.domains))
msg.WriteString("` and have them appear in this room.")
b.SendNotice(ctx, roomID, msg.String())
@@ -300,8 +300,9 @@ func (b *Bot) sendHelp(ctx context.Context) {
msg.WriteString("(currently `")
msg.WriteString(value)
if cmd.key == roomOptionMailbox {
msg.WriteString("@")
msg.WriteString(b.domains[0])
msg.WriteString(" (")
msg.WriteString(utils.EmailsList(value, b.domains))
msg.WriteString(")")
}
msg.WriteString("`)")
}

View File

@@ -53,9 +53,7 @@ func (b *Bot) sendMailboxes(ctx context.Context) {
for _, mailbox := range slice {
cfg := mailboxes[mailbox]
msg.WriteString("* `")
msg.WriteString(mailbox)
msg.WriteString("@")
msg.WriteString(b.domains[0])
msg.WriteString(utils.EmailsList(mailbox, b.domains))
msg.WriteString("` by ")
msg.WriteString(cfg.Owner())
msg.WriteString("\n")
@@ -160,7 +158,7 @@ func (b *Bot) runDKIM(ctx context.Context, commandSlice []string) {
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf(
"DKIM signature is: `%s`.\n"+
"You need to add it to your DNS records (if not already):\n"+
"You need to add it to DNS records of all domains added to postmoogle (if not already):\n"+
"Add new DNS record with type = `TXT`, key (subdomain/from): `postmoogle._domainkey` and value (to):\n ```\n%s\n```\n"+
"Without that record other email servers may reject your emails as spam, kupo.\n"+
"To reset the signature, send `%s dkim reset`",
@@ -175,6 +173,9 @@ func (b *Bot) runCatchAll(ctx context.Context, commandSlice []string) {
msg.WriteString("Currently: `")
if cfg.CatchAll() != "" {
msg.WriteString(cfg.CatchAll())
msg.WriteString(" (")
msg.WriteString(utils.EmailsList(cfg.CatchAll(), b.domains))
msg.WriteString(")")
} else {
msg.WriteString("not set")
}
@@ -202,5 +203,5 @@ func (b *Bot) runCatchAll(ctx context.Context, commandSlice []string) {
return
}
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf("Catch-all is set to: `%s@%s`.", mailbox, b.domains[0]))
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf("Catch-all is set to: `%s` (%s).", mailbox, utils.EmailsList(mailbox, b.domains)))
}

View File

@@ -5,6 +5,8 @@ import (
"fmt"
"github.com/raja/argon2pw"
"gitlab.com/etke.cc/postmoogle/utils"
)
func (b *Bot) runStop(ctx context.Context) {
@@ -58,7 +60,7 @@ func (b *Bot) getOption(ctx context.Context, name string) {
}
if name == roomOptionMailbox {
value = value + "@" + b.domains[0]
value = utils.EmailsList(value, b.domains)
}
msg := fmt.Sprintf("`%s` of this room is `%s`\n"+
@@ -85,7 +87,7 @@ func (b *Bot) setOption(ctx context.Context, name, value string) {
if name == roomOptionMailbox {
existingID, ok := b.getMapping(value)
if ok && existingID != "" && existingID != evt.RoomID {
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf("Mailbox `%s@%s` already taken, kupo", value, b.domains[0]))
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf("Mailbox `%s` (%s) already taken, kupo", value, utils.EmailsList(value, b.domains)))
return
}
}

View File

@@ -14,6 +14,22 @@ func Mailbox(email string) string {
return email[:index]
}
// EmailsList returns human-readable list of mailbox's emails for all available domains
func EmailsList(mailbox string, domains []string) string {
var msg strings.Builder
count := len(domains) - 1
for i, domain := range domains {
msg.WriteString(mailbox)
msg.WriteString("@")
msg.WriteString(domain)
if i < count {
msg.WriteString(", ")
}
}
return msg.String()
}
// Hostname returns hostname part from email address
func Hostname(email string) string {
return email[strings.LastIndex(email, "@")+1:]