EML ve MSG Dönüşümleri
EML ve MSG Dönüşümleri
Aspose.Email FOSS for C++ converts bidirectionally between EML (RFC 5322 / MIME) ve MSG (Outlook MAPI) Kullanılan biçimleri mapi_message.Dönüşüm yolu şudur: load_from_eml() In-Memory ile ilgili mapi_message → save() EML ve MSG için; ve from_file() / from_stream() → save_to_eml() MSG için EML.
EML’yi MSG’ye dönüştürmek
EML dosyası ile yükleme mapi_message::load_from_eml(),Bu arada MSG ile serialize etmeye devam edin. save():
#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';
message.save(std::filesystem::path("converted.msg"));
std::cout << "Saved converted.msg\n";
}load_from_eml() MIME yapısını parsize eder ve MAPI konusunu, düz metni nüfuz eder. vücut, HTML vücudu, gönderen kimliği, alıcı listesi ve tüm eklenti parçaları.
MSG’yi EML’ye dönüştürmek
MSG dosyası ile yükleme mapi_message::from_file(),Sonra arama save_to_eml():
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";
}
---
### Stream Basit Dönüşüm
4 Uygun Yöntemler Kabul Edilir `std::istream` / `std::ostream` Yüklenme için Dosya sistemine dokunmadan boru tipi işleme:
```cpp
#include <fstream>
#include <filesystem>
#include "aspose/email/foss/msg/mapi_message.hpp"
int main()
{
// EML → MSG via streams
std::ifstream eml_in("message.eml", std::ios::binary);
const auto message = aspose::email::foss::msg::mapi_message::load_from_eml(eml_in);
std::ofstream msg_out("converted.msg", std::ios::binary);
message.save(msg_out);
// MSG → EML via streams
std::ifstream msg_in("converted.msg", std::ios::binary);
const auto reloaded = aspose::email::foss::msg::mapi_message::from_stream(msg_in);
std::ofstream eml_out("roundtrip.eml", std::ios::binary);
reloaded.save_to_eml(eml_out);
}Her zaman açık akışlar ile std::ios::binary. metin modu akışları çeviri çizgi sonları Windows, biner CFB verilerini bozuyor.
In-Memory Dönüşüm (Bytes)
save() ve save_to_eml() İkisi de sıfır argüman yükü geri dönüşü var std::vector<std::uint8_t>.Tüm I/O dosya sistemleri önlemek için bunları kullanın:
#include <filesystem>
#include <vector>
#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"));
const std::vector<std::uint8_t> msg_bytes = message.save();
const std::vector<std::uint8_t> eml_bytes = message.save_to_eml();
// Write to a database, network socket, or other destination...
}Batch Directory Dönüşümleri
Bir dizin ile bir std::filesystem::directory_iterator Her şeyi dönüştürmek için .eml 1 adet dosya:
int main() { const std::filesystem::path input_dir(“emails/eml”); const std::filesystem::path output_dir(“emails/msg”); std::filesystem::create_directories(output_dir);
for (const auto& entry : std::filesystem::directory_iterator(input_dir))
{
if (entry.path().extension() != ".eml")
continue;
const auto message = aspose::email::foss::msg::mapi_message::load_from_eml(
entry.path());
auto out_path = output_dir / entry.path().filename();
out_path.replace_extension(".msg");
message.save(out_path);
std::cout << "Converted: " << entry.path().filename() << '\n';
}
}
---
### İpuçları ve En İyi Uygulamalar
- Tüm dosya akışlarını açın `std::ios::binary` Hem giriş hem de çıkış.
- Prefer `load_from_eml(path)` Yürüyüş yolunda bir yol varsa, yolda bir Yüklenme dosya içeride açılır ve biraz daha basittir.
- Bu sayede bu tür bir uygulama (`save()` ve `save_to_eml()` (Daha fazla bilgi verimliliği yaparken) Geçici dosyaları önlemek için hizmetler arasında.
- Konu, vücut, HTML vücudu, gönderenler, alıcılar ve MIME eklentileri tüm tam yuvarlak yolculuk boyunca korunur.
- IMAP bayrakları, yönlendirme başlıkları ve TNEF kodlanmış içerikler dönüşüm yoluyla taşınmaz.
---
### ortak sorunlar
| Issue | Cause | Fix |
| ------------------------------------------- | -------------------------------------- | --------------------------------------------------------------------------------------------- |
| `load_from_eml` Geçerli bir dosyaya atılır. | EML'de CRLF olmayan hatlar | EML RFC 5322 CRLF kullanır; bazı ihracat araçları sadece LF yazar |
| EML → MSG sonrası eksik eklentiler | Standart MIME Ek kodlama | EML Kullanımını Kontrol Edin `multipart/mixed` Standart ile `Content-Disposition: attachment` |
| MSG → EML sonrası boş HTML vücudu | MSG'nin sadece düz metin vücudu var. | Check `message.html_body()`;boş ise, yalnızca düz metin kaydedilir. |
| Akım üretimi yolsuz | Tekstil modunda açılır | Her zaman kullanın `std::ios::binary` |
| Subject gösterileri `?=` Sezonları | RFC 2047 orijinal EML kodlanmış kelime | RFC 2047 kütüphanesi ile dekod; kütüphane kodlanmış formu korur |
---
### FAQ
#### EML → MSG HTML vücudunu korur mu?
Evet A `text/html` MIME parçası, MAPI HTML vücut mülkiyetinde kaydedilir ve erişilebilirdir. yolda `message.html_body()` Yükleme sonrası.
#### İkisi de yönde tutar mı?
Evet. tüm MIME eklenti parçaları aracılığıyla taşınır `mapi_message` Ek listesi . Binary attachment verileri mevcuttur `attachment.data` (A) A `std::vector<std::uint8_t>`).
#### Bir EML'yi aynı anda birden fazla çıkış biçimine dönüştürebilir miyim?
Evet. EML ile bir kez yükleme `load_from_eml()`,İkisi de aradılar `save()` ve `save_to_eml()` Aynı anıta `mapi_message` nesne için.
#### O da `load_from_eml()` Trayum güvenli mi?
Her çağrı bağımsız bir çağrıyı oluşturur. `mapi_message` Örneğin, çok sayıda çubuk çağrısı yapabilir. `load_from_eml()` Her çubuk kendi çıkış nesnesini kullanırken, bu süre zarfında.
#### Peki, düz metin olmayan mesajlara ne oluyor?
Eğer EML yalnızca bir `text/html` Bir kısmı , `message.body()` Boş bir çubuk geri getirir ve `message.html_body()` HTML içeriğini taşıyor. her ikisi de MSG aracılığıyla korunuyor Seriyeye katılmak.
---
### API Referans Özetleri
| Sınıf / Yöntem | Description |
| ------------------------------------- | ---------------------------------------------- |
| `mapi_message::load_from_eml(path)` | Bir EML dosyasını bir `mapi_message` |
| `mapi_message::load_from_eml(stream)` | EML'den bir `std::istream` |
| `mapi_message::save(path)` | Serialize `mapi_message` MSG dosyası için |
| `mapi_message::save(stream)` | MSG bytes'i bir `std::ostream` |
| `mapi_message::save()` | MSG'ye geri dönmek `std::vector<std::uint8_t>` |
| `mapi_message::from_file(path)` | Bir MSG dosyasını bir `mapi_message` |
| `mapi_message::from_stream(stream)` | MSG'yi birden yüklemek için `std::istream` |
| `mapi_message::save_to_eml(path)` | EML'yi bir dosya yolu için yazın |
| `mapi_message::save_to_eml(stream)` | EML bytes'i bir `std::ostream` |
| `mapi_message::save_to_eml()` | EML'e geri dönmek `std::vector<std::uint8_t>` |
## See Also
- [Aspose.Email for C++ — Enterprise Documentation](https://docs.aspose.com/email/cpp/)