Skip to content

Commit

Permalink
Handle Carbon instances in message search criteria (#82)
Browse files Browse the repository at this point in the history
Allow searching messages using a Carbon instance for the date criteria
(BEFORE, ON, SINCE)
  • Loading branch information
Stéphane Coinon authored and Webklex committed Apr 14, 2018
1 parent 7bbce7c commit fba8326
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Search for specific emails:

//Get all messages since march 15 2018
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->searchMessages([['SINCE', Carbon::parse('15.03.2018')->format('d M y')]]);
$aMessage = $oFolder->searchMessages([['SINCE', Carbon::parse('15.03.2018')]]);

//Get all messages containing "hello world"
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
Expand Down
8 changes: 6 additions & 2 deletions src/IMAP/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function getUnseenMessages($criteria = 'UNSEEN', $fetch_options = null, $
* [['FROM' => 'someone@example.com'],[' TEXT' => 'Hello world!']]
* ---------------------------------------------------------------------------------------
* The following sample would search for all messages received since march 15 2018:
* [['SINCE' => Carbon::parse('15.03.2018')->format('d M y')]]
* [['SINCE' => Carbon::parse('15.03.2018')]]
* ---------------------------------------------------------------------------------------
* The following sample would search for all flagged messages:
* [['FLAGGED']]
Expand Down Expand Up @@ -279,7 +279,11 @@ public function searchMessages(array $where, $fetch_options = null, $fetch_body
if (count($statement) == 1) {
$query .= $statement[0];
} else {
$query .= $statement[0].' "'.$statement[1].'"';
$value = $statement[1];
if ($value instanceof \Carbon\Carbon) {
$value = $value->format('d M y');
}
$query .= $statement[0].' "'.$value.'"';
}
}

Expand Down

0 comments on commit fba8326

Please sign in to comment.