Example #1
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir  = RunExamples.GetDataDir_Outlook();
            string dst      = dataDir + "Outlook.pst";
            String dstSplit = dataDir + @"Chunks-Split\";

            // Delete the files if already present
            foreach (string file in Directory.GetFiles(dstSplit))
            {
                File.Delete(file);
            }

            using (PersonalStorage pst = PersonalStorage.FromFile(dst))
            {
                // The events subscription is an optional step for the tracking process only.
                pst.StorageProcessed += PstSplit_OnStorageProcessed;
                pst.ItemMoved        += PstSplit_OnItemMoved;

                // Splits into pst chunks with the size of 300 KB
                pst.SplitInto(300 * 1024, dstSplit);
            }

            Console.WriteLine(Environment.NewLine + "PST split successfully at " + dst);
        }
Example #2
0
        public static void Run()
        {
            // The path to the File directory.
            // ExStart:AddMapiTaskToPST
            string   dataDir = RunExamples.GetDataDir_Outlook();
            MapiTask task    = new MapiTask("To Do", "Just click and type to add new task", DateTime.Now, DateTime.Now.AddDays(3));

            task.PercentComplete    = 20;
            task.EstimatedEffort    = 2000;
            task.ActualEffort       = 20;
            task.History            = MapiTaskHistory.Assigned;
            task.LastUpdate         = DateTime.Now;
            task.Users.Owner        = "Darius";
            task.Users.LastAssigner = "Harkness";
            task.Users.LastDelegate = "Harkness";
            task.Users.Ownership    = MapiTaskOwnership.AssignersCopy;

            string alreadyCreated = dataDir + "AddMapiTaskToPST_out.pst";

            if (File.Exists(alreadyCreated))
            {
                File.Delete(alreadyCreated);
            }
            else
            {
            }

            using (PersonalStorage personalStorage = PersonalStorage.Create(dataDir + "AddMapiTaskToPST_out.pst", FileFormatVersion.Unicode))
            {
                FolderInfo taskFolder = personalStorage.CreatePredefinedFolder("Tasks", StandardIpmFolder.Tasks);
                taskFolder.AddMapiMessageItem(task);
            }
            // ExEnd:AddMapiTaskToPST
        }
        /// <summary>
        /// This is a recursive method to display contents of a folder
        /// </summary>
        /// <param name="folderInfo"></param>
        /// <param name="pst"></param>
        private static void DisplayFolderContents(FolderInfo folderInfo, PersonalStorage pst)
        {
            // ExStart:GetMessageInformationDisplayFolderContents
            // Display the folder name
            Console.WriteLine("Folder: " + folderInfo.DisplayName);
            Console.WriteLine("==================================");
            // Display information about messages inside this folder
            MessageInfoCollection messageInfoCollection = folderInfo.GetContents();
            foreach (MessageInfo messageInfo in messageInfoCollection)
            {
                Console.WriteLine("Subject: " + messageInfo.Subject);
                Console.WriteLine("Sender: " + messageInfo.SenderRepresentativeName);
                Console.WriteLine("Recipients: " + messageInfo.DisplayTo);
                Console.WriteLine("------------------------------");
            }

            // Call this method recursively for each subfolder
            if (folderInfo.HasSubFolders == true)
            {
                foreach (FolderInfo subfolderInfo in folderInfo.GetSubFolders())
                {
                    DisplayFolderContents(subfolderInfo, pst);
                }
            }
            // ExEnd:GetMessageInformationDisplayFolderContents
        }
Example #4
0
        public static void Run()
        {
            //ExStart:1
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_IMAP();
            // Create an instance of the ImapClient class
            ImapClient imapClient = new ImapClient();

            // Specify host, username and password, and set port for your client
            imapClient.Host            = "imap.gmail.com";
            imapClient.Username        = "******";
            imapClient.Password        = "******";
            imapClient.Port            = 993;
            imapClient.SecurityOptions = SecurityOptions.Auto;

            imapClient.UseMultiConnection = MultiConnectionMode.Enable;

            RestoreSettings settings = new RestoreSettings();

            settings.Recursive = true;
            PersonalStorage pst = PersonalStorage.FromFile(dataDir + @"\Outlook.pst");

            imapClient.Restore(pst, settings);
            //ExEnd:1
        }
        public static void Run()
        {
            // The path to the File directory.
            // ExStart:MergePSTFolders
            string dataDir = RunExamples.GetDataDir_Outlook();

            try
            {
                using (PersonalStorage destinationPst = PersonalStorage.FromFile(dataDir + @"destination.pst"))
                    using (PersonalStorage sourcePst = PersonalStorage.FromFile(dataDir + @"source.pst"))
                    {
                        FolderInfo destinationFolder = destinationPst.RootFolder.AddSubFolder("FolderFromAnotherPst");
                        FolderInfo sourceFolder      = sourcePst.GetPredefinedFolder(StandardIpmFolder.DeletedItems);

                        // The events subscription is an optional step for the tracking process only.
                        destinationFolder.ItemMoved += destinationFolder_ItemMoved;

                        // Merges with the folder from another pst.
                        destinationFolder.MergeWith(sourceFolder);
                        Console.WriteLine("Total messages added: {0}", totalAdded);
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose Email License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }
            // ExEnd:MergePSTFolders
        }
        /// <summary>
        /// This is a recursive method to display contents of a folder
        /// </summary>
        /// <param name="folderInfo"></param>
        /// <param name="pst"></param>
        private static void ExtractMsgFiles(FolderInfo folderInfo, PersonalStorage pst)
        {
            // ExStart:ExtractMessagesFromPSTFileExtractMsgFiles
            // display the folder name
            Console.WriteLine("Folder: " + folderInfo.DisplayName);
            Console.WriteLine("==================================");
            // loop through all the messages in this folder
            MessageInfoCollection messageInfoCollection = folderInfo.GetContents();
            foreach (MessageInfo messageInfo in messageInfoCollection)
            {
                Console.WriteLine("Saving message {0} ....", messageInfo.Subject);
                // get the message in MapiMessage instance
                MapiMessage message = pst.ExtractMessage(messageInfo);
                // save this message to disk in msg format
                message.Save(message.Subject.Replace(":", " ") + ".msg");
                // save this message to stream in msg format
                MemoryStream messageStream = new MemoryStream();
                message.Save(messageStream);
            }

            // Call this method recursively for each subfolder
            if (folderInfo.HasSubFolders == true)
            {
                foreach (FolderInfo subfolderInfo in folderInfo.GetSubFolders())
                {
                    ExtractMsgFiles(subfolderInfo, pst);
                }
            }
            // ExEnd:ExtractMessagesFromPSTFileExtractMsgFiles
        }
        public static void Run()
        {
            // ExStart:DeleteMessagesFromPSTFiles
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Outlook() + "Sub.pst";

            // Load the Outlook PST file
            PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir);

            // Get the Sent items folder
            FolderInfo folderInfo = personalStorage.GetPredefinedFolder(StandardIpmFolder.SentItems);

            MessageInfoCollection msgInfoColl = folderInfo.GetContents();

            foreach (MessageInfo msgInfo in msgInfoColl)
            {
                Console.WriteLine(msgInfo.Subject + ": " + msgInfo.EntryIdString);
                if (msgInfo.Subject.Equals("some delete condition") == true)
                {
                    // Delete this item
                    folderInfo.DeleteChildItem(msgInfo.EntryId);
                    Console.WriteLine("Deleted this message");
                }
            }
            // ExStart:DeleteMessagesFromPSTFiles
        }
        public static void Run()
        {
            // The path to the File directory.
            // ExStart:SplitSinglePSTInToMultiplePST
            string dataDir = RunExamples.GetDataDir_Outlook();

            try
            {
                String dstSplit = dataDir + Convert.ToString("Chunks\\");

                // Delete the files if already present
                foreach (string file__1 in Directory.GetFiles(dstSplit))
                {
                    File.Delete(file__1);
                }

                using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "Sub.pst"))
                {
                    // The events subscription is an optional step for the tracking process only.
                    personalStorage.StorageProcessed += PstSplit_OnStorageProcessed;
                    personalStorage.ItemMoved        += PstSplit_OnItemMoved;

                    // Splits into pst chunks with the size of 5mb
                    personalStorage.SplitInto(5000000, dataDir + @"\Chunks\");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose Email License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }
            // ExEnd:SplitSinglePSTInToMultiplePST
        }
        static void Main(string[] args)
        {
            string pstFilePath = "sample.pst";

            // Create an instance of PersonalStorage and load the PST from file
            using (PersonalStorage personalStorage = PersonalStorage.FromFile(pstFilePath))
            {
                // Get the list of subfolders in PST file
                FolderInfoCollection folderInfoCollection = personalStorage.RootFolder.GetSubFolders();
                // Traverse through all folders in the PST file
                // TODO: This is not recursive
                foreach (FolderInfo folderInfo in folderInfoCollection)
                {
                    // Get all messages in this folder
                    MessageInfoCollection messageInfoCollection = folderInfo.GetContents();
                    // Loop through all the messages in this folder
                    foreach (MessageInfo messageInfo in messageInfoCollection)
                    {
                        // Extract the message in MapiMessage instance
                        MapiMessage message = personalStorage.ExtractMessage(messageInfo);
                        Console.WriteLine("Saving message {0} ....", message.Subject);
                        // Save the message to disk in MSG format
                        // TODO: File name may contain invalid characters [\ / : * ? " < > |]
                        message.Save(@"\extracted\" + message.Subject + ".msg");
                    }
                }
            }
        }
        public static void Run()
        {
            // The path to the File directory.
            // ExStart:ExtractAttachmentsFromPSTMessages
            string dataDir = RunExamples.GetDataDir_Outlook();

            using (PersonalStorage personalstorage = PersonalStorage.FromFile(dataDir + "Outlook.pst"))
            {
                FolderInfo folder = personalstorage.RootFolder.GetSubFolder("Inbox");

                foreach (var messageInfo in folder.EnumerateMessagesEntryId())
                {
                    MapiAttachmentCollection attachments = personalstorage.ExtractAttachments(messageInfo);

                    if (attachments.Count != 0)
                    {
                        foreach (var attachment in attachments)
                        {
                            if (!string.IsNullOrEmpty(attachment.LongFileName))
                            {
                                if (attachment.LongFileName.Contains(".msg"))
                                {
                                    continue;
                                }
                                else
                                {
                                    attachment.Save(dataDir + @"\Attachments\" + attachment.LongFileName);
                                }
                            }
                        }
                    }
                }
            }
            // ExEnd:ExtractAttachmentsFromPSTMessages
        }
        Response ConvertPstToMht(string fileName, string folderName)
        {
            return(ProcessTask(fileName, folderName, delegate(string inputFilePath, string outputFolderPath)
            {
                // Save as mht with header
                var mhtSaveOptions = new MhtSaveOptions
                {
                    //Specify formatting options required
                    //Here we are specifying to write header informations to output without writing extra print header
                    //and the output headers should display as the original headers in message
                    MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader | MhtFormatOptions.DisplayAsOutlook,
                    // Check the body encoding for validity.
                    CheckBodyContentEncoding = true
                };

                using (var personalStorage = PersonalStorage.FromFile(inputFilePath))
                {
                    int i = 0;
                    HandleFolderAndSubfolders(mapiMessage =>
                    {
                        mapiMessage.Save(Path.Combine(outputFolderPath, "Message" + i++ + ".mht"), mhtSaveOptions);
                    }, personalStorage.RootFolder, new MailConversionOptions());
                }
            }));
        }
        /// <summary>
        /// This is a recursive method to display contents of a folder
        /// </summary>
        /// <param name="folderInfo"></param>
        /// <param name="pst"></param>
        private static void DisplayFolderContents(FolderInfo folderInfo, PersonalStorage pst)
        {
            // ExStart:GetMessageInformationDisplayFolderContents
            // Display the folder name
            Console.WriteLine("Folder: " + folderInfo.DisplayName);
            Console.WriteLine("==================================");
            // Display information about messages inside this folder
            MessageInfoCollection messageInfoCollection = folderInfo.GetContents();

            foreach (MessageInfo messageInfo in messageInfoCollection)
            {
                Console.WriteLine("Subject: " + messageInfo.Subject);
                Console.WriteLine("Sender: " + messageInfo.SenderRepresentativeName);
                Console.WriteLine("Recipients: " + messageInfo.DisplayTo);
                Console.WriteLine("------------------------------");
            }

            // Call this method recursively for each subfolder
            if (folderInfo.HasSubFolders == true)
            {
                foreach (FolderInfo subfolderInfo in folderInfo.GetSubFolders())
                {
                    DisplayFolderContents(subfolderInfo, pst);
                }
            }
            // ExEnd:GetMessageInformationDisplayFolderContents
        }
Example #13
0
        public static void Run()
        {
            // ExStart:AddMessagesToPSTFiles
            // The path to the file directory.
            string dataDir = RunExamples.GetDataDir_Outlook() + "AddMessagesToPSTFiles_out.pst";

            if (File.Exists(dataDir))
            {
                File.Delete(dataDir);
            }
            else
            {
            }

            // Create new PST
            PersonalStorage personalStorage = PersonalStorage.Create(dataDir, FileFormatVersion.Unicode);

            // Add new folder "Inbox"
            personalStorage.RootFolder.AddSubFolder("Inbox");

            // Select the "Inbox" folder
            FolderInfo inboxFolder = personalStorage.RootFolder.GetSubFolder("Inbox");

            // Add some messages to "Inbox" folder
            inboxFolder.AddMessage(MapiMessage.FromFile(RunExamples.GetDataDir_Outlook() + "MapiMsgWithPoll.msg"));
            // ExEnd:AddMessagesToPSTFiles
        }
        public static void Run()
        {
            // The path to the File directory.
            // ExStart:SearchStringInPSTWithIgnoreCaseParameter
            string dataDir = RunExamples.GetDataDir_Outlook();

            string path = dataDir + "SearchStringInPSTWithIgnoreCaseParameter_out.pst";

            if (File.Exists(path))
            {
                File.Delete(path);
            }


            using (PersonalStorage personalStorage = PersonalStorage.Create(dataDir + "SearchStringInPSTWithIgnoreCaseParameter_out.pst", FileFormatVersion.Unicode))
            {
                FolderInfo folderInfo = personalStorage.CreatePredefinedFolder("Inbox", StandardIpmFolder.Inbox);

                folderInfo.AddMessage(MapiMessage.FromMailMessage(MailMessage.Load(dataDir + "Message.eml")));

                PersonalStorageQueryBuilder builder = new PersonalStorageQueryBuilder();
                // IgnoreCase is True
                builder.From.Contains("automated", true);

                MailQuery             query = builder.GetQuery();
                MessageInfoCollection coll  = folderInfo.GetContents(query);
                Console.WriteLine(coll.Count);
            }
            // ExEnd:SearchStringInPSTWithIgnoreCaseParameter
        }
Example #15
0
        public static void Run()
        {
            // The path to the File directory.
            // ExStart:MoveItemsToOtherFolders
            string dataDir = RunExamples.GetDataDir_Outlook();

            using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "Outlook_1.pst"))
            {
                FolderInfo inbox     = personalStorage.GetPredefinedFolder(StandardIpmFolder.Inbox);
                FolderInfo deleted   = personalStorage.GetPredefinedFolder(StandardIpmFolder.DeletedItems);
                FolderInfo subfolder = inbox.GetSubFolder("Inbox");

                if (subfolder != null)
                {
                    // Move folder to the Deleted Items
                    personalStorage.MoveItem(subfolder, deleted);

                    // Move message to the Deleted Items
                    MessageInfoCollection contents = subfolder.GetContents();
                    personalStorage.MoveItem(contents[0], deleted);

                    // Move all inbox subfolders to the Deleted Items
                    inbox.MoveSubfolders(deleted);

                    // Move all subfolder contents to the Deleted Items
                    subfolder.MoveContents(deleted);
                }
            }
            // ExEnd:MoveItemsToOtherFolders
        }
        Response ConvertMailToOst(string fileName, string folderName)
        {
            return(ProcessTask(fileName, folderName, delegate(string inFilePath, string outPath)
            {
                var msg = MapiHelper.GetMailMessageFromFile(inFilePath);
                var temporaryPstFileName = Path.Combine(outPath, Path.GetFileNameWithoutExtension(fileName) + ".pst");

                try
                {
                    using (var personalStorage = PersonalStorage.Create(temporaryPstFileName, FileFormatVersion.Unicode))
                    {
                        var inbox = personalStorage.RootFolder.AddSubFolder("Inbox");

                        inbox.AddMessage(MapiMessage.FromMailMessage(msg, MapiConversionOptions.UnicodeFormat));

                        var ostFileName = Path.Combine(outPath, Path.GetFileNameWithoutExtension(fileName) + ".ost");
                        personalStorage.SaveAs(ostFileName, FileFormat.Ost);
                    }
                }
                finally
                {
                    if (System.IO.File.Exists(temporaryPstFileName))
                    {
                        System.IO.File.Delete(temporaryPstFileName);
                    }
                }
            }));
        }
Example #17
0
        public static void Run()
        {
            // ExStart:ExtractMessagesFromPSTFile
            // The path to the file directory.
            string dataDir = RunExamples.GetDataDir_Outlook();

            // Load the Outlook file
            string path = dataDir + "PersonalStorage.pst";

            try
            {
                // load the Outlook PST file
                PersonalStorage pst = PersonalStorage.FromFile(path);

                // get the Display Format of the PST file
                Console.WriteLine("Display Format: " + pst.Format);

                // get the folders and messages information
                FolderInfo folderInfo = pst.RootFolder;

                // Call the recursive method to extract msg files from each folder
                ExtractMsgFiles(folderInfo, pst);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:ExtractMessagesFromPSTFile
        }
Example #18
0
        public static void Run()
        {
            // The path to the File directory.
            // ExStart:SetPasswordOnPST
            string dataDir = RunExamples.GetDataDir_Outlook();

            string alreadyCreated = dataDir + "SetPasswordOnPST_out.pst";

            if (File.Exists(alreadyCreated))
            {
                File.Delete(alreadyCreated);
            }
            else
            {
            }


            using (PersonalStorage pst = PersonalStorage.Create(dataDir + "SetPasswordOnPST_out.pst", FileFormatVersion.Unicode))
            {
                // Set the password
                const string password = "******";
                pst.Store.ChangePassword(password);
                // Remove the password
                pst.Store.ChangePassword(null);
            }
            // ExEnd:SetPasswordOnPST
        }
Example #19
0
        /// <summary>
        /// This is a recursive method to display contents of a folder
        /// </summary>
        /// <param name="folderInfo"></param>
        /// <param name="pst"></param>
        private static void ExtractMsgFiles(FolderInfo folderInfo, PersonalStorage pst)
        {
            // ExStart:ExtractMessagesFromPSTFileExtractMsgFiles
            // display the folder name
            Console.WriteLine("Folder: " + folderInfo.DisplayName);
            Console.WriteLine("==================================");
            // loop through all the messages in this folder
            MessageInfoCollection messageInfoCollection = folderInfo.GetContents();

            foreach (MessageInfo messageInfo in messageInfoCollection)
            {
                Console.WriteLine("Saving message {0} ....", messageInfo.Subject);
                // get the message in MapiMessage instance
                MapiMessage message = pst.ExtractMessage(messageInfo);
                // save this message to disk in msg format
                message.Save(message.Subject.Replace(":", " ") + ".msg");
                // save this message to stream in msg format
                MemoryStream messageStream = new MemoryStream();
                message.Save(messageStream);
            }

            // Call this method recursively for each subfolder
            if (folderInfo.HasSubFolders == true)
            {
                foreach (FolderInfo subfolderInfo in folderInfo.GetSubFolders())
                {
                    ExtractMsgFiles(subfolderInfo, pst);
                }
            }
            // ExEnd:ExtractMessagesFromPSTFileExtractMsgFiles
        }
Example #20
0
        public static void Run()
        {
            // ExStart:DeleteBulkItemsFromPSTFile
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Outlook() + @"Sub.pst";

            using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir))
            {
                // Get Inbox SubFolder from Outlook file
                FolderInfo inbox = personalStorage.RootFolder.GetSubFolder("Inbox");

                // Create instance of PersonalStorageQueryBuilder
                PersonalStorageQueryBuilder queryBuilder = new PersonalStorageQueryBuilder();

                queryBuilder.From.Contains("*****@*****.**");
                MessageInfoCollection messages   = inbox.GetContents(queryBuilder.GetQuery());
                IList <string>        deleteList = new List <string>();
                foreach (MessageInfo messageInfo in messages)
                {
                    deleteList.Add(messageInfo.EntryIdString);
                }

                // delete messages having From = "*****@*****.**"
                inbox.DeleteChildItems(deleteList);
            }
            // ExEnd:DeleteBulkItemsFromPSTFile
        }
        public static void Run()
        {
            // ExStart:GetMessageInformation
            string dataDir = RunExamples.GetDataDir_Outlook();

            // Load the Outlook file
            string path = dataDir + "PersonalStorage.pst";

            try
            {
                // Load the Outlook PST file
                PersonalStorage personalStorage = PersonalStorage.FromFile(path);

                // Get the Display Format of the PST file
                Console.WriteLine("Display Format: " + personalStorage.Format);

                // Get the folders and messages information
                FolderInfo folderInfo = personalStorage.RootFolder;

                // Call the recursive method to display the folder contents
                DisplayFolderContents(folderInfo, personalStorage);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:GetMessageInformation
        }
        public static void Run()
        {
            // ExStart:MergePSTFiles
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Outlook();
            string dst     = dataDir + "Sub.pst";

            totalAdded = 0;
            try
            {
                using (PersonalStorage personalStorage = PersonalStorage.FromFile(dst))
                {
                    // The events subscription is an optional step for the tracking process only.
                    personalStorage.StorageProcessed += PstMerge_OnStorageProcessed;
                    personalStorage.ItemMoved        += PstMerge_OnItemMoved;

                    // Merges with the pst files that are located in separate folder.
                    personalStorage.MergeWith(Directory.GetFiles(dataDir + @"MergePST\"));
                    Console.WriteLine("Total messages added: {0}", totalAdded);
                }
                Console.WriteLine(Environment.NewLine + "PST merged successfully at " + dst);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose Email License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }
            // ExEnd:MergePSTFiles
        }
Example #23
0
        public static void Run()
        {
            // ExStart:AccessContactInformation
            // Load the Outlook file
            string dataDir = RunExamples.GetDataDir_Outlook();

            // Load the Outlook PST file
            PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "SampleContacts.pst");
            // Get the Contacts folder
            FolderInfo folderInfo = personalStorage.RootFolder.GetSubFolder("Contacts");
            // Loop through all the contacts in this folder
            MessageInfoCollection messageInfoCollection = folderInfo.GetContents();

            foreach (MessageInfo messageInfo in messageInfoCollection)
            {
                // Get the contact information
                MapiMessage mapi = personalStorage.ExtractMessage(messageInfo);

                MapiContact contact = (MapiContact)mapi.ToMapiMessageItem();

                // Display some contents on screen
                Console.WriteLine("Name: " + contact.NameInfo.DisplayName);
                // Save to disk in MSG format
                if (contact.NameInfo.DisplayName != null)
                {
                    MapiMessage message = personalStorage.ExtractMessage(messageInfo);
                    // Get rid of illegal characters that cannot be used as a file name
                    string messageName = message.Subject.Replace(":", " ").Replace("\\", " ").Replace("?", " ").Replace("/", " ");
                    message.Save(dataDir + "Contacts\\" + messageName + "_out.msg");
                }
            }
            // ExEnd:AccessContactInformation
        }
Example #24
0
 // ExStart:AddingBulkMessages
 private static void AddMessagesInBulkMode(string fileName, string msgFolderName)
 {
     using (PersonalStorage personalStorage = PersonalStorage.FromFile(fileName))
     {
         FolderInfo folder = personalStorage.RootFolder.GetSubFolder("myInbox");
         folder.MessageAdded += OnMessageAdded;
         folder.AddMessages(new MapiMessageCollection(msgFolderName));
     }
 }
Example #25
0
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Outlook();

            // ExStart:LoadingPSTFile
            // Load the Outlook PST file
            PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + @"PersonalStorage.pst");
            // ExEnd:LoadingPSTFile
        }
Example #26
0
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Outlook();

            // ExStart:CreateFolderHierarchyUsingStringNotation
            PersonalStorage personalStorage = PersonalStorage.Create(dataDir + "CreateFolderHierarchyUsingStringNotation.pst", FileFormatVersion.Unicode);

            personalStorage.RootFolder.AddSubFolder(@"Inbox\Folder1\Folder2", true);
            // ExEnd:CreateFolderHierarchyUsingStringNotation
        }
 /// <summary>
 /// Determines whether the specified PST is password protected.
 /// </summary>
 private static bool IsPasswordProtected(PersonalStorage pst)
 {
     // If the property exists and is nonzero, then the PST file is password protected.
     if (pst.Store.Properties.ContainsKey(MapiPropertyTag.PR_PST_PASSWORD))
     {
         long passwordHash = pst.Store.Properties[MapiPropertyTag.PR_PST_PASSWORD].GetLong();
         return(passwordHash != 0);
     }
     return(false);
 }
        public static void Run()
        {
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Outlook();

            using (PersonalStorage pst = PersonalStorage.FromFile(dataDir + "passwordprotectedPST.pst"))
            {
                Console.WriteLine("PST is protected: {0}", IsPasswordProtected(pst));
            }
        }
 ///<Summary>
 /// ConvertPstToOst method to convert pst to ost file
 ///</Summary>
 public Response ConvertPstToOst(string fileName, string folderName)
 {
     return(ProcessTask(fileName, folderName, ".ost", false, false, delegate(string inFilePath, string outPath, string zipOutFolder)
     {
         using (var personalStorage = PersonalStorage.FromFile(inFilePath))
         {
             personalStorage.SaveAs(outPath, FileFormat.Ost);
         }
     }));
 }
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Outlook();

            // ExStart:ConvertingOSTToPST
            using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "PersonalStorageFile.ost"))
            {
                personalStorage.SaveAs(dataDir + "test.pst", FileFormat.Pst);
            }
            // ExEnd:ConvertingOSTToPST
        }
Example #31
0
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Outlook();

            // ExStart:ReadingOSTFiles
            PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "PersonalStorageFile.ost");

            // Get the format of the file
            Console.WriteLine("File Format of OST: " + personalStorage.Format);
            // ExEnd:ReadingOSTFiles
        }
        public static void Run()
        {
            //ExStart: ModifyDeleteOccurrenceInRecurrence
            DateTime startDate = DateTime.Now.Date.AddHours(12);

            MapiCalendarEventRecurrence   recurrence = new MapiCalendarEventRecurrence();
            MapiCalendarRecurrencePattern pattern    = recurrence.RecurrencePattern = new MapiCalendarDailyRecurrencePattern();

            pattern.PatternType = MapiCalendarRecurrencePatternType.Day;
            pattern.Period      = 1;
            pattern.EndType     = MapiCalendarRecurrenceEndType.NeverEnd;

            DateTime exceptionDate = startDate.AddDays(1);

            // adding one exception
            pattern.Exceptions.Add(new MapiCalendarExceptionInfo
            {
                Location          = "London",
                Subject           = "Subj",
                OriginalStartDate = exceptionDate,
                StartDateTime     = exceptionDate,
                EndDateTime       = exceptionDate.AddHours(5)
            });
            pattern.ModifiedInstanceDates.Add(exceptionDate);
            // every modified instance also has to have an entry in the DeletedInstanceDates field with the original instance date.
            pattern.DeletedInstanceDates.Add(exceptionDate);

            // adding one deleted instance
            pattern.DeletedInstanceDates.Add(exceptionDate.AddDays(2));


            MapiRecipientCollection recColl = new MapiRecipientCollection();

            recColl.Add("*****@*****.**", "receiver", MapiRecipientType.MAPI_TO);
            MapiCalendar newCal = new MapiCalendar(
                "This is Location",
                "This is Summary",
                "This is recurrence test",
                startDate,
                startDate.AddHours(3),
                "*****@*****.**",
                recColl);

            newCal.Recurrence = recurrence;

            using (MemoryStream memory = new MemoryStream())
            {
                PersonalStorage pst            = PersonalStorage.Create(memory, FileFormatVersion.Unicode);
                FolderInfo      calendarFolder = pst.CreatePredefinedFolder("Calendar", StandardIpmFolder.Appointments);
                calendarFolder.AddMapiMessageItem(newCal);
            }
            //ExEnd: ModifyDeleteOccurrenceInRecurrence
        }
 /// <summary>
 /// Determines whether the specified PST is password protected.
 /// </summary>
 private static bool IsPasswordProtected(PersonalStorage pst)
 {
     // ExStart:CheckPasswordProtection-IsPasswordProtected
     // If the property exists and is nonzero, then the PST file is password protected.
     if (pst.Store.Properties.Contains(MapiPropertyTag.PR_PST_PASSWORD))
     {
         long passwordHash = pst.Store.Properties[MapiPropertyTag.PR_PST_PASSWORD].GetLong();
         return passwordHash != 0;
     }
     return false;
     // ExEnd:CheckPasswordProtection-IsPasswordProtected
 }