예제 #1
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");
                    }
                }
            }
        }
예제 #2
0
        static void CountContents(FolderInfo folder)
        {
            FolderInfoCollection rootFolders = folder.GetSubFolders();

            totalItems += folder.ContentCount;

            if (folder.ContentCount > 0)
            {
                //foreach (var message in folder.GetContents(i, 50))
                foreach (var message in folder.EnumerateMapiMessages())
                {
                    var mi = new MessageInfo {
                        Id = message.InternetMessageId, Subject = message.Subject, AttachmentCount = message.Attachments.Count
                    };
                    Console.WriteLine(mi.Subject);
                    outputData.Add(mi);
                }
            }

            Console.WriteLine(folder.DisplayName + ": " + folder.ContentCount.ToString());

            foreach (FolderInfo subFolder in rootFolders)
            {
                // totalItems += subFolder.GetSubFolders().Count();
                CountContents(subFolder);
            }
        }
예제 #3
0
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Outlook();

            // ExStart:1
            using (PersonalStorage pst = PersonalStorage.FromFile(dataDir + "Outlook.pst"))
            {
                PersonalStorageQueryBuilder queryBuilder = new PersonalStorageQueryBuilder();
                queryBuilder.OnlyFoldersCreatedByUser.Equals(true);


                FolderInfoCollection subfolders = pst.RootFolder.GetSubFolders(queryBuilder.GetQuery());
                foreach (FolderInfo folder in subfolders)
                {
                    Console.WriteLine(folder.DisplayName);
                }
            }
            // ExEnd:1
        }
예제 #4
0
        public static void Run()
        {
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Outlook();
            string dst     = dataDir + "PersonalStorage.pst";

            // load PST file
            PersonalStorage personalStorage = PersonalStorage.FromFile(dst);

            // Get the folders information
            FolderInfoCollection folderInfoCollection = personalStorage.RootFolder.GetSubFolders();

            // Browse through each folder to display folder name and number of messages
            foreach (FolderInfo folderInfo in folderInfoCollection)
            {
                Console.WriteLine("Folder: " + folderInfo.DisplayName);
                Console.WriteLine("Total items: " + folderInfo.ContentCount);
                Console.WriteLine("Total unread items: " + folderInfo.ContentUnreadCount);
                Console.WriteLine("-----------------------------------");
            }
        }
예제 #5
0
        // Walk the folder structure recursively
        private static void WalkFolders(FolderInfo folder, string parentFolderName, IList <string> folderData)
        {
            string displayName = (string.IsNullOrEmpty(folder.DisplayName)) ? "ROOT" : folder.DisplayName;
            string folderNames = string.Format("DisplayName = {0}; Parent.DisplayName = {1}", displayName, parentFolderName);

            folderData.Add(folderNames);
            if (displayName == "Finder")
            {
                Console.WriteLine("Test this case");
            }

            if (!folder.HasSubFolders)
            {
                return;
            }
            FolderInfoCollection coll = folder.GetSubFolders(FolderKind.Search | FolderKind.Normal);

            foreach (FolderInfo subfolder in coll)
            {
                WalkFolders(subfolder, displayName, folderData);
            }
        }
예제 #6
0
            public AndroidFileSystemInfo()
            {
                var folders = new FolderInfoCollection()
                {
                    new AndroidFolderInfo("Data", Environment.DataDirectory),
                    new AndroidFolderInfo("Alarms", Environment.DirectoryAlarms),
                    new AndroidFolderInfo("DCIM (Digital Camera Images)", Environment.DirectoryDcim),
                    new AndroidFolderInfo("Documents", Environment.DirectoryDocuments),
                    new AndroidFolderInfo("Downloads", Environment.DirectoryDownloads),
                    new AndroidFolderInfo("Movies", Environment.DirectoryMovies),
                    new AndroidFolderInfo("Music", Environment.DirectoryMusic),
                    new AndroidFolderInfo("Notifications", Environment.DirectoryNotifications),
                    new AndroidFolderInfo("Pictures", Environment.DirectoryPictures),
                    new AndroidFolderInfo("Podcasts", Environment.DirectoryPodcasts),
                    new AndroidFolderInfo("Ringtones", Environment.DirectoryRingtones),
                    new AndroidFolderInfo("Download Cache", Environment.DownloadCacheDirectory),
                    new AndroidFolderInfo("External Storage", Environment.ExternalStorageDirectory),
                    new AndroidFolderInfo("Root", Environment.RootDirectory)
                };

                InterestingFolders = folders;

                SdcardInfo = new AndroidSdcardInfo();
            }
        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
        }