File SDK では、他のファイルの種類と同じ方法で.msg ファイルのラベル付け操作がサポートされます。ただし、SDK では、アプリケーションで MSG 機能フラグを有効にする必要があります。 ここでは、このフラグを設定する方法について説明します。
前に説明したように、 IFileEngine
のインスタンス化には設定オブジェクト FileEngineSettings
が必要です。 FileEngineSettings を使用すると、アプリケーションが特定のインスタンスに対して設定する必要があるカスタム設定のパラメーターを渡すことができます。 CustomSettings
FileEngineSettings
のプロパティは、.msg ファイルの処理を有効にするenable_msg_file_type
のフラグを設定するために使用されます。
前提条件
まだ行っていない場合は、続行する前に次の前提条件を満たしていることを確認してください。
- クイック スタート: 最初に、スターター Visual Studio ソリューションをビルドする File SDK アプリケーション初期化 (C#) を完了します。 この"方法 - 電子メール メッセージ .msg ファイルを処理する (C#)" クイック スタートは、前のクイック スタートに基づいています。
- 電子メール ファイル MIP SDK の概念を確認します。
- 必要に応じて、 MIP SDK の概念でファイル エンジン を確認します。
- 必要に応じて、 MIP SDK の概念でファイル ハンドラー を確認します。
enable_msg_file_typeを設定し、File SDKを使用して.msgファイルにラベルを付ける。
File API アプリケーションの初期化クイック スタートの継続中に、ファイル エンジンの構築コードを変更して enable_msg_file_type flag
設定してから、ファイル エンジンを使用して.msg ファイルにラベルを付けます。
前の「クイック スタート: File SDK アプリケーション初期化 (C#)」で作成した Visual Studio ソリューションを開きます。
ソリューション エクスプローラーを使用して、
Main()
メソッドの実装を含む.cs ファイルをプロジェクトで開きます。 既定の名前は、それが含まれるプロジェクトと同じであり、プロジェクトの作成時に指定したものです。前のクイック スタートから
Main()
関数の実装を削除します。Main()
本文内に、次のコードを挿入します。 次のコード ブロックでは、ファイル エンジンの作成時にenable_msg_file_type
フラグが設定され、ファイル エンジンを使用して作成されたオブジェクトIFileHandler
.msg ファイルを処理できます。static void Main(string[] args) { // Initialize Wrapper for File SDK operations. MIP.Initialize(MipComponent.File); // Create ApplicationInfo, setting the clientID from Azure AD App Registration as the ApplicationId. ApplicationInfo appInfo = new ApplicationInfo() { ApplicationId = clientId, ApplicationName = appName, ApplicationVersion = "1.0.0" }; // Instantiate the AuthDelegateImpl object, passing in AppInfo. AuthDelegateImplementation authDelegate = new AuthDelegateImplementation(appInfo); MipContext mipContext = MIP.CreateMipContext(appInfo,"mip_data",LogLevel.Trace,null,null); // Initialize and instantiate the File Profile. // Create the FileProfileSettings object. // Initialize file profile settings to create/use local state. var profileSettings = new FileProfileSettings(mipContext, CacheStorageType.OnDiskEncrypted, new ConsentDelegateImplementation()); // Load the Profile async and wait for the result. var fileProfile = Task.Run(async () => await MIP.LoadFileProfileAsync(profileSettings)).Result; // Create a FileEngineSettings object, then use that to add an engine to the profile. var customSettings = new List<KeyValuePair<string, string>>(); customSettings.Add(new KeyValuePair<string, string>("enable_msg_file_type", "true")); // Create a FileEngineSettings object, then use that to add an engine to the profile. var engineSettings = new FileEngineSettings("user1@tenant.com", authDelegate, "", "en-US"); engineSettings.Identity = new Identity("user1@tenant.com"); //set custom settings for the engine engineSettings.CustomSettings = customSettings; //Add fileEngine to profile var fileEngine = Task.Run(async () => await fileProfile.AddEngineAsync(engineSettings)).Result; //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 var fileHandler = Task.Run(async () => await fileEngine.CreateFileHandlerAsync(inputFilePath, actualFilePath, true)).Result; // List labels available to the user and use one of them to label the MSG file. foreach (var label in fileEngine.SensitivityLabels) { Console.WriteLine(string.Format("{0} - {1}", label.Name, label.Id)); if (label.Children.Count > 0) { foreach (Label child in label.Children) { Console.WriteLine(string.Format("\t{0} - {1}", child.Name, child.Id)); } } } string labelId = "<label-id>"; //label retrieved using file engine LabelingOptions labelingOptions = new LabelingOptions() { AssignmentMethod = options.AssignmentMethod }; fileHandler.SetLabel(labelId, labelingOptions, new ProtectionSettings()); // Commit changes, save as outputFilePath var result = Task.Run(async () => await fileHandler.CommitAsync(outputFilePath)).Result; // Create a new handler to read the labeled file metadata var handlerModified = Task.Run(async () => await fileEngine.CreateFileHandlerAsync(outputFilePath, actualOutputFilePath, true)).Result; Console.WriteLine(string.Format("Original file: {0}", inputFilePath)); Console.WriteLine(string.Format("Labeled file: {0}", outputFilePath)); Console.WriteLine(string.Format("Label applied to file: {0}", handlerModified.Label.Name)); Console.WriteLine("Press a key to continue."); Console.ReadKey(); // Application Shutdown fileHandler = null; handlerModified = null; fileEngine = null; fileProfile = null; mipContext = null; }
ファイル操作の詳細については、 ファイル ハンドラーの概念を参照してください。
次の値を使用して、ソース コード内のプレースホルダーの値を置き換えます。
プレースホルダー 価値 <入力ファイルパス> テスト入力メッセージ ファイルへの完全なパス (例: c:\\Test\\message.msg
)。<出力ファイルパス> 出力ファイルへの完全なパス。入力ファイルのラベル付きコピーになります (例: c:\\Test\\message_labeled.msg
)。<label-id> ファイル エンジンを使用して取得された labelId (例: 667466bf-a01b-4b0a-8bbf-a79a3d96f720
)。
アプリケーションのビルドとテスト
F6 (ソリューションのビルド) を使用して、クライアント アプリケーションをビルドします。 ビルド エラーがない場合は、 F5 (デバッグの開始) を使用してアプリケーションを実行します。
Original file: C:\Test.msg
Labeled file: C:\Test_Labeled.msg
Label applied to file: Confidential
Press a key to continue.