承接 hfig/mapi 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hfig/mapi

Composer 安装命令:

composer require hfig/mapi

包简介

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

README 文档

README

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 library.

The library is ostensibly a port of the 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

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

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 <john.smith@example.com>
    echo sprintf('%s: %s', $recipient->getType(), (string)$recipient), "\n";
}

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

MAPI property names are documented by Microsoft in an inscrutible manner at https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2007/cc815517(v%3doffice.12).

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 => display_name
  • PR_ATTACH_FILENAME => attach_filename
  • etc

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.

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

For PHP, installing the 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:

hfig/mapi 适用场景与选型建议

hfig/mapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 481.84k 次下载、GitHub Stars 达 41, 最近一次更新时间为 2018 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 hfig/mapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hfig/mapi 我们能提供哪些服务?
定制开发 / 二次开发

基于 hfig/mapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 481.84k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 41
  • 点击次数: 22
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 41
  • Watchers: 1
  • Forks: 42
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-27