Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 04e330b

Browse files
authored
Merge pull request #21 from yepzy/master
Add get multiple messages + get bcc of a message
2 parents b636766 + abaa1cd commit 04e330b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

‎src/Mailtrap.php‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,50 @@ public function seeAnAttachment($bool)
275275

276276
$this->assertEquals($bool, count($attachments) > 0);
277277
}
278+
279+
/**
280+
* Get the most recent messages of the default inbox.
281+
*
282+
* @param int $number
283+
*
284+
* @return array
285+
*/
286+
public function fetchLastMessages($number = 1)
287+
{
288+
$messages = $this->client->get("inboxes/{$this->config['inbox_id']}/messages")->getBody();
289+
if ($messages instanceof Stream) {
290+
$messages = $messages->getContents();
291+
}
292+
293+
$messages = json_decode($messages, true);
294+
295+
$firstIndex = count($messages) - $number;
296+
297+
$messages = array_slice($messages, $firstIndex, $number);
298+
299+
$this->assertCount($number, $messages);
300+
301+
return $messages;
302+
}
303+
304+
/**
305+
* Get the bcc property of a message
306+
*
307+
* @param int $messageId
308+
*
309+
* @return string
310+
*/
311+
public function getBccEmailOfMessage($messageId)
312+
{
313+
$message = $this->client->get("inboxes/{$this->config['inbox_id']}/messages/$messageId/body.eml")->getBody();
314+
if ($message instanceof Stream) {
315+
$message = $message->getContents();
316+
}
317+
$matches = [];
318+
preg_match('/Bcc:\s[\w.-]+@[\w.-]+\.[a-z]{2,6}/', $message, $matches);
319+
320+
$bcc = substr(array_shift($matches),5);
321+
322+
return $bcc;
323+
}
278324
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /