PST 파일에서 배포 목록 관리

Outlook 배포 목록은 여러 수신자를 하나의 이름 아래에 그룹화하는 연락처-폴더 항목입니다. PST 파일에서는 해당 연락처와 같은 폴더에 위치하며, Aspose.Email for C++는 이를 MapiDistributionList 클래스입니다. 이 문서는 PST 내부에 이러한 목록을 생성하고, 스토리지가 보유한 목록을 읽으며, 구성원을 변경하는 방법을 보여줍니다. 독립형 MSG 또는 VCF 파일로 저장된 목록은 배포 목록 작업.

목록 구성원은 MapiDistributionListMember. 해당 EntryIdType 구성원 유형을 나타냅니다:

| MapiDistributionListEntryIdType | 구성원은 | | — | — | | Contact | 연락처 항목에 대한 링크; | EntryId 연락처의 엔트리 ID를 보유하므로 Outlook은 현재 연락처 세부 정보를 표시합니다 | | OneOff | 이름과 주소가 목록 자체에 저장된 경우, 뒤에 연락처가 없는 경우 - 이름과 주소만으로 만든 구성원의 기본값 | | DistributionList | 이 목록에 중첩된 또 다른 배포 목록 |

이 문서의 샘플은 다음 헤더와 네임스페이스를 사용합니다:

#include <Mapi/MapiMessage.h>
#include <Mapi/MapiContact.h>
#include <Mapi/MapiContactNamePropertySet.h>
#include <Mapi/MapiContactElectronicAddress.h>
#include <Mapi/MapiContactElectronicAddressPropertySet.h>
#include <Mapi/MapiDistributionList.h>
#include <Mapi/MapiDistributionListMember.h>
#include <Mapi/MapiDistributionListMemberCollection.h>
#include <Mapi/MapiDistributionListEntryIdType.h>
#include <Storage/Pst/PersonalStorage.h>
#include <Storage/Pst/FileFormatVersion.h>
#include <Storage/Pst/FolderInfo.h>
#include <Storage/Pst/MessageInfo.h>
#include <Storage/Pst/StandardIpmFolder.h>
#include <system/convert.h>

using namespace System;
using namespace Aspose::Email::Mapi;
using namespace Aspose::Email::Storage::Pst;

PST에 배포 목록 만들기

구성원을 연락처에 연결하려면 먼저 연락처가 스토리지에 있어야 합니다. FolderInfo::AddMapiMessageItem 항목을 저장하고 엔트리 ID를 Base64 문자열로 반환합니다; Convert::FromBase64String 구성원이 기대하는 바이트로 변환합니다. 이름과 주소만으로 만든 구성원은 이러한 단계가 필요 없으며 일시적 구성원이 됩니다.

완성된 구성원 컬렉션은 MapiDistributionList 생성자와 목록 이름을 함께 사용하며, 목록은 같은 연락처 폴더에 저장됩니다.

SharedPtr<PersonalStorage> pst = PersonalStorage::Create(u"lists.pst", FileFormatVersion::Unicode);
SharedPtr<FolderInfo> contacts = pst->CreatePredefinedFolder(u"Contacts", StandardIpmFolder::Contacts);

// the contacts the list will point to; AddMapiMessageItem returns the entry ID of each stored item
SharedPtr<MapiContact> susanne = MakeObject<MapiContact>(u"Susanne Nielsen", u"SusanneNielsen@example.com");
SharedPtr<MapiContact> lars = MakeObject<MapiContact>(u"Lars Rosing", u"LarsRosing@example.com");
String susanneId = contacts->AddMapiMessageItem(susanne);
String larsId = contacts->AddMapiMessageItem(lars);

// members linked to those contacts: the entry ID string is Base64, the member needs the raw bytes
SharedPtr<MapiDistributionListMember> first = MakeObject<MapiDistributionListMember>(
    susanne->get_NameInfo()->get_DisplayName(), susanne->get_ElectronicAddresses()->get_Email1()->get_EmailAddress());
first->set_EntryIdType(MapiDistributionListEntryIdType::Contact);
first->set_EntryId(Convert::FromBase64String(susanneId));

SharedPtr<MapiDistributionListMember> second = MakeObject<MapiDistributionListMember>(
    lars->get_NameInfo()->get_DisplayName(), lars->get_ElectronicAddresses()->get_Email1()->get_EmailAddress());
second->set_EntryIdType(MapiDistributionListEntryIdType::Contact);
second->set_EntryId(Convert::FromBase64String(larsId));

// a one-off member: just a name and an address, with no contact behind it
SharedPtr<MapiDistributionListMember> external = MakeObject<MapiDistributionListMember>(
    u"Tilly Bates", u"TillyBates@example.com");

SharedPtr<MapiDistributionListMemberCollection> members = MakeObject<MapiDistributionListMemberCollection>();
members->Add(first);
members->Add(second);
members->Add(external);

SharedPtr<MapiDistributionList> list = MakeObject<MapiDistributionList>(u"Project team", members);
list->set_Body(u"Everyone working on the project");
list->set_Subject(u"Project team");

contacts->AddMapiMessageItem(list);
Console::WriteLine(u"Items in the Contacts folder: " + Convert::ToString(contacts->get_ContentCount()));

pst->Dispose();

PST의 배포 목록 읽기

연락처와 배포 목록은 연락처 폴더를 공유합니다. MessageClass 목록의 IPM.DistList, 경량 MessageInfo 추출되기 전에 캐스팅합니다. ToMapiMessageItem 그런 다음 해당 객체를 MapiDistributionList, 그리고 그 Members 그것에 속한 구성원을 수집합니다.

SharedPtr<PersonalStorage> pst = PersonalStorage::FromFile(u"lists.pst", false);
SharedPtr<FolderInfo> contacts = pst->GetPredefinedFolder(StandardIpmFolder::Contacts);

for (SharedPtr<MessageInfo> messageInfo : contacts->EnumerateMessages())
{
    // contacts and distribution lists share the folder; the message class tells them apart
    if (messageInfo->get_MessageClass() != u"IPM.DistList")
    {
        continue;
    }

    SharedPtr<MapiDistributionList> list =
        System::DynamicCast<MapiDistributionList>(pst->ExtractMessage(messageInfo)->ToMapiMessageItem());
    Console::WriteLine(u"List: " + list->get_DisplayName());

    for (SharedPtr<MapiDistributionListMember> member : list->get_Members())
    {
        String kind = member->get_EntryIdType() == MapiDistributionListEntryIdType::Contact
            ? String(u"contact") : String(u"one-off");
        Console::WriteLine(u"   " + member->get_DisplayName() + u" <" + member->get_EmailAddress() + u">, " + kind);
    }
}

pst->Dispose();

위에서 만든 목록은 출력 이름으로 Susanne Nielsen과 Lars Rosing을 연락처 구성원으로, Tilly Bates를 일시적 구성원으로 표시합니다.

배포 목록 업데이트

저장된 항목 위에 씁니다. MapiDistributionList 그것을 가져와서 FolderInfo::UpdateMessage. 목록은 그 엔트리 ID를 유지하므로 폴더는 오래된 복사본과 새 복사본이 아닌 하나의 목록만 보유합니다.

전달된 각 구성원은 이름과 주소에서 새로 생성됩니다; 연락처를 나타내는 구성원은 연락처의 엔트리 ID를 다시 받아 연결이 업데이트를 통해 유지됩니다. 샘플은 한 구성원을 제거하고, 다른 구성원을 추가한 다음, 결과를 보여주기 위해 저장된 목록을 다시 읽습니다.

SharedPtr<PersonalStorage> pst = PersonalStorage::FromFile(u"lists.pst", true);
SharedPtr<FolderInfo> contacts = pst->GetPredefinedFolder(StandardIpmFolder::Contacts);

for (SharedPtr<MessageInfo> messageInfo : contacts->EnumerateMessages())
{
    if (messageInfo->get_MessageClass() != u"IPM.DistList")
    {
        continue;
    }

    SharedPtr<MapiDistributionList> stored =
        System::DynamicCast<MapiDistributionList>(pst->ExtractMessage(messageInfo)->ToMapiMessageItem());

    // the new member list: everyone except Lars, plus Edward
    SharedPtr<MapiDistributionListMemberCollection> members = MakeObject<MapiDistributionListMemberCollection>();
    for (SharedPtr<MapiDistributionListMember> member : stored->get_Members())
    {
        if (member->get_EmailAddress() == u"LarsRosing@example.com")
        {
            continue;
        }

        SharedPtr<MapiDistributionListMember> copy =
            MakeObject<MapiDistributionListMember>(member->get_DisplayName(), member->get_EmailAddress());
        if (member->get_EntryIdType() == MapiDistributionListEntryIdType::Contact)
        {
            // keep the link to the contact item
            copy->set_EntryIdType(MapiDistributionListEntryIdType::Contact);
            copy->set_EntryId(member->get_EntryId());
        }
        members->Add(copy);
    }
    members->Add(MakeObject<MapiDistributionListMember>(u"Edward R. Manuel", u"EdwardRManuel@example.com"));

    SharedPtr<MapiDistributionList> updated = MakeObject<MapiDistributionList>(stored->get_DisplayName(), members);
    updated->set_Subject(stored->get_Subject());
    updated->set_Body(stored->get_Body());

    // replace the stored list, keeping its entry ID
    contacts->UpdateMessage(messageInfo->get_EntryIdString(), updated);
}

pst->Dispose();

// check the stored result
SharedPtr<PersonalStorage> check = PersonalStorage::FromFile(u"lists.pst", false);
SharedPtr<FolderInfo> folder = check->GetPredefinedFolder(StandardIpmFolder::Contacts);
for (SharedPtr<MessageInfo> messageInfo : folder->EnumerateMessages())
{
    if (messageInfo->get_MessageClass() == u"IPM.DistList")
    {
        SharedPtr<MapiDistributionList> list =
            System::DynamicCast<MapiDistributionList>(check->ExtractMessage(messageInfo)->ToMapiMessageItem());
        for (SharedPtr<MapiDistributionListMember> member : list->get_Members())
        {
            Console::WriteLine(u"   " + member->get_DisplayName() + u" <" + member->get_EmailAddress() + u">");
        }
    }
}
Console::WriteLine(u"Items in the Contacts folder: " + Convert::ToString(folder->get_ContentCount()));
check->Dispose();

관련 항목