Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Mark IMAP Email as Read/Unread (Seen/Unseen)Demonstrates how to mark emails as read or unread.
integer li_rc oleobject loo_Imap integer li_Success integer li_NumMsgs integer i oleobject loo_Email integer li_BIsUid // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Imap = create oleobject // Use "Chilkat_9_5_0.Imap" for versions of Chilkat < 10.0.0 li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap") if li_rc < 0 then destroy loo_Imap MessageBox("Error","Connecting to COM object failed") return end if // Connect to an IMAP server. // Use TLS loo_Imap.Ssl = 1 loo_Imap.Port = 993 li_Success = loo_Imap.Connect("imap.someMailServer.com") if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if // Login li_Success = loo_Imap.Login("myLogin","myPassword") if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if // Select an IMAP mailbox li_Success = loo_Imap.SelectMailbox("Inbox") if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if // Set PeekMode so that downloaded messages are not // automatically marked as seen. loo_Imap.PeekMode = 1 // The NumMessages property contains the number of messages // in the currently selected mailbox. li_NumMsgs = loo_Imap.NumMessages if li_NumMsgs = 0 then destroy loo_Imap return end if for i = 1 to li_NumMsgs // Download each email by sequence number (not UID) loo_Email = loo_Imap.FetchSingle(i,0) if loo_Imap.LastMethodSuccess = 0 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if // If desired, mark the email as SEEN. There are two // ways to do it: // 1) Set the flag directly by using the sequence number // Indicate that we are passing a sequence number and // not a UID: li_BIsUid = 0 // Set the SEEN flag = 1 to mark the email as SEEN, // or set it to 0 to mark it as not-seen. li_Success = loo_Imap.SetFlag(i,li_BIsUid,"SEEN",1) if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if // 2) Alternatively, we can use the email object. // When an email is downloaded from the IMAP server // Chilkat will add a "ckx-imap-uid" header to the email. // This makes it possible to know the UID associated with // the email. (This is not the sequence number, which may change // from session to session, but the UID which does not change. // The SetMailFlag method is identical to SetFlag, except // it gets the UID from the ckx-imap-uid header. // For example: li_Success = loo_Imap.SetMailFlag(loo_Email,"SEEN",1) if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if destroy loo_Email next // Disconnect from the IMAP server. li_Success = loo_Imap.Disconnect() destroy loo_Imap |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.