파일 SDK - 전자 메일 .msg 파일 처리(C#)

파일 SDK는 MSG 기능 플래그를 사용하도록 설정하기 위해 애플리케이션이 필요하다는 점을 제외하고 다른 파일 형식과 동일한 방식으로 .msg 파일에 대한 레이블 지정 작업을 지원합니다. 이 빠른 시작에서는 이 플래그를 설정하는 방법을 보여줍니다.

앞에서 설명한 대로 인스턴스화 IFileEngine 하려면 설정 개체가 FileEngineSettings 필요합니다. 애플리케이션은 특정 인스턴스에 대한 사용자 지정 설정을 전달하는 데 사용합니다 FileEngineSettings . enable_msg_file_type의 CustomSettings 속성은 .msg 파일 처리를 활성화하기 위해 FileEngineSettings 플래그를 설정합니다.

필수 조건

아직 완료하지 않은 경우 계속하기 전에 다음 필수 조건을 완료해야 합니다.

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

파일 API 애플리케이션 초기화 빠른 시작에 이어 파일 엔진 생성 코드를 수정하여 enable_msg_file_type flag을 설정한 다음, 파일 엔진을 사용하여 .msg 파일에 레이블을 지정합니다.

  1. 이전 "빠른 시작: 파일 SDK 애플리케이션 초기화(C#)"에서 만든 Visual Studio 솔루션을 엽니다.

  2. 솔루션 탐색기 메서드 구현 Main() 이 포함된 프로젝트에서 .cs 파일을 엽니다. 기본 이름은 프로젝트 생성 시 지정한 이름을 포함한 프로젝트와 동일합니다.

  3. 이전 빠른 시작에서 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);
    
        MipConfiguration mipConfiguration = new MipConfiguration(appInfo, "mip_data", LogLevel.Trace, false, CacheStorageType.OnDiskEncrypted);
        MipContext mipContext = MIP.CreateMipContext(mipConfiguration);
    
        // 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 = AssignmentMethod.Standard
        };
    
        Label label = fileEngine.GetLabelById(labelId);
        fileHandler.SetLabel(label, 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.Label.Name));
        Console.WriteLine("Press a key to continue.");
        Console.ReadKey();
    
        // Application Shutdown
        fileHandler = null;
        handlerModified = null;
        fileEngine = null;
        fileProfile = null;
        mipContext = null;
    }
    
    

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

  4. 소스 코드의 자리 표시자 값을 다음 값으로 바꿉다.

    플레이스홀더 가치
    <입력 파일 경로> 테스트 입력 메시지 파일의 전체 경로(예: c:\\Test\\message.msg.
    <출력 파일 경로> 입력 파일의 레이블이 지정된 복사본인 출력 파일의 전체 경로입니다. 예를 들면 다음과 c:\\Test\\message_labeled.msg같습니다.
    <label-id> 파일 엔진을 사용하여 검색된 레이블 ID(예: 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.