Giriş

Aspose.Email FOSS for C++ yeni bir açık kaynak kütüphanesidir; Outlook MSG dosyalarını, RFC 5322 EML mesajlarını ve MSG formatının temelini oluşturan Compound File Binary (CFB) konteynerlerini okuma, oluşturma ve dönüştürme işlevi sağlar. C++17 ile yazılmıştır, harici çalışma zamanı bağımlılığı yoktur ve CMake aracılığıyla Linux, macOS ve Windows üzerinde derlenir — COM bağımlılığı ve platforma özgü kod yolu yoktur.

Outlook MSG dosyaları, kurumsal entegrasyon çalışmalarında — arşivleme hatları, taşıma araçları, uyumluluk ihracatları — sürekli olarak karşımıza çıkar — ancak Outlook olmadan bunları okumak genellikle Windows üzerinde COM otomasyonu veya ticari bir kütüphane gerektirir. Aspose.Email FOSS for C++ size taşınabilir bir alternatif sunar: günlük mesaj okuma ve oluşturma için yüksek seviyeli bir mapi_message sınıfı ve gerektiğinde temel konteyner formatına doğrudan erişim sağlayan düşük seviyeli msg_reader, msg_document ve cfb_reader sınıfları.

Kütüphane, MIT lisansı altında C++17 kaynak kodu olarak dağıtılır ve bir projeye CMake alt dizini olarak eklenir; AsposeEmailFoss hedefi ortaya çıkar — paket yöneticisi kaydı ve önceden derlenmiş ikili dosyalar gerektirmez.


Temel Özellikler

Outlook MSG Dosyalarını Okuma

.msg dosyasını msg_reader::from_file() veya msg_reader::from_stream() ile açın. Bir mesajın depolarına ve akışlarına doğrudan erişmek için okuyucuyu msg_document içinde msg_document::from_reader() ile sarmalayın.

#include "aspose/email/foss/msg/msg_reader.hpp"
#include "aspose/email/foss/msg/msg_document.hpp"
#include <filesystem>

namespace aef = aspose::email::foss;

auto reader = aef::msg::msg_reader::from_file(
    std::filesystem::path("message.msg"), /*strict=*/false);
auto document = aef::msg::msg_document::from_reader(reader);

Mesajları Programlı Olarak Oluşturun

mapi_message::create() bir konu ve gövde ile yeni bir bellek içi mesaj oluşturur. Göndereni ayarlayın, alıcıları ekleyin ve save() ile kaydetmeden önce ikili veya metin yüklerini ekleyin.

#include "aspose/email/foss/msg/mapi_message.hpp"
#include <filesystem>

namespace aef = aspose::email::foss;

auto message = aef::msg::mapi_message::create(
    "Quarterly status update", "Hello team,\n\nRollout summary attached.");
message.set_sender_name("Build Agent");
message.set_sender_email_address("build.agent@example.com");
message.add_recipient("alice@example.com", "Alice Example");
message.add_recipient("carol@example.com", "Carol Example",
    aef::msg::mapi_message::recipient_type_cc);
message.add_attachment("report.txt", std::vector<std::uint8_t>{'o', 'k'}, "text/plain");
message.save(std::filesystem::path("output.msg"));

MSG ve EML Arasında Dönüştürme

mapi_message::save_to_eml() geçerli mesajı bir RFC 5322 EML dosyası olarak yazar ve mapi_message::load_from_eml() bunu geri okur. Her iki yön de konuyu, göndereni, alıcıları ve ekleri korur, böylece bir mesaj Outlook olmadan MSG ve EML arasında taşınabilir.

auto message = aef::msg::mapi_message::from_file(
    std::filesystem::path("message.msg"), /*strict=*/false);
message.save_to_eml(std::filesystem::path("message.eml"));

auto restored = aef::msg::mapi_message::load_from_eml(std::filesystem::path("message.eml"));
restored.save(std::filesystem::path("restored.msg"));

Mesaj Özelliklerini ve Ekleri İnceleyin

Yüklenmiş bir mapi_message, standart başlık alanlarını doğrudan ortaya çıkar — subject(), sender_name(), sender_email_address(), message_class() ve internet_message_id() — ayrıca recipients() ve attachments() mapi_recipient ve mapi_attachment vektörleri olarak. Ayrı bir erişimciye sahip olmayan MAPI alanları için, get_property_value() herhangi bir özelliği common_message_property_id ve property_type_code ile okur.

#include "aspose/email/foss/msg/mapi_message.hpp"
#include "aspose/email/foss/msg/common_message_property_id.hpp"
#include "aspose/email/foss/msg/property_type_code.hpp"
#include <iostream>

namespace aef = aspose::email::foss;

template <typename E>
constexpr auto to_underlying(E value) noexcept {
    return static_cast<std::underlying_type_t<E>>(value);
}

auto message = aef::msg::mapi_message::from_file(
    std::filesystem::path("message.msg"), /*strict=*/false);

std::cout << "Subject: " << message.subject() << '\n';
std::cout << "From: " << message.sender_name()
           << " <" << message.sender_email_address() << ">\n";
std::cout << "Recipients: " << message.recipients().size() << '\n';

for (const auto& attachment : message.attachments()) {
    std::cout << "- " << attachment.filename
               << " (" << attachment.mime_type << ", "
               << attachment.data.size() << " bytes)\n";
}

const auto display_cc = message.get_property_value(
    to_underlying(aef::msg::common_message_property_id::display_cc),
    to_underlying(aef::msg::property_type_code::ptyp_string));

Düşük Seviyeli CFB Kapsayıcı Erişimi

MSG dosyaları, bir Compound File Binary (CFB) kapsayıcısının içinde depolanır — bu yapılandırılmış depolama formatı, eski Office ikili formatları tarafından da kullanılır. cfb_reader ham kapsayıcıyı açar ve dizin ağacını doğrudan ortaya çıkar: storage_ids() ve stream_ids() her girişi listeler, directory_entry_count() toplamı rapor eder ve header() kapsayıcının sektör düzenini döndürür. Bu, mapi_message API’nin ortaya çıkarmadığı MAPI verilerine ihtiyaç duyduğunuzda yararlıdır.

#include "aspose/email/foss/cfb/cfb_reader.hpp"
#include <iostream>

namespace aef = aspose::email::foss;

auto cfb = aef::cfb::cfb_reader::from_file(std::filesystem::path("message.msg"));
std::cout << "Directory entries: " << cfb.directory_entry_count() << '\n';
std::cout << "Storages: " << cfb.storage_ids().size() << '\n';
std::cout << "Streams: " << cfb.stream_ids().size() << '\n';

Hızlı Başlangıç

Kütüphaneyi projenize ekleyin:

git clone https://github.com/aspose-email-foss/Aspose.Email-FOSS-for-Cpp.git
# CMakeLists.txt
add_subdirectory(Aspose.Email-FOSS-for-Cpp)
target_link_libraries(your_target PRIVATE AsposeEmailFoss::AsposeEmailFoss)

Ardından bir mesaj oluşturun, MSG olarak kaydedin ve EML’ye dönüşümünü gerçekleştirin:

#include "aspose/email/foss/msg/mapi_message.hpp"
#include <filesystem>
#include <vector>
#include <cstdint>

namespace aef = aspose::email::foss;

int main() {
    auto message = aef::msg::mapi_message::create("Hello from C++", "Body text here");
    message.set_sender_name("Alice");
    message.set_sender_email_address("alice@example.com");
    message.add_recipient("bob@example.com", "Bob");
    message.add_attachment("note.txt", std::vector<std::uint8_t>{'a', 'b', 'c'}, "text/plain");
    message.save(std::filesystem::path("hello.msg"));

    auto loaded = aef::msg::mapi_message::from_file(
        std::filesystem::path("hello.msg"), /*strict=*/false);
    loaded.save_to_eml(std::filesystem::path("hello.eml"));

    return 0;
}

Desteklenen Formatlar

BiçimUzantıOkumaYazma
Outlook Mesajı (MSG).msg✓✓
EML (RFC 5322 / MIME).eml✓✓
Bileşik Dosya İkili (CFB).cfb✓✓

Açık Kaynak & Lisanslama

Aspose.Email FOSS for C++ MIT lisansı altında yayınlanmıştır. Tam kaynak kodu aspose-email-foss/Aspose.Email-FOSS-for-Cpp adresinde mevcuttur ve ticari kullanım royalty ödemesi olmadan izin verilir. Kütüphane, bir C++17 derleyicisi ve CMake 3.26 veya daha yeni bir sürümünden başka bir çalışma zamanı bağımlılığına sahip değildir.


Başlarken

İlgili Kaynaklar