View on GitHub

zbateson/mail-mime-parser

A PHP email parser

Home - API Documentation - Upgrading to 4.0

Upgrading to 4.0

Changes in 4.0 focus on API cleanup, stricter typing, and improved configurability. The minimum PHP version is now 8.1. Basic usage of parsing messages and reading content remains unchanged, but several interface signatures have been updated for consistency and correctness.

PHP 8.1 Requirement

The minimum required PHP version has been bumped from 8.0 to 8.1.

Breaking Changes

Method return type changes

Interface changes

Class changes

Parameter renames

Stream layer

New Features

Configurable fallback charset

Text parts without a declared charset default to ISO-8859-1 per RFC 2045. Many modern messages omit the charset and are actually UTF-8. You can now configure the fallback globally:

MailMimeParser::setFallbackCharset('UTF-8');

Or via the DI configuration by overriding the 'defaultFallbackCharset' entry. The fallback charset is injected through proper dependency injection into MimePart, NonMimePart, and their factories.

IHeader::getDecodedValue()

A new method on all header objects that returns the full decoded value reconstructed from parsed parts (excluding comments). See the interface changes section above for details.

PHPDoc return type hints on getHeader()

IMimePart::getHeader() now includes PHPDoc documentation listing the concrete header types that may be returned (AddressHeader, DateHeader, GenericHeader, IdHeader, ParameterHeader, ReceivedHeader, SubjectHeader). This improves IDE autocompletion and static analysis support.

Bug Fixes