From 4a1d86b7376b57284915b7930cdb35e0a5983c92 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 18 Sep 2021 20:05:42 +0200 Subject: [PATCH 01/18] Added isAutoReply() method to InboundEmail --- src/InboundEmail.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/InboundEmail.php b/src/InboundEmail.php index 9e7949f..74e5bf0 100644 --- a/src/InboundEmail.php +++ b/src/InboundEmail.php @@ -185,4 +185,43 @@ public function isValid(): bool { return $this->from() !== '' && ($this->isText() || $this->isHtml()); } + + public function isAutoReply($checkCommonSubjects = true): bool + { + if ($this->headerValue('x-autorespond')) { + return true; + } + + if (in_array($this->headerValue('precedence'), ['auto_reply', 'bulk', 'junk'])) { + return true; + } + + if (in_array($this->headerValue('x-precedence'), ['auto_reply', 'bulk', 'junk'])) { + return true; + } + if (in_array($this->headerValue('auto-submitted'), ['auto-replied', 'auto-generated'])) { + return true; + } + + if ($checkCommonSubjects) { + return Str::startsWith($this->subject(), [ + 'Auto:', + 'Automatic reply', + 'Autosvar', + 'Automatisk svar', + 'Automatisch antwoord', + 'Abwesenheitsnotiz', + 'Risposta Non al computer', + 'Automatisch antwoord', + 'Auto Response', + 'Respuesta automática', + 'Fuori sede', + 'Out of Office', + 'Frånvaro', + 'Réponse automatique', + ]); + } + + return false; + } } From f4eee1626883fb4c9ff87b80bf5bb54b9e3672fb Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 18 Sep 2021 20:27:30 +0200 Subject: [PATCH 02/18] Fixed code style --- src/InboundEmail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/InboundEmail.php b/src/InboundEmail.php index 74e5bf0..a61e0c7 100644 --- a/src/InboundEmail.php +++ b/src/InboundEmail.php @@ -185,7 +185,7 @@ public function isValid(): bool { return $this->from() !== '' && ($this->isText() || $this->isHtml()); } - + public function isAutoReply($checkCommonSubjects = true): bool { if ($this->headerValue('x-autorespond')) { From 6a36b6405b9bbe1c517262d8d18789de826d7e27 Mon Sep 17 00:00:00 2001 From: emargareten <46111162+emargareten@users.noreply.github.com> Date: Wed, 25 May 2022 09:21:45 +0300 Subject: [PATCH 03/18] Update drivers.md --- docs/drivers/drivers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/drivers/drivers.md b/docs/drivers/drivers.md index d3896e0..263553e 100644 --- a/docs/drivers/drivers.md +++ b/docs/drivers/drivers.md @@ -66,5 +66,5 @@ See ["MailCare"](https://mailcare.io) for more information. When working locally, you might not want to use real incoming emails while testing your application. Out of the box, this package supports Laravel's "log" mail driver for incoming emails. -To test incoming emails, set both your `MAIL_DRIVER` and your `MAILBOX_DRIVER` in your `.env` file to "log". +To test incoming emails, set both your `MAIL_MAILER` and your `MAILBOX_DRIVER` in your `.env` file to "log". Now every time you send an email in your application, this email will appear in your `laravel.log` file and will try to call one of your configured Mailboxes. From 92453248f210394b1100553bfcd9932533e45430 Mon Sep 17 00:00:00 2001 From: MailCare Date: Fri, 3 Mar 2023 00:03:43 +0100 Subject: [PATCH 04/18] Update MailCareRequest.php --- src/Http/Requests/MailCareRequest.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Http/Requests/MailCareRequest.php b/src/Http/Requests/MailCareRequest.php index fd4405b..7af9420 100644 --- a/src/Http/Requests/MailCareRequest.php +++ b/src/Http/Requests/MailCareRequest.php @@ -8,15 +8,11 @@ class MailCareRequest extends FormRequest { - public function validator() - { - return Validator::make($this->all(), [ - 'email' => 'required', - ]); - } - public function email() { - return InboundEmail::fromMessage($this->get('email')); + /** @var InboundEmail $modelClass */ + $modelClass = config('mailbox.model'); + + return $modelClass::fromMessage($this->getContent()); } } From 53f68bd1ed0cb932a54f36a0872e6bdf18d835f3 Mon Sep 17 00:00:00 2001 From: MailCare Date: Fri, 3 Mar 2023 00:11:42 +0100 Subject: [PATCH 05/18] Update MailCareRequest.php --- src/Http/Requests/MailCareRequest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Http/Requests/MailCareRequest.php b/src/Http/Requests/MailCareRequest.php index 7af9420..f20b79b 100644 --- a/src/Http/Requests/MailCareRequest.php +++ b/src/Http/Requests/MailCareRequest.php @@ -8,6 +8,11 @@ class MailCareRequest extends FormRequest { + public function validator() + { + return Validator::make($this->all(), []); + } + public function email() { /** @var InboundEmail $modelClass */ From 024578a3c0a2658fb8b5b14e4736400068b04573 Mon Sep 17 00:00:00 2001 From: MailCare Date: Fri, 3 Mar 2023 00:19:40 +0100 Subject: [PATCH 06/18] Update drivers.md --- docs/drivers/drivers.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/drivers/drivers.md b/docs/drivers/drivers.md index d3896e0..d924ddb 100644 --- a/docs/drivers/drivers.md +++ b/docs/drivers/drivers.md @@ -53,12 +53,16 @@ Be sure the check the box labeled "Post the raw, full MIME message." when settin ## MailCare +::: warning +To use MailCare with Laravel Mailbox, you will need to generate a random password and store it as the `MAILBOX_HTTP_PASSWORD` environment variable. The default username is "laravel-mailbox", but you can change it using the `MAILBOX_HTTP_USERNAME` environment variable. +::: + You can then set your `MAILBOX_DRIVER` to "mailcare". -Next you will need to configure MailCare, to send incoming emails to your application at `/laravel-mailbox/mailcare`: -- Activate authentication and automation features. -- Create a new automation with the URL `https://your-application.com/laravel-mailbox/mailcare` -- Be sure the check the box labeled "Post the raw, full MIME message." +Next you will need to configure MailCare, to send incoming emails to your application at `/laravel-mailbox/mailcare`. +- Ask support to activate authentication and automation features. +- Create a new automation, if your application is at `https://awesome-laravel.com`, it would be with the URL `https://MAILBOX_HTTP_USERNAME:MAILBOX_HTTP_PASSWORD@awesome-laravel.com/laravel-mailbox/mailcare` +- Be sure the check the box labeled "Post the raw, full MIME message " See ["MailCare"](https://mailcare.io) for more information. From 30c3e9c75b8391d381bdef778bda9f4825bcc7b0 Mon Sep 17 00:00:00 2001 From: Vincent Dauce Date: Wed, 24 Jan 2024 10:46:45 +0100 Subject: [PATCH 07/18] Update MailCareRequest.php --- src/Http/Requests/MailCareRequest.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Http/Requests/MailCareRequest.php b/src/Http/Requests/MailCareRequest.php index f20b79b..7fc4e6a 100644 --- a/src/Http/Requests/MailCareRequest.php +++ b/src/Http/Requests/MailCareRequest.php @@ -8,9 +8,18 @@ class MailCareRequest extends FormRequest { - public function validator() + public function rules() { - return Validator::make($this->all(), []); + return [ + "content_type" => "required|in:message/rfc2822", + ]; + } + + public function prepareForValidation() + { + $this->merge([ + "content_type" => $this->headers->get("Content-type"), + ]); } public function email() From 8a33895072bf0a7ab660160d53d947cb4967a635 Mon Sep 17 00:00:00 2001 From: Vincent Dauce Date: Wed, 24 Jan 2024 10:47:35 +0100 Subject: [PATCH 08/18] Update MailCareRequest.php --- src/Http/Requests/MailCareRequest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Http/Requests/MailCareRequest.php b/src/Http/Requests/MailCareRequest.php index 7fc4e6a..90482cb 100644 --- a/src/Http/Requests/MailCareRequest.php +++ b/src/Http/Requests/MailCareRequest.php @@ -4,7 +4,6 @@ use BeyondCode\Mailbox\InboundEmail; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Support\Facades\Validator; class MailCareRequest extends FormRequest { From 4404e66f6f5929e607ddcc6ef2d8daec837ae099 Mon Sep 17 00:00:00 2001 From: Vincent Dauce Date: Wed, 24 Jan 2024 10:49:04 +0100 Subject: [PATCH 09/18] Update MailCareRequest.php --- src/Http/Requests/MailCareRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Http/Requests/MailCareRequest.php b/src/Http/Requests/MailCareRequest.php index 90482cb..0e2215d 100644 --- a/src/Http/Requests/MailCareRequest.php +++ b/src/Http/Requests/MailCareRequest.php @@ -10,14 +10,14 @@ class MailCareRequest extends FormRequest public function rules() { return [ - "content_type" => "required|in:message/rfc2822", + 'content_type' => 'required|in:message/rfc2822', ]; } public function prepareForValidation() { $this->merge([ - "content_type" => $this->headers->get("Content-type"), + 'content_type' => $this->headers->get('Content-type'), ]); } From 6597aa29b36d7b63066fe488e58fb139b7015665 Mon Sep 17 00:00:00 2001 From: Di Date: Wed, 14 Feb 2024 09:22:03 +0100 Subject: [PATCH 10/18] Apply fixes from StyleCI (#121) --- src/Http/Middleware/MailboxBasicAuthentication.php | 2 +- src/Routing/Route.php | 10 +++++----- tests/MailboxRouteTest.php | 5 +++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Http/Middleware/MailboxBasicAuthentication.php b/src/Http/Middleware/MailboxBasicAuthentication.php index 09020fc..6e747d9 100644 --- a/src/Http/Middleware/MailboxBasicAuthentication.php +++ b/src/Http/Middleware/MailboxBasicAuthentication.php @@ -12,7 +12,7 @@ public function handle($request, Closure $next) $user = $request->getUser(); $password = $request->getPassword(); - if (($user === config('mailbox.basic_auth.username') && $password === config('mailbox.basic_auth.password'))) { + if ($user === config('mailbox.basic_auth.username') && $password === config('mailbox.basic_auth.password')) { return $next($request); } diff --git a/src/Routing/Route.php b/src/Routing/Route.php index 33e4eca..e4f9ff2 100644 --- a/src/Routing/Route.php +++ b/src/Routing/Route.php @@ -83,24 +83,24 @@ protected function gatherMatchSubjectsFromMessage(InboundEmail $message) switch ($this->subject) { case self::FROM: return [$message->from()]; - break; + break; case self::TO: return $this->convertMessageAddresses($message->to()); - break; + break; case self::CC: return $this->convertMessageAddresses($message->cc()); - break; + break; case self::BCC: return $this->convertMessageAddresses($message->bcc()); break; case self::SUBJECT: return [$message->subject()]; - break; + break; } } /** - * @param $addresses AddressPart[] + * @param $addresses AddressPart[] * @return array */ protected function convertMessageAddresses($addresses): array diff --git a/tests/MailboxRouteTest.php b/tests/MailboxRouteTest.php index 7e1de29..a9bc13a 100644 --- a/tests/MailboxRouteTest.php +++ b/tests/MailboxRouteTest.php @@ -18,6 +18,7 @@ public function emailDataProvider() /** * @test + * * @dataProvider emailDataProvider */ public function it_matches_from_mails($fromMail, $successfulPattern, $failingPattern) @@ -36,6 +37,7 @@ public function it_matches_from_mails($fromMail, $successfulPattern, $failingPat /** * @test + * * @dataProvider emailDataProvider */ public function it_matches_to_mails($toMail, $successfulPattern, $failingPattern) @@ -54,6 +56,7 @@ public function it_matches_to_mails($toMail, $successfulPattern, $failingPattern /** * @test + * * @dataProvider emailDataProvider */ public function it_matches_cc_mails($ccMail, $successfulPattern, $failingPattern) @@ -72,6 +75,7 @@ public function it_matches_cc_mails($ccMail, $successfulPattern, $failingPattern /** * @test + * * @dataProvider emailDataProvider */ public function it_matches_bcc_mails($bccMail, $successfulPattern, $failingPattern) @@ -90,6 +94,7 @@ public function it_matches_bcc_mails($bccMail, $successfulPattern, $failingPatte /** * @test + * * @dataProvider subjectDataProvider */ public function it_matches_subjects($subject, $successfulPattern, $failingPattern) From 60507cbc8234d6659e9d5808aebf17f5f7d28cba Mon Sep 17 00:00:00 2001 From: Shift Date: Fri, 1 Mar 2024 20:38:49 +0000 Subject: [PATCH 11/18] Bump dependencies for Laravel 11 --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 46d849f..54c8a4d 100644 --- a/composer.json +++ b/composer.json @@ -17,19 +17,19 @@ ], "require": { "php": "^8.0", - "illuminate/container": "^6.0|^7.0|^8.0|^9.0|^10.0", - "illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0", - "illuminate/log": "^6.0|^7.0|^8.0|^9.0|^10.0", - "illuminate/routing": "^6.0|^7.0|^8.0|^9.0|^10.0", - "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/container": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/log": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/routing": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", "willdurand/email-reply-parser": "^2.8", - "zbateson/mail-mime-parser": "^1.1" + "zbateson/mail-mime-parser": "^1.1|^2.4" }, "require-dev": { "laminas/laminas-mail": "^2.13", "mockery/mockery": "^1.2", - "orchestra/testbench": "^4.0|^5.0|^7.0|^8.0", - "phpunit/phpunit": "^7.0|^8.0|^9.3" + "orchestra/testbench": "^4.0|^5.0|^7.0|^8.0|^9.0", + "phpunit/phpunit": "^7.0|^8.0|^9.3|^10.5" }, "autoload": { "psr-4": { From b9ad026fd8c661b33f2cb2b6ee122541e995cdef Mon Sep 17 00:00:00 2001 From: Shift Date: Fri, 1 Mar 2024 20:38:49 +0000 Subject: [PATCH 12/18] Update GitHub Actions for Laravel 11 --- .github/workflows/run-tests.yml | 102 +++++++++++++++++--------------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e1e360c..4769dc8 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,53 +1,57 @@ name: run-tests -on: [push, pull_request] +on: + - push + - pull_request jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - php: [8.0, 8.1, 8.2] - laravel: [9.*, 8.*, 10.*] - stability: [prefer-stable] - exclude: - - php: 8.0 - laravel: 10.* - - php: 8.2 - laravel: 8.* - include: - - laravel: 10.* - testbench: 8.* - - laravel: 9.* - testbench: 7.* - - laravel: 8.* - testbench: 6.23 - - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: none - -# - name: Setup problem matchers -# run: | -# echo "::add-matcher::${{ runner.tool_cache }}/php.json" -# echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" -# - - name: Install dependencies - run: | - composer install - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update - composer update --${{ matrix.stability }} --prefer-dist --no-interaction - - - name: Execute tests - run: vendor/bin/phpunit + test: + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + php: [8.0, 8.1, 8.2] + laravel: ['8.*', '9.*', '10.*', '11.*'] + stability: [prefer-stable] + exclude: + - php: 8.0 + laravel: 10.* + - php: 8.2 + laravel: 8.* + - laravel: 11.* + php: 8.0 + - laravel: 11.* + php: 8.1 + include: + - laravel: 10.* + testbench: 8.* + - laravel: 9.* + testbench: 7.* + - laravel: 8.* + testbench: 6.23 + - laravel: 11.* + testbench: 9.* + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick + coverage: none + + - name: Install dependencies + run: | + composer install + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: Execute tests + run: vendor/bin/phpunit From 6cb0dfee513080b2c1e28c7d156e6531d0bdaf42 Mon Sep 17 00:00:00 2001 From: Di Date: Wed, 3 Apr 2024 15:02:14 +0200 Subject: [PATCH 13/18] Chores --- .scrutinizer.yml | 19 ------------------- .travis.yml | 21 --------------------- README.md | 8 +------- 3 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 .scrutinizer.yml delete mode 100644 .travis.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index df16b68..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,19 +0,0 @@ -filter: - excluded_paths: [tests/*] - -checks: - php: - remove_extra_empty_lines: true - remove_php_closing_tag: true - remove_trailing_whitespace: true - fix_use_statements: - remove_unused: true - preserve_multiple: false - preserve_blanklines: true - order_alphabetically: true - fix_php_opening_tag: true - fix_linefeed: true - fix_line_ending: true - fix_identation_4spaces: true - fix_doc_comments: true - diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2780ef2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: php - -php: - - 7.3 - - 7.4 - - 8.0 - -env: - matrix: - - COMPOSER_FLAGS="--prefer-lowest" - - COMPOSER_FLAGS="" - -before_script: - - travis_retry composer self-update - - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source - -script: - - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover - -after_script: - - php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover diff --git a/README.md b/README.md index ffe1a31..cf9098f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # Laravel Mailbox 📬 [![Latest Version on Packagist](https://img.shields.io/packagist/v/beyondcode/laravel-mailbox.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-mailbox) -[![Build Status](https://img.shields.io/travis/beyondcode/laravel-mailbox/master.svg?style=flat-square)](https://travis-ci.org/beyondcode/laravel-mailbox) -[![Quality Score](https://img.shields.io/scrutinizer/g/beyondcode/laravel-mailbox.svg?style=flat-square)](https://scrutinizer-ci.com/g/beyondcode/laravel-mailbox) [![Total Downloads](https://img.shields.io/packagist/dt/beyondcode/laravel-mailbox.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-mailbox) Handle incoming emails in your Laravel application. @@ -11,15 +9,11 @@ Handle incoming emails in your Laravel application. Mailbox::from('{username}@gmail.com', function (InboundEmail $email, $username) { // Access email attributes and content $subject = $email->subject(); - + $email->reply(new ReplyMailable); }); ``` -[![https://phppackagedevelopment.com](https://beyondco.de/courses/phppd.jpg)](https://phppackagedevelopment.com) - -If you want to learn how to create reusable PHP packages yourself, take a look at my upcoming [PHP Package Development](https://phppackagedevelopment.com) video course. - ## Installation From e951cb190d935a61d67f43cb1303fd457f360d5d Mon Sep 17 00:00:00 2001 From: Di Date: Wed, 3 Apr 2024 17:27:36 +0200 Subject: [PATCH 14/18] Updated method parameter for zbateson/mail-mime-parser --- src/InboundEmail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/InboundEmail.php b/src/InboundEmail.php index 089bb02..930699c 100644 --- a/src/InboundEmail.php +++ b/src/InboundEmail.php @@ -141,7 +141,7 @@ public function attachments() public function message(): MimeMessage { - $this->mimeMessage = $this->mimeMessage ?: MimeMessage::from($this->message); + $this->mimeMessage = $this->mimeMessage ?: MimeMessage::from($this->message, true); return $this->mimeMessage; } From 8dffc889d67e3c6c7019c4bb5aaf5f12dd94e722 Mon Sep 17 00:00:00 2001 From: Di Date: Wed, 3 Apr 2024 17:27:45 +0200 Subject: [PATCH 15/18] Updated tests for PHPUnit 10 --- tests/MailboxRouteTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/MailboxRouteTest.php b/tests/MailboxRouteTest.php index a9bc13a..5adfcd0 100644 --- a/tests/MailboxRouteTest.php +++ b/tests/MailboxRouteTest.php @@ -8,7 +8,7 @@ class MailboxRouteTest extends TestCase { - public function emailDataProvider() + public static function emailDataProvider() { return [ ['hello@beyondco.de', 'hello@beyondco.de', 'wrong@beyondco.de'], @@ -130,7 +130,7 @@ public function it_matches_requirements() $this->assertTrue($route->matches($message)); } - public function subjectDataProvider() + public static function subjectDataProvider() { return [ ['New Laravel Packages', 'New Laravel Packages', 'Old Laravel Packages'], From a3902cfffa7e3b0bd6fe0ad31d537fe6a27c53d3 Mon Sep 17 00:00:00 2001 From: Di Date: Wed, 3 Apr 2024 17:27:57 +0200 Subject: [PATCH 16/18] Update .gitignore and phpunit.xml.dist files --- .gitignore | 1 + phpunit.xml.dist | 41 ++++++++++------------------------------- phpunit.xml.dist.bak | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 31 deletions(-) create mode 100644 phpunit.xml.dist.bak diff --git a/.gitignore b/.gitignore index 6cc69e4..cd85aa3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ vendor coverage .phpunit.result.cache .idea +.phpunit.cache \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 89d7e61..8a7588d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,33 +1,12 @@ - - - - tests - - - - - src/ - - - - - - - - - - - - - + + + + tests + + + + + + diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak new file mode 100644 index 0000000..6967f7f --- /dev/null +++ b/phpunit.xml.dist.bak @@ -0,0 +1,21 @@ + + + + + tests + + + + + + + From 6b9a84008c65dd79fd68e3d0dd094d12513b9359 Mon Sep 17 00:00:00 2001 From: Di Date: Wed, 3 Apr 2024 17:59:26 +0200 Subject: [PATCH 17/18] Fix memory limit issues when running mailbox:clean --- src/Console/CleanEmails.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Console/CleanEmails.php b/src/Console/CleanEmails.php index 2631192..9ff7fbf 100644 --- a/src/Console/CleanEmails.php +++ b/src/Console/CleanEmails.php @@ -12,6 +12,8 @@ class CleanEmails extends Command protected $description = 'Clean up old incoming email logs.'; + protected $amountDeleted = 0; + public function handle() { $this->comment('Cleaning old incoming email logs...'); @@ -29,13 +31,22 @@ public function handle() /** @var InboundEmail $modelClass */ $modelClass = config('mailbox.model'); - $models = $modelClass::where('created_at', '<', $cutOffDate)->get(); + // chunk the deletion to avoid memory issues + + $this->amountDeleted = 0; - $models->each->delete(); + $modelClass::where('created_at', '<', $cutOffDate) + ->select('id') + ->chunk(100, function ($models) use ($modelClass) { + foreach ($models as $model) { + $modelInstance = $modelClass::find($model->id); + $modelInstance->delete(); + $this->amountDeleted++; + } + }); - $amountDeleted = $models->count(); - $this->info("Deleted {$amountDeleted} record(s) from the Mailbox logs."); + $this->info("Deleted {$this->amountDeleted} record(s) from the Mailbox logs."); $this->comment('All done!'); } From 57cb8a8773f228bdc7f4d96c08d40298a6a9784d Mon Sep 17 00:00:00 2001 From: Di Date: Wed, 3 Apr 2024 17:59:43 +0200 Subject: [PATCH 18/18] Apply fixes from StyleCI (#126) --- src/Console/CleanEmails.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Console/CleanEmails.php b/src/Console/CleanEmails.php index 9ff7fbf..8cd8e3c 100644 --- a/src/Console/CleanEmails.php +++ b/src/Console/CleanEmails.php @@ -45,7 +45,6 @@ public function handle() } }); - $this->info("Deleted {$this->amountDeleted} record(s) from the Mailbox logs."); $this->comment('All done!');