email-dns-tools/assets/scripts/records/DmarcRecord.js

106 lines
3.0 KiB
JavaScript

import { ConstantTag } from "../tags/ConstantTag.js";
import { EnumTag } from "../tags/EnumTag.js";
import { IntTag } from "../tags/IntTag.js";
import { Tag } from "../tags/Tag.js";
import { DmarcUriListTag } from "../tags/DmarcUriListTag.js";
import { TagListRecord } from "./TagListRecord.js";
export class DmarcRecord extends TagListRecord {
static fields = [
new ConstantTag("v", "DMARC1")
.required()
.pos(0),
new EnumTag("p", ["none", "quarantine", "reject"])
.label("Mail Receiver policy")
.desc("How to handle failed validations. The email may be quarantined (usually means sent to spam) or rejected")
.options(["None", "Quarantine", "Reject"])
.required()
.pos(1),
new EnumTag("adkim", ["r", "s"])
.label("DKIM")
.desc("How strictly to handle DKIM validation")
.options(["Relaxed", "Strict"])
.default("r")
.pos(2),
new EnumTag("aspf", ["r", "s"])
.label("SPF")
.desc("How strictly to handle SPF validation")
.options(["Relaxed", "Strict"])
.default("r")
.pos(2),
new EnumTag("sp", ["none", "quarantine", "reject"])
.label("Mail Receiver policy (for subdomains)")
.desc("Same as Mail Receiver policy, but applies only to subdomains. If not set, Mail Receiver policy applies to both top-level domain and subdomains")
.category("advanced")
.options(["None", "Quarantine", "Reject"])
.pos(2),
new IntTag("pct", 0, 100)
.label("Percentage")
.desc("Percentage of emails to apply DMARC validation on. Useful for split-testing and continuous rollout")
.category("advanced")
.default(100)
.pos(2),
new DmarcUriListTag("ruf")
.label("Send failure reports to")
.desc("When DMARC validation fails, reports are sent to this email")
.category("failure-reporting")
.pos(2),
new EnumTag("fo", ["0", "1", "d", "s"])
.label("Failure reporting options")
.desc("Define how reports will be generated")
.category("failure-reporting")
.options([
"Generate DMARC failure report if any fail",
"Generate DMARC failure report if all fail",
"Generate DKIM failure report",
"Generate SPF failure report",
])
.default("0")
.pos(2),
new DmarcUriListTag("rua")
.label("Send aggregate feedback to")
.desc("Aggregate reports will be sent to this email, if defined")
.category("failure-reporting"),
new IntTag("ri", 0, 2 ** 32)
.label("Aggregate report interval")
.desc("Interval (in seconds) between aggregate reports")
.category("failure-reporting")
.default(86400)
.pos(2),
new Tag("rf").default("afrf"), // Other values not supported
];
static categories = {
"advanced": "Advanced",
"failure-reporting": "Failure reporting",
};
constructor(text) {
super(text);
}
tokenize() {
return this.text
.replace(/;\s*$/, "")
.split(/;\s*/);
}
fieldsToString() {
let tokens = this.constructor.fields
.filter(field => !field.defaultValue || field.getInputValue() !== field.defaultValue)
.filter(field => field.getInputValue())
.map(field => field.key + "=" + field.getInputValue());
return tokens.join("; ");
}
}