/// <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)
        {
            var settings = new Pop3Settings(input, _configuration);
            await _client.ConnectAsync(settings.Connection.Server, settings.Connection.Port, settings.Connection.Secure);

            try
            {
                if (settings.Connection.HasCredentials)
                {
                    await _client.AuthenticateAsync(settings.Connection.Username, settings.Connection.Password);
                }

                var count = await _client.GetMessageCountAsync();

                for (var idx = 0; Done(idx, count, settings.Max); idx++)
                {
                    var lambda  = settings.Lambda.Clone();
                    var message = await _client.GetMessageAsync(idx);

                    HandleMessage(message, signaler, lambda, settings.Raw);
                    await signaler.SignalAsync("eval", lambda);
                }
            }
            finally
            {
                await _client.DisconnectAsync(true);
            }
        }
Beispiel #2
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 arguments.
            var lambdaOriginal = input.Children.FirstOrDefault(x => x.Name == ".lambda") ??
                                 throw new HyperlambdaException("No [.lambda] object supplied to [mail.pop3.fetch]");
            var raw = input.Children.FirstOrDefault(x => x.Name == "raw")?.GetEx <bool>() ?? false;
            var max = input.Children.FirstOrDefault(x => x.Name == "max")?.GetEx <int>() ?? 50;

            // Connecting to POP3 server.
            await Utilities.Connect(input, _client, _server);

            try
            {
                // Authenticating if we're supposed to authenticate.
                await Utilities.Authenticate(input, _client, _server);

                // Retrieving message count from server.
                var count = await _client.GetMessageCountAsync();

                // Retrieving unread messages for as long as we're supposed to.
                for (var idx = 0; Done(idx, count, max); idx++)
                {
                    var lambda  = lambdaOriginal.Clone();
                    var message = await _client.GetMessageAsync(idx);

                    HandleMessage(
                        message,
                        signaler,
                        lambda,
                        raw);
                    await signaler.SignalAsync("eval", lambda);
                }
            }
            finally
            {
                await _client.DisconnectAsync(true);
            }
        }