파일 SDK - 이메일 .msg 파일 처리(C++)

파일 SDK는 MSG 기능 플래그를 활성화하기 위해 애플리케이션이 필요하다는 점을 제외하고 다른 파일 형식과 동일한 방식으로 .msg 파일의 레이블 지정 작업을 지원합니다. 여기서는 이 플래그를 설정하는 방법을 볼 수 있습니다.

앞서 설명한 것처럼 mip::FileEngine의 인스턴스화에는 설정 개체 mip::FileEngineSettings가 필요합니다. FileEngineSettings를 사용하여 애플리케이션이 특정 인스턴스에 대해 설정해야 하는 사용자 지정 설정에 대한 매개 변수를 전달할 수 있습니다. mip::FileEngineSettingsCustomSettings 속성은 .msg 파일을 처리할 수 있도록 enable_msg_file_type에 대한 플래그를 설정하는 데 사용됩니다.

필수 조건

아직 완료하지 않은 경우 계속하기 전에 다음 필수 구성 요소를 완료해야 합니다.

필수 구성 요소 구현 단계

  1. 이전 "빠른 시작: 클라이언트 애플리케이션 초기화(C++)" 문서에서 만든 Visual Studio 솔루션을 엽니다.

  2. 빠른 시작 "민감도 레이블 나열(C++)"에 설명된 대로 액세스 토큰을 생성하는 PowerShell 스크립트를 만듭니다.

  3. 빠른 시작 "민감도 레이블 설정/가져오기(C++)"에 설명된 대로 mip::FileHandler를 모니터링할 관찰자 클래스를 구현합니다.

enable_msg_file_type을 설정하고 파일 SDK를 사용하여 .msg 파일에 레이블 지정

아래 파일 엔진 구성 코드를 추가하여 enable_msg_file_type flag를 설정하고 파일 엔진을 사용하여 .msg 파일에 레이블을 지정합니다.

  1. 솔루션 탐색기를 사용하여 main() 메서드 구현을 포함하는 프로젝트에서 .cpp 파일을 엽니다. 기본값은 프로젝트 생성 중에 지정한 이름이 포함된 프로젝트와 동일한 이름입니다.

  2. 파일 상단의 해당 기존 지시문 아래에 #include 및 using 지시문을 추가합니다.

    #include "filehandler_observer.h" 
    #include "mip/file/file_handler.h" 
    #include <iostream>    
    using mip::FileHandler;   
    using std::endl;
    
  3. 이전 빠른 시작에서 main() 함수 구현을 제거합니다. main() 본문 내부에 다음 코드를 삽입합니다. 아래 코드 블록에서 enable_msg_file_type 플래그는 파일 엔진 생성 중에 설정되며 .msg 파일은 파일 엔진을 사용하여 생성된 mip::FileHandler 개체에 의해 처리될 수 있습니다.

int main()
{
    // Construct/initialize objects required by the application's profile object
    ApplicationInfo appInfo { "<application-id>",                    // ApplicationInfo object (App ID, name, version)
                              "<application-name>", 
                              "1.0" 
    };

    std::shared_ptr<mip::MipConfiguration> mipConfiguration = std::make_shared<mip::MipConfiguration>(mAppInfo,
				                                                                                       "mip_data",
                                                                                        			   mip::LogLevel::Trace,
                                                                                                       false);

    std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);

    auto profileObserver = make_shared<ProfileObserver>();                      // Observer object
    auto authDelegateImpl = make_shared<AuthDelegateImpl>("<application-id>");  // Authentication delegate object (App ID)
    auto consentDelegateImpl = make_shared<ConsentDelegateImpl>();              // Consent delegate object

    // Construct/initialize profile object
    FileProfile::Settings profileSettings(mipContext,mip::CacheStorageType::OnDisk,authDelegateImpl,
        consentDelegateImpl,profileObserver);

    // Set up promise/future connection for async profile operations; load profile asynchronously
    auto profilePromise = make_shared<promise<shared_ptr<FileProfile>>>();
    auto profileFuture = profilePromise->get_future();
    try
    {
        mip::FileProfile::LoadAsync(profileSettings, profilePromise);
    }
    catch (const std::exception& e)
    {
        std::cout << "An exception occurred. Are the Settings and ApplicationInfo objects populated correctly?\n\n"<< e.what() << "'\n";
        system("pause");
        return 1;
    }

    auto profile = profileFuture.get();

    // Construct/initialize engine object
    FileEngine::Settings engineSettings(
                            mip::Identity("<engine-account>"),      // Engine identity (account used for authentication)
                            "<engine-state>",                       // User-defined engine state
                            "en-US");                               // Locale (default = en-US)

    //Set enable_msg_file_type flag as true
    std::vector<std::pair<string, string>> customSettings;
    customSettings.emplace_back(mip::GetCustomSettingEnableMsgFileType(), "true");
    engineSettings.SetCustomSettings(customSettings);

    // Set up promise/future connection for async engine operations; add engine to profile asynchronously
    auto enginePromise = make_shared<promise<shared_ptr<FileEngine>>>();
    auto engineFuture = enginePromise->get_future();
    profile->AddEngineAsync(engineSettings, enginePromise);
    std::shared_ptr<FileEngine> engine;

    try
    {
        engine = engineFuture.get();
    }
    catch (const std::exception& e)
    {
        cout << "An exception occurred... is the access token incorrect/expired?\n\n"<< e.what() << "'\n";
        system("pause");
        return 1;
    }

    //Set file paths
    string inputFilePath = "<input-file-path>"; //.msg file to be labeled
    string actualFilePath = inputFilePath;
    string outputFilePath = "<output-file-path>"; //labeled .msg file
    string actualOutputFilePath = outputFilePath;

    //Create a file handler for original file
    auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<FileHandler>>>();
    auto handlerFuture = handlerPromise->get_future();

    engine->CreateFileHandlerAsync(inputFilePath,
                                    actualFilePath,
                                    true,
                                    std::make_shared<FileHandlerObserver>(),
                                    handlerPromise);

    auto fileHandler = handlerFuture.get();

    //List labels available to the user    

    // Use mip::FileEngine to list all labels
    labels = mEngine->ListSensitivityLabels();

    // Iterate through each label, first listing details
    for (const auto& label : labels) {
        cout << label->GetName() << " : " << label->GetId() << endl;

        // get all children for mip::Label and list details
        for (const auto& child : label->GetChildren()) {
            cout << "->  " << child->GetName() << " : " << child->GetId() << endl;
        }
    }

    string labelId = "<labelId-id>"; //set a label ID to use

    // Labeling requires a mip::LabelingOptions object. 
    // Review API ref for more details. The sample implies that the file was labeled manually by a user.
    mip::LabelingOptions labelingOptions(mip::AssignmentMethod::PRIVILEGED);

    fileHandler->SetLabel(labelId, labelingOptions, mip::ProtectionSettings());

    // Commit changes, save as outputFilePath
    auto commitPromise = std::make_shared<std::promise<bool>>();
    auto commitFuture = commitPromise->get_future();

    if(fileHandler->IsModified())
    {
        fileHandler->CommitAsync(outputFilePath, commitPromise);
    }
    
    if (commitFuture.get()) {
        cout << "\n Label applied to file: " << outputFilePath << endl;
    }
    else {
        cout << "Failed to label: " + outputFilePath << endl;
        return 1;
    }

    // Create a new handler to read the label
    auto msgHandlerPromise = std::make_shared<std::promise<std::shared_ptr<FileHandler>>>();
    auto msgHandlerFuture = handlerPromise->get_future();

    engine->CreateFileHandlerAsync(inputFilePath,
                                    actualFilePath,
                                    true,
                                    std::make_shared<FileHandlerObserver>(),
                                    msgHandlerPromise);

    auto msgFileHandler = msgHandlerFuture.get();

    cout << "Original file: " << inputFilePath << endl;
    cout << "Labeled file: " << outputFilePath << endl;
    cout << "Label applied to file : " 
            << msgFileHandler->GetName() 
            << endl;
    
    // Application shutdown. Null out profile, engine, handler.
    // Application may crash at shutdown if resources aren't properly released.
    msgFileHandler = nullptr;
    fileHandler = nullptr;
    engine = nullptr;
    profile = nullptr;
    mipContext = nullptr;

    return 0;
}

파일 작업에 대한 자세한 내용은 파일 처리기 개념을 참조하세요.

  1. 다음 값을 사용하여 소스 코드의 자리 표시자 값을 바꿉니다.

    자리 표시자
    <application-id> Microsoft Entra 테넌트에 등록된 애플리케이션 ID(예: 0edbblll-8773-44de-b87c-b8c6276d41eb.
    <engine-account> 엔진의 ID에 사용되는 계정(예: user@tenant.onmicrosoft.com).
    <engine-state> 사용자 정의 애플리케이션 상태(예: My engine state).
    <input-file-path> 테스트 입력 메시지 파일에 대한 전체 경로(예: c:\\Test\\message.msg).
    <output-file-path> 입력 파일의 레이블이 지정된 복사본인 출력 파일의 전체 경로(예: c:\\Test\\message_labeled.msg).
    <label-id> ListSensitivityLabels를 사용하여 검색된 labelId(예: 667466bf-a01b-4b0a-8bbf-a79a3d96f720).

응용 프로그램 구축 및 테스트

F6(솔루션 빌드)을 사용하여 클라이언트 애플리케이션을 빌드합니다. 빌드 오류가 없는 경우 F5(디버깅 시작) 키를 사용하여 애플리케이션을 실행합니다.