ویژگیهای MAPI
ویژگیهای MAPI
هر فایل MSG دادهها را بهصورت ویژگیهای MAPI ذخیره میکند — جفتهای کلید‑مقدار برچسبدار که با شناسه ویژگی و کد نوع شناسایی میشوند. Aspose.Email FOSS برای .NET دسترسی مستقیم به این ویژگیها را از طریق MapiMessage، MapiPropertyCollection و شمارنده CommonMessagePropertyId فراهم میکند.
خواندن ویژگیها
ویژگیهای راحتی
MapiMessage ویژگیهای رایجترین را بهصورت ویژگیهای تایپشده C# نمایش میدهد:
using Aspose.Email.Foss.Msg;
using var message = MapiMessage.FromFile("sample.msg");
Console.WriteLine(message.Subject); // string?
Console.WriteLine(message.Body); // string?
Console.WriteLine(message.HtmlBody); // string?
Console.WriteLine(message.SenderName); // string?
Console.WriteLine(message.SenderEmailAddress); // string?
Console.WriteLine(message.InternetMessageId); // string?
Console.WriteLine(message.MessageDeliveryTime); // DateTime?
Console.WriteLine(message.MessageClass); // string?دسترسی خام به ویژگی
برای ویژگیهایی که بهعنوان فیلدهای راحتی در دسترس نیستند، از GetPropertyValue استفاده کنید:
// Read a string property by ID and type
var displayTo = message.GetPropertyValue(
(ushort)CommonMessagePropertyId.DisplayTo,
(ushort)PropertyTypeCode.PtypString,
decode: true);
Console.WriteLine($"Display To: {displayTo}");تکرار تمام ویژگیها
// List all property keys (ID + type pairs)
foreach (var key in message.IterPropertyKeys())
Console.WriteLine($"Property: 0x{key:X8}");
// Iterate full property objects
foreach (var prop in message.IterProperties())
{
Console.WriteLine($"ID=0x{prop.PropertyId:X4} " +
$"Type=0x{prop.PropertyType:X4} " +
$"Tag=0x{prop.PropertyTag:X8} " +
$"Value={prop.Value}");
}ویژگیهای نوشتن
تنظیم ویژگیها برای پیام جدید
var message = MapiMessage.Create("Test", "Body");
message.SetProperty(
(ushort)CommonMessagePropertyId.SenderName,
(ushort)PropertyTypeCode.PtypString,
"Alice");
message.SetProperty(
(ushort)CommonMessagePropertyId.SenderEmailAddress,
(ushort)PropertyTypeCode.PtypString,
"alice@example.com");
message.SetProperty(
(ushort)CommonMessagePropertyId.MessageDeliveryTime,
(ushort)PropertyTypeCode.PtypTime,
new DateTime(2026, 3, 15, 10, 30, 0, DateTimeKind.Utc));دسترسی مستقیم به مجموعه
MapiPropertyCollection ارائه میدهد Add، Set، Get و Remove:
// Access the property collection
var props = message.Properties;
// Add a property
props.Add(
(ushort)CommonMessagePropertyId.InternetCodepage,
(ushort)PropertyTypeCode.PtypInteger32,
65001, // UTF-8
flags: 0);
// Read it back
var codepage = props.Get(
(ushort)CommonMessagePropertyId.InternetCodepage,
(ushort)PropertyTypeCode.PtypInteger32);
Console.WriteLine($"Codepage: {codepage?.Value}");
// Remove a property
props.Remove(
(ushort)CommonMessagePropertyId.InternetCodepage,
(ushort)PropertyTypeCode.PtypInteger32);شناسههای ویژگی عمومی
enum CommonMessagePropertyId ثابتهای نامگذاریشدهای را برای شناسههای پراپرتی MAPI که بهطور مکرر استفاده میشوند، فراهم میکند:
| ویژگی | توضیح |
|---|---|
Subject | موضوع پیام |
Body | متن ساده |
BodyHtml | بدنه HTML |
SenderName | نام نمایشی فرستنده |
SenderEmailAddress | آدرس ایمیل فرستنده |
DisplayTo | رشته نمایش گیرندگان To |
DisplayCc | رشته نمایش گیرندگان Cc |
DisplayBcc | رشته نمایش گیرندگان Bcc |
InternetMessageId | شناسه پیام RFC 5322 |
MessageDeliveryTime | زمان تحویل |
TransportMessageHeaders | سرآیندهای خام RFC 5322 |
AttachFilename | نام فایل کوتاه پیوست |
AttachLongFilename | نام فایل طولانی پیوست |
AttachMimeTag | نوع MIME پیوست |
AttachContentId | شناسه محتوا (Content-ID) پیوست |
کدهای نوع ملک
enum PropertyTypeCode کدهای نوع MAPI را نگاشت میکند:
| نوع | توضیح |
|---|---|
PtypString | رشته یونیکد |
PtypString8 | رشته ANSI |
PtypInteger32 | عدد صحیح ۳۲ بیتی |
PtypInteger64 | عدد صحیح ۶۴ بیتی |
PtypBoolean | بولی |
PtypTime | تاریخ و زمان (FILETIME) |
PtypBinary | آرایه بایت |
PtypGuid | GUID |
ویژگیهای پیوست
هر MapiAttachment همچنین مجموعهٔ Properties خود را دارد:
foreach (var attachment in message.Attachments)
{
Console.WriteLine($"Attachment: {attachment.Filename}");
foreach (var prop in attachment.Properties.IterProperties())
Console.WriteLine($" 0x{prop.PropertyTag:X8} = {prop.Value}");
}همچنین ببینید
- خواندن فایلهای MSG — بارگذاری و بررسی فایلهای MSG
- تبدیل EML — تبدیل بین فرمتها
- کانتینرهای CFB — دسترسی به کانتینر باینری سطح پایین