PHPackages                             hfig/mapi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hfig/mapi

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hfig/mapi
=========

Pure PHP library for reading and manipulating Microsoft Outlook .msg messages (MAPI documents)

v1.4.2(12mo ago)42468.0k↓41.1%42[9 issues](https://github.com/hfig/MAPI/issues)[2 PRs](https://github.com/hfig/MAPI/pulls)2MITPHPPHP ^7.1||^8.0CI failing

Since Jul 27Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/hfig/MAPI)[ Packagist](https://packagist.org/packages/hfig/mapi)[ RSS](/packages/hfig-mapi/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (7)Versions (14)Used By (2)

Hfig/MAPI
=========

[](#hfigmapi)

Introduction
------------

[](#introduction)

`Hfig/MAPI` is a PHP library for reading and working with Microsoft Outlook/Exchange format email messages (`.msg` files, aka MAPI documents).

The library can parse MAPI documents, and programatically extract the properties and streams of the document.

It can be used to convert messages to `RFC822` (MIME) format by utilising the [`Swiftmailer/Switfmailer`](https://github.com/swiftmailer/swiftmailer) library.

The library is ostensibly a port of the [`aquasync/ruby-msg`](https://github.com/aquasync/ruby-msg) library from the Ruby language. Some questionable PHP architectural decisions come from migrating Ruby constructs. Some awful, but functional, code comes from a direct migration of the Ruby library.

Compared to `ruby-msg`, this library:

- Does not implement a command line entry point for message conversion
- Only handles MAPI documents in `.msg` files (or a PHP stream of `.msg` file data)
- Does not implement the conversion of RTF-format message bodies to plain text or HTML
- Has better support for decoding MAPI document properties
- Produces a more faithful MIME conversion of the MAPI document

Installation
------------

[](#installation)

Install using composer

```
composer require hfig/mapi

# our dependency pear/ole has an unresolved dependency currently
# therefore you need to install one of these explicitly:
composer require pear/pear-core-minimal
# or
composer require pear/pear-core

# needed if you want to convert to MIME format
composer require swiftmailer/swiftmailer
```

Usage
-----

[](#usage)

### Accessing document properties

[](#accessing-document-properties)

```
require 'vendor/autoload.php';

use Hfig\MAPI;
use Hfig\MAPI\OLE\Pear;

// message parsing and file IO are kept separate
$messageFactory = new MAPI\MapiMessageFactory();
$documentFactory = new Pear\DocumentFactory();

$ole = $documentFactory->createFromFile('source-file.msg');
$message = $messageFactory->parseMessage($ole);

// raw properties are available from the "properties" member
echo $message->properties['subject'], "\n";

// some properties have helper methods
echo $message->getSender(), "\n";
echo $message->getBody(), "\n";

// recipients and attachments are composed objects
foreach ($message->getRecipients() as $recipient) {
    // eg "To: John Smith
    echo sprintf('%s: %s', $recipient->getType(), (string)$recipient), "\n";
}
```

### Conversion to MIME

[](#conversion-to-mime)

```
require 'vendor/autoload.php';

use Hfig\MAPI;
use Hfig\MAPI\OLE\Pear;
use Hfig\MAPI\Mime\Swiftmailer;

$messageFactory = new MAPI\MapiMessageFactory(new Swiftmailer\Factory());
$documentFactory = new Pear\DocumentFactory();

$ole = $documentFactory->createFromFile('source-file.msg');
$message = $messageFactory->parseMessage($ole);

// returns a \Swift_Message object representaiton of the email
$mime = $message->toMime();

// or write it to file
$fd = fopen('dest-file.eml', 'w');
$message->copyMimeToStream($fd);
```

Property Names
--------------

[](#property-names)

MAPI property names are documented by Microsoft in an inscrutible manner at .

A list of property names available for use in this library is included in the `MAPI/Schema/MapiFieldsMessage.yaml` file.

Keeping with the convention of the `ruby-msg` library, message properties are converted to a *nice* name:

- `PR_DISPLAY_NAME` =&gt; `display_name`
- `PR_ATTACH_FILENAME` =&gt; `attach_filename`
- etc

About MAPI Documents
--------------------

[](#about-mapi-documents)

MAPI documents are Microsoft OLE Structured Storage databases, much like old `.doc`, `.xls` and `.ppt` files. They consist of an internal directory structure of streams of 4K blocks that resemble a virtual FAT filesystem. For economy reasons, every structured storage database contains a root stream which contains 64-byte blocks which in turn stores small pieces of data. For further information see [Microsoft's documentation](https://docs.microsoft.com/en-us/windows/desktop/Stg/structured-storage-start-page).

The PEAR library `OLE` can read these database files. However this PEAR library is ancient and does not meet any modern coding standards, hence it's kept entirely decoupled from the message parsing code of this library. Hopefully it can be replaced one day.

Alternatives
------------

[](#alternatives)

For PHP, installing the [Kopano Core](https://github.com/Kopano-dev/kopano-core) project on your server will make available `ext-mapi`, a PHP extension which implements allows access to a port of the low-level MAPI Win32 API.

See also:

- [`Email::Outlook::Message`](https://github.com/mvz/email-outlook-message-perl) (Perl)
- [`aquasync/ruby-msg`](https://github.com/aquasync/ruby-msg) (Ruby)
- [`JTNEF`](https://www.freeutils.net/source/jtnef/) (Java)

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance45

Moderate activity, may be stable

Popularity51

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 59.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~209 days

Recently: every ~387 days

Total

13

Last Release

360d ago

PHP version history (3 changes)v1.0.0PHP ^7.0

v1.1PHP ^7.1

v1.2.0PHP ^7.1||^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/12edf306efa7b1056efcb2b88278bdb44d23f25f4906d25c9fa64c8abbda8b16?d=identicon)[hornetfig](/maintainers/hornetfig)

---

Top Contributors

[![hfig](https://avatars.githubusercontent.com/u/29371182?v=4)](https://github.com/hfig "hfig (29 commits)")[![Zombaya](https://avatars.githubusercontent.com/u/13340313?v=4)](https://github.com/Zombaya "Zombaya (6 commits)")[![khorsky](https://avatars.githubusercontent.com/u/160295?v=4)](https://github.com/khorsky "khorsky (3 commits)")[![sietzekeuning](https://avatars.githubusercontent.com/u/11088108?v=4)](https://github.com/sietzekeuning "sietzekeuning (2 commits)")[![Arzaroth](https://avatars.githubusercontent.com/u/5888705?v=4)](https://github.com/Arzaroth "Arzaroth (1 commits)")[![HoussemTN](https://avatars.githubusercontent.com/u/33376041?v=4)](https://github.com/HoussemTN "HoussemTN (1 commits)")[![adjenks](https://avatars.githubusercontent.com/u/10687569?v=4)](https://github.com/adjenks "adjenks (1 commits)")[![LukeUsher](https://avatars.githubusercontent.com/u/740003?v=4)](https://github.com/LukeUsher "LukeUsher (1 commits)")[![mathiasz76](https://avatars.githubusercontent.com/u/81567536?v=4)](https://github.com/mathiasz76 "mathiasz76 (1 commits)")[![matteocostantini](https://avatars.githubusercontent.com/u/5763421?v=4)](https://github.com/matteocostantini "matteocostantini (1 commits)")[![unstoppablecarl](https://avatars.githubusercontent.com/u/913047?v=4)](https://github.com/unstoppablecarl "unstoppablecarl (1 commits)")[![ChristianVermeulen](https://avatars.githubusercontent.com/u/1062751?v=4)](https://github.com/ChristianVermeulen "ChristianVermeulen (1 commits)")[![adrichel](https://avatars.githubusercontent.com/u/1708594?v=4)](https://github.com/adrichel "adrichel (1 commits)")

---

Tags

mapioutlookphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hfig-mapi/health.svg)

```
[![Health](https://phpackages.com/badges/hfig-mapi/health.svg)](https://phpackages.com/packages/hfig-mapi)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.8M710](/packages/sylius-sylius)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k11](/packages/tempest-framework)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M506](/packages/shopware-core)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

562565.8k41](/packages/ecotone-ecotone)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

317117.1k1](/packages/cognesy-instructor-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
