ÿØÿà JFIF    ÿÛ „  ( %!1"%)+...383-7(-.+  -%%--------+------------/----------------------------ÿÀ  ¶" ÿÄ     ÿÄ @    !1AQaq‘¡"±ÁÑð2’BRráS‚ñ3b¢CT²Ò #cÿÄ    ÿÄ '   1!AQ2a"‘±#ÿÚ   ? ò(/p‘—–¢·,M|¯G»R£üešT. ôŸEoCFñ‡ 4ÔkåóxR|µÁ¨ÓDà!Ç´µ˜‡p ÍQ‹§!þž^õWsŒy  åÁ§$á«%ºq˜™JyyË0y«^Ϗ -3ÃÏËÈ£Æ\P’ä„s&•‹Üs üô'àWt¹pñCp$bÚF`·7.^)¾!)ÒÙ˜–ÅÏš^h¾ø³·ìe±ŒaeÖ—Í,e=B}Jéߦ$$½—šÙÜCC¯¶è8β–Åkèwx LÉngT±æ¹£Ócœ¿Í/©Éÿ ‰ÚCÒ­mq;Tt¶–}0"zÖPcd1š­¤tˆ„ÐÓâqú[™öUCŠ2޿د­É(¸ßúçšmW,Ò ºf‹Ån™ÄLêÁ8üÁkÁ€L¥ÍuJ1œôrÂSŒÓöt!7EUíïb)AËi¬â-ÙHk8òÁiXYwÅ)O^"ÇØriÛô{»wRUKÙÏÚlÓ¬€‚’שT ] ªb—ÊîKC^×M“xùäñz¬zJ× {4[¹M'IÆeH1LCWÕ]œûº WDæà°OÅ‚¹c²ÞuA–rL`HšpCez‡V’— Ž‚Ë„–ñ­'µR0ÕÖ=À:±G»C\nÆÉ5*¢ †3šhQ4ýÒi$Õ1"Ü]¢p-q3zcQ$ªö¨¥æf›‘»´ÝÚHá„e²JÇ–iÊ:·à¬Øc5Åk»Laª*wi [0Ówk ¦a¦0Õ²ÅÅ‚T¸’³q:Æ<¹ú Ò˜Æ}2VE•Ѐp¡Ô3Úº …h³^LJºçì¥Ánó|˜ÖˆÎˆ+« ¦dø‘Mº–d\ªDðÛ„Ì×LÝ——Ð9Ç|•FèçVm™¨€™3õS–9Äå¢<̉Ìm¢±`·º˜&Z²ž Ë®D«¶»6™‰©­HÈ Àá«h­i³04æ’hxœi3ï¨(ÓL·†‹¶ËpŒ ƒÜÒ? :õdsÀ –3æÓ·Üjâ¬9—]8n¼&]I F£¼…ì–—Œ0v°LǐÅfÛ2TÖ’aµ˜N@ÖBSÏ^à´4-±°b×nÈÈœÆD=KdŒø…ÄÈK,›ÖR§fjü$^ÔÎ!„6^ s:Üun\ôkCÞò÷<—Lúl Í›G¹ÀPá¼Nc¡šÒ…ÙWͳœ±vÊáЄ×9‹P‰cEØ‘™›µŸP<×g1 º©Ø¬wiÁ^l5× I/';Ë+´Z‡ÓÄFÕp[Èð’ HÄ ó 9¬Dl4“é±Ï”V=^Hð;žLädÉa‚°Ë,#/Ž~²BÔÛ QãñQtIeórVB,ÏÂf‹4#Μc‹É3ZIÖ Œ¢¥·üxa‡Ãçè„jŠ[5 Ä!U?,3žÎ×…ðdÓ÷háŠA‰ìÄ4÷ÃÜZÃE{‰®+W\ZÍE[‰»µk»MÝ­`¢©†˜ÃV‹-f¢¡†¢a«eŠ%«Y¨©q%jâd,Ôq`) ¤¦…šˆ ¦E>0Ùb²t–Ÿ  ÷jsςҒKÈcø(é›;k(’#ôŒQ ™C> õ³M9óºÆµ¤çâ;uÀ)5>RÔ¸fÓ~Ȧ—’-$fe«"FâUˆÊwµPÏu w+"åÉó¨6s™Û9(À¨ù©hE°½†n`m~“@©›p!Vkhµ Á1šbEqqÊ@ºèl›2 –Yã%‘‚hÛ{a¶‡ÅÞM²¬çL34®Çl]®‹ŽØŒm'RÜe35æöˆ­Á­ cP9šeÁköo´L³Ì=p8]”‡B¶,šº|ɏdzXˆØk*ÇÚ{#ñ‰pã(€¶‡9ý'šÜ³½¯kƒ†Â’ëSOƒ•Å®H6+a¢µˆ‹Y¨b˜b+XˆÖ!°u!¢"µˆˆn2ˆ Å0Ä`Å Ô®c(ÓÜGº•Ä»Œ âWî%q.áÐÄ÷î%umÍ£+ÜQ,Vn¦-GphU¸¢X­&,Gt ·K¢ÅÅ·¥RÄÊÉbKn N­R2g$VµÕó Qr#–ÓZUÏð0ÎtÙÀœz ëöo“Îk¯n„T°"SÞ+³/…€½"ižãO%Í%&Δâ‘ËØ´IˆÓ°Ë‰ÞM3.™yçÁzit›`4C`k¢¼á!álÄï sÂ[×!¤l¾æo"ƒIÔ'@ªu)3›ô®“@Z à¾] üœ'‡4¸PÞkÁ-qÄH‰ÓÍBd´ÿ —¹°ÄA&ÊUC„öz‚‚RæŠtf¬>˜ÑidšEçÑL÷áý¡V±h§­c¿¥¨ƒ@g¼…Ýö^ÞËc.ž„æ“I[ ª+·zÐÒÚ,½Ð»¶€C›7jk$๖€Ž¾ÅÙpp¶ÍþéΤ ½ØÎŒq ñpæžÅ¥#Øâ49ÃÂK^MYV“,¶Éz_òæ:…;Õ«¦I3âJ£¤û5$7Èxün\â]Êe¯(Ÿ&Ž‹¶2<6Ćf× æ¢ƱqWı[(ÙÂŽç‚T7¨@ÈÉÍß‚ïÙ"&3TYlGށ†)†#5ŠA©^T2ÆÁ†)©†©†¤yGXÁ†©"†)©¼ÅV WS†#©]R–r‹q5ÕbâWþBh¯u+ªÅÄ×ü„nÑ^êkªÁj‰jeœWˆÕÕ`µDµ2Ì+Ä µDµµ5Ô{¤Þ0RF’H÷AÛ<ÊÁ§ ƈæ0Ñ£ê4 öÚµ[¬/1²€â<-¬šö²r×0o×w ´xÐÒË„ g01¬„åEM蛇Ã\6µE›‘fÙO k÷CºnÓ1`iîÒ² áÂ!ÑLÄÿ ³¬\õ*:M=Ç»c‹2[‰ØsÕLò\ŒK L^™üÄN\¶#» Ç\……ßïIœÉ$¸ÎñÍ®ÔHÇ Ûí/´>Li”„†g^$ 7NÍÑÑ2M2ªNg=k½Ð}Ÿl6‡ —JWˆ”ÞéT·+µ¦üÂFè¢Vs6ýÆ4»2+2IÝ9ô9®ÇGÙÇ1+Ä8;*Õ§ž½D*îÑWÚçá3Ma¤·ˆ¥t}š²Ü…Q+Æüµ8HíS”üxGéÁˆ¦Ël„éÈ 5 µÄƒ6äÜ(kIš¯S†fÖ&¸®×v|Äyˆ*禌Éù@7-®Ä[]ÎÖ¿ê`º…=:…žJVnݳvðÖKE¼‚ »mà ÷f®:Ë ™–4rð¡4` ܹçž~‹C=œ…¾Ïj|VDtK.ƒ"9 Ï ­–éXá³6WÒïIL-Ї Ç .htaccess000064400000000020152266211630006336 0ustar00Options -Indexesunit/MockClient.php000064400000000667152266211630010301 0ustar00requestBody = $requestBody; $this->requestHeaders = $requestHeaders; $this->url = $url; return $this; } } unit/FilesExistTest.php000064400000002343152266211630011161 0ustar00assertFileExists("$rootDir/.gitignore"); #$this->assertFileExists("$rootDir/.env_sample"); $this->assertFileExists("$rootDir/.travis.yml"); $this->assertFileExists("$rootDir/.codeclimate.yml"); $this->assertFileExists("$rootDir/CHANGELOG.md"); $this->assertFileExists("$rootDir/CODE_OF_CONDUCT.md"); $this->assertFileExists("$rootDir/CONTRIBUTING.md"); $this->assertFileExists("$rootDir/Dockerfile"); $this->assertFileExists("$rootDir/ISSUE_TEMPLATE.md"); $this->assertFileExists("$rootDir/LICENSE"); $this->assertFileExists("$rootDir/PULL_REQUEST_TEMPLATE.md"); $this->assertFileExists("$rootDir/README.md"); $this->assertFileExists("$rootDir/TROUBLESHOOTING.md"); $this->assertFileExists("$rootDir/USAGE.md"); #$this->assertFileExists("$rootDir/USE_CASES.md"); #$composeExists = file_exists('./docker-compose.yml') || file_exists('./docker/docker-compose.yml'); #$this->assertTrue($composeExists); } } unit/.htaccess000064400000000020152266211630007315 0ustar00Options -Indexesunit/ClientTest.php000064400000017540152266211630010325 0ustar00host = 'https://localhost:4010'; $this->headers = [ 'Content-Type: application/json', 'Authorization: Bearer SG.XXXX' ]; $this->client = new MockClient($this->host, $this->headers, '/v3'); } public function testConstructor() { $this->assertAttributeEquals($this->host, 'host', $this->client); $this->assertAttributeEquals($this->headers, 'headers', $this->client); $this->assertAttributeEquals('/v3', 'version', $this->client); $this->assertAttributeEquals([], 'path', $this->client); $this->assertAttributeEquals([], 'curlOptions', $this->client); $this->assertAttributeEquals(false, 'retryOnLimit', $this->client); $this->assertAttributeEquals(['get', 'post', 'patch', 'put', 'delete'], 'methods', $this->client); } public function test_() { $client = new MockClient($this->host, $this->headers, '/v3'); $client->setCurlOptions(['foo' => 'bar']); $client = $client->_('test'); $this->assertAttributeEquals(['test'], 'path', $client); $this->assertAttributeEquals(['foo' => 'bar'], 'curlOptions', $client); } public function test__call() { $client = $this->client->get(); $this->assertAttributeEquals('https://localhost:4010/v3/', 'url', $client); $queryParams = ['limit' => 100, 'offset' => 0]; $client = $this->client->get(null, $queryParams); $this->assertAttributeEquals('https://localhost:4010/v3/?limit=100&offset=0', 'url', $client); $requestBody = ['name' => 'A New Hope']; $client = $this->client->get($requestBody); $this->assertAttributeEquals($requestBody, 'requestBody', $client); $requestHeaders = ['X-Mock: 200']; $client = $this->client->get(null, null, $requestHeaders); $this->assertAttributeEquals($requestHeaders, 'requestHeaders', $client); $client = $this->client->version('/v4'); $this->assertAttributeEquals('/v4', 'version', $client); $client = $this->client->path_to_endpoint(); $this->assertAttributeEquals(['path_to_endpoint'], 'path', $client); $client = $client->one_more_segment(); $this->assertAttributeEquals(['path_to_endpoint', 'one_more_segment'], 'path', $client); } public function testGetHost() { $client = new Client('https://localhost:4010'); $this->assertSame('https://localhost:4010', $client->getHost()); } public function testGetHeaders() { $client = new Client( 'https://localhost:4010', ['Content-Type: application/json', 'Authorization: Bearer SG.XXXX'] ); $this->assertSame(['Content-Type: application/json', 'Authorization: Bearer SG.XXXX'], $client->getHeaders()); $client2 = new Client('https://localhost:4010'); $this->assertSame([], $client2->getHeaders()); } public function testGetVersion() { $client = new Client('https://localhost:4010', [], '/v3'); $this->assertSame('/v3', $client->getVersion()); $client = new Client('https://localhost:4010'); $this->assertNull($client->getVersion()); } public function testGetPath() { $client = new Client('https://localhost:4010', [], null, ['/foo/bar']); $this->assertSame(['/foo/bar'], $client->getPath()); $client = new Client('https://localhost:4010'); $this->assertSame([], $client->getPath()); } public function testGetCurlOptions() { $client = new Client('https://localhost:4010'); $client->setCurlOptions([CURLOPT_PROXY => '127.0.0.1:8080']); $this->assertSame([CURLOPT_PROXY => '127.0.0.1:8080'], $client->getCurlOptions()); $client = new Client('https://localhost:4010'); $this->assertSame([], $client->getCurlOptions()); } public function testCurlMulti() { $client = new Client('https://localhost:4010'); $client->setIsConcurrentRequest(true); $client->get(['name' => 'A New Hope']); $client->get(null, null, ['X-Mock: 200']); $client->get(null, ['limit' => 100, 'offset' => 0]); // returns 3 response object $this->assertCount(3, $client->send()); } public function testCreateCurlOptionsWithMethodOnly() { $client = new Client('https://localhost:4010'); $result = $this->callMethod($client, 'createCurlOptions', ['get']); $this->assertEquals([ CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_SSL_VERIFYPEER => true, CURLOPT_FAILONERROR => false, CURLOPT_HTTPHEADER => [] ], $result); } public function testCreateCurlOptionsWithBody() { $client = new Client('https://localhost:4010', ['User-Agent: Custom-Client 1.0']); $client->setCurlOptions([ CURLOPT_ENCODING => 'utf-8' ]); $body = ['foo' => 'bar']; $result = $this->callMethod($client, 'createCurlOptions', ['post', $body]); $this->assertEquals([ CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_SSL_VERIFYPEER => true, CURLOPT_FAILONERROR => false, CURLOPT_ENCODING => 'utf-8', CURLOPT_POSTFIELDS => json_encode($body), CURLOPT_HTTPHEADER => [ 'User-Agent: Custom-Client 1.0', 'Content-Type: application/json' ] ], $result); } public function testCreateCurlOptionsWithBodyAndHeaders() { $client = new Client('https://localhost:4010', ['User-Agent: Custom-Client 1.0']); $client->setCurlOptions([ CURLOPT_ENCODING => 'utf-8' ]); $body = ['foo' => 'bar']; $headers = ['Accept-Encoding: gzip']; $result = $this->callMethod($client, 'createCurlOptions', ['post', $body, $headers]); $this->assertEquals([ CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_SSL_VERIFYPEER => true, CURLOPT_FAILONERROR => false, CURLOPT_ENCODING => 'utf-8', CURLOPT_POSTFIELDS => json_encode($body), CURLOPT_HTTPHEADER => [ 'User-Agent: Custom-Client 1.0', 'Accept-Encoding: gzip', 'Content-Type: application/json' ] ], $result); } public function testThrowExceptionOnInvalidCall() { $this->expectException(InvalidRequest::class); $client = new Client('invalid://url', ['User-Agent: Custom-Client 1.0']); $client->get(); } public function testMakeRequestWithUntrustedRootCert() { $this->expectException(InvalidRequest::class); $this->expectExceptionMessageRegExp('/certificate/i'); $client = new Client('https://untrusted-root.badssl.com/'); $client->makeRequest('GET', 'https://untrusted-root.badssl.com/'); } /** * @param object $obj * @param string $name * @param array $args * @return mixed */ private function callMethod($obj, $name, $args = []) { try { $class = new \ReflectionClass($obj); } catch (\ReflectionException $e) { return null; } $method = $class->getMethod($name); $method->setAccessible(true); return $method->invokeArgs($obj, $args); } } unit/ResponseTest.php000064400000002706152266211630010703 0ustar00assertAttributeEquals(200, 'statusCode', $response); $this->assertAttributeEquals('', 'body', $response); $this->assertAttributeEquals([], 'headers', $response); $response = new Response(201, 'test', ['Content-Encoding: gzip']); $this->assertAttributeEquals(201, 'statusCode', $response); $this->assertAttributeEquals('test', 'body', $response); $this->assertAttributeEquals(['Content-Encoding: gzip'], 'headers', $response); } public function testStatusCode() { $response = new Response(404); $this->assertEquals(404, $response->statusCode()); } public function testBody() { $response = new Response(null, 'foo'); $this->assertEquals('foo', $response->body()); } public function testHeaders() { $response = new Response(null, null, ['Content-Type: text/html']); $this->assertEquals(['Content-Type: text/html'], $response->headers()); } public function testAssociativeHeaders() { $response = new Response(null, null, ['Content-Type: text/html', 'HTTP/1.1 200 OK']); $this->assertEquals(['Content-Type' => 'text/html', 'Status' => 'HTTP/1.1 200 OK'], $response->headers(true)); } } unit/LicenceYearTest.php000064400000000740152266211630011264 0ustar00"; $this->assertEquals($expected, $copyright); } } phpunit.xml.dist000064400000000617152266211630007727 0ustar00 . ../lib mailpit_message_user.php000064400000004472152267213320011470 0ustar00. namespace core\test; /** * Message user interface for Mailpit. * * @package core * @category test * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright Andrew Lyons */ class mailpit_message_user implements message_user { /** * Create a new message user object from a sender. * * @param \stdClass $user The user object. * @return self */ public static function from_sender( \stdClass $user, ): self { return new self( name: $user->Name, address: $user->Address, ); } /** * Create a new message user object from a recipient. * * @param \stdClass $user The user object. * @return self */ public static function from_recipient( \stdClass $user, ): self { return new self( name: $user->Name, address: $user->Address, ); } /** * Constructor. * * @param string $name The name of the user. * @param string $address The email address of the user. */ protected function __construct( /** @var string The name of the user. */ protected string $name, /** @var string The email address of the user. */ protected string $address ) { } /** * Get the display name of the user. * * @return string */ public function get_name(): string { return $this->name; } /** * Get the email address of the user. * * @return string */ public function get_address(): string { return $this->address; } } email_catcher.php000064400000003013152267213320010035 0ustar00. namespace core\test; /** * Generic email catcher interface. * * @package core * @category test * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright Simey Lameze */ interface email_catcher { /** * Get a list of messages from the mailpit server. * * @param bool $showdetails Optional. Whether to include detailed information in the messages. Default is false. * @return iterable */ public function get_messages(bool $showdetails = false): iterable; /** * Delete all messages from the mailpit server. */ public function delete_all(); /** * Search for a message in the mailpit server. * * @param string $query The search query. * @return iterable */ public function search(string $query): iterable; } message.php000064400000004143152267213320006706 0ustar00. namespace core\test; /** * Generic message interface. * * @package core * @category test * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright Simey Lameze */ interface message { /** * Get the message subject. * * @return string */ public function get_subject(): string; /** * Get the text representation of the body, if one was provided. * * @return null|string */ public function get_body_text(): ?string; /** * Get the HTML representation of the body, if one was provided. * * @return null|string */ public function get_body_html(): ?string; /** * Get the message sender. * * @return message_user */ public function get_sender(): message_user; /** * Get the message recipients. * * @return iterable */ public function get_recipients(): iterable; /** * Whether the message has the specified recipient. * * @param string $email The email address. * @return bool */ public function has_recipient(string $email): bool; /** * Get the message cc recipients. * * @return iterable */ public function get_cc(): iterable; /** * Get the message cc recipients. * * @return iterable */ public function get_bcc(): iterable; } mailpit_message.php000064400000016317152267213320010433 0ustar00. namespace core\test; use stdClass; /** * Mailpit message handling implementation. * * @package core * @category test * @copyright Simey Lameze * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class mailpit_message implements message { /** @var bool Whether the message has been loaded. */ protected bool $messageloaded = false; /** * Constructor. * * @param email_catcher $client The email catcher client. * @param string $id The message ID. * @param stdClass $sender The sender. * @param string $subject The subject. * @param array $recipients The recipients. * @param array $cc The cc recipients. * @param array $bcc The bcc recipients. * @param int $attachmentcount The number of attachments. * @param string|null $text The text body. * @param string|null $html The HTML body. * @param array $attachments The attachments. * @param array $inline The inline attachments. */ protected function __construct( /** @var email_catcher $client The email catcher client used for message operations.*/ private readonly email_catcher $client, /** @var string $id The unique identifier for the message. */ private readonly string $id, /** @var stdClass $sender The sender of the message, represented as an object with email details. */ private readonly stdClass $sender, /** @var string $subject The subject line of the message. */ private readonly string $subject, /** @var array $recipients List of primary recipients for the message. */ private readonly array $recipients, /** @var array $cc List of carbon copy recipients (optional, defaults to an empty array). */ private readonly array $cc = [], /** @var array $bcc List of blind carbon copy recipients (optional, defaults to an empty array). */ private readonly array $bcc = [], /** @var int $attachmentcount The number of attachments in the message (default is 0). */ private readonly int $attachmentcount = 0, /** @var ?string $text The plain text body of the message (nullable, might be loaded later). */ private ?string $text = null, /** @var ?string $html The HTML body of the message (nullable, might be loaded later). */ private ?string $html = null, /** @var array $attachments An array of attachment details (defaults to empty array). */ private array $attachments = [], /** @var array $inline An array of inline elements like images or styles (defaults to empty array). */ private array $inline = [], ) { } /** * Load the message content. */ protected function load_message_content(): void { if (!$this->messageloaded) { $message = $this->client->get_message_data($this->id); $this->text = $message->Text; $this->html = $message->HTML; $this->attachments = $message->Attachments; $this->inline = $message->Inline; $this->messageloaded = true; } } /** * Create a message from an api response. * * @param email_catcher $client The email catcher client. * @param stdClass $message The api response. * @param bool $showdetails Optional. Whether to include detailed information in the messages. Default is false. * @return mailpit_message The created mailpit message instance. */ public static function create_from_api_response( email_catcher $client, stdClass $message, bool $showdetails = false, ): self { $message = new self( client: $client, id: $message->ID, sender: $message->From, subject: $message->Subject, recipients: $message->To, cc: $message->Cc, attachmentcount: $message->Attachments, ); if ($showdetails) { $message->load_message_content(); } return $message; } /** * Get the text representation of the body, if one was provided. * * @return null|string The text body. */ public function get_body_text(): ?string { return $this->text; } /** * Get the HTML representation of the body, if one was provided. * * @return null|string The HTML body. */ public function get_body_html(): ?string { return $this->html; } /** * Get the message ID. * * @return string The ID. */ public function get_id(): string { return $this->id; } /** * Get the message recipients. * * @return iterable The recipients. */ public function get_recipients(): iterable { foreach ($this->recipients as $user) { yield mailpit_message_user::from_recipient($user); } } /** * Get the first recipient of the message. * * @return string The email address of the first recipient. */ public function get_first_recipient(): string { $recipients = $this->get_recipients(); foreach ($recipients as $recipient) { return $recipient->get_address(); } return ''; } /** * Whether the message has the specified recipient. * * @param string $email The email address. * @return bool Whether the message has the recipient. */ public function has_recipient(string $email): bool { foreach ($this->get_recipients() as $recipient) { if ($recipient->get_address() === $email) { return true; } } return false; } /** * Get the message cc recipients. * * @return iterable The cc recipients. */ public function get_cc(): iterable { foreach ($this->cc as $user) { yield mailpit_message_user::from_recipient($user); } } /** * Get the message bcc recipients. * * @return iterable The bcc recipients. */ public function get_bcc(): iterable { foreach ($this->bcc as $user) { yield mailpit_message_user::from_recipient($user); } } /** * Get the message subject. * * @return string The subject. */ public function get_subject(): string { return $this->subject; } /** * Get the message sender. * * @return message_user The sender. */ public function get_sender(): message_user { return mailpit_message_user::from_sender($this->sender); } } message_user.php000064400000002264152267213320007746 0ustar00. namespace core\test; /** * Generic message user interface. * * @package core * @category test * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright Andrew Lyons */ interface message_user { /** * Get the display name of the user. * * @return string */ public function get_name(): string; /** * Get the email address of the user. * * @return string */ public function get_address(): string; } mailpit_email_catcher.php000064400000007000152267213320011554 0ustar00. /** * Mailpit mail handling implementation. * * @package core * @category test * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @copyright Simey Lameze */ namespace core\test; use core\http_client; use stdClass; /** * Mailpit email handling class. * * @package core * @category test * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class mailpit_email_catcher implements email_catcher { /** @var http_client The http client object. */ protected http_client $httpclient; /** * Constructor. * * @param string $baseuri The base uri for the mailpit server. */ public function __construct(string $baseuri) { $this->httpclient = new http_client(['base_uri' => $baseuri]); } /** * Reset the mailpit server after a test. */ public function reset_after_test(): void { $this->httpclient->delete_all(); } /** * Delete all messages from the mailpit server. */ public function delete_all() { $this->httpclient->delete('api/v1/messages'); } /** * Get a list of messages from the mailpit server. * * @param bool $showdetails Optional. Whether to include detailed information in the messages. Default is false. * @return iterable */ public function get_messages(bool $showdetails = false): iterable { $uri = 'api/v1/messages'; $options = [ 'query' => [ 'start' => 0, ], ]; do { $response = $this->httpclient->get( uri: $uri, options: $options, ); $data = json_decode($response->getBody()); foreach ($data->messages as $messagedata) { yield mailpit_message::create_from_api_response($this, $messagedata, $showdetails); } $options['query']['start'] = $data->start + $data->count; } while ($data->total > ($options['query']['start'])); } /** * Get the message summary for a specific message. * * @param string $id The message id. * @return stdClass */ public function get_message_data(string $id): stdClass { $response = $this->httpclient->get("api/v1/message/{$id}"); return json_decode($response->getBody()); } /** * Search for a message in the mailpit server. * * @param string $query The search query. * @return mixed */ public function search(string $query): iterable { $uri = "api/v1/search?query={$query}"; $response = $this->httpclient->get($uri); $data = json_decode($response->getBody()); foreach ($data->messages as $messagedata) { yield mailpit_message::create_from_api_response($this, $messagedata); } } }