EMLをMSGにC++で変換する方法
Aspose.Email FOSS for C++ supports bidirectional conversion between EML (RFC 5322 / MIME(MAPI)とMSG(Outlook MAPI)、使用する方法 mapi_message::load_from_eml() 輸入するA EMLファイル、その後 mapi_message::save() 書くのはMSG(逆に)と、 mapi_message::from_file() 追跡 → mapi_message::save_to_eml().
ステップ1 - プロジェクトの設定
git clone https://github.com/aspose-email-foss/Aspose.Email-FOSS-for-Cpp.gitadd_subdirectory(Aspose.Email-FOSS-for-Cpp)
target_link_libraries(your_target PRIVATE AsposeEmailFoss::AsposeEmailFoss)ステップ2 - EML を MSG (ファイルパス) に変換する
mapi_message::load_from_eml() EMLファイルをパルスし、その特性を明らかにする。 標準 mapi_message インターフェイス - Call save() 結果をMSGとして書く:
#include <filesystem>
#include <iostream>
#include "aspose/email/foss/msg/mapi_message.hpp"
int main()
{
const auto message = aspose::email::foss::msg::mapi_message::load_from_eml(
std::filesystem::path("message.eml"));
std::cout << "Subject: " << message.subject() << '\n';
std::cout << "From: " << message.sender_email_address() << '\n';
message.save(std::filesystem::path("converted.msg"));
std::cout << "Saved converted.msg\n";
}ステップ3 - EMLをMSG(ストリーム)に変換する
流れの過剰な使用を用いる。 load_from_eml() EMLデータがネットワークから来る場合 ソケット、メモリバッファー、またはその他の std::istream:
#include <fstream>
#include <filesystem>
#include "aspose/email/foss/msg/mapi_message.hpp"
int main()
{
std::ifstream eml_stream("message.eml", std::ios::binary);
const auto message = aspose::email::foss::msg::mapi_message::load_from_eml(eml_stream);
message.save(std::filesystem::path("converted.msg"));
}ステップ4 - MSG を EML に変換する
既存のMSGファイルをダウンロードする mapi_message::from_file(),次に、EMLでシリアル化する。 フォーマットと共に save_to_eml():
#include <filesystem>
#include <iostream>
#include "aspose/email/foss/msg/mapi_message.hpp"
int main()
{
const auto message = aspose::email::foss::msg::mapi_message::from_file(
std::filesystem::path("sample.msg"));
message.save_to_eml(std::filesystem::path("exported.eml"));
std::cout << "Saved exported.eml\n";
}ステップ5 - フルラウンドトリップ(EML → MSG → EML)
以下の例では、対象、体、送信者、受信者のすべてが完全な回転ツアーを通して保存されていることを示しています。:
#include <filesystem>
#include <iostream>
#include "aspose/email/foss/msg/mapi_message.hpp"
int main()
{
const auto msg_path = std::filesystem::path("roundtrip.msg");
const auto eml_out = std::filesystem::path("roundtrip.eml");
// EML → MSG
auto message = aspose::email::foss::msg::mapi_message::load_from_eml(
std::filesystem::path("original.eml"));
message.save(msg_path);
// MSG → EML
auto reloaded = aspose::email::foss::msg::mapi_message::from_file(msg_path);
reloaded.save_to_eml(eml_out);
std::cout << "Subject preserved: " << reloaded.subject() << '\n';
std::cout << "Attachments: " << reloaded.attachments().size() << '\n';
}ステップ6 - EML ビットをメモリに変換する
2位 両方 save() で、 save_to_eml() ゼロ論点の過剰負荷が戻ってくる std::vector<std::uint8_t>,ネットワーク接続にストリーミング結果を提供するために有用か、または ファイルシステムに触れずにデータベース:
#include <filesystem>
#include "aspose/email/foss/msg/mapi_message.hpp"
int main()
{
const auto message = aspose::email::foss::msg::mapi_message::load_from_eml(
std::filesystem::path("message.eml"));
// In-memory MSG bytes
const auto msg_bytes = message.save();
// In-memory EML bytes
const auto eml_bytes = message.save_to_eml();
}一般問題と修正
load_from_eml() 実現可能なEMLファイルに投げ込む。. ファイルを確認する RFC 5322 を使用します。 いくつかのツールによって輸出されるEMLファイルは、単純なLFを使用することができます。 標準に準拠するラインの終了を期待しています。.
EML から MSG に変換した後の欠けている付属性。. EML が標準を含むことを確認する MIME multipart/mixed あるいは multipart/related 関連画像:インラインイメージ参照 経由 cid: MSGに付属するものとして運ばれ、存在しなければならない。.
体はMSG→EMLの後に失われた。. HTML コンテンツは、ラウンドトリップを通して保存されます。 いつ message.html_body() 無駄だよ、ただし message.body() 人口に含まれているのは、 ソース MSG、EMLは単なるフラインテキスト部分を含む。.
save_to_eml() 流出は空っぽです。. オープン出力ストリーム std::ios::binary.テキストモードの流れは、Windows上のMIME構造を腐敗させます。.
対象は含む ?= コードアーティファクト. RFC 2047 コードワードの順序 図書館はそれらを保存します. RFC 2047 ライブラリでデコードする ユニコードのテーマが必要な場合。.
よくある質問
両方向に付属が保存されているか。?
EML → MSG と MSM → EMM 変換はすべての MIME 付属を送信します。 mapi_message 添付リスト. バイナリー添加物は、原料バイトとして表示されます。 mapi_attachment::data.
EML → MSG は HTML 体を保存しますか?
もし、EMLが含まれている場合、A text/html MIME 部分、MAPI HTML ボディに保存されています。 財産と返品 message.html_body() 充電後。.
EML ファイルのディレクトリをバッチ変換できますか?
ディレクトリをイタリアに std::filesystem::directory_iterator 呼びかけ mapi_message::load_from_eml() 各に .eml 道を歩き、その後救い。 save():
#include <filesystem>
#include "aspose/email/foss/msg/mapi_message.hpp"
int main()
{
for (const auto& entry : std::filesystem::directory_iterator("emails/"))
{
if (entry.path().extension() == ".eml")
{
auto msg = aspose::email::foss::msg::mapi_message::load_from_eml(entry.path());
auto out = entry.path();
out.replace_extension(".msg");
msg.save(out);
}
}
}EML ↔ MSG の変換時に何が保存されますか?
対象、平文体、HTML体の送信者名とメールアドレス、受信リストおよびすべてのMIME付属物。IMAP旗、基本輸送ヘッドルーを超えるルートヘッダー、TNEF暗号化されたデータは保存されません。.
は、 load_from_eml() セキュアな?
各呼びかけは、 load_from_eml() 独立を創造する。 mapi_message 例:あなた 複数の線から同時に呼び出すことができる限り、それぞれの線が独自のものを使用する。 メッセージオブジェクト.