I try using the SetMailFlag method to delete a specific mail from my inbox but it doesn't work. I get the following error message from the set SetMailFlag method:
ChilkatLog: SetMailFlag: DllDate: Aug 5 2012 UnlockPrefix: Anything for 30-day trial Username: SELND39C29X0:SEDAVFRE Architecture: Little Endian; 32-bit Language: ActiveX VerboseLogging: 0 No ckx-imap-uid header field. --SetMailFlag --ChilkatLog
Here is my code. EmailId is a variable with the uid fetched from the mailbox at an earlier stage.
Public Sub DeleteMail(EmailId) Dim Imap As New ChilkatImap Dim Email
Imap.UnlockComponent ("Anything for 30-day trial") Imap.Ssl = 1 Imap.Port = 993
Imap.Connect "imapserver..." Imap.Login "login...", "pass..." Imap.SelectMailbox "Inbox" Set Email = Imap.FetchSingle(EmailId, 1) debug.print Imap.SetMailFlag(Email, "Deleted", 1) debug.print Imap.LastErrorText debug.print Imap.Expunge debug.print Imap.LastErrorText Imap.Disconnect Set Imap = Nothing
When emails are downloaded in other ways, such as by calling FetchBundle, where multiple emails are returned, Chilkat adds the ckx-imap-uid header so that an application can know the email's UID on the server.
The FetchSingle method call has two arguments: the first is a UID or sequence number, and the second is a boolean (which is 0/1 for the ActiveX) that indicates whether the 1st argument is a UID or sequence number. Given that the application already knows the UID, it can call the SetFlag method directly. The arguments for SetFlag are, in VBScript/ActiveX terms are shown below (see the online reference documentation for more information).
SetFlag(msgId As Long, bUid As Long, flagName As String, value As Long) As Long
The purpose of the SetMailFlag method is to allow an application to indirectly specify the UID via the email object, assuming the email object contains the ckx-imap-uid header. The application does not need to trouble itself with extracting the value of the ckx-imap-uid header and then interpret the value and pass the correct value to SetFlag.
In summary: The solution is to call SetFlag instead, passing the already-known UID to that method. To prevent this pitfall from happening in the future, I'm going to modify FetchSingle so that it adds the ckx-imap-uid header anyway. This will be a feature in the next version..