Skip to content

Commit c3827a1

Browse files
authored
Merge pull request #125 from beyondcode/updates
[Draft] Laravel 11 Support
2 parents 8353dcb + 4a5de8c commit c3827a1

15 files changed

+184
-158
lines changed

.github/workflows/run-tests.yml

+53-49
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,57 @@
11
name: run-tests
22

3-
on: [push, pull_request]
3+
on:
4+
- push
5+
- pull_request
46

57
jobs:
6-
test:
7-
runs-on: ${{ matrix.os }}
8-
strategy:
9-
fail-fast: false
10-
matrix:
11-
os: [ubuntu-latest]
12-
php: [8.0, 8.1, 8.2]
13-
laravel: [9.*, 8.*, 10.*]
14-
stability: [prefer-stable]
15-
exclude:
16-
- php: 8.0
17-
laravel: 10.*
18-
- php: 8.2
19-
laravel: 8.*
20-
include:
21-
- laravel: 10.*
22-
testbench: 8.*
23-
- laravel: 9.*
24-
testbench: 7.*
25-
- laravel: 8.*
26-
testbench: 6.23
27-
28-
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
29-
30-
steps:
31-
- name: Checkout code
32-
uses: actions/checkout@v2
33-
34-
- name: Setup PHP
35-
uses: shivammathur/setup-php@v2
36-
with:
37-
php-version: ${{ matrix.php }}
38-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
39-
coverage: none
40-
41-
# - name: Setup problem matchers
42-
# run: |
43-
# echo "::add-matcher::${{ runner.tool_cache }}/php.json"
44-
# echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
45-
#
46-
- name: Install dependencies
47-
run: |
48-
composer install
49-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
50-
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
51-
52-
- name: Execute tests
53-
run: vendor/bin/phpunit
8+
test:
9+
runs-on: ${{ matrix.os }}
10+
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
os: [ubuntu-latest]
15+
php: [8.0, 8.1, 8.2]
16+
laravel: ['8.*', '9.*', '10.*', '11.*']
17+
stability: [prefer-stable]
18+
exclude:
19+
- php: 8.0
20+
laravel: 10.*
21+
- php: 8.2
22+
laravel: 8.*
23+
- laravel: 11.*
24+
php: 8.0
25+
- laravel: 11.*
26+
php: 8.1
27+
include:
28+
- laravel: 10.*
29+
testbench: 8.*
30+
- laravel: 9.*
31+
testbench: 7.*
32+
- laravel: 8.*
33+
testbench: 6.23
34+
- laravel: 11.*
35+
testbench: 9.*
36+
37+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
38+
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v2
42+
43+
- name: Setup PHP
44+
uses: shivammathur/setup-php@v2
45+
with:
46+
php-version: ${{ matrix.php }}
47+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
48+
coverage: none
49+
50+
- name: Install dependencies
51+
run: |
52+
composer install
53+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
54+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
55+
56+
- name: Execute tests
57+
run: vendor/bin/phpunit

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ vendor
44
coverage
55
.phpunit.result.cache
66
.idea
7+
.phpunit.cache

.scrutinizer.yml

-19
This file was deleted.

.travis.yml

-21
This file was deleted.

README.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Laravel Mailbox 📬
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/beyondcode/laravel-mailbox.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-mailbox)
4-
[![Build Status](https://img.shields.io/travis/beyondcode/laravel-mailbox/master.svg?style=flat-square)](https://travis-ci.org/beyondcode/laravel-mailbox)
5-
[![Quality Score](https://img.shields.io/scrutinizer/g/beyondcode/laravel-mailbox.svg?style=flat-square)](https://scrutinizer-ci.com/g/beyondcode/laravel-mailbox)
64
[![Total Downloads](https://img.shields.io/packagist/dt/beyondcode/laravel-mailbox.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-mailbox)
75

86
Handle incoming emails in your Laravel application.
@@ -11,15 +9,11 @@ Handle incoming emails in your Laravel application.
119
Mailbox::from('{username}@gmail.com', function (InboundEmail $email, $username) {
1210
// Access email attributes and content
1311
$subject = $email->subject();
14-
12+
1513
$email->reply(new ReplyMailable);
1614
});
1715
```
1816

19-
[![https://phppackagedevelopment.com](https://beyondco.de/courses/phppd.jpg)](https://phppackagedevelopment.com)
20-
21-
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.
22-
2317

2418
## Installation
2519

composer.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
],
1818
"require": {
1919
"php": "^8.0",
20-
"illuminate/container": "^6.0|^7.0|^8.0|^9.0|^10.0",
21-
"illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0",
22-
"illuminate/log": "^6.0|^7.0|^8.0|^9.0|^10.0",
23-
"illuminate/routing": "^6.0|^7.0|^8.0|^9.0|^10.0",
24-
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0",
20+
"illuminate/container": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
21+
"illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
22+
"illuminate/log": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
23+
"illuminate/routing": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
24+
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
2525
"willdurand/email-reply-parser": "^2.8",
26-
"zbateson/mail-mime-parser": "^1.1"
26+
"zbateson/mail-mime-parser": "^1.1|^2.4"
2727
},
2828
"require-dev": {
2929
"laminas/laminas-mail": "^2.13",
3030
"mockery/mockery": "^1.2",
31-
"orchestra/testbench": "^4.0|^5.0|^7.0|^8.0",
32-
"phpunit/phpunit": "^7.0|^8.0|^9.3"
31+
"orchestra/testbench": "^4.0|^5.0|^7.0|^8.0|^9.0",
32+
"phpunit/phpunit": "^7.0|^8.0|^9.3|^10.5"
3333
},
3434
"autoload": {
3535
"psr-4": {

docs/drivers/drivers.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,22 @@ Be sure the check the box labeled "Post the raw, full MIME message." when settin
5353

5454
## MailCare
5555

56+
::: warning
57+
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.
58+
:::
59+
5660
You can then set your `MAILBOX_DRIVER` to "mailcare".
5761

58-
Next you will need to configure MailCare, to send incoming emails to your application at `/laravel-mailbox/mailcare`:
59-
- Activate authentication and automation features.
60-
- Create a new automation with the URL `https://your-application.com/laravel-mailbox/mailcare`
61-
- Be sure the check the box labeled "Post the raw, full MIME message."
62+
Next you will need to configure MailCare, to send incoming emails to your application at `/laravel-mailbox/mailcare`.
63+
- Ask support to activate authentication and automation features.
64+
- 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`
65+
- Be sure the check the box labeled "Post the raw, full MIME message "
6266

6367
See ["MailCare"](https://mailcare.io) for more information.
6468

6569
## Local development / log driver
6670

6771
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.
6872

69-
To test incoming emails, set both your `MAIL_DRIVER` and your `MAILBOX_DRIVER` in your `.env` file to "log".
73+
To test incoming emails, set both your `MAIL_MAILER` and your `MAILBOX_DRIVER` in your `.env` file to "log".
7074
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.

phpunit.xml.dist

+10-31
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
verbose="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false">
12-
<testsuites>
13-
<testsuite name="BeyondCode Test Suite">
14-
<directory>tests</directory>
15-
</testsuite>
16-
</testsuites>
17-
<filter>
18-
<whitelist>
19-
<directory suffix=".php">src/</directory>
20-
</whitelist>
21-
</filter>
22-
<logging>
23-
<log type="tap" target="build/report.tap"/>
24-
<log type="junit" target="build/report.junit.xml"/>
25-
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
26-
<log type="coverage-text" target="build/coverage.txt"/>
27-
<log type="coverage-clover" target="build/logs/clover.xml"/>
28-
</logging>
29-
<php>
30-
<env name="MAIL_MAILER" value="log"/>
31-
<env name="DB_CONNECTION" value="testing"/>
32-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="BeyondCode Test Suite">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<php>
9+
<env name="MAIL_MAILER" value="log"/>
10+
<env name="DB_CONNECTION" value="testing"/>
11+
</php>
3312
</phpunit>

phpunit.xml.dist.bak

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="BeyondCode Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<php>
18+
<env name="MAIL_MAILER" value="log"/>
19+
<env name="DB_CONNECTION" value="testing"/>
20+
</php>
21+
</phpunit>

src/Console/CleanEmails.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class CleanEmails extends Command
1212

1313
protected $description = 'Clean up old incoming email logs.';
1414

15+
protected $amountDeleted = 0;
16+
1517
public function handle()
1618
{
1719
$this->comment('Cleaning old incoming email logs...');
@@ -29,13 +31,21 @@ public function handle()
2931
/** @var InboundEmail $modelClass */
3032
$modelClass = config('mailbox.model');
3133

32-
$models = $modelClass::where('created_at', '<', $cutOffDate)->get();
34+
// chunk the deletion to avoid memory issues
3335

34-
$models->each->delete();
36+
$this->amountDeleted = 0;
3537

36-
$amountDeleted = $models->count();
38+
$modelClass::where('created_at', '<', $cutOffDate)
39+
->select('id')
40+
->chunk(100, function ($models) use ($modelClass) {
41+
foreach ($models as $model) {
42+
$modelInstance = $modelClass::find($model->id);
43+
$modelInstance->delete();
44+
$this->amountDeleted++;
45+
}
46+
});
3747

38-
$this->info("Deleted {$amountDeleted} record(s) from the Mailbox logs.");
48+
$this->info("Deleted {$this->amountDeleted} record(s) from the Mailbox logs.");
3949

4050
$this->comment('All done!');
4151
}

src/Http/Middleware/MailboxBasicAuthentication.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function handle($request, Closure $next)
1212
$user = $request->getUser();
1313
$password = $request->getPassword();
1414

15-
if (($user === config('mailbox.basic_auth.username') && $password === config('mailbox.basic_auth.password'))) {
15+
if ($user === config('mailbox.basic_auth.username') && $password === config('mailbox.basic_auth.password')) {
1616
return $next($request);
1717
}
1818

src/Http/Requests/MailCareRequest.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,28 @@
44

55
use BeyondCode\Mailbox\InboundEmail;
66
use Illuminate\Foundation\Http\FormRequest;
7-
use Illuminate\Support\Facades\Validator;
87

98
class MailCareRequest extends FormRequest
109
{
11-
public function validator()
10+
public function rules()
1211
{
13-
return Validator::make($this->all(), [
14-
'email' => 'required',
12+
return [
13+
'content_type' => 'required|in:message/rfc2822',
14+
];
15+
}
16+
17+
public function prepareForValidation()
18+
{
19+
$this->merge([
20+
'content_type' => $this->headers->get('Content-type'),
1521
]);
1622
}
1723

1824
public function email()
1925
{
20-
return InboundEmail::fromMessage($this->get('email'));
26+
/** @var InboundEmail $modelClass */
27+
$modelClass = config('mailbox.model');
28+
29+
return $modelClass::fromMessage($this->getContent());
2130
}
2231
}

0 commit comments

Comments
 (0)