Results 1 to 11 of 11

Thread: Delete messages from the listview AND the server inbox

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Delete messages from the listview AND the server inbox

    How would I go about doing this with the Winsock control? I have a list of POP3 commands enumerated already to help.

    VB Code:
    1. Private Enum POP3States
    2.     POP3_Connect
    3.     POP3_USER
    4.     POP3_PASS
    5.     POP3_STAT
    6.     POP3_RETR
    7.     POP3_DELE
    8.     POP3_QUIT
    9. End Enum

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    I thought that the POP3 retrieval command had a parameter on it that would delete the messages in the Inbox once they had been retrieved?

    If not, then use of the POP3 delete command will allow a message to be removed from the Inbox.

    Removal from the ListBox is JASMOP - but you probably need to count through the list box backwards, and remove selected items.

  3. #3

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    I don't know about that.

    However, I did find a small bit of code on PlanetSourceCode that's supposed to do what I want to do. Here is that code, refined for use with my program:

    VB Code:
    1. Private Sub mnuDelete_Click()
    2.     Dim Item As ListItem
    3.     Set Item = lvwMail.ListItems(1)
    4.     Set lvwMail.SelectedItem = Item
    5.     DoEvents
    6.     Do Until lvwMail.SelectedItem.Index = lvwMail.ListItems.Count
    7.         If lvwMail.SelectedItem.Selected = True Then
    8.             lvwMail.SelectedItem.EnsureVisible
    9.             DoEvents
    10.             MessageState = POP3_DELE
    11.             Winsock1.SendData "DELE " & lvwMail.SelectedItem.text & vbCrLf
    12.             DoEvents
    13.             lvwMail.SelectedItem.Checked = False
    14.         End If
    15.         lvwMail.SelectedItem = lvwMail.ListItems(lvwMail.SelectedItem.Index + 1)
    16.     Loop
    17.     If lvwMail.SelectedItem.Checked = True Then
    18.         lvwMail.SelectedItem.EnsureVisible
    19.         DoEvents
    20.         MessageState = POP3_DELE
    21.         Winsock1.SendData "DELE " & lvwMail.SelectedItem.text & vbCrLf
    22.         DoEvents
    23.         lvwMail.SelectedItem.Checked = False
    24.     End If
    25. End Sub

    This gives me a Wrong protocol or connection state message. Isn't that supposed to mean that you're disconnected from the server? I am connected though.

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    These simple instructions were obtasined from the MS Knowledge Base, by searching for POP3. It shows the DELE command needs a number after it. s that what you are passing??

    Note: These are all TELNET commands. Using interactive TelNet to the correct port would be an easy way of testing these things.

    POP3 Commands:
    USER
    This command identifies you as a registered account on the server. After you see the server welcome message mentioned above, type USER <account name> After entering the USER information, the server will return a line that reads, "+OK Password required for <account name>."
    PASS
    Type PASS <your password> If the password is accepted, the server will return a line similar to: "+OK <account name> has <n> message(s) (MMMMM) octets", where <n> is the number of messages stored in your mailbox on the server and (MMMMM) is the total size of all messages.
    LIST
    Type LIST at the prompt. The server will return "+OK <n> messages <MMMMM> octets), a list of the messages including their numbers, and the individual message sizes.
    RETR
    This command will retrieve the text of a message. For example, if you wish to retrieve message number 4, type at the prompt, "RETR 4."
    DELE
    This command allows you to delete a message from the POP server. To delete a message enter DELE <n>, where <n> is the message number determined from the LIST command. For example, to delete message number 4, enter the command "DELE 4."
    IMPORTANT: The DELE command should be used with care and in extreme cases where a specific message is blocking mail delivery. It is strongly recommended that you retrieve the text of the message into a log file as described above before attempting to delete it.

  5. #5

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    By using Debug.Print I found it's returning a text value instead of the message number.
    Last edited by hothead; Nov 28th, 2002 at 09:27 AM.

  6. #6

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Hmm, weird... it works when I telnet to the server, but not when I implement it in my program. I'm returning the ListIndex of the selected item now.

  7. #7
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    If Telnet works, then there is no problem with the remote server end and processing the POP3 commands.

    Therefore it must be the command you are sending.....

    Spaces? non-printing characters? Is the number correct? Do you need to delete in a certain order? Do you need to step through the ListBox backwards (last to first) to allow removal from the listbox as well as from the POP3 server?

  8. #8

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    The number appears to be correct. I did a Debug.Print, and it's returning a number. I changed the MessageState variable to reflect that it was in the process of deleting a message. It still won't work.


    VB Code:
    1. Private Sub mnuDelete_Click()
    2.     For i = lvwMail.ListItems.Count To 1 Step -1
    3.         If lvwMail.ListItems(i).Selected = True Then
    4.             lvwMail.ListItems(i).EnsureVisible
    5.             DoEvents
    6.             MessageState = POP3_DELE
    7.             Winsock1.SendData "DELE " & lvwMail.ListItems(i).Index & vbCrLf
    8.             DoEvents
    9.             lvwMail.ListItems.Remove i
    10.         End If
    11.     Next i
    12. End Sub

  9. #9
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Is the number valid?
    The number would need to match a numer that has been retrieved from the POP3 server using the LIST or RETR commands.

    What code are you using to retrieve messages? The RETR command and the DELE comand should both use the same number.

  10. #10

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Here's the code I'm using for RETR:

    VB Code:
    1. Case POP3_RETR
    2.                 Buffer = Buffer & Data
    3.                 If InStr(1, Buffer, vbLf & "." & vbCrLf) Then
    4.                     Buffer = Mid$(Buffer, InStr(1, Buffer, vbCrLf) + 2)
    5.                     Buffer = Left$(Buffer, Len(Buffer) - 3)
    6.                     Set m_oMessage = New CMessage
    7.                     m_oMessage.CreateFromText Buffer
    8.                     m_colMessages.Add m_oMessage, m_oMessage.MessageID
    9.                     Set m_oMessage = Nothing
    10.                     Buffer = ""
    11.                     If CurrentMessage = Messages Then
    12.                         MessageState = POP3_QUIT
    13.                         Winsock1.SendData "QUIT" & vbCrLf
    14.                     Else
    15.                         CurrentMessage = CurrentMessage + 1
    16.                         MessageState = POP3_RETR
    17.                         Winsock1.SendData "RETR " & CStr(CurrentMessage) & vbCrLf
    18.                     End If
    19.                 End If

    The numbers appear to be correct, I just compared the sizes of the messages I got through my program with the sizes of the messages I got when I telnetted to the mail server, and the order in which they appear match exactly.
    Last edited by hothead; Nov 28th, 2002 at 04:35 PM.

  11. #11

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Now I know for sure the numbers are correct.

    I just tried passing the message number to lvwMail.ListItems.Add, then tried calling the number that way, and I got the same error.

    Error 40009: Wrong protocol or connection state for selected transaction or request

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width