خصائص MAPI
خصائص MAPI
كل ملف MSG يخزن البيانات كخصائص MAPI — أزواج مفتاح‑قيمة مُعلمة يتم التعرف عليها بواسطة معرف الخاصية ورمز النوع. توفر Aspose.Email FOSS for .NET وصولًا مباشرًا إلى هذه الخصائص عبر MapiMessage، MapiPropertyCollection، وCommonMessagePropertyId enum.
قراءة الخصائص
خصائص الراحة
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);معرفات الخصائص العامة
يقدم تعداد CommonMessagePropertyId ثوابت مسماة لمعرفات خصائص MAPI المستخدمة بشكل متكرر:
| Property | Description |
|---|---|
Subject | موضوع الرسالة |
Body | نص الرسالة العادي |
BodyHtml | نص HTML |
SenderName | اسم المرسل المعروض |
SenderEmailAddress | عنوان بريد المرسل الإلكتروني |
DisplayTo | سلسلة عرض المستلمين (إلى) |
DisplayCc | سلسلة عرض المستلمين (نسخة) |
DisplayBcc | سلسلة عرض المستلمين (نسخة مخفية) |
InternetMessageId | معرف الرسالة RFC 5322 |
MessageDeliveryTime | طابع زمن التسليم |
TransportMessageHeaders | رؤوس RFC 5322 الخام |
AttachFilename | اسم ملف المرفق القصير |
AttachLongFilename | اسم ملف المرفق الطويل |
AttachMimeTag | نوع MIME للمرفق |
AttachContentId | معرف محتوى المرفق (Content-ID) |
رموز نوع العقار
تقوم تعداد PropertyTypeCode بربط رموز نوع MAPI:
| Type | Description |
|---|---|
PtypString | سلسلة Unicode |
PtypString8 | سلسلة ANSI |
PtypInteger32 | عدد صحيح 32‑بت |
PtypInteger64 | عدد صحيح 64‑بت |
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 — الوصول إلى حاويات ثنائية منخفضة المستوى