Esempio n. 1
0
        public static void _p5_mime_load_from_stream(ApplicationContext context, ActiveEventArgs e)
        {
            // Making sure we clean up after ourselves.
            using (new ArgsRemover(e.Args, true)) {
                // Sanity check.
                var stream = e.Args.Value as Stream;
                if (e.Args.Value == null)
                {
                    throw new LambdaException(
                              "No stream provided to [.p5.mime.parse-from-stream]",
                              e.Args,
                              context);
                }

                // Loading MimeEntity from specified stream.
                MimeEntity entity = null;
                if (e.Args ["Content-Type"] != null)
                {
                    entity = MimeEntity.Load(ContentType.Parse(e.Args ["Content-Type"].Get <string> (context)), stream);
                }
                else
                {
                    entity = MimeEntity.Load(stream);
                }
                var parser = new helpers.MimeParser(
                    context,
                    e.Args,
                    entity,
                    e.Args.GetExChildValue <string> ("attachment-folder", context),
                    e.Args.GetExChildValue <bool> ("attachment-folder-no-prefix", context, true));

                // Parses the MimeEntity and stuffs results into e.Args node
                parser.Process();
            }
        }
Esempio n. 2
0
        public static void p5_mime_load_file(ApplicationContext context, ActiveEventArgs e)
        {
            // Making sure we clean up after ourselves
            using (new ArgsRemover(e.Args, true)) {
                // Keeping base folder to application around
                string baseFolder = Common.GetRootFolder(context).TrimEnd('/');

                // Looping through each filename supplied by caller
                foreach (var idxFilename in XUtil.Iterate <string> (context, e.Args))
                {
                    // Verifying user is authorized to reading from currently iterated file
                    context.RaiseEvent(".p5.io.authorize.read-file", new Node("", idxFilename).Add("args", e.Args));

                    // Loading, processing and returning currently iterated message
                    var parser = new helpers.MimeParser(
                        context,
                        e.Args,
                        MimeEntity.Load(baseFolder + idxFilename),
                        e.Args.GetExChildValue <string> ("attachment-folder", context));

                    // Parses the MimeEntity and stuffs results into e.Args node
                    parser.Process();
                }
            }
        }
Esempio n. 3
0
        static void _p5_mime_parse_native(ApplicationContext context, ActiveEventArgs e)
        {
            // Retrieving MimeEntity from caller's arguments
            var entity = e.Args.Get <MimeEntity> (context);
            var parser = new helpers.MimeParser(
                context,
                e.Args,
                entity,
                e.Args.GetExChildValue <string> ("attachment-folder", context));

            // Parses the MimeEntity and stuffs results into e.Args node
            parser.Process();
        }
        public static void p5_mime_parse(ApplicationContext context, ActiveEventArgs e)
        {
            // House cleaning.
            using (new ArgsRemover(e.Args, true)) {
                // Looping through each MIME message supplied.
                foreach (var idxMimeMessage in XUtil.Iterate <string> (context, e.Args))
                {
                    // Sanity check.
                    if (string.IsNullOrEmpty(idxMimeMessage))
                    {
                        throw new LambdaException(
                                  "No MIME message provided to [p5.mime.parse]",
                                  e.Args,
                                  context);
                    }

                    // Loading MIME entity from stream.
                    using (var writer = new StreamWriter(new MemoryStream())) {
                        // Writing MIME content to StreamWriter, flushing the stream, and setting stream's read head back to beginning.
                        writer.Write(idxMimeMessage);
                        writer.Flush();
                        writer.BaseStream.Position = 0;

                        // Creating the MIME entity to hold our parsed content.
                        MimeEntity entity = null;

                        // Checking if an explicit [Content-Type] was supplied.
                        if (e.Args ["Content-Type"] != null)
                        {
                            entity = MimeEntity.Load(ContentType.Parse(e.Args ["Content-Type"].GetExValue <string> (context)), writer.BaseStream);
                        }
                        else
                        {
                            entity = MimeEntity.Load(writer.BaseStream);
                        }

                        // Creating our parser wrapper.
                        var parser = new helpers.MimeParser(
                            context,
                            e.Args,
                            entity,
                            e.Args.GetExChildValue <string> ("attachment-folder", context),
                            e.Args.GetExChildValue <bool> ("attachments-use-prefix", context, true));

                        // Parses the MimeEntity and stuffs results into e.Args node.
                        parser.Process();
                    }
                }
            }
        }
        public static void p5_mime_load(ApplicationContext context, ActiveEventArgs e)
        {
            // House cleaning.
            using (new ArgsRemover(e.Args, true)) {
                // Looping through each file supplied by caller.
                foreach (var idxMimeMessage in XUtil.Iterate <string> (context, e.Args))
                {
                    // Sanity check.
                    if (string.IsNullOrEmpty(idxMimeMessage))
                    {
                        throw new LambdaException(
                                  "No file supplied to [p5.mime.load]",
                                  e.Args,
                                  context);
                    }

                    // Retrieving output filename, unrolling path, and authorising that user has read access to file.
                    var filePath = idxMimeMessage;
                    filePath = context.RaiseEvent(".p5.io.unroll-path", new Node("", filePath)).Get <string> (context);
                    context.RaiseEvent(".p5.io.authorize.read-file", new Node("", filePath).Add("args", e.Args));

                    // Creating a FileStream wrapping our file.
                    using (var reader = File.OpenRead(Common.GetRootFolder(context) + filePath)) {
                        // Creating our MIME entity.
                        MimeEntity entity = null;

                        // Checking if caller supplied an explicit [Content-Type].
                        if (e.Args ["Content-Type"] != null)
                        {
                            entity = MimeEntity.Load(ContentType.Parse(e.Args ["Content-Type"].GetExValue <string> (context)), reader);
                        }
                        else
                        {
                            entity = MimeEntity.Load(reader);
                        }

                        // Creating our MIME parser.
                        var parser = new helpers.MimeParser(
                            context,
                            e.Args,
                            entity,
                            e.Args.GetExChildValue <string> ("attachment-folder", context),
                            e.Args.GetExChildValue <bool> ("attachments-use-prefix", context, true));

                        // Parses the MimeEntity and stuffs the results into e.Args node.
                        parser.Process();
                    }
                }
            }
        }
        public static void _p5_mime_load_from_stream(ApplicationContext context, ActiveEventArgs e)
        {
            // House cleaning.
            using (new ArgsRemover(e.Args, true)) {
                // Sanity check.
                var tuple = e.Args.Value as Tuple <object, Stream>;
                if (tuple == null)
                {
                    throw new LambdaException(
                              "No Tuple<object, Stream> provided to [.p5.mime.load-from-stream]",
                              e.Args,
                              context);
                }
                var stream = tuple.Item2;
                if (stream == null)
                {
                    throw new LambdaException(
                              "No stream provided to [.p5.mime.load-from-stream]",
                              e.Args,
                              context);
                }

                // Creating our MIME entity.
                MimeEntity entity = null;

                // Checking if caller supplied an explicit [Content-Type].
                if (e.Args ["Content-Type"] != null)
                {
                    entity = MimeEntity.Load(ContentType.Parse(e.Args ["Content-Type"].Get <string> (context)), stream);
                }
                else
                {
                    entity = MimeEntity.Load(stream);
                }

                // Creating our parser.
                var parser = new helpers.MimeParser(
                    context,
                    e.Args,
                    entity,
                    e.Args.GetExChildValue <string> ("attachment-folder", context),
                    e.Args.GetExChildValue <bool> ("attachments-use-prefix", context, true));

                // Parses the MimeEntity and stuffs the results into e.Args node.
                parser.Process();
            }
        }
Esempio n. 7
0
        public static void p5_mime_load(ApplicationContext context, ActiveEventArgs e)
        {
            // Making sure we clean up after ourselves
            using (new ArgsRemover(e.Args, true)) {
                // Looping through each MIME message supplied
                foreach (var idxMimeMessage in XUtil.Iterate <string> (context, e.Args))
                {
                    // Sanity check
                    if (string.IsNullOrEmpty(idxMimeMessage))
                    {
                        throw new LambdaException(
                                  "No MIME message provided to [p5.mime.parse]",
                                  e.Args,
                                  context);
                    }

                    // Retrieving output filename, and doing some basic sanity checking.
                    var filePath = idxMimeMessage;
                    filePath = context.RaiseEvent(".p5.io.unroll-path", new Node("", filePath)).Get <string> (context);
                    context.RaiseEvent(".p5.io.authorize.read-file", new Node("", filePath).Add("args", e.Args));

                    // Loading MIME entity from currentl iterated file.
                    using (var reader = File.OpenRead(Common.GetRootFolder(context) + filePath)) {
                        // Loading MimeEntity from MemoryStream
                        MimeEntity entity = null;
                        if (e.Args ["Content-Type"] != null)
                        {
                            entity = MimeEntity.Load(ContentType.Parse(e.Args ["Content-Type"].Get <string> (context)), reader);
                        }
                        else
                        {
                            entity = MimeEntity.Load(reader);
                        }
                        var parser = new helpers.MimeParser(
                            context,
                            e.Args,
                            entity,
                            e.Args.GetExChildValue <string> ("attachment-folder", context),
                            e.Args.GetExChildValue <bool> ("attachment-folder-no-prefix", context, true));

                        // Parses the MimeEntity and stuffs results into e.Args node
                        parser.Process();
                    }
                }
            }
        }
Esempio n. 8
0
        public static void p5_mime_parse(ApplicationContext context, ActiveEventArgs e)
        {
            // Making sure we clean up after ourselves
            using (new ArgsRemover(e.Args, true)) {
                // Looping through each MIME message supplied
                foreach (var idxMimeMessage in XUtil.Iterate <string> (context, e.Args))
                {
                    // Sanity check
                    if (string.IsNullOrEmpty(idxMimeMessage))
                    {
                        throw new LambdaException(
                                  "No MIME message provided to [p5.mime.parse]",
                                  e.Args,
                                  context);
                    }

                    // Loading MIME entity from stream
                    using (var writer = new StreamWriter(new MemoryStream())) {
                        // Writing MIME content to StreamWriter, flushing the stream, and setting reader head back to beginning
                        writer.Write(idxMimeMessage);
                        writer.Flush();
                        writer.BaseStream.Position = 0;

                        // Loading MimeEntity from MemoryStream
                        MimeEntity entity = null;
                        if (e.Args["Content-Type"] != null)
                        {
                            entity = MimeEntity.Load(ContentType.Parse(e.Args["Content-Type"].Get <string> (context)), writer.BaseStream);
                        }
                        else
                        {
                            entity = MimeEntity.Load(writer.BaseStream);
                        }
                        var parser = new helpers.MimeParser(
                            context,
                            e.Args,
                            entity,
                            e.Args.GetExChildValue <string> ("attachment-folder", context));

                        // Parses the MimeEntity and stuffs results into e.Args node
                        parser.Process();
                    }
                }
            }
        }