Download the PHP package melloww/laravel-mailfiles without Composer

On this page you can find all versions of the php package melloww/laravel-mailfiles. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-mailfiles

Laravel MailFiles — one API for .eml and .msg

Latest Version on Packagist Tests Total Downloads

Read RFC 822 .eml files and Outlook .msg (MAPI) files through a single, consistent, read-only API. Subject, sender, recipients, dates, text/HTML bodies and attachments all come back the same way no matter which format you started with.

Why this package

To handle support for both the .eml and .msg format, I often found myself duck taping together several parsers for either format to read the email properly depending on whether it was a .eml from a Mac client or a .msg from an Outlook inbox on Windows. To streamline this process, this package can hopefully fill that need for others as well.

Installation

The service provider and MailFiles facade are auto-discovered. Optionally publish the config file:

Requires PHP 8.2+ and the mbstring extension (iconv is used as a fallback for exotic charsets when present).

Reading a message

Format detection is based on file content (the OLE2 signature), not the extension, so a mislabelled file still reads correctly.

The unified API

Every accessor below works identically for .eml and .msg.

Envelope

Method Returns Notes
format() MailFormat enum MailFormat::Eml or MailFormat::Msg
subject() ?string RFC 2047 encoded-words decoded to UTF-8
from() ?Address the author of the message
sender() ?Address the actual submitter; falls back to from()
to() list<Address>
cc() list<Address>
bcc() list<Address>
replyTo() list<Address>
recipients() list<Address> To + Cc + Bcc combined
date() ?DateTimeImmutable when the message was sent
messageId() ?string without the surrounding < >

Metadata

Beyond the envelope, richer metadata is first-class (and works for .msg too — MAPI priority/sensitivity/threading properties are surfaced through the same API):

Bodies

Method Returns Notes
textBody() ?string the text/plain part, UTF-8
htmlBody() ?string the text/html part, UTF-8
body() ?string text body, or the HTML stripped to text
markdown() ?string the HTML body converted to Markdown (or the text body)
cleanHtml() ?string HTML with scripts/styles/tags removed
bodyAs(BodyFormat $f) ?string the body as Html, Text or Markdown
rtfBody() ?string the decompressed RTF body (.msg only)
hasTextBody() / hasHtmlBody() / hasRtfBody() bool

For Outlook .msg files that carry only a compressed-RTF body, the reader decompresses it (MS-OXRTFCP) and, when the RTF encapsulates HTML, de-encapsulates that HTML into htmlBody(); otherwise it falls back to text. rtfBody() always exposes the raw decompressed RTF.

The HTML→Markdown conversion is built in (no dependency); it uses the bundled dom extension when available and degrades to plain text otherwise.

Attachments

Method Returns Notes
attachments() list<Attachment> genuine attachments only (no inline images)
inlineAttachments() list<Attachment> embedded body images (logos, icons, pixels)
allAttachments() list<Attachment> everything
hasAttachments() bool true only when there are genuine attachments
inlineAttachmentByContentId($cid) ?Attachment resolve a cid: reference

contentType() returns the type exactly as the message declared it (fast, and null when omitted). mimeType() falls back to detecting the type from the payload's magic bytes (via ext-fileinfo) — never from the file-name extension, which is attacker-controlled and can lie. Use mimeType() when you need a dependable type; note it resolves the content to sniff it.

Real attachments vs. inline/embedded images

A common headache with other libraries is that the four tiny social-media icons in a signature, an embedded logo or a tracking pixel all show up as "attachments", drowning out the one PDF the sender actually attached.

attachments() returns only the genuine ones. Each part is tagged with an AttachmentDisposition (Attachment or Inline), decided from what the message actually does rather than a single unreliable header:

  1. Is the part referenced by the body? If the HTML contains cid:<its-id> (or its Content-Location), it is body content → Inline. This is the decisive signal, and it catches the notorious case where Outlook marks a body-referenced image as Content-Disposition: attachment.
  2. Content-Disposition: inline, or the MAPI ATT_MHTML_REF / hidden flags for .msg → Inline.
  3. Sits in a multipart/related container as an image → Inline.
  4. Otherwise → a real Attachment (an unreferenced image with a stray Content-ID is still a file the sender attached).

Nested / embedded messages

When an attachment is itself an email — a .eml attached to a .eml, a .msg embedded in a .msg, or one format inside the other — it is parsed recursively into its own Email:

Recursion (and its depth limit) is configurable — see Nested message options. It is bounded by max_depth to stay safe against maliciously deep files.

Headers

For .msg files the headers bag is populated from the original transport headers (PR_TRANSPORT_MESSAGE_HEADERS) when present, and otherwise synthesised from the MAPI properties so Subject, From, To, Date and Message-ID are always there.

Address

Serialising

$email->toArray() returns a plain array of everything (minus attachment bytes), handy for logging, JSON responses or persisting metadata.

Email threads (forwards & replies)

When a message forwards or replies to earlier ones, the chain can be reconstructed — including the different contacts at each hop.

Thread helpers: current() (the message itself), original() (the oldest recovered message), hasHistory(), count(), isForwarded(), isReply().

How the chain is recovered, in order of reliability:

  1. Attached originals — a message forwarded as an attachment (message/rfc822 or an embedded .msg) is parsed structurally, so its contacts are exact (ThreadEntryType::Attached).
  2. Quoted "forwarded message" header blocks in the body — the From:/To:/ Cc:/Subject: lines are parsed, giving full per-item contacts (ThreadEntryType::Forwarded).
  3. Reply attribution lines ("On … wrote:") — yield the quoted author (ThreadEntryType::Reply).
  4. Forwarding headers — X-Original-Sender, Resent-From, X-MS-Exchange-Organization-OriginalSender, etc., as a fallback.

Body-based recovery (2 & 3) is heuristic: it reads text a human wrote, so it copes with quirks like non-breaking spaces, Outlook HTML-table layouts and ~15 languages of labels/verbs — but it cannot be perfect. Prefer forwarded-as-attachment when accuracy is critical. ThreadMessage::isReliable() tells you whether an entry came from a structural source (1) or a heuristic one.

Signed, encrypted & special parts

For signed messages the signed content is what you read through body() and attachments() — the detached signature part is not surfaced as an attachment.

Calendar invitations (text/calendar) are parsed into events:

Automated messages are flagged too:

Mailboxes and batch reading

Read a whole Unix mbox spool (streaming — one message in memory at a time):

Or every .eml/.msg in a directory (keyed by path):

Memory & performance

Scope & boundaries

In scope: reading .eml (RFC 822/MIME) and .msg (Outlook MAPI), mbox spools, and directories. Deliberately out of scope:

Laravel usage

Artisan command

A small reference command prints a parsed summary of any file:

EML drivers

.eml parsing has two interchangeable drivers, configured in config/mailfiles.php:

.msg files are always read by the bundled native MAPI reader.

Nested message options

Recursive extraction of messages-within-messages is on by default and tunable in config/mailfiles.php:

Outside Laravel, pass a ParseOptions to the reader:

How it works

Replacing php-mime-mail-parser + hfig/mapi

Previously Now
(new Parser)->setText($eml)->getSubject() MailFile::read($path)->subject()
$parser->getHeader('from') $email->from() / $email->header('from')
$parser->getTo() $email->to()
$parser->getMessageBody('text') $email->textBody()
$parser->getMessageBody('html') $email->htmlBody()
$parser->getAttachments() $email->attachments()
$messageFactory->parseMessage($doc)->getProperties()['subject'] $email->subject()
$msg->getAttachments()[0]->getContent() $email->attachments()[0]->content()

Testing

The test suite runs against real .eml and .msg fixtures in tests/Fixtures.

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-mailfiles with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-mbstring Version *
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0||^12.0||^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package melloww/laravel-mailfiles contains the following files

Loading the files please wait ...