파일 SDK는 MSG 기능 플래그를 사용하도록 설정하기 위해 애플리케이션이 필요하다는 점을 제외하고 다른 파일 형식과 동일한 방식으로 .msg 파일에 대한 레이블 지정 작업을 지원합니다. 이 빠른 시작에서는 이 플래그를 설정하는 방법을 보여줍니다.
앞에서 설명한 대로 인스턴스화 mip::FileEngine 하려면 설정 개체가 mip::FileEngineSettings 필요합니다. 애플리케이션은 특정 인스턴스에 대한 사용자 지정 설정을 전달하는 데 사용합니다 FileEngineSettings .
enable_msg_file_type의 CustomSettings 속성은 .msg 파일 처리를 활성화하기 위해 mip::FileEngineSettings 플래그를 설정합니다.
필수 조건
아직 완료하지 않은 경우 계속하기 전에 다음 필수 조건을 완료해야 합니다.
- 빠른 시작 완료: 먼저 시작 Visual Studio 솔루션을 빌드하는 파일 SDK 애플리케이션 초기화(C++) 이 "방법 - 전자 메일 메시지 .msg 파일 처리(C++)" 빠른 안내서는 이전 버전을 기반으로 구축되었습니다.
- 빠른 시작: 민감도 레이블 목록 검토(C++).
- 빠른 시작 가이드: 민감도 레이블 설정/가져오기(C++).
- 이메일 파일 MIP SDK 개념을 검토합니다.
- 선택 사항: MIP SDK 개념에서 파일 엔진 을 검토합니다.
- 선택 사항: MIP SDK 개념에서 파일 처리기를 검토합니다.
필수 구성 요소 구현 단계
이전 "빠른 시작: 클라이언트 애플리케이션 초기화(C++)" 문서에서 만든 Visual Studio 솔루션을 엽니다.
빠른 시작: 민감도 레이블 나열(C++)에 설명된 대로 액세스 토큰을 생성하는 PowerShell 스크립트를 만듭니다.
빠른 시작: 민감도 레이블 설정/가져오기(C++)에 설명된 대로 모니터링
mip::FileHandler할 관찰자 클래스를 구현합니다.
enable_msg_file_type 설정하고 파일 SDK를 사용하여 .msg 파일에 레이블 지정
다음 파일 엔진 생성 코드를 추가하여 플래그를 enable_msg_file_type 설정하고 파일 엔진을 사용하여 .msg 파일에 레이블을 지정합니다.
솔루션 탐색기 메서드 구현이 포함된
main()프로젝트에서 .cpp 파일을 엽니다. 기본 이름은 프로젝트 생성 시 지정한 이름을 포함한 프로젝트와 동일합니다.파일 맨 위에 해당하는 기존 지시문 다음에 다음 #include 및 using 지시문을 추가합니다.
#include "filehandler_observer.h" #include "mip/file/file_handler.h" #include <iostream> using mip::FileHandler; using std::endl;이전 빠른 시작에서
main()함수의 구현을 제거합니다. 본문 내부에main()다음 코드를 삽입합니다. 다음 코드 블록에서 파일 엔진 생성은 플래그를enable_msg_file_type설정합니다.mip::FileHandler파일 엔진을 사용하여 만든 개체는 .msg 파일을 처리할 수 있습니다.
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>(appInfo,
"mip_data",
mip::LogLevel::Trace,
false,
mip::CacheStorageType::OnDisk);
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(mMipContext, mip::CacheStorageType::OnDisk,
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)
authDelegateImpl, // Token acquisition implementation
"<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
auto labels = engine->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);
// Resolve the label ID to a mip::Label, then apply it.
auto label = engine->GetLabelById(labelId);
fileHandler->SetLabel(label, 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 = msgHandlerPromise->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->GetLabel()->GetLabel()->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;
mMipContext->ShutDown();
mMipContext = nullptr;
return 0;
}
파일 작업에 대한 자세한 내용은 파일 처리기 개념을 참조하세요.
소스 코드의 자리 표시자 값을 다음 값으로 바꿉다.
자리 표시자 가치 <application-id> Microsoft Entra 테넌트에 등록된 애플리케이션 ID입니다. 예를 들면 다음과 00001111-aaaa-2222-bbbb-3333cccc4444같습니다.<엔진 계정> 엔진 ID에 사용되는 계정(예: user@tenant.onmicrosoft.com.<엔진 상태> 사용자 정의 애플리케이션 상태(예: My engine state.<입력 파일 경로> 테스트 입력 메시지 파일의 전체 경로(예: c:\\Test\\message.msg.<출력 파일 경로> 입력 파일의 레이블이 지정된 복사본인 출력 파일의 전체 경로입니다. 예를 들면 다음과 c:\\Test\\message_labeled.msg같습니다.<label-id> ListSensitivityLabels을(를) 사용하여 가져온 레이블 ID입니다. 예:667466bf-a01b-4b0a-8bbf-a79a3d96f720.
응용 프로그램 구축 및 테스트
F6(솔루션 빌드)을 사용하여 클라이언트 애플리케이션을 빌드합니다. 빌드 오류가 없는 경우 F5 (디버깅 시작)를 사용하여 애플리케이션을 실행합니다.