MAPI tulajdonságok

MAPI tulajdonságok

Minden MSG fájl adatokat tárol MAPI tulajdonságokként — címkézett kulcs‑érték párok, amelyeket egy tulajdonságazonosító és típuskód határoz meg. Az Aspose.Email FOSS for .NET közvetlen hozzáférést biztosít ezekhez a tulajdonságokhoz a MapiMessage, MapiPropertyCollection és a CommonMessagePropertyId enum segítségével.


Tulajdonságok olvasása

Kényelmi tulajdonságok

MapiMessage a leggyakoribb tulajdonságokat típusos C# tulajdonságokként teszi elérhetővé:

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?

Nyers tulajdonság elérése

A kényelmi mezőként nem elérhető tulajdonságok esetén használja a GetPropertyValue-t:

// 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}");

Iterálja az összes tulajdonságot

// 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}");
}

Tulajdonságok írása

Új üzenet tulajdonságainak beállítása

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));

Közvetlen gyűjteményhozzáférés

MapiPropertyCollection biztosítja Add, Set, Get és 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);

Általános tulajdonság-azonosítók

A CommonMessagePropertyId enum elnevezett állandókat biztosít a gyakran használt MAPI tulajdonságazonosítókhoz:

PropertyDescription
SubjectÜzenet tárgya
BodyEgyszerű szöveges törzs
BodyHtmlHTML törzs
SenderNameFeladó megjelenített neve
SenderEmailAddressFeladó e‑mail címe
DisplayToCímzett (To) megjelenítő karakterlánc
DisplayCcMásolat (Cc) címzettek megjelenítő karakterlánca
DisplayBccRejtett másolat (Bcc) címzettek megjelenítő karakterlánca
InternetMessageIdRFC 5322 Message-ID
MessageDeliveryTimeKézbesítési időbélyeg
TransportMessageHeadersNyers RFC 5322 fejlécek
AttachFilenameRövid csatolmány fájlnév
AttachLongFilenameHosszú csatolmány fájlnév
AttachMimeTagCsatolmány MIME típusa
AttachContentIdCsatolmány Content-ID

Tulajdonság típus kódok

A PropertyTypeCode enum leképezi a MAPI típuskódokat:

TípusLeírás
PtypStringUnicode karakterlánc
PtypString8ANSI karakterlánc
PtypInteger3232 bites egész szám
PtypInteger6464 bites egész szám
PtypBooleanLogikai
PtypTimeDateTime (FILETIME)
PtypBinaryByte tömb
PtypGuidGUID

Melléklet tulajdonságai

Minden MapiAttachment-nek saját Properties gyűjteménye is van:

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}");
}

Lásd még

 Magyar