public static void _p5_mime_serialize_to_stream(ApplicationContext context, ActiveEventArgs e)
        {
            // Retrieving output filename, and doing some basic sanity checking.
            var tuple  = e.Args.Value as Tuple <object, Stream>;
            var output = tuple.Item2;

            // Have to remove value of node, before iteration starts.
            e.Args.Value = null;

            // Making sure we clean up after ourselves
            using (new ArgsRemover(e.Args, true)) {
                // Iterating through each node given, either as child of main node, or through expression
                var mimeNode = XUtil.Iterate <Node> (context, e.Args).First();

                // Making sure we keep track of, closes, and disposes all streams created during process
                List <Stream> streams = new List <Stream> ();
                try {
                    // Creating MIME message and serializing to file.
                    var creator = new MimeCreator(
                        context,
                        mimeNode,
                        streams);
                    creator.Create().WriteTo(output);
                } finally {
                    // Disposing all streams created during process
                    foreach (var idxStream in streams)
                    {
                        // Closing and disposing currently iterated stream
                        idxStream.Close();
                        idxStream.Dispose();
                    }
                }
            }
        }
 public static void p5_mime_create(ApplicationContext context, ActiveEventArgs e)
 {
     // Making sure we clean up after ourselves
     using (new ArgsRemover(e.Args, true)) {
         // Iterating through each node given, either as child of main node, or through expression
         foreach (var idxMimeNode in XUtil.Iterate <Node> (context, e.Args))
         {
             // Making sure we keep track of, closes, and disposes all streams created during process
             List <Stream> streams = new List <Stream> ();
             try {
                 // Creating and returning MIME message to caller as string
                 var creator = new MimeCreator(
                     context,
                     idxMimeNode,
                     streams);
                 e.Args.Add("result", creator.Create().ToString());
             } finally {
                 // Disposing all streams created during process
                 foreach (var idxStream in streams)
                 {
                     // Closing and disposing currently iterated stream
                     idxStream.Close();
                     idxStream.Dispose();
                 }
             }
         }
     }
 }
        /// <summary>
        /// Implementation of your slot.
        /// </summary>
        /// <param name="signaler">Signaler that raised the signal.</param>
        /// <param name="input">Arguments to your slot.</param>
        public void Signal(ISignaler signaler, Node input)
        {
            var entity = MimeCreator.Create(signaler, input);

            try
            {
                input.Value = entity.ToString();
                input.Clear();
            }
            finally
            {
                MimeCreator.DisposeEntity(entity);
            }
        }
        private static void _p5_mime_create_native(ApplicationContext context, ActiveEventArgs e)
        {
            // Basic syntax checking
            if (e.Args.Count != 1)
            {
                throw new LambdaException(
                          "You must have exactly one root node of your MIME message",
                          e.Args,
                          context);
            }

            // Creating and returning MIME message to caller as MimeEntity
            MimeCreator creator = new MimeCreator(
                context,
                e.Args.FirstChild,
                (List <Stream>)e.Args.Value);

            e.Args.Value = creator.Create();
        }
Exemple #5
0
        public static void p5_mime_save_file(ApplicationContext context, ActiveEventArgs e)
        {
            // Making sure we clean up after ourselves
            using (new Utilities.ArgsRemover(e.Args, true)) {
                // Keeping base folder to application around
                string baseFolder = Common.GetRootFolder(context);

                // Retrieving filename supplied by caller to serialize MimeEntity to
                var filename = XUtil.Single <string> (context, e.Args, true);

                // Verifying user is authorized to saving to the specified file
                context.Raise(".p5.io.authorize.modify-file", new Node("", filename).Add("args", e.Args));

                // Retrieving root MIME entity from args
                var mimeNode = e.Args [0];

                // Making sure we keep track of, closes, and disposes all streams created during process
                List <Stream> streams = new List <Stream> ();
                try {
                    // Creating and returning MIME message to caller as string
                    MimeCreator creator = new MimeCreator(
                        context,
                        mimeNode,
                        streams);
                    var mimeEntity = creator.Create();

                    // Creating file to store MIME entity into
                    using (var stream = File.Create(baseFolder + filename)) {
                        // Writing MimeEntity to file stream
                        mimeEntity.WriteTo(stream);
                    }
                } finally {
                    // Disposing all streams created during process
                    foreach (var idxStream in streams)
                    {
                        // Closing and disposing currently iterated stream
                        idxStream.Close();
                        idxStream.Dispose();
                    }
                }
            }
        }
        public static void p5_mime_save(ApplicationContext context, ActiveEventArgs e)
        {
            // Retrieving output filename, and doing some basic sanity checking.
            var filePath = e.Args.GetExValue <string> (context);

            filePath = context.RaiseEvent(".p5.io.unroll-path", new Node("", filePath)).Get <string> (context);
            context.RaiseEvent(".p5.io.authorize.modify-file", new Node("", filePath).Add("args", e.Args));

            // We have to remove value of node, to make sure our iteration process below doesn't prioritize the value of the node.
            e.Args.Value = null;

            // Making sure we clean up after ourselves
            using (new ArgsRemover(e.Args, true)) {
                // Notice, we open up our output stream, before we start iterating, in case multiple MIME envelopes are to be created,
                // and inserted into the same output file.
                using (var output = File.Create(Common.GetRootFolder(context) + filePath)) {
                    // Iterating through each node given, either as child of main node, or through expression
                    foreach (var idxMimeNode in XUtil.Iterate <Node> (context, e.Args))
                    {
                        // Making sure we keep track of, closes, and disposes all streams created during process
                        List <Stream> streams = new List <Stream> ();
                        try {
                            // Creating MIME message and serializing to file.
                            var creator = new MimeCreator(
                                context,
                                idxMimeNode,
                                streams);
                            creator.Create().WriteTo(output);
                        } finally {
                            // Disposing all streams created during process
                            foreach (var idxStream in streams)
                            {
                                // Closing and disposing currently iterated stream
                                idxStream.Close();
                                idxStream.Dispose();
                            }
                        }
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Implementation of your slot.
        /// </summary>
        /// <param name="signaler">Signaler that raised the signal.</param>
        /// <param name="input">Arguments to your slot.</param>
        public async Task SignalAsync(ISignaler signaler, Node input)
        {
            // Retrieving server connection settings.
            var settings = new ConnectionSettings(
                _configuration,
                input.Children.FirstOrDefault(x => x.Name == "server"),
                "smtp");

            // Connecting and authenticating (unless username is null).
            await _client.ConnectAsync(settings.Server, settings.Port, settings.Secure);

            try
            {
                // Checking if we're supposed to authenticate
                if (settings.Username != null || settings.Password != null)
                {
                    await _client.AuthenticateAsync(settings.Username, settings.Password);
                }

                // Iterating through each message and sending.
                foreach (var idxMsgNode in input.Children.Where(x => x.Name == "message"))
                {
                    // Creating MimeMessage, making sure we dispose any streams created in the process.
                    var message = CreateMessage(signaler, idxMsgNode);
                    try
                    {
                        // Sending message over existing SMTP connection.
                        await _client.SendAsync(message);
                    }
                    finally
                    {
                        MimeCreator.DisposeEntity(message.Body);
                    }
                }
            }
            finally
            {
                // Disconnecting and sending QUIT signal to SMTP server.
                await _client.DisconnectAsync(true);
            }
        }
Exemple #8
0
        /// <summary>
        /// Implementation of your slot.
        /// </summary>
        /// <param name="signaler">Signaler that raised the signal.</param>
        /// <param name="input">Arguments to your slot.</param>
        public void Signal(ISignaler signaler, Node input)
        {
            // Figuring out if caller wants a structured result.
            var structured = input.Children
                             .FirstOrDefault(x => x.Name == "structured")?
                             .GetEx <bool>() ?? false;

            // Creating entity.
            using (var entity = MimeCreator.Create(signaler, input, _streamService, _rootResolver))
            {
                // House cleaning.
                input.Value = null;
                input.Clear();

                // Serialising entity into temporary stream such that we can correctly return it to caller.
                using (var stream = new MemoryStream())
                {
                    entity.WriteTo(stream, structured);
                    stream.Position = 0;

                    // Reading back entity's content again.
                    using (var reader = new StreamReader(stream))
                    {
                        // Checking if caller wants a structured result or not.
                        if (structured)
                        {
                            input.AddRange(entity.Headers.Select(x => new Node(x.Field, x.Value)));
                            input.Add(new Node("content", reader.ReadToEnd()));
                        }
                        else
                        {
                            input.Value = reader.ReadToEnd();
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Implementation of your slot.
 /// </summary>
 /// <param name="signaler">Signaler that raised the signal.</param>
 /// <param name="input">Arguments to your slot.</param>
 public void Signal(ISignaler signaler, Node input)
 {
     input.Value = MimeCreator.Create(signaler, input);
     input.Clear();
 }
 /// <summary>
 /// Implementation of your slot.
 /// </summary>
 /// <param name="signaler">Signaler that raised the signal.</param>
 /// <param name="input">Arguments to your slot.</param>
 public void Signal(ISignaler signaler, Node input)
 {
     // Creating entity and returning to caller as is.
     input.Value = MimeCreator.Create(signaler, input, _streamService, _rootResolver);
     input.Clear();
 }