IMAP Wrapper client for PHP & Default IMAP Search Criteria

There are many variations of these out there, SSilence/php-imap-client is a lib with a nice set of methods, clean integration and pretty good documentation.
Adding it to my goto essentials !

  1. $mailbox = 'my.imapserver.com';
  2. $username = 'username';
  3. $password = 'secret';
  4. $encryption = Imap::ENCRYPT_SSL;
  5.  
  6. // Open connection
  7. try{
  8.     $imap = new Imap($mailbox, $username, $password, $encryption);
  9.     // You can also check out example-connect.php for more connection options
  10.  
  11. }catch (ImapClientException $error){
  12.     echo $error->getMessage().PHP_EOL;
  13.     die(); // Oh no :( we failed
  14. }
  15.  
  16. // Get all folders as array of strings
  17. $folders = $imap->getFolders();
  18. foreach($folders as $folder) {
  19.     echo $folder;
  20. }
  21.  
  22. // Select the folder Inbox
  23. $imap->selectFolder('INBOX');
  24.  
  25. // Count the messages in current folder
  26. $overallMessages = $imap->countMessages();
  27. $unreadMessages = $imap->countUnreadMessages();

GitHub

Enjoy coding …

Default IMAP Search Criteria

  1. ALL
  2.       All messages in the mailbox; the default initial key for
  3.         ANDing.
  4.  
  5. ANSWERED
  6.         Messages with the \Answered flag set.
  7.  
  8. BCC
  9.         Messages that contain the specified string in the envelope
  10.         structure's BCC field.
  11.  
  12. BEFORE
  13.         Messages whose internal date (disregarding time and timezone)
  14.         is earlier than the specified date.
  15.  
  16. BODY
  17.         Messages that contain the specified string in the body of the
  18.         message.
  19.  
  20. CC
  21.         Messages that contain the specified string in the envelope
  22.         structure's CC field.
  23.  
  24. DELETED
  25.         Messages with the \Deleted flag set.
  26.  
  27. DRAFT
  28.         Messages with the \Draft flag set.
  29.  
  30. FLAGGED
  31.         Messages with the \Flagged flag set.
  32.  
  33. FROM
  34.         Messages that contain the specified string in the envelope
  35.         structure's FROM field.
  36.  
  37. HEADER  
  38.         Messages that have a header with the specified field-name (as
  39.         defined in [RFC-2822]) and that contains the specified string
  40.         in the text of the header (what comes after the colon).  If the
  41.         string to search is zero-length, this matches all messages that
  42.         have a header line with the specified field-name regardless of
  43.         the contents.
  44.  
  45. KEYWORD
  46.         Messages with the specified keyword flag set.
  47.  
  48. LARGER
  49.         Messages with an [RFC-2822] size larger than the specified
  50.         number of octets.
  51.  
  52. NEW
  53.         Messages that have the \Recent flag set but not the \Seen flag.
  54.         This is functionally equivalent to "(RECENT UNSEEN)".
  55.  
  56. NOT
  57.         Messages that do not match the specified search key.
  58.  
  59. OLD
  60.         Messages that do not have the \Recent flag set.  This is
  61.         functionally equivalent to "NOT RECENT" (as opposed to "NOT
  62.         NEW").
  63.  
  64. ON
  65.         Messages whose internal date (disregarding time and timezone)
  66.         is within the specified date.
  67.  
  68. OR  
  69.         Messages that match either search key.
  70.  
  71. RECENT
  72.         Messages that have the \Recent flag set.
  73.  
  74. SEEN
  75.         Messages that have the \Seen flag set.
  76.  
  77. SENTBEFORE
  78.         Messages whose [RFC-2822] Date: header (disregarding time and
  79.         timezone) is earlier than the specified date.
  80.  
  81. SENTON
  82.         Messages whose [RFC-2822] Date: header (disregarding time and
  83.         timezone) is within the specified date.
  84.  
  85. SENTSINCE
  86.         Messages whose [RFC-2822] Date: header (disregarding time and
  87.         timezone) is within or later than the specified date.
  88.  
  89. SINCE
  90.         Messages whose internal date (disregarding time and timezone)
  91.         is within or later than the specified date.
  92.  
  93. SMALLER
  94.         Messages with an [RFC-2822] size smaller than the specified
  95.         number of octets.
  96.  
  97. SUBJECT
  98.         Messages that contain the specified string in the envelope
  99.         structure's SUBJECT field.
  100.  
  101. TEXT
  102.         Messages that contain the specified string in the header or
  103.         body of the message.
  104.  
  105. TO
  106.         Messages that contain the specified string in the envelope
  107.         structure's TO field.
  108.  
  109. UID
  110.         Messages with unique identifiers corresponding to the specified
  111.         unique identifier set.  Sequence set ranges are permitted.
  112.  
  113. UNANSWERED
  114.         Messages that do not have the \Answered flag set.
  115.  
  116. UNDELETED
  117.         Messages that do not have the \Deleted flag set.
  118.  
  119. UNDRAFT
  120.         Messages that do not have the \Draft flag set.
  121.  
  122. UNFLAGGED
  123.         Messages that do not have the \Flagged flag set.
  124.  
  125. UNKEYWORD
  126.         Messages that do not have the specified keyword flag set.
  127.  
  128. UNSEEN
  129.         Messages that do not have the \Seen flag set.

 

Alex

I am a full-stack developer. I love programming,  design and know my way around server architecture as well.  I would never feel complete, with one of these missing. I have a broad range of interests, that’s why I constantly dive into new technologies and expand my knowledge where ever required. Technologies are evolving fast and I enjoy using the latest. Apart from that, I am a peace loving guy who tries to have people around him that think the same.  I truly believe in the principle: “If you help someone, someone will help you, when you need it."

Recent Posts

B&B / Hotel Booking Solutions for WordPress | 2024

BOOKING SOLUTIONS 202x This is my take on a subset of booking, appointment, PMS or… Read More

4 weeks ago

WordPress Cron + WP-CLI + Ntfy

THE GOAL Create a system cron for WordPress, that is accessible and can be easily… Read More

2 months ago

2024 is here and now :)

2024, what's cooking? Slowly getting into the 2024 spirit. 3 projects coming to a close… Read More

4 months ago

2023 ends and whats next !

Short look back at 2023 This has been a busy and interesting year. I am… Read More

4 months ago

cubicFUSION Grid Tweaker – Elementor Grid made easy.

Elementor Pro provides grid containers as an experimental feature. The options provided are limited, when… Read More

5 months ago

Archaeology Travel Booth – Travel Innovation Summit 2023

Archaeology Travel is an online travel guide for people who enjoy exploring the world’s pasts.… Read More

6 months ago