Email Delete

It appears to be simple but not fully explained in the docs. The syntax, given an existing POP connection, is meant to be:

myPop3Socket.DeleteMessage index

It isn’t explained in the docs where that index comes from.

It’s probably the index of the email inside the pop mailbox.

Yes I imagine that using 0 would always work. As long as 0 always represented the oldest message. I was wanting to call this from inside the MessageReceived event. So grab the message then immediately delete.

I could reverse engineer, just hoping someone already knew.

Oh actually apparently the “id” argument to the MessageReceived event is “index”.
I tried using the delete with id, from within the MessageReceived event, to no avail.
I question is of course, does deleting that index change the indices of all the other messages.

The slightly modified sample code:
#Pragma Unused id
Dim s As String

// display the message
s = email.BodyHTML
If s = “” Then
s = email.BodyPlainText
End If
If s.Encoding = Nil Then
s = DefineEncoding(s, Encodings.ASCII)
End If
MsgBox ReplaceLineEndings(s, EndOfLine) // I changed this line to MsgBox
Me.DeleteMessage id // I added this line

This has the peculiar behaviour of “deleting” each email, as long as the socket is connected. But the messages are still on the server. When I stop and restart my program, it will deliver the same messages again, but only the first time I request them.

The rest of the code is pretty much from the email sample (non-secure)

So if I put a MsgBox in the MessageDeleted event (and with 8 messages on the server), I get 8 MsgBox’s with indices 1 to 8 saying messages received, then 8 MsgBox’s with indices 1 to 8 saying messages deleted.

Since index=1 is the oldest message, then once it is deleted, does that make the next message index again be 1? It seems it should. But in any case, none of the messages are actually deleted.

OK I’ve more or less figured it out. I grabbed the count from the messageCount event, and stored it in a property emailCount. Then after getting all the messages, run this code:

If id = Self.emailCount Then // if this is the last message to be retreived…
For i = 1 To Self.emailCount // delete al of them
Me.DeleteMessage i
Next
Me.SendServerCommand “QUIT” // this commits the deletes
End If

“For future reference”
Documentation improvement would be nice.