7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Outlook のメールデータ:インポート・エクスポート

Last updated at Posted at 2019-07-05

御託

インターネット黎明期 (1995 年ぐらい?) から生き残っている Microsoft 製のメーラーの中で、異彩を放っているのが Outlook です。

メールデータの保管方法という観点からみると:

Outlook Express

  • Outlook Express は dbx という独自データベースを採用。
  • dbx は 2GB を超えると壊れてメールデータが無くなるという重大な不具合があり、騒ぎになりました。
  • dbx は解析が成功しているようで DbxRescue という有名なツールがあります。

Windows Live メール

  • Windows Live メールではデータベースに ESE を採用しています。ESE は ISAM エンジンの一種であり、OS のコンポーネントでもあるから信頼性が高いです。
  • データベースとは別に .eml ファイルを保存しています。
  • 実際のフォルダー階層にそって保存していることから、メーラーの移行は簡単にできます。 メーラーから見えるフォルダ階層と、ファイルシステムのフォルダ階層は異なることがあります。フォルダ作成後の「フォルダ名の変更」「フォルダの移動」操作は、データベース内の情報が書き変わるのみで、ファイルシステムのフォルダ階層には反映されませんでした。 .eml ファイルのみを用いてメーラーを移行する際には注意が必要です。

Outlook

Outlook からエクスポート

そういう訳で Outlook からの脱出にあたって、役立つと思われるツールを紹介いたします:

Outlook Export Tool

Outlook Export Tool

Thunderbird

Thunderbird 58 以上で ツール設定とデータのインポートメールボックスOutlook

2021-12-14_21h09_21.png

2021-12-14_21h09_24.png

次へ をクリックすると、作業完了まで UI がフリーズします。気長に待ってください。

2021-12-14_21h09_58.png

ローカルフォルダーOutlook インポート にあります。

2021-12-14_21h11_20.png

こちらは、真偽不明の情報です。

Thunderbird のインポート手順を用いるには、Thunderbird バージョン 38 およびそれ以降のバージョンでは Outlook と Eudora 向けのインポートウィザードが無効化されているため、古いバージョンの Thunderbird を使用する必要があります。

Thunderbird への移行 | Thunderbird ヘルプ

技術的な側面

ソースコードの MapiApi.cpp をサラッと読みました。
MAPILogonEx からの IMAPISessionで、ガチの MAPI を叩いています。

readpst

(2025-08-20 追記) ChatGPT か何かに尋ねたところ、 libpst の readpst でエクスポートする方法が紹介されました。

readpst は Cygwin などで入手できます。

Thunderbird 向け

PST ファイルは、メール、連絡先、スケジュールなど、複数種類のオブジェクトをストアします。

readpst では、オプション指定により出力対象を選択できます。

$ readpst -h
ReadPST / LibPST v0.6.71
Little Endian implementation being used.
Usage: readpst [OPTIONS] {PST FILENAME}
OPTIONS:
        -V      - Version. Display program version
        -C charset      - character set for items with an unspecified character set
        -D      - Include deleted items in output
        -L <level>      - Set debug level; 1=debug,2=info,3=warn.
        -M      - Write emails in the MH (rfc822) format
        -S      - Separate. Write emails in the separate format
        -a <attachment-extension-list>  - Discard any attachment without an extension on the list
        -b      - Dont save RTF-Body attachments
        -c[v|l] - Set the Contact output mode. -cv = VCard, -cl = EMail list
        -d <filename>   - Debug to file.
        -e      - As with -M, but include extensions on output files
        -h      - Help. This screen
        -j <integer>    - Number of parallel jobs to run
        -k      - KMail. Output in kmail format
        -m      - As with -e, but write .msg files also
        -o <dirname>    - Output directory to write files to. CWD is changed *after* opening pst file
        -q      - Quiet. Only print error messages
        -r      - Recursive. Output in a recursive format
        -t[eajc]        - Set the output type list. e = email, a = attachment, j = journal, c = contact
        -u      - Thunderbird mode. Write two extra .size and .type files
        -w      - Overwrite any output mbox files
        -8      - Output bodies in UTF-8, rather than original encoding, if UTF-8 version is available

Only one of -M -S -e -k -m -r should be specified

ここではメールのみを対象としたエクスポートを試します。

$ readpst -C CP932 -M -o export -u Outlook2003.pst
Opening PST file and indexes...
Processing Folder "削除済みアイテム"
Processing Folder "サンプル"
        "サンプル" - 16 items done, 0 items skipped.
        "Outlook2003" - 2 items done, 0 items skipped.

Thunderbird のメッセージストアの中へ直接コピーする形でインポートできるように便宜を図っているのかもしれませんが、
今の Thunderbird 142 とは互換性がありません。
リネームしたり移動したりが必要になります。

変更前:

$ tree export -ah
export
└── [   0]  Outlook2003
    ├── [   4]  .size
    ├── [   2]  .type
    └── [   0]  サンプル
        ├── [   6]  .size
        ├── [   2]  .type
        └── [6.9M]  mbox

2 directories, 5 files

変更後:

$ tree export -ah
export
├── [   0]  Outlook2003
└── [   0]  Outlook2003.sbd
    ├── [6.9M]  サンプル
    └── [   0]  サンプル.sbd

2 directories, 2 files

Note: Outlook2003 (*.) が mbox ファイル、 Outlook2003.sbd (*.sbd) はフォルダーです。

pst_to_eml

Thunderbird 向け

Thunderbird 向けに PST ファイル内のメールを一括エクスポートしたいが readpst の実行結果に多少不便があると感じたので、代替手段を開発しました。 pst_to_eml を改修して Thunderbird 向けの mbox を出力できるようにしました。

npx (Node package executor) で使用可能です。

C:\Users\KU>npx @hiraokahypertools/pst_to_eml export-mbox -h
Usage: pst_to_eml export-mbox [options] <pstFilePath> <saveToDir>

export items inside pst file to Thunderbird mbox format

Options:
  --ansi-encoding <encoding>  Set ANSI encoding (used by iconv-lite) for non Unicode text in msg file
  -h, --help                  display help for command

こちらの pst_to_eml は、 readpst のベースである libpst とは異なる技術を使用しています。
epfromer/pst-extractor: Extract objects from MS Outlook/Exchange PST filesfork を使用して開発しています。
そのため変換結果に不具合があったり、想定しないものが出力されたりする可能性があります。ご注意ください。

変換します:

C:\Users\KU>npx @hiraokahypertools/pst_to_eml export-mbox Outlook2003.pst export
convert export\Outlook2003
convert export\Outlook2003.sbd\削除済みアイテム
convert export\Outlook2003.sbd\サンプル

エクスポート結果です:

$ tree export -ah
export
├── [   0]  Outlook2003
└── [   0]  Outlook2003.sbd
    ├── [7.0M]  サンプル
    ├── [   0]  サンプル.sbd
    ├── [   0]  削除済みアイテム
    └── [   0]  削除済みアイテム.sbd

3 directories, 3 files

Outlook へインポート

逆に「これから Outlook を使いたいので、他のメーラーからデータを引っ越しする」ことを想定して、ツールを探してみました。

Windows Live Mail

エクスポート機能で、Outlook にメールをエクスポートする機能があります。

ファイル電子メールのエクスポート電子メール メッセージ を選択します。

2021-12-14_21h31_45.png

Microsoft Exchange を選択します。

2021-12-14_21h31_52.png

2021-12-14_21h31_57.png

プロファイルを選択するようになっている場合は尋ねられます。

2021-12-14_21h32_04.png

2021-12-14_21h32_07.png

複数のフォルダーを選択する場合は、Ctrl 押下のマウス左クリックで On/Off 切り替えです。

2021-12-14_21h40_29.png

2021-12-14_21h32_11.png

Outlook の Outlook データ ファイル にできるようです。

2021-12-14_21h32_59.png

IMAP4 server 経由

mozillaZine の Import .pst files より。
IMAP4 サーバー (例えば hMailServer) を経由して、メールデータを移行する方法があります。

失敗例: 受信トレイへドロップする

方法:

  • .eml ファイルを 受信トレイ へドロップする。

結果:

  • 新規メールの作成画面が表示されて、.eml ファイルが添付されました。

2021-12-14_12h33_36.png

失敗例: フォルダーへドロップする

方法:

  • .eml ファイルを 受信トレイ 以外のフォルダーへドロップする。

結果:

  • フォルダーにメールは追加されました。
  • しかしプレビューには適さないようです。
    • プレビュー画面での表示: このファイルのプレビューを表示できません。このファイル形式のプレビューアーがインストールされていません。
    • ダブルクリックした際のプロンプト表示: ファイルを開く前に、ファイルが信頼できる所からのものであることを確認してください。

2021-12-14_12h35_41.png

2021-12-14_12h37_20.png

msg → eml ファイル

msg (Outlook が主に扱う) ファイルから eml (一般的なメーラーで扱う RFC822 形式) に変換する方法について検討します。

msg ファイルは 1 通のメッセージです。 形式は様々あり、メール・連絡先・スケジュールあるいはその他の形式である可能性があります。 Outlook で開いてみるまでは、通常わかりません。

7-Zip を使用すると中身を確認できます:

7z-msg.png

__substg1.0_001A001F (Unicode msg の場合) あるいは __substg1.0_001A001E (ANSI msg の場合) ファイルを開くと (F3 キー押下)

msg-1a-notepad.png

IPM.Note などのテキストが露出します。これがメッセージの形式を示します。

参考: アイテムの種類とメッセージ クラス | Microsoft Learn

ruby-msg

Google Code Archive - Long-term storage for Google Code Project Hosting.

紹介サイト

mfcmapi

Releases · stephenegriffin/mfcmapi

紹介サイト

libpst

libpst Utilities - Version 0.6.76

紹介サイト

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?