npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bernierllc/validators-mime-structure

v1.2.0

Published

Primitive validator for MIME type structure validation - MIME parts, content-type correctness

Readme

@bernierllc/validators-mime-structure

Primitive validator for MIME message structure validation - multipart boundaries, content-type correctness, transfer encoding, and MIME part structure.

Installation

npm install @bernierllc/validators-mime-structure

Usage

Basic Validation

import { validateMimeStructure, isValidMimeStructure } from '@bernierllc/validators-mime-structure';

const mimeMessage = `Content-Type: multipart/mixed; boundary="boundary123"

--boundary123
Content-Type: text/plain

Hello World
--boundary123--`;

// Get detailed validation problems
const problems = await validateMimeStructure(mimeMessage);

if (problems.length === 0) {
  console.log('Valid MIME structure');
} else {
  problems.forEach(problem => {
    console.log(`${problem.severity}: ${problem.message}`);
  });
}

// Quick validation check
const isValid = await isValidMimeStructure(mimeMessage);
console.log(isValid ? 'Valid' : 'Invalid');

Configuration Options

import { validateMimeStructure } from '@bernierllc/validators-mime-structure';

const problems = await validateMimeStructure(content, {
  // Enable/disable specific checks
  checkBoundaries: true,            // Validate multipart boundaries
  checkContentType: true,           // Validate Content-Type headers
  checkTransferEncoding: true,      // Validate Content-Transfer-Encoding
  checkPartStructure: true,         // Validate MIME part structure
  checkBoundaryMismatch: true,      // Detect boundary mismatches

  // Configuration
  maxNestingDepth: 10              // Maximum multipart nesting depth
});

Helper Functions

import {
  extractBoundary,
  isMultipart,
  parseMimeParts
} from '@bernierllc/validators-mime-structure';

// Extract boundary from Content-Type header
const boundary = extractBoundary('multipart/mixed; boundary="test"');
console.log(boundary); // "test"

// Check if message is multipart
const isMultipartMsg = isMultipart(mimeMessage);
console.log(isMultipartMsg); // true

// Parse MIME message into parts
const parts = parseMimeParts(mimeMessage);
parts.forEach(part => {
  console.log('Headers:', part.headers);
  console.log('Body:', part.body);
});

API Reference

validateMimeStructure(content, options?, utils?)

Validates MIME message structure and returns an array of validation problems.

Parameters:

  • content: string - MIME message content to validate
  • options?: Partial<MimeStructureOptions> - Validation options
  • utils?: SharedUtils - Shared utilities from validators-core

Returns: Promise<Problem[]>

Example:

const problems = await validateMimeStructure(mimeMessage, {
  checkBoundaries: true,
  maxNestingDepth: 5
});

isValidMimeStructure(content, options?)

Checks if MIME message structure is valid (no errors).

Parameters:

  • content: string - MIME message content to validate
  • options?: Partial<MimeStructureOptions> - Validation options

Returns: Promise<boolean>

Example:

if (await isValidMimeStructure(mimeMessage)) {
  console.log('Valid MIME structure');
}

extractBoundary(contentType)

Extracts boundary string from Content-Type header value.

Parameters:

  • contentType: string - Content-Type header value

Returns: string | null

Example:

const boundary = extractBoundary('multipart/mixed; boundary="abc123"');
// Returns: "abc123"

isMultipart(content)

Checks if content is a multipart MIME message.

Parameters:

  • content: string - Content to check

Returns: boolean

Example:

if (isMultipart(content)) {
  console.log('This is a multipart message');
}

parseMimeParts(content)

Parses MIME message into individual parts with headers and body.

Parameters:

  • content: string - MIME message content

Returns: Array<{ headers: string; body: string }>

Example:

const parts = parseMimeParts(mimeMessage);
console.log(`Found ${parts.length} parts`);

Validation Rules

Boundary Validation (boundary-validator)

Validates multipart boundaries according to RFC 2046:

  • Boundary parameter presence in Content-Type
  • Boundary format and characters
  • Boundary length (max 70 characters)
  • Boundary markers in message body
  • Closing boundary marker presence

Content-Type Validation (content-type-validator)

Validates Content-Type headers according to RFC 2045:

  • MIME type format (type/subtype)
  • Token validity for type and subtype
  • Parameter format and syntax
  • Required boundary for multipart types
  • Recommended charset for text types

Transfer Encoding Validation (transfer-encoding-validator)

Validates Content-Transfer-Encoding according to RFC 2045:

  • Valid encoding values (7bit, 8bit, binary, quoted-printable, base64)
  • Base64 format and padding
  • Quoted-printable escape sequences
  • Line length requirements
  • Character restrictions for 7bit encoding

Part Structure Validation (part-structure-validator)

Validates MIME message part structure:

  • Header-body separation (blank line)
  • Header format and continuation
  • Nested multipart messages
  • Maximum nesting depth
  • Empty body warnings

Boundary Mismatch Detection (boundary-mismatch-validator)

Detects boundary mismatches and inconsistencies:

  • Declared boundaries used in body
  • Undeclared boundary markers
  • Multiple closing markers
  • Incorrect boundary marker format
  • Duplicate boundary declarations

Examples

Validating Email with Attachments

const email = `Content-Type: multipart/mixed; boundary="outer"

--outer
Content-Type: multipart/alternative; boundary="inner"

--inner
Content-Type: text/plain; charset=utf-8

Plain text version
--inner
Content-Type: text/html; charset=utf-8

<html><body>HTML version</body></html>
--inner--
--outer
Content-Type: application/pdf; name="document.pdf"
Content-Transfer-Encoding: base64

JVBERi0xLjQK
--outer--`;

const problems = await validateMimeStructure(email);
console.log(`Found ${problems.length} validation issues`);

Selective Validation

// Only validate boundaries and content-type
const problems = await validateMimeStructure(content, {
  checkBoundaries: true,
  checkContentType: true,
  checkTransferEncoding: false,
  checkPartStructure: false,
  checkBoundaryMismatch: false
});

Custom Nesting Depth

// Allow deeper nesting for complex email structures
const problems = await validateMimeStructure(content, {
  maxNestingDepth: 15
});

Integration Status

  • Logger: not-applicable - Primitive validator with no internal logging
  • Docs-Suite: ready - Complete API documentation and examples
  • NeverHub: not-applicable - Stateless validation utility

See Also

License

Copyright (c) 2025 Bernier LLC. All rights reserved.