Esempio n. 1
0
        /// <summary>
        /// Saves all the embedded object from the RTF <paramref name="inputFile"/> to the
        /// <see cref="outputFolder"/> and returns the files with full path as a list of strings
        /// </summary>
        /// <param name="inputFile">The RTF file</param>
        /// <param name="outputFolder">The output folder</param>
        /// <returns>List with files or en empty list when there are nog embedded files</returns>
        internal static List <string> SaveToFolder(string inputFile, string outputFolder)
        {
            var result = new List <string>();

            using (var streamReader = new StreamReader(inputFile))
            {
                var rtfReader  = new RtfParser.Reader(streamReader);
                var enumerator = rtfReader.Read().GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current?.Text != "object")
                    {
                        continue;
                    }
                    if (!RtfParser.Reader.MoveToNextControlWord(enumerator, "objclass"))
                    {
                        continue;
                    }
                    var className = RtfParser.Reader.GetNextText(enumerator);

                    if (!RtfParser.Reader.MoveToNextControlWord(enumerator, "objdata"))
                    {
                        continue;
                    }
                    var data = RtfParser.Reader.GetNextTextAsByteArray(enumerator);
                    using (var stream = new MemoryStream(data))
                    {
                        switch (className)
                        {
                        case "Outlook.FileAttach":
                        case "MailMsgAtt":
                            result.Add(ExtractOutlookAttachmentObject(stream, outputFolder));
                            break;

                        default:
                            var fileName = ExtractOle10(stream, outputFolder);
                            if (!string.IsNullOrWhiteSpace(fileName))
                            {
                                result.Add(fileName);
                            }
                            break;
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Saves all the embedded object from the RTF <paramref name="inputFile"/> to the 
        /// <see cref="outputFolder"/> and returns the files with full path as a list of strings
        /// </summary>
        /// <param name="inputFile">The RTF file</param>
        /// <param name="outputFolder">The output folder</param>
        /// <returns>List with files or en empty list when there are nog embedded files</returns>
        internal static List<string> SaveToFolder(string inputFile, string outputFolder)
        {
            var result = new List<string>();

            using (var streamReader = new StreamReader(inputFile))
            {
                var rtfReader = new RtfParser.Reader(streamReader);
                var enumerator = rtfReader.Read().GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.Text == "object")
                    {
                        if (RtfParser.Reader.MoveToNextControlWord(enumerator, "objclass"))
                        {
                            var className = RtfParser.Reader.GetNextText(enumerator);

                            if (RtfParser.Reader.MoveToNextControlWord(enumerator, "objdata"))
                            {
                                var data = RtfParser.Reader.GetNextTextAsByteArray(enumerator);
                                using (var stream = new MemoryStream(data))
                                {

                                    switch (className)
                                    {
                                        case "Outlook.FileAttach":
                                        case "MailMsgAtt":
                                            result.Add(ExtractOutlookAttachmentObject(stream, outputFolder));
                                            break;

                                        default:
                                            var fileName = ExtractOle10(stream, outputFolder);
                                            if (!string.IsNullOrWhiteSpace(fileName))
                                                result.Add(fileName);
                                            break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return result;
        }