|
-
Nov 27th, 2002, 12:39 PM
#1
Thread Starter
Fanatic Member
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:
Private Enum POP3States
POP3_Connect
POP3_USER
POP3_PASS
POP3_STAT
POP3_RETR
POP3_DELE
POP3_QUIT
End Enum
-
Nov 28th, 2002, 05:46 AM
#2
Frenzied Member
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.
-
Nov 28th, 2002, 08:44 AM
#3
Thread Starter
Fanatic Member
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:
Private Sub mnuDelete_Click()
Dim Item As ListItem
Set Item = lvwMail.ListItems(1)
Set lvwMail.SelectedItem = Item
DoEvents
Do Until lvwMail.SelectedItem.Index = lvwMail.ListItems.Count
If lvwMail.SelectedItem.Selected = True Then
lvwMail.SelectedItem.EnsureVisible
DoEvents
MessageState = POP3_DELE
Winsock1.SendData "DELE " & lvwMail.SelectedItem.text & vbCrLf
DoEvents
lvwMail.SelectedItem.Checked = False
End If
lvwMail.SelectedItem = lvwMail.ListItems(lvwMail.SelectedItem.Index + 1)
Loop
If lvwMail.SelectedItem.Checked = True Then
lvwMail.SelectedItem.EnsureVisible
DoEvents
MessageState = POP3_DELE
Winsock1.SendData "DELE " & lvwMail.SelectedItem.text & vbCrLf
DoEvents
lvwMail.SelectedItem.Checked = False
End If
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.
-
Nov 28th, 2002, 09:08 AM
#4
Frenzied Member
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.
-
Nov 28th, 2002, 09:23 AM
#5
Thread Starter
Fanatic Member
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.
-
Nov 28th, 2002, 09:52 AM
#6
Thread Starter
Fanatic Member
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.
-
Nov 28th, 2002, 09:55 AM
#7
Frenzied Member
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?
-
Nov 28th, 2002, 10:11 AM
#8
Thread Starter
Fanatic Member
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:
Private Sub mnuDelete_Click()
For i = lvwMail.ListItems.Count To 1 Step -1
If lvwMail.ListItems(i).Selected = True Then
lvwMail.ListItems(i).EnsureVisible
DoEvents
MessageState = POP3_DELE
Winsock1.SendData "DELE " & lvwMail.ListItems(i).Index & vbCrLf
DoEvents
lvwMail.ListItems.Remove i
End If
Next i
End Sub
-
Nov 28th, 2002, 10:23 AM
#9
Frenzied Member
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.
-
Nov 28th, 2002, 04:23 PM
#10
Thread Starter
Fanatic Member
Here's the code I'm using for RETR:
VB Code:
Case POP3_RETR
Buffer = Buffer & Data
If InStr(1, Buffer, vbLf & "." & vbCrLf) Then
Buffer = Mid$(Buffer, InStr(1, Buffer, vbCrLf) + 2)
Buffer = Left$(Buffer, Len(Buffer) - 3)
Set m_oMessage = New CMessage
m_oMessage.CreateFromText Buffer
m_colMessages.Add m_oMessage, m_oMessage.MessageID
Set m_oMessage = Nothing
Buffer = ""
If CurrentMessage = Messages Then
MessageState = POP3_QUIT
Winsock1.SendData "QUIT" & vbCrLf
Else
CurrentMessage = CurrentMessage + 1
MessageState = POP3_RETR
Winsock1.SendData "RETR " & CStr(CurrentMessage) & vbCrLf
End If
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.
-
Nov 28th, 2002, 07:30 PM
#11
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|