Exemple #1
0
        public void Execute(Arguments arguments)
        {
            if (arguments.IgnoreCertificateErrors.Value)
            {
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            }
            var credentials           = new NetworkCredential(arguments.Login.Value, arguments.Password.Value);
            var uri                   = new UriBuilder("imaps", arguments.Host.Value, arguments.Port.Value).Uri;
            var timeout               = (int)arguments.Timeout.Value.TotalMilliseconds;
            var markAllMessagesAsRead = arguments.MarkAsRead.Value;

            var client = ImapHelper.CreateImapClient(credentials, uri, !markAllMessagesAsRead, timeout);

            if (client.IsConnected && client.IsAuthenticated)
            {
                var folder = client.GetFolder(arguments.Folder.Value);
                folder.Open(FolderAccess.ReadOnly);
                var messages = ReceiveMesssages(folder, arguments);
                SendMessageListToScripter(folder, arguments, messages);

                if (markAllMessagesAsRead)
                {
                    MarkMessagesAsRead(folder, messages);
                }
            }
        }
        private ImapClient CreateClient(Arguments arguments)
        {
            var credentials = new NetworkCredential(arguments.Login.Value, arguments.Password.Value);
            var uri         = new UriBuilder("imaps", arguments.Host.Value, arguments.Port.Value).Uri;
            var timeout     = (int)arguments.Timeout.Value.TotalMilliseconds;

            return(ImapHelper.CreateImapClient(credentials, uri, false, timeout));
        }