Exemple #1
0
        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);
            }
        }
Exemple #2
0
        private void processSingleImageFile(string inFile, string outFile)
        {
            FileInfo nwFileInfo = new FileInfo(outFile);

            try
            {
                if (!nwFileInfo.Exists)
                {
                    Directory.CreateDirectory(nwFileInfo.Directory.FullName);
                }
            }
            catch (Exception ex)
            {
                Output.AddLogEntry($"Exception creating dirctory: {ex.Message}", true);
            }

            try
            {
                File.Copy(inFile, outFile, true);
            }
            catch (Exception ex)
            {
                Output.AddLogEntry($"Exception copying file {inFile} to {outFile}: {ex.Message}", true);
            }
        }
Exemple #3
0
        private void processSingleMessage(string folderName, Message inMessage)
        {
            ParsedPstMessage parsedMessage = new ParsedPstMessage()
            {
                FolderName = folderName,
            };

            try
            {
                parsedMessage.CreationTime     = convertPtypTimeToDateTime(inMessage.GetProperty(MAPIProperties.PidTagCreationTime).Value.Value.ToInt64());
                parsedMessage.ModificationTime = convertPtypTimeToDateTime(inMessage.GetProperty(MAPIProperties.PidTagLastModificationTime).Value.Value.ToInt64());
            }
            catch { }

            try
            {
                parsedMessage.Subject = inMessage.GetProperty(MAPIProperties.PidTagSubject).Value.Value.ToUnicode().Trim();
            }
            catch { }
            try
            {
                parsedMessage.Sender = inMessage.GetProperty(MAPIProperties.PidTagSenderEmailAddress).Value.Value.ToUnicode().Trim();
            }
            catch { }
            try
            {
                parsedMessage.Body = inMessage.GetProperty(MAPIProperties.PidTagBody).Value.Value.ToUnicode().Trim();
            }
            catch { }

            try
            {
                foreach (Recipient recipient in inMessage.GetRecipients())
                {
                    try
                    {
                        string recipientAddress = recipient.GetProperty(MAPIProperties.PidTagEmailAddress).Value.Value.ToUnicode();
                        parsedMessage.Recipients.Add(recipientAddress);
                    }
                    catch (Exception ex)
                    {
                        Output.AddLogEntry("recipient.GetProperty(): " + ex.Message, true);
                    }
                }
            }
            catch (Exception ex)
            {
                Output.AddLogEntry("message.GetRecipients(): " + ex.Message, true);
            }

            // TODO: reenable fetching of attachements when rest is working properly -->
            //try
            //{
            //    foreach (Attachment attachment in inMessage.GetAttachments())
            //    {
            //        try
            //        {
            //            string attFilename = attachment.GetProperty(MAPIProperties.PidTagAttachLongFilename).Value.Value.ToUnicode();
            //            parsedMessage.AttachmentNames.Add(attFilename);
            //        }
            //        catch (Exception ex)
            //        {
            //            log.Error(ex.Message);
            //            Errors.Add(ex.Message);
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    updateLogAndJournal(null, "message.GetAttachments(): " + ex.Message, true);
            //}

            ParsedContent.Add(parsedMessage);
            //string filePart = $"{parsedMessage.Sender} - {parsedMessage.Subject}";
            //foreach (char invalidChar in System.IO.Path.GetInvalidFileNameChars())
            //{
            //    filePart = filePart.Replace(invalidChar, '_');
            //}
            //string outFile = $"{outDir}\\{filePart}";



            ////outFile = $"{outDir}\\{msgCounter++.ToString()}";
            //string outFileTxt = outFile + ".txt";
            //string outFilePdf = outFile + ".pdf";


            //string result = parsedMessage.MsgAsString;
            //File.WriteAllText(outFileTxt, result);
            //// TODO: reenable after test -->
            //converter.Convert(outFileTxt, outFilePdf);

            //if (!KeepIntermediateFiles)
            //{
            //    File.Delete(outFileTxt);
            //}

            ////extractAndConvertAttachements(inFile, outFile);
        }