llibspf
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

SPF Validator Library

Reference: RFC 7208

Extra Features

These features are (normally) not supported by existing, crappy, implementations.

  1. MACROS

Supported Directives

  1. MX
  2. A
  3. PTR
  4. IP4
  5. IP6
  6. EXISTS
  7. INCLUDE
  8. ALL

Supported Modifiers

  1. EXP
  2. REDIRECT

Example

import { IPv4Address } from "llibipaddress";
import { SPFValidator } from "llibspf";
import { MimeHeaders } from "llibmime";
import winston from "winston";

// Creates the example logger.
const logger = winston.createLogger({
  transports: [
    new winston.transports.Console({
      level: "debug",
      format: winston.format.combine(
        winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss.SSS" }),
        winston.format.colorize(),
        winston.format.printf(
          ({ level, message, label, timestamp }) =>
            `${timestamp} ${label || "-"} ${level}: ${message}`
        )
      ),
    }),
  ],
});

// Runs the next code using async.
(async () => {
  try {
    // Creates the context, this will be used during the validation and macro processing.
    const context: ISPFContext = {
      message: {
        emailDomain: "rijksoverheid.nl",
        emailUsername: "test123",
      },
      client: {
        greetHostname: "test123",
        ipAddress: IPv4Address.decode("29.85.216.54"),
      },
      server: {
        hostname: "example.com",
      },
    };

    // Constructs the spf validator, and validates.
    const result: SPFResult = await new SPFValidator(
      context,
      logger
    ).validate();

    // Constructs new MimeHeaders class, and puts the result inside it.
    const headers = new MimeHeaders();
    headers.set(...result.asHeader());
    console.log(headers.encode());
  } catch (e) {
    console.log(e);
  }
})();

Readme

Keywords

none

Package Sidebar

Install

npm i llibspf

Weekly Downloads

2

Version

1.0.4

License

ISC

Unpacked Size

83 kB

Total Files

26

Last publish

Collaborators

  • skywa04885