public override WFState Run()
        {
            WFState retval = new WFState()
            {
                Value = "Success"
            };

            OpenMcdf.CompoundFile cf = null;
            try
            {
                cf = new CompoundFile(this.FileToProcess);
                bool attachfound = false;
                int  attachinc   = 0;
                do
                {
                    CFStorage cfstorage = this.GetStorage(cf.RootStorage, MakeAttachStorageName(attachinc));
                    if (cfstorage != null)
                    {
                        // check if attachment is embedded message - if so do not process
                        if (this.GetStorage(cfstorage, nameOfEmbeddedMessageStream) == null)
                        {
                            string filename = string.Format("attachment{0}", attachinc);

                            // first get filename
                            CFStream cfstream = this.GetStream(cfstorage, MakeSubStorageStreamName(0x3001, 0x001F));
                            if (cfstream != null)
                            {
                                filename = System.Text.UnicodeEncoding.Unicode.GetString(cfstream.GetData());
                            }
                            // second get filename
                            cfstream = this.GetStream(cfstorage, MakeSubStorageStreamName(0x3701, 0x0102));
                            if (cfstream != null)
                            {
                                string filedir = string.Format("{0}\\{1}", this.ExportDirectory, WFUtilities.GetNextDirectoryNumber(this.ExportDirectory));
                                if (!Directory.Exists(filedir))
                                {
                                    Directory.CreateDirectory(filedir);
                                }
                                if (Directory.Exists(filedir))
                                {
                                    using (var bw = new BinaryWriter(File.OpenWrite(string.Format("{0}\\{1}", filedir, filename))))
                                    {
                                        bw.Write(cfstream.GetData());
                                        this.OutputFiles.Add(string.Format("{0}\\{1}", filedir, filename), "Success");
                                    }
                                }
                            }
                        }
                        attachfound = true;
                    }
                    else
                    {
                        attachfound = false;
                    }
                    attachinc++;
                } while(attachfound);
            }
            catch (Exception)
            {
                retval.Value = "Fail";
            }
            finally
            {
                if (cf != null)
                {
                    cf.Close();
                }
            }

            return(retval);
        }
Beispiel #2
0
        private void HandleMessage(Message rdomail, string exportdir)
        {
            if (this.ProcessedMsgs.Contains(rdomail.Node))
            {
                return;
            }

            this.ProcessedMsgs.Add(rdomail.Node);

            string msgdir = exportdir;

            if (this.SaveAsTypes != SaveAsType.None || this.SaveAttachments == true)
            {
                msgdir = msgdir + @"\" + rdomail.Node.ToString();
            }

            if (!Directory.Exists(msgdir))
            {
                Directory.CreateDirectory(msgdir);
            }
            if (Directory.Exists(msgdir))
            {
                if ((this.SaveAsTypes & SaveAsType.Xml) == SaveAsType.Xml)
                {
                    this.OutputFiles.Add(rdomail.Write(this.Pst2MsgCompatible ? exportdir + @"\XML" : msgdir, Message.SaveAsMessageType.Xml, true), "Xml");
                }
                if ((this.SaveAsTypes & SaveAsType.Eml) == SaveAsType.Eml)
                {
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Eml, true));
                }
                if ((this.SaveAsTypes & SaveAsType.Msg) == SaveAsType.Msg)
                {
                    this.OutputFiles.Add(rdomail.Write(this.Pst2MsgCompatible ? exportdir + @"\MSG" : msgdir, Message.SaveAsMessageType.Msg, true), "Msg");
                }
                if ((this.SaveAsTypes & SaveAsType.Html) == SaveAsType.Html)
                {
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Html, true), "Html");
                }
                if (rdomail.HasBody && ((this.SaveAsTypes & SaveAsType.Text) == SaveAsType.Text))
                {
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Text, true), "Text");
                }
                if (rdomail.HasRtfBody && ((this.SaveAsTypes & SaveAsType.Rtf) == SaveAsType.Rtf))
                {
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Rtf, true));
                }
                foreach (pstsdk.definition.pst.message.IAttachment rdoattachment in rdomail.Attachments)
                {
                    if (rdoattachment.IsMessage)
                    {
                        Message attachmsg = null;
                        try
                        {
                            attachmsg     = (Message)rdoattachment.OpenAsMessage();
                            attachmsg.Pst = rdomail.Pst;
                        }
                        catch (Exception ex)
                        {
                            WFLogger.NLogger.ErrorException(string.Format("PSTFile={0}  NodeID={1}", this.PSTFile, this.FileToProcess), ex);
                        }
                        finally
                        {
                            if (attachmsg != null)
                            {
                                if (this.SaveEmbeddedMsgs == true && attachmsg.Node == Convert.ToUInt32(this.FileToProcess))
                                {
                                    SaveAsType origsaveastype = this.SaveAsTypes;
                                    this.SaveAsTypes = SaveAsType.Msg | SaveAsType.Xml | SaveAsType.Html;
                                    HandleMessage(attachmsg, exportdir);
                                    this.SaveAsTypes = origsaveastype;
                                }
                                else
                                {
                                    this.OutputFiles.Add(attachmsg.Node.Value.ToString(), "EmbeddedMsg");
                                }
                            }
                        }
                    }
                    else if (this.SaveAttachments)
                    {
                        string filedir = string.Format("{0}\\{1}", msgdir, WFUtilities.GetNextDirectoryNumber(msgdir));
                        if (!Directory.Exists(filedir))
                        {
                            Directory.CreateDirectory(filedir);
                        }
                        if (Directory.Exists(filedir))
                        {
                            string filename = filedir + @"\" + rdoattachment.Filename;
                            using (var bw = new BinaryWriter(File.OpenWrite(filename)))
                            {
                                bw.Write(rdoattachment.Bytes);
                                this.OutputFiles.Add(filename, "Attachment");
                            }
                        }
                    }
                    rdoattachment.Dispose();
                }
            }
        }
        public override void Process(PdfFileParserData data)
        {
            data.WFState.Value = WFState.WFStateFail;

            Dictionary <String, byte[]> files = new Dictionary <String, byte[]>();

            PdfReader reader = new PdfReader(data.DocumentToProcess);
            PdfReaderContentParser parser   = new PdfReaderContentParser(reader);
            MyImageRenderListener  listener = new MyImageRenderListener();

            for (int i = 1; i <= reader.NumberOfPages; i++)
            {
                parser.ProcessContent(i, listener);
            }
            for (int i = 0; i < listener.Images.Count; ++i)
            {
                string filedir = string.Format("{0}\\{1}", Path.GetDirectoryName(data.DocumentToProcess), WFUtilities.GetNextDirectoryNumber(Path.GetDirectoryName(data.DocumentToProcess)));
                if (!Directory.Exists(filedir))
                {
                    Directory.CreateDirectory(filedir);
                }
                if (Directory.Exists(filedir))
                {
                    using (FileStream fs = new FileStream(string.Format("{0}\\{1}", filedir, listener.ImageNames[i]), FileMode.Create, FileAccess.Write))
                    {
                        fs.Write(listener.Images[i], 0, listener.Images[i].Length);
                    }
                    data.OutputDocuments.Add(string.Format("{0}\\{1}", filedir, listener.ImageNames[i]));
                }
            }

            data.WFState.Value = KRSrcWorkflow.WFState.WFStateSuccess;
        }