- SMTP-сервер переписан: разбор по строкам, AUTH PLAIN/LOGIN, нет открытого релея, MAIL FROM только свой после входа, 250 только после сохранения (иначе 451), лимит размера - отправка наружу: очередь outbound_queue (V2) с повторами ~22 ч и уведомлением о недоставке; Jakarta Mail, режимы off / mx / smarthost, байты письма не меняются (DKIM) - DKIM: подпись utils-mail-dkim, проверка Apache jDKIM; ключ PKCS#8, старый PKCS#1 читается - права: письма, папки, вложения — только владельцу (было: любой по номеру); имена вложений без ../ - секреты без значений по умолчанию (DB_PASSWORD, JWT_SECRET), регистрация закрыта, admin123 и /api/simulate/receive — только профиль dev - веб-клиент внутри jar (относительный /api), Dockerfile в 3 этапа, не root, health; docker-compose.jambotron.yml: секреты создаются при первом запуске, наружу только 8080 - gradle-wrapper.jar был в .gitignore — сборка не запускалась - тесты: 26 (SMTP реальным клиентом и сокетом, GreenMail, DKIM подпись+проверка, очередь) α Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.7 KiB
Java
52 lines
1.7 KiB
Java
package com.mailserver.config;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Locale;
|
|
import java.util.Set;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* Domains whose mailboxes live on this server ({@code mailserver.domains}), and the optional catch-all mailbox
|
|
* ({@code mailserver.catch-all}): when set, mail to ANY address is stored there and nothing is delivered outside —
|
|
* a mail trap for dev/staging.
|
|
*/
|
|
@Component
|
|
public class MailDomains {
|
|
|
|
private final Set<String> domains;
|
|
private final String catchAll;
|
|
|
|
public MailDomains(@Value("${mailserver.domains:localhost}") String domains,
|
|
@Value("${mailserver.catch-all:}") String catchAll) {
|
|
this.domains = Arrays.stream(domains.split(","))
|
|
.map(d -> d.trim().toLowerCase(Locale.ROOT))
|
|
.filter(d -> !d.isEmpty())
|
|
.collect(Collectors.toUnmodifiableSet());
|
|
this.catchAll = catchAll.trim().toLowerCase(Locale.ROOT);
|
|
if (this.domains.isEmpty()) {
|
|
throw new IllegalStateException("mailserver.domains is empty");
|
|
}
|
|
}
|
|
|
|
public boolean isLocal(String address) {
|
|
return domains.contains(domainOf(address));
|
|
}
|
|
|
|
/** Mailbox that receives everything, or null. */
|
|
public String catchAll() {
|
|
return catchAll.isEmpty() ? null : catchAll;
|
|
}
|
|
|
|
public Set<String> domains() {
|
|
return domains;
|
|
}
|
|
|
|
public static String domainOf(String address) {
|
|
int at = address == null ? -1 : address.lastIndexOf('@');
|
|
return at < 0 ? "" : address.substring(at + 1).toLowerCase(Locale.ROOT);
|
|
}
|
|
}
|