private static List <int> GetFoldersToProcess(MailBee.Outlook.PstFolderCollection folderObjects) { /* Loops through folder names in the PST file and determines which folders to process. * * Args: * - folderObjects: The MailBee PST folder objects. * * Returns: * list: Each item is an identifier for each folder to process. */ Console.WriteLine("Collecting folders to process."); List <int> foldersToProcess = new List <int>(); foreach (MailBee.Outlook.PstFolder folder in folderObjects) { string folderName = NormalizeFolderName(folder.Name); // skip folders starting with "delete" (case insensitive). bool skipFolder = folder.SafeShortName.ToLower().StartsWith("delete"); if (skipFolder == true) { Console.WriteLine("Skipping message folder: " + folderName); } else { Console.WriteLine("Adding message folder: " + folderName); foldersToProcess.Add(folder.PstID); } } return(foldersToProcess); }
static void Main(string[] args) { /* Parses positional command line arguments and converts a PST file to MIME. * * Args: * - accountName: An identifier for the email account. * - pstFile: The PST file to convert. * - outputPath: The directory in which to place the MIME data. * * Example: * `[mono] pst_to_mime.exe sample ../../tests/sample_files/sample.pst ../../tests/sample_files` */ // !!! DO NOT DISTRIBUTE SOURCE CODE WITH THIS VALUE FILLED OUT. !!! string licenseKey = "License_Key_Goes_Here"; // set MailBee license key; exit if the key is invalid/expired. try { MailBee.Global.LicenseKey = licenseKey; } catch (Exception error) { Console.WriteLine("WARNING: Can't use MailBee license key ending in: " + ( licenseKey.Substring(licenseKey.Length - 4))); Console.WriteLine("ERROR: " + error.Message); System.Environment.Exit(1); } // get command line arguments. if (args.Length < 3) { Console.WriteLine("ERROR: Missing required argument(s)"); System.Environment.Exit(1); } string accountName = args[0]; string pstFile = args[1]; string outputPath = args[2]; // set EML output folder. string mimePath = outputPath + "/" + accountName; Console.WriteLine("DEBUG: Setting MIME folder: " + mimePath); // create a MailBee PST object and folder collection; extract PST to EML. Console.WriteLine("Extracting MIME data from PST file: " + pstFile); try { MailBee.Outlook.PstReader pstObject = new MailBee.Outlook.PstReader(pstFile); MailBee.Outlook.PstFolderCollection folderObjects = pstObject.GetPstRootFolders(true); List <int> foldersToProcess = GetFoldersToProcess(folderObjects); ProcessFolders(mimePath, foldersToProcess, folderObjects); System.Environment.Exit(0); } catch (Exception error) { Console.WriteLine("ERROR: " + error.Message); System.Environment.Exit(1); } }
private static void ProcessFolders(string mimePath, List <int> foldersToProcess, MailBee.Outlook.PstFolderCollection folderObjects) { /* Loops through the PST @folderObjects and extracts messages if the PST folder is in * @foldersToProcess. * * Args: * - mimePath: The folder in which to extract the PST. * - foldersToProcess: A list of identifiers of folders to process. * - folderObjects: The MailBee PST folder objects. * * Returns: * null */ Console.WriteLine("Processing folders."); // loop through each PST folder. int totalFromPST = 0; foreach (MailBee.Outlook.PstFolder folder in folderObjects) { // skip folders not in @foldersToProcess. if (foldersToProcess.Contains(folder.PstID) == false) { continue; } // normalize the folder name; create the output path. string folderName = NormalizeFolderName(folder.Name); string folderPath = mimePath + "/" + folderName; Console.WriteLine("Processing folder: " + folderPath); Directory.CreateDirectory(folderPath); // extract messages from the @folder and write them to @folderPath. try { totalFromPST += ProcessMessages(folderPath, folder); } catch (Exception error) { Console.WriteLine("ERROR: " + error.Message); } } Console.WriteLine("Total messages extracted from PST: " + totalFromPST); return; }