Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 11 Support #125

Merged
merged 23 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 53 additions & 49 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vendor
coverage
.phpunit.result.cache
.idea
.phpunit.cache
19 changes: 0 additions & 19 deletions .scrutinizer.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 9 additions & 5 deletions docs/drivers/drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ 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.

## Local development / log driver

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.
41 changes: 10 additions & 31 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="BeyondCode Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<php>
<env name="MAIL_MAILER" value="log"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
<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">
<testsuites>
<testsuite name="BeyondCode Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="MAIL_MAILER" value="log"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
</phpunit>
21 changes: 21 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="BeyondCode Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="MAIL_MAILER" value="log"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
</phpunit>
18 changes: 14 additions & 4 deletions src/Console/CleanEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
Expand All @@ -29,13 +31,21 @@ public function handle()
/** @var InboundEmail $modelClass */
$modelClass = config('mailbox.model');

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

$models->each->delete();
$this->amountDeleted = 0;

$amountDeleted = $models->count();
$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++;
}
});

$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!');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/MailboxBasicAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
19 changes: 14 additions & 5 deletions src/Http/Requests/MailCareRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@

use BeyondCode\Mailbox\InboundEmail;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Validator;

class MailCareRequest extends FormRequest
{
public function validator()
public function rules()
{
return Validator::make($this->all(), [
'email' => 'required',
return [
'content_type' => 'required|in:message/rfc2822',
];
}

public function prepareForValidation()
{
$this->merge([
'content_type' => $this->headers->get('Content-type'),
]);
}

public function email()
{
return InboundEmail::fromMessage($this->get('email'));
/** @var InboundEmail $modelClass */
$modelClass = config('mailbox.model');

return $modelClass::fromMessage($this->getContent());
}
}
Loading
Loading