מאפייני MAPI
מאפייני MAPI
כל קובץ MSG מאחסן נתונים כמאפייני MAPI — זוגות מפתח‑ערך מתוייגים המזהים על‑ידי
מזהה מאפיין וקוד סוג. Aspose.Email FOSS for .NET נותן גישה ישירה למאפיינים אלה דרך MapiMessage, MapiPropertyCollection, וה‑enum 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);מזהי נכסים משותפים
ה‑CommonMessagePropertyId enum מספק קבועים בשם עבור מזהי מאפייני MAPI שבשימוש תדיר:
| Property | Description |
|---|---|
Subject | נושא ההודעה |
Body | גוף טקסט רגיל |
BodyHtml | גוף HTML |
SenderName | שם תצוגה של השולח |
SenderEmailAddress | כתובת דוא"ל של השולח |
DisplayTo | מחרוזת תצוגה של נמעני “אל” |
DisplayCc | מחרוזת תצוגה של נמעני “העתק” |
DisplayBcc | מחרוזת תצוגה של נמעני “העתק מוסתר” |
InternetMessageId | Message-ID של RFC 5322 |
MessageDeliveryTime | חותמת זמן של המסירה |
TransportMessageHeaders | כותרות גולמיות של RFC 5322 |
AttachFilename | שם קובץ קיצור של הקובץ המצורף |
AttachLongFilename | שם קובץ ארוך של הקובץ המצורף |
AttachMimeTag | סוג MIME של הקובץ המצורף |
AttachContentId | Content-ID של הקובץ המצורף |
קודי סוג נכס
ה‑PropertyTypeCode enum ממפה קודי סוג MAPI:
| סוג | תיאור |
|---|---|
PtypString | מחרוזת Unicode |
PtypString8 | מחרוזת ANSI |
PtypInteger32 | מספר שלם 32‑ביט |
PtypInteger64 | מספר שלם 64‑ביט |
PtypBoolean | בוליאני |
PtypTime | DateTime (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 — גישה ברמת נמוכה למכולות בינריות