Skip to content

Commit

Permalink
Merge pull request #79 from captbaritone/issue/78-support-for-https-urls
Browse files Browse the repository at this point in the history
HTTPS URL support for `grabUrlsFromLastEmail` with tests
  • Loading branch information
Jamesking56 authored Mar 8, 2021
2 parents b96143c + 47e9c7a commit c1819d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Module/MailCatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,16 @@ public function grabFromLastEmailTo(string $address, string $regex): string
*/
public function grabUrlsFromLastEmail(): array
{
$regex = '#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#';
$email = $this->lastMessage();

$message = Message::from($email->getSource());

$text = $message->getTextContent();
preg_match_all('#\bhttp?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $text, $text_matches);
preg_match_all($regex, $text, $text_matches);

$html = $message->getHtmlContent();
preg_match_all('#\bhttp?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $html, $html_matches);
preg_match_all($regex, $html, $html_matches);

return array_merge($text_matches[0], $html_matches[0]);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/acceptance/MailcatcherCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ public function test_grab_from_last_email_to(AcceptanceTester $I)
* @example ["http://localhost.com/index.php?auth&token=123"]
* @example ["http://localhost.com/index.php?auth&id=12&token=123"]
* @example ["http://example.com/list.php?page=56"]
*
* @example ["https://localhost"]
* @example ["https://localhost/"]
* @example ["https://localhost.com"]
* @example ["https://localhost.com/"]
* @example ["https://localhost.com/index.html"]
* @example ["https://localhost.com/index.php"]
* @example ["https://localhost.com/index.php?token=123"]
* @example ["https://localhost.com/index.php?auth&token=123"]
* @example ["https://localhost.com/index.php?auth&id=12&token=123"]
* @example ["https://example.com/list.php?page=56"]
*/
public function test_grab_urls_from_last_email(
AcceptanceTester $I,
Expand Down

0 comments on commit c1819d2

Please sign in to comment.