private void AddMailsToFolder(FolderMailItem folderMailItem, RDOFolder parent = null)
        {
            RDOFolder folder = GetFolder(folderMailItem.Name, parent);

            AddFilesToFolder(folderMailItem.Files, folder);

            if (folderMailItem.Folders != null && folderMailItem.Folders.Any())
            {
                foreach (FolderMailItem nestedFolderMailItem in folderMailItem.Folders)
                {
                    AddMailsToFolder(nestedFolderMailItem, folder);
                }
            }
        }
        //suppose to have a folder structure like:
        //Deleted Items
        //Drafts
        //Inbox
        //Junk E-mail
        //Sent Items
        //SPAMfighter
        //the string[] are the eml files
        private FolderMailItem GetFoldersFromWindowsLiveMailLocation(string baseFolderLocation)
        {
            FolderMailItem result = null;

            if (Directory.Exists(baseFolderLocation))
            {
                result = new FolderMailItem();
                string fullPath      = Path.GetFullPath(baseFolderLocation).TrimEnd(Path.DirectorySeparatorChar);
                string directoryName = fullPath.Split(Path.DirectorySeparatorChar).Last();
                result.Name  = directoryName;
                result.Files = Directory.GetFiles(fullPath, "*.eml").Select(mailItemFullPath => new MailItem(mailItemFullPath)).ToList();
                //also subdirectories in directory
                foreach (string directory in Directory.GetDirectories(baseFolderLocation))
                {
                    var folderItem = GetFoldersFromWindowsLiveMailLocation(directory);
                    if (folderItem != null)
                    {
                        result.Folders.Add(folderItem);
                    }
                }
            }
            return(result);
        }
        public void CreatePSTFromWindowsLiveMailFolder(string outputPstFullPath, string windowsLiveMailDirectory)
        {
            //http://www.dimastr.com/redemption/RDOMail.htm
            if (File.Exists(outputPstFullPath) == false && Directory.Exists(windowsLiveMailDirectory))
            {
                session = RedemptionLoader.new_RDOSession();
                session.LogonPstStore(outputPstFullPath);

                FolderMailItem rootFolderMap = GetFoldersFromWindowsLiveMailLocation(windowsLiveMailDirectory);
                if (rootFolderMap != null && rootFolderMap.Folders != null && rootFolderMap.Folders.Any())
                {
                    //add files to root folder
                    AddFilesToFolder(rootFolderMap.Files, session.Stores.DefaultStore.IPMRootFolder);

                    //folders in root folder
                    foreach (FolderMailItem rootFolderMailItem in rootFolderMap.Folders)
                    {
                        AddMailsToFolder(rootFolderMailItem);
                    }
                }
                session.Logoff();
            }
            session = null;
        }