private void processSingleMsgFile(string inFile, string outFile) { FileInfo nwFileInfo = new FileInfo(outFile); if (!nwFileInfo.Exists) { Directory.CreateDirectory(nwFileInfo.Directory.FullName); } string outFileTxt = outFile + ".txt", outFilePdf = outFile + ".pdf"; Output.AddJournalEntry($"Original: {inFile}. New: {outFile}"); var parser = new OutlookMsgParser(inFile); if (parser.Parse()) { IParsedContent parsedContent = parser.ParsedContent.Single <IParsedContent>(); string result = parsedContent.ContentAsString; File.WriteAllText(outFileTxt, result); Converter.ConvertFromCom(outFileTxt, outFilePdf); if (!KeepIntermediateFiles) { File.Delete(outFileTxt); } //extractAndConvertAttachements(inFile, outFile); } else { Output.AddLogEntry($"Failed to parse file {inFile}", true); } }
private void WriteOutputFiles(MailItem mailItem, string destPath) { var outputFileName = $"{mailItem.SenderEmailAddress} - {mailItem.Subject}.msg"; // Save the message to disk in MSG format // File name may contain invalid characters [\ / : * ? " < > |] foreach (char invalidChar in System.IO.Path.GetInvalidFileNameChars()) { outputFileName = outputFileName.Replace(invalidChar, '_'); } Directory.CreateDirectory(destPath); string destinationFilenameMsg = destPath + outputFileName; string destinationFilenameTxt = destinationFilenameMsg + ".txt"; string destinationFilenamePdf = destinationFilenameMsg + ".pdf"; mailItem.SaveAs(destinationFilenameMsg, OlSaveAsType.olMSG); if (_outlookMsgParser.Parse(destinationFilenameMsg)) { IParsedContent parsedContent = _outlookMsgParser.ParsedContent.Single <IParsedContent>(); File.WriteAllText(destinationFilenameTxt, parsedContent.ContentAsString); _converter.ConvertFromCom(destinationFilenameTxt, destinationFilenamePdf); if (!_keepIntermediateFiles) { File.Delete(destinationFilenameTxt); File.Delete(destinationFilenameMsg); } } }