OpenPop deleting messages

2.7k views Asked by At

When I try and delete a message it deletes 4 at a time even though I explicitly state otherwise, since I have like 700 messages, I had to display a maximum of 4.

public void inboxupdate()
    {
        client.Connect("pop.googlemail.com", 995, true);
        if (client.Connected)
        {
            client.Authenticate(tbxEmail.Text, tbxPassword.Text, OpenPop.Pop3.AuthenticationMethod.UsernameAndPassword);
        }
        int MessageCount = client.GetMessageCount();

        for (int i = 1; i <= 4; i++ )
        {
            try
            {
                cbxInbox.Items.Add(client.GetMessage(i).ToMailMessage().Subject, false);
            }
            catch
            {
            }
        }
    }

The code to delete:

private void btnDelete_Click(object sender, EventArgs e)
    {
        if (cbxInbox.CheckedItems.Count > 1)
        {
            for (int i = 1; i <= cbxInbox.CheckedItems.Count; i++)
            {
                client.DeleteMessage(i + 1);
            }
        }
        cbxInbox.Items.Clear();
        client.Disconnect();
        inboxupdate();
    }

Even when I do

client.DeleteMessage(1)

It deletes 4 at a time. Also these messages appear to be old since they don't show up on the first page when I visit mail.google.com Is there a way to distinguish between spam and messages?

1

There are 1 answers

4
foens On

Gmail has some funny POP3 implementation. Once you download a message, it will not display it for you next time. So your problem is most likely not that OpenPop deletes 4 messages, but that you download 4 messages which Gmail then hides from you.

Please see What non-standard behaviour features does Gmail exhibit, when it is programmatically used as a POP3 server?

As a side note: Next time you ask a question, please use some time on asking it, cleaning it up. For example, why have you included commented out code?

A second side note. The below codes does not take into account what messages are "marked" as should be deleted. Should you not lookup the index? You are always deleted the first n items if the user selected n items, but what if he selected the n last items?

if (cbxInbox.CheckedItems.Count > 1)
{
    for (int i = 1; i <= cbxInbox.CheckedItems.Count; i++)
    {
        client.DeleteMessage(i + 1);
    }
}

Hope it helps.