Lianja
Lianja
Delete Email Individually (One at a time) from an IMAP Mailbox
Downloads email from an IMAP mailbox and deletes emails individually (one by one).Chilkat Lianja Downloads
llSuccess = .F.
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loImap = createobject("CkImap")
// Connect to an IMAP server.
// Use TLS
loImap.Ssl = .T.
loImap.Port = 993
llSuccess = loImap.Connect("imap.example.com")
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
return
endif
// Login
llSuccess = loImap.Login("myLogin","myPassword")
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
return
endif
// Select an IMAP mailbox
llSuccess = loImap.SelectMailbox("Inbox")
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
return
endif
// We can choose to fetch UIDs or sequence numbers.
llFetchUids = .T.
// Get the message IDs of all the emails in the mailbox
loMessageSet = createobject("CkMessageSet")
llSuccess = loImap.QueryMbx("ALL",llFetchUids,loMessageSet)
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
release loMessageSet
return
endif
// Fetch the emails into a bundle object:
loBundle = createobject("CkEmailBundle")
llHeadersOnly = .F.
llSuccess = loImap.FetchMsgSet(llHeadersOnly,loMessageSet,loBundle)
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
release loMessageSet
release loBundle
return
endif
// To mark a complete set of emails for deletion, call SetFlags:
llSuccess = loImap.SetFlags(loMessageSet,"Deleted",1)
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
release loMessageSet
release loBundle
return
endif
// Messages can also be marked for deletion individually:
// Loop over the bundle and mark each message for deletion.
loEmail = createobject("CkEmail")
i = 0
lnNumEmails = loBundle.MessageCount
do while i < lnNumEmails
loBundle.EmailAt(i,loEmail)
? loEmail.From
? loEmail.Subject
// To delete this email, set the "Deleted" flag to 1.
// The email is not actually deleted until Expunge or
// ExpungeAndClose is called.
llSuccess = loImap.SetMailFlag(loEmail,"Deleted",1)
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
release loMessageSet
release loBundle
release loEmail
return
endif
? "--"
i = i + 1
enddo
llSuccess = loImap.ExpungeAndClose()
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
release loMessageSet
release loBundle
release loEmail
return
endif
// Disconnect from the IMAP server.
llSuccess = loImap.Disconnect()
release loImap
release loMessageSet
release loBundle
release loEmail