Skip to content

Commit fba8326

Browse files
Stéphane CoinonWebklex
authored andcommitted
Handle Carbon instances in message search criteria (#82)
Allow searching messages using a Carbon instance for the date criteria (BEFORE, ON, SINCE)
1 parent 7bbce7c commit fba8326

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Search for specific emails:
178178

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

183183
//Get all messages containing "hello world"
184184
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */

src/IMAP/Folder.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function getUnseenMessages($criteria = 'UNSEEN', $fetch_options = null, $
211211
* [['FROM' => '[email protected]'],[' TEXT' => 'Hello world!']]
212212
* ---------------------------------------------------------------------------------------
213213
* The following sample would search for all messages received since march 15 2018:
214-
* [['SINCE' => Carbon::parse('15.03.2018')->format('d M y')]]
214+
* [['SINCE' => Carbon::parse('15.03.2018')]]
215215
* ---------------------------------------------------------------------------------------
216216
* The following sample would search for all flagged messages:
217217
* [['FLAGGED']]
@@ -279,7 +279,11 @@ public function searchMessages(array $where, $fetch_options = null, $fetch_body
279279
if (count($statement) == 1) {
280280
$query .= $statement[0];
281281
} else {
282-
$query .= $statement[0].' "'.$statement[1].'"';
282+
$value = $statement[1];
283+
if ($value instanceof \Carbon\Carbon) {
284+
$value = $value->format('d M y');
285+
}
286+
$query .= $statement[0].' "'.$value.'"';
283287
}
284288
}
285289

0 commit comments

Comments
 (0)