Пример #1
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
        }
Пример #2
0
        private MessageInfo GetEmailMessagesById(FolderInfo folderInfo, string fieldId)
        {
            MessageInfo           result = null;
            MessageInfoCollection messageInfoCollection = folderInfo.GetContents();

            foreach (MessageInfo messageInfo in messageInfoCollection)
            {
                if (messageInfo.EntryIdString == fieldId)
                {
                    result = messageInfo;
                    break;
                }
            }

            if (result == null && folderInfo.HasSubFolders)
            {
                foreach (FolderInfo subfolderInfo in folderInfo.GetSubFolders())
                {
                    result = GetEmailMessagesById(subfolderInfo, fieldId);
                    if (result != null)
                    {
                        break;
                    }
                }
            }
            return(result);
        }
Пример #3
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
        }
Пример #4
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
        }
Пример #5
0
        public void OpenFoundMessageUsingAsposeEmail(string searchString)
        {
            string myPstFile = Utilities.pathToPstFile;
            // Indexing MS Outlook storage with email messages
            Index index = new Index(Utilities.indexPath);

            index.OperationFinished += Utilities.index_OperationFinished;
            index.AddToIndex(myPstFile);

            // Searching in index
            SearchResults results = index.Search(searchString);

            // User gets all messages that qualify to search query using Aspose.Email API
            MessageInfoCollection messages = new MessageInfoCollection();

            foreach (DocumentResultInfo searchResult in results)
            {
                if (searchResult.DocumentType == DocumentType.OutlookEmailMessage)
                {
                    OutlookEmailMessageResultInfo emailResultInfo = searchResult as OutlookEmailMessageResultInfo;
                    MessageInfo message = GetEmailMessagesById(Utilities.pathToPstFile, emailResultInfo.EntryIdString);
                    if (message != null)
                    {
                        messages.Add(message);
                    }
                }
            }
        }
        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
        }
Пример #7
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
        }
Пример #8
0
        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()
        {
            // 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
        }
        /// <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
        }
Пример #11
0
        // ExStart:AddMessagesFromOtherPST
        private static void BulkAddFromAnotherPst(string source)
        {
            using (PersonalStorage pst = PersonalStorage.FromFile(source, false))
                using (PersonalStorage pstDest = PersonalStorage.FromFile(RunExamples.GetDataDir_Outlook() + "PersonalStorageFile1.pst"))
                {
                    // Get the folder by name
                    FolderInfo            folderInfo = pst.RootFolder.GetSubFolder("Contacts");
                    MessageInfoCollection ms         = folderInfo.GetContents();

                    // Get the folder by name
                    FolderInfo f = pstDest.RootFolder.GetSubFolder("myInbox");
                    f.MessageAdded += new MessageAddedEventHandler(OnMessageAdded);
                    f.AddMessages(folderInfo.EnumerateMapiMessages());
                    FolderInfo            fi   = pstDest.RootFolder.GetSubFolder("myInbox");
                    MessageInfoCollection msgs = fi.GetContents();
                }
        }
        public static void Run()
        {
            // ExStart:ExtractNumberOfMessages
            // The path to the file directory.
            string dataDir = RunExamples.GetDataDir_Outlook();

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

            // Save message to file
            using (PersonalStorage personalStorage = PersonalStorage.FromFile(path))
            {
                FolderInfo            inbox    = personalStorage.RootFolder.GetSubFolder("Inbox");
                MessageInfoCollection messages = inbox.GetContents(10, 100);    // Extracts messages starting from 10th index top and extract total 100 messages
            }
            // ExEnd:ExtractNumberOfMessages
        }
        public static void Run()
        {
            // ExStart:UpdateBulkMessagesInPSTFile
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Outlook() + "Sub.pst";

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

            // Get Requierd Subfolder
            FolderInfo inbox = personalStorage.RootFolder.GetSubFolder("Inbox");

            // find messages having From = "*****@*****.**"
            PersonalStorageQueryBuilder queryBuilder = new PersonalStorageQueryBuilder();

            queryBuilder.From.Contains("*****@*****.**");

            // Get Contents from Query
            MessageInfoCollection messages = inbox.GetContents(queryBuilder.GetQuery());

            // Save (MessageInfo,EntryIdString) in List
            IList <string> changeList = new List <string>();

            foreach (MessageInfo messageInfo in messages)
            {
                changeList.Add(messageInfo.EntryIdString);
            }

            // Compose the new properties
            MapiPropertyCollection updatedProperties = new MapiPropertyCollection();

            updatedProperties.Add(MapiPropertyTag.PR_SUBJECT_W, new MapiProperty(MapiPropertyTag.PR_SUBJECT_W, Encoding.Unicode.GetBytes("New Subject")));
            updatedProperties.Add(MapiPropertyTag.PR_IMPORTANCE, new MapiProperty(MapiPropertyTag.PR_IMPORTANCE, BitConverter.GetBytes((long)2)));

            // update messages having From = "*****@*****.**" with new properties
            inbox.ChangeMessages(changeList, updatedProperties);
            // ExEnd:UpdateBulkMessagesInPSTFile
        }
Пример #14
0
        public static void Run()
        {
            // ExStart:SaveContactInformation
            // Load the Outlook file
            string dataDir = RunExamples.GetDataDir_Outlook();

            // Load the Outlook PST file
            PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "Outlook.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
                MapiContact contact = (MapiContact)personalStorage.ExtractMessage(messageInfo).ToMapiMessageItem();
                // Display some contents on screen
                Console.WriteLine("Name: " + contact.NameInfo.DisplayName + " - " + messageInfo.EntryIdString);
                // Save to disk in vCard VCF format
                contact.Save(dataDir + "Contacts\\" + contact.NameInfo.DisplayName + ".vcf", ContactSaveFormat.VCard);
            }
            // ExEnd:SaveContactInformation
        }
        public static void Run()
        {
            // ExStart:SaveCalendarItems
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Outlook();

            // Load the Outlook PST file
            PersonalStorage pst = PersonalStorage.FromFile(dataDir + "Sub.pst");
            // Get the Calendar folder
            FolderInfo folderInfo = pst.RootFolder.GetSubFolder("Inbox");
            // Loop through all the calendar items in this folder
            MessageInfoCollection messageInfoCollection = folderInfo.GetContents();

            foreach (MessageInfo messageInfo in messageInfoCollection)
            {
                // Get the calendar information
                MapiMessage calendar = (MapiMessage)pst.ExtractMessage(messageInfo).ToMapiMessageItem();
                // Display some contents on screen
                Console.WriteLine("Name: " + calendar.Subject);
                // Save to disk in ICS format
                calendar.Save(dataDir + @"\Calendar\" + calendar.Subject + "_out.ics");
            }
            // ExEnd:SaveCalendarItems
        }
        public static void Run()
        {
            // ExStart:SearchMessagesAndFoldersInPST
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Outlook();

            using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "Outlook.pst"))
            {
                FolderInfo folder = personalStorage.RootFolder.GetSubFolder("Inbox");
                PersonalStorageQueryBuilder builder = new PersonalStorageQueryBuilder();

                // High importance messages
                builder.Importance.Equals((int)MapiImportance.High);
                MessageInfoCollection messages = folder.GetContents(builder.GetQuery());
                Console.WriteLine("Messages with High Imp:" + messages.Count);

                builder = new PersonalStorageQueryBuilder();
                builder.MessageClass.Equals("IPM.Note");
                messages = folder.GetContents(builder.GetQuery());
                Console.WriteLine("Messages with IPM.Note:" + messages.Count);

                builder = new PersonalStorageQueryBuilder();
                // Messages with attachments AND high importance
                builder.Importance.Equals((int)MapiImportance.High);
                builder.HasFlags(MapiMessageFlags.MSGFLAG_HASATTACH);
                messages = folder.GetContents(builder.GetQuery());
                Console.WriteLine("Messages with atts: " + messages.Count);

                builder = new PersonalStorageQueryBuilder();
                // Messages with size > 15 KB
                builder.MessageSize.Greater(15000);
                messages = folder.GetContents(builder.GetQuery());
                Console.WriteLine("messags size > 15Kb:" + messages.Count);

                builder = new PersonalStorageQueryBuilder();
                // Unread messages
                builder.HasNoFlags(MapiMessageFlags.MSGFLAG_READ);
                messages = folder.GetContents(builder.GetQuery());
                Console.WriteLine("Unread:" + messages.Count);

                builder = new PersonalStorageQueryBuilder();
                // Unread messages with attachments
                builder.HasNoFlags(MapiMessageFlags.MSGFLAG_READ);
                builder.HasFlags(MapiMessageFlags.MSGFLAG_HASATTACH);
                messages = folder.GetContents(builder.GetQuery());
                Console.WriteLine("Unread msgs with atts: " + messages.Count);

                // Folder with name of 'SubInbox'
                builder = new PersonalStorageQueryBuilder();
                builder.FolderName.Equals("SubInbox");
                FolderInfoCollection folders = folder.GetSubFolders(builder.GetQuery());
                Console.WriteLine("Folder having subfolder: " + folders.Count);

                builder = new PersonalStorageQueryBuilder();
                // Folders with subfolders
                builder.HasSubfolders();
                folders = folder.GetSubFolders(builder.GetQuery());
                Console.WriteLine(folders.Count);
            }
            // ExEnd:SearchMessagesAndFoldersInPST
        }
Пример #17
0
 public static void RefreshMessages()
 {
     XDocument doc = XDocument.Load(MessagesUrl);
     MessageInfoCollection messages = new MessageInfoCollection(doc.Element("messages").Elements("messageInfo"));
     ZCache.InsertCache(MessagesCacheKey, messages, CacheTime);
 }