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

            try
            {
                client = new Imap();
                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
            {
                await client.SelectAsync("INBOX");

                FolderCollection rootFolders = await client.ListFoldersAsync();

                output.AppendFormat("{0} folders in the root folder.\n", rootFolders.Count);
                ImapMessageCollection msgs = await client.ListMessagesAsync(ImapEnvelopeParts.Size);

                long size = 0;
                for (int i = 0; i < msgs.Count; i++)
                {
                    size += msgs [i].Size;
                }
                output.AppendFormat("{0} messages in INBOX folder. Total size: {1} bytes.\n", msgs.Count, size);
            }
            catch (Exception ex)
            {
                _window.Busy = false;
                Util.ShowException(ex);
                return;
            }
            _window.Busy = false;
            Util.ShowMessage("Mailbox Info", output.ToString());
        }
Esempio n. 2
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            // Create an imapclient with host, user and password
            ImapClient client = new ImapClient();

            client.Host                = this.HostInput.Text;
            client.Username            = this.Username.Text;
            client.Password            = this.Password.Text;
            client.ConnectionProtocols = ConnectionProtocols.Ssl;
            client.Port                = int.Parse(this.PortInput.Text);
            client.Connect();
            client.Select("Inbox");
            // Get a collection of messages
            ImapMessageCollection msgs = client.Search("'Subject' Contains 'Spire.Email'");

            MessageBox.Show("Imap: " + msgs.Count + " message(s) found.");
        }
Esempio n. 3
0
        void ShowMessageList(ImapMessageCollection col)
        {
            // Clear the message list.
            listView.Items.Clear();

            // Update the progress bar control.
            toolStripProgressBar.Maximum = col.Count;
            toolStripProgressBar.Value   = 0;

            MessageListInfo info = new MessageListInfo();

            info.List = col;

            if (info.List.Count > 0)
            {
                DownloadImapMessage(info);
            }
            else
            {
                EnableProgress(false, 0);
                // Update the state.
                listView_SelectedIndexChanged(null, null);
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Imap client = new Imap();

            // connect to server

            client.Connect("imap.gmail.com", 993, SslMode.Implicit);

            // authenticate
            client.Login("username", "password");

            // select folder
            client.SelectFolder("Inbox");

            int NoOfEmailsPerPage = 10;
            int totalEmails       = client.CurrentFolder.TotalMessageCount;
            // get message list - envelope headers
            ImapMessageCollection messages = client.GetMessageList(ImapListFields.Envelope);

            // display info about each message


            foreach (ImapMessageInfo message in messages)
            {
                TableCell noCell = new TableCell();

                noCell.CssClass = "emails-table-cell";

                noCell.Text = Convert.ToString(message.To);
                TableCell fromCell = new TableCell();
                fromCell.CssClass = "emails-table-cell";
                fromCell.Text     = Convert.ToString(message.From);
                TableCell subjectCell = new TableCell();
                subjectCell.CssClass       = "emails-table-cell";
                subjectCell.Style["width"] = "300px";
                subjectCell.Text           = Convert.ToString(message.Subject);
                TableCell dateCell = new TableCell();
                dateCell.CssClass = "emails-table-cell";
                if (message.Date.OriginalTime != DateTime.MinValue)
                {
                    dateCell.Text = message.Date.OriginalTime.ToString();
                }
                TableRow emailRow = new TableRow();
                emailRow.Cells.Add(noCell);
                emailRow.Cells.Add(fromCell);
                emailRow.Cells.Add(subjectCell);
                emailRow.Cells.Add(dateCell);
                EmailsTable.Rows.AddAt(2 + 0, emailRow);
            }
            int totalPages;
            int mod = totalEmails % NoOfEmailsPerPage;

            if (mod == 0)
            {
                totalPages = totalEmails / NoOfEmailsPerPage;
            }
            else
            {
                totalPages = ((totalEmails - mod) / NoOfEmailsPerPage) + 1;
            }
        }
Esempio n. 5
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 IMAP server {0}:{1}...", server, port);

            Imap client = null;

            try
            {
                client = new Imap();

                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
            {
                await client.SelectAsync("INBOX");

                FolderCollection rootFolders = await client.ListFoldersAsync();

                output.AppendFormat("{0} folders in the root folder.\n", rootFolders.Count);
                ImapMessageCollection msgs = await client.ListMessagesAsync(ImapEnvelopeParts.Size);

                long size = 0;
                for (int i = 0; i < msgs.Count; i++)
                {
                    size += msgs [i].Size;
                }
                output.AppendFormat("{0} messages in INBOX folder. Total size: {1} bytes.\n", msgs.Count, 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();
        }