示例#1
0
        /// <summary>
        /// Connect to the server and display mailbox statistics.
        /// </summary>
        private async void Connect(object sender, EventArgs e)
        {
            _window.Busy = true;
            Pop3 client = null;

            try
            {
                client = new Pop3();
                await client.ConnectAsync(ServerName, ServerPort, Mode);
            }
            catch (Exception ex)
            {
                _window.Busy = false;
                Util.ShowException(ex);
                return;
            }

            if (!string.IsNullOrEmpty(UserName))
            {
                try
                {
                    await client.AuthenticateAsync(UserName, Password);
                }
                catch (Exception ex)
                {
                    _window.Busy = false;
                    Util.ShowException(ex);
                    return;
                }
            }

            StringBuilder output = new StringBuilder();

            try
            {
                Pop3MailboxStat stat = await client.GetMailboxStatAsync();

                output.AppendFormat("There are {0} message(s). Total size: {1} bytes.", stat.MessageCount, stat.Size);
            }
            catch (Exception ex)
            {
                _window.Busy = false;
                Util.ShowException(ex);
                return;
            }
            _window.Busy = false;
            Util.ShowMessage("Mailbox Info", output.ToString());
        }
示例#2
0
        /// <summary>
        /// Retrieves the DNS query result and displays it.
        /// </summary>
        protected override async void OnResume()
        {
            base.OnResume();

            string       server   = Intent.GetStringExtra("server");
            int          port     = Intent.GetIntExtra("port", 110);
            SecurityMode mode     = (SecurityMode)Intent.GetIntExtra("security", 0);
            string       username = Intent.GetStringExtra("username");
            string       password = Intent.GetStringExtra("password");

            // switch to 'show output' layout
            SetContentView(Resource.Layout.Progress);
            var lblDesc = (TextView)FindViewById(Resource.Id.lblDescription);

            lblDesc.Text = string.Format("Connecting to POP3 server {0}:{1}...", server, port);

            Pop3 client = null;

            try
            {
                client = new Pop3();
                await client.ConnectAsync(server, port, mode);
            }
            catch (Exception ex)
            {
                HandleException(ex, "Error occurred while connecting to the server. ", true);
                return;
            }

            if (!string.IsNullOrEmpty(username))
            {
                try
                {
                    await client.AuthenticateAsync(username, password);
                }
                catch (Exception ex)
                {
                    HandleException(ex, "Error occurred while authenticating the user. ", true);
                    return;
                }
            }

            StringBuilder output = new StringBuilder();

            try
            {
                Pop3MailboxStat stat = await client.GetMailboxStatAsync();

                output.AppendFormat("There are {0} message(s). Total size: {1} bytes.\n", stat.MessageCount, stat.Size);
            }
            catch (Exception ex)
            {
                HandleException(ex, "Error while obtaining mailbox information. ", true);
                return;
            }

            // switch to 'show output' layout
            SetContentView(Resource.Layout.Result);

            // Show output
            var lblResult = (TextView)FindViewById(Resource.Id.lblResult);

            lblResult.Text = output.ToString();
        }