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
(DataFlex) Search IMAP Mailbox for Email Matching CriteriaSearching an IMAP mailbox for messages that match search criteria.
Use ChilkatAx-win32.pkg Procedure Test Handle hoImap Boolean iSuccess Variant vMessageSet Handle hoMessageSet Boolean iFetchUids String sAllMsgs String sAnswered String sOnDate String sBetweenDates String sComplexSearch1 String sBodySearch String sOrSearch String sFromSearch String sJohnSearch String sRecentSearch String sNotRecentSearch String sOldSearch String sMarkedForDeleteSearch String sHeaderSearch String sHeaderExistsSearch String sNewSearch String sSizeLargerSearch String sSeenSearch String sNotSeenSearch String sToSearch String sToSearch2 String sSmallerSearch String sFullSubstringSearch Variant vBundle Handle hoBundle Integer i Variant vEmail Handle hoEmail String sTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatImap)) To hoImap If (Not(IsComObjectCreated(hoImap))) Begin Send CreateComObject of hoImap End // Connect to an IMAP server. // Use TLS Set ComSsl Of hoImap To True Set ComPort Of hoImap To 993 Get ComConnect Of hoImap "imap.someMailServer.com" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End // Login Get ComLogin Of hoImap "myLogin" "myPassword" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End // Select an IMAP mailbox Get ComSelectMailbox Of hoImap "Inbox" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End // We can choose to fetch UIDs or sequence numbers. Move True To iFetchUids // Here are examples of different search criteria: // Return all messages. Move "ALL" To sAllMsgs // Search for already-answered emails. Move "ANSWERED" To sAnswered // Search for messages on a specific date. // The date string is DD-Month-YYYY where Month is // Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, or Dec. Move "SENTON 05-Mar-2007" To sOnDate // Search for messages between two dates. SENTBEFORE // finds emails sent before a date, and SENTSINCE finds // email sent on or after a date. The "AND" operation // is implied by joining criteria, separated by spaces. Move "SENTSINCE 01-Mar-2007 SENTBEFORE 05-Mar-2007" To sBetweenDates // Another example of AND: find all unanswered emails // sent after 04-Mar-2007 with "Problem" in the subject: Move 'UNANSWERED SENTSINCE 04-Mar-2007 Subject "Problem"' To sComplexSearch1 // Find messages with a specific string in the body: Move 'BODY "problem solved"' To sBodySearch // Using OR. The syntax is OR <criteria1> <criteria2>. // The "OR" comes first, followed by each criteria. // For example, to match all emails with "Help" or "Question" in the subject. // You'll notice that literal strings may be quoted or unquoted. // If a literal contains SPACE characters, quote it: Move "OR SUBJECT Help SUBJECT Question" To sOrSearch // ---------------------------------------------- // Strings are case-insensitive when searching.... // ---------------------------------------------- // Find all emails sent from yahoo.com addresses: Move "FROM yahoo.com" To sFromSearch // Find all emails sent from anyone with "John" in their name: Move "FROM John" To sJohnSearch // Find emails with the RECENT flag set: Move "RECENT" To sRecentSearch // Find emails that don't have the recent flag set: Move "NOT RECENT" To sNotRecentSearch // This is synonymous with "OLD": Move "OLD" To sOldSearch // Find all emails marked for deletion: Move "DELETED" To sMarkedForDeleteSearch // Find all emails having a specified header field with a value // containing a substring: Move "HEADER DomainKey-Signature paypal.com" To sHeaderSearch // Find any emails having a specific header field. If the // 2nd argument to the "HEADER" criteria is an empty string, // any email having the header field is returned regardless // of the header field's content. // Find any emails with a DomainKey-Signature field: Move 'HEADER DomainKey-Signature ""' To sHeaderExistsSearch // Find NEW emails: these are emails that have the RECENT flag // set, but not the SEEN flag: Move "NEW" To sNewSearch // Find emails larger than a certain number of bytes: Move "LARGER 500000" To sSizeLargerSearch // Find emails marked as seen or not already seen: Move "SEEN" To sSeenSearch Move "NOT SEEN" To sNotSeenSearch // Find emails having a given substring in the TO header field: Move "TO support@chilkatsoft.com" To sToSearch // A more long-winded way to do the same thing: Move "HEADER TO support@chilkatsoft.com" To sToSearch2 // Find emails smaller than a size in bytes: Move "SMALLER 30000" To sSmallerSearch // Find emails that have a substring anywhere in the header // or body: Move 'TEXT "Zip Component"' To sFullSubstringSearch // Pass any of the above strings here to test a search: Get ComSearch Of hoImap sOrSearch iFetchUids To vMessageSet If (IsComObject(vMessageSet)) Begin Get Create (RefClass(cComChilkatMessageSet)) To hoMessageSet Set pvComObject Of hoMessageSet To vMessageSet End Get ComLastMethodSuccess Of hoImap To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End // Fetch the email headers into a bundle object: Get ComFetchHeaders Of hoImap vMessageSet To vBundle If (IsComObject(vBundle)) Begin Get Create (RefClass(cComChilkatEmailBundle)) To hoBundle Set pvComObject Of hoBundle To vBundle End Get ComLastMethodSuccess Of hoImap To bTemp1 If (bTemp1 = False) Begin Send Destroy of hoMessageSet Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End // Display the Subject and From of each email. Move 0 To i While (i < (ComMessageCount(hoBundle))) Get ComGetEmail Of hoBundle i To vEmail If (IsComObject(vEmail)) Begin Get Create (RefClass(cComChilkatEmail)) To hoEmail Set pvComObject Of hoEmail To vEmail End Get ComGetHeaderField Of hoEmail "Date" To sTemp1 Showln sTemp1 Get ComSubject Of hoEmail To sTemp1 Showln sTemp1 Get ComFrom Of hoEmail To sTemp1 Showln sTemp1 Showln "--" Send Destroy of hoEmail Move (i + 1) To i Loop // Disconnect from the IMAP server. Get ComDisconnect Of hoImap To iSuccess Send Destroy of hoMessageSet Send Destroy of hoBundle End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.