EML을 MSG로 C++로 변환하는 방법

EML을 MSG로 C++로 변환하는 방법

Aspose.Email FOSS for C++ supports bidirectional conversion between EML (RFC 5322 / MIME 및 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.git
add_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 인터페이스 - 전화 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 비트로 변환

둘 다 save() 그리고 save_to_eml() 0 논쟁이 있는 이 반환을 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에 첨부된 것처럼 수행되며, 존재해야 합니다.

HTML 시체는 MSG → EML 후에 손실되었습니다. HTML 콘텐츠는 라운드 트리프를 통해 보존됩니다. 언제 message.html_body() 빈자리만 있는 경우, 만약 message.body() 인구가 있는 곳에서, 그곳에서 MSG 출처, EML은 단지 평면 텍스트 부분을 포함합니다.

save_to_eml() 스트림 출력은 텅 비어있다. 오픈 출력 스트림과 함께 std::ios::binary.텍스트 모드 스트림은 Windows에서 MIME 구조를 파괴합니다.

주제가 포함되어 있습니다. ?= 아티스트를 암호화하는 방법. RFC 2047 암호화된 단어 순서입니다. 원래 EML. 도서관은 RFC 2047 도서를 사용하여 그들을 보존합니다. 원하는 경우 유니코드 주제가 필요합니다.

자주 묻는 질문들

두 방향으로 첨부 파일이 보존되나요?

EML → MSG 및 MSM → EMM 변환은 모든 MIME 첨부 파일을 통과합니다. mapi_message 첨부 목록. 바이너리 삽입은 원료 바이트로 표시됩니다. mapi_attachment::data.

EML → MSG는 HTML 몸을 보존합니까?

예. EML이 포함되어 있는 경우에는 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 예를 들어, 당신은 각 열이 자신의 것을 사용하는 한 동시에 여러 줄에서 그것을 호출 할 수 있습니다. 메시지 객체.

또한 보기

 한국어