Skip to content

Commit

Permalink
[2.x] Laravel 9 Support Only - Breaking change (#17)
Browse files Browse the repository at this point in the history
* Laravel 9 support only - moving from SwiftMailer to Symfony\Component\Mime\Email

Co-authored-by: Robert Fridzema <fridzema@gmail.com>
  • Loading branch information
clemblanco and fridzema authored Aug 5, 2022
1 parent 739d0b4 commit 26f5b21
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 67 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-16.04
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [ 7.3, 8.0 ]
laravel: [ 7.*, 8.* ]
php: [ 8.0, 8.1 ]
laravel: [ 9.* ]
include:
- laravel: 7.*
testbench: 5.*
- laravel: 8.*
testbench: 6.*
- laravel: 9.*
testbench: 7.*

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.idea
/.vscode
/vendor
composer.lock
/phpunit.xml
Expand Down
37 changes: 36 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,41 @@

All notable changes to `laravel-mail-export` will be documented in this file.

## 2.0.0 - 2022-08-04

- Laravel 9 Support **Breaking change** [#17](https://github.com/Pod-Point/laravel-mail-export/pull/17)
- Moved from `swiftmailer/swiftmailer` to `symfony/mailer`
- Thank you to [fridzema](https://github.com/fridzema) for contributing [#14](https://github.com/Pod-Point/laravel-mail-export/pull/14)

## 1.0.0 - 2022-08-04

- Minor improvements + bump up to `1.x` [#18](https://github.com/Pod-Point/laravel-mail-export/pull/18)
- New contributor [MatusBoa](https://github.com/MatusBoa) see [#15](https://github.com/Pod-Point/laravel-mail-export/pull/15)

**Full Changelog**: https://github.com/Pod-Point/laravel-mail-export/compare/0.2.2...1.0.0

## 0.2.2 - 2021-09-14

- Bug: issue [#7](https://github.com/Pod-Point/laravel-mail-export/issues/7) Fix filesystems config file typo
- Enhancement: Add `MAIL_EXPORT` environment variable support

## 0.2.1 - 2021-04-01

- Specify proper `.eml` mime type when saving the file into storage

## 0.2.0 - 2021-04-01

- Support for PHP 8.x, Laravel 7.x and 8.x

## 0.1.2 - 2021-09-14

- Bug: issue [#7](https://github.com/Pod-Point/laravel-mail-export/issues/7) Fix filesystems config file typo
- Enhancement: Add `MAIL_EXPORT` environment variable support

## 0.1.1 - 2021-04-01

- Specify proper `.eml` mime type when saving the file into storage

## 0.1.0 - 2021-03-29

- first release supporting PHP 7.x & Laravel 5.x and 6.x
- First release supporting PHP 7.x, Laravel 5.x and 6.x
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ This can be useful when wanting to store emails sent for archive purposes.

You can install the package via composer:

For Laravel 5.x and 6.x
For Laravel 9.x

```bash
composer require pod-point/laravel-mail-export:^0.1
composer require pod-point/laravel-mail-export
```

For Laravel 7.x and 8.x

```bash
composer require pod-point/laravel-mail-export:^0.2
composer require pod-point/laravel-mail-export:^1.0
```

For Laravel 5.x and 6.x

```bash
composer require pod-point/laravel-mail-export:^0.1
```

### Publishing the config file
Expand All @@ -35,9 +41,9 @@ php artisan vendor:publish --provider="PodPoint\MailExport\MailExportServiceProv

You will be able to specify:

* `enabled`: wether this package is enabled or not.
* `enabled`: whether this package is enabled or not. Once installed, it's enabled by default but the `MAIL_EXPORT` environment variable can be used to configure this.
* `disk`: which disk to use by default. `null` will use the default disk from your application filesystem.
* `path`: the default path you would like to export your mails within a storage disk.
* `path`: the default path, within the configured disk, where mail will be exported.

See our [`config/mail-export.php`](config/mail-export.php) for more details.

Expand All @@ -57,7 +63,7 @@ use PodPoint\MailExport\Contracts\ShouldExport;
class OrderShipped extends Mailable implements ShouldExport
{
use Exportable;

// ...
}
```
Expand All @@ -84,13 +90,13 @@ use PodPoint\MailExport\Contracts\ShouldExport;
class OrderShipped extends Mailable implements ShouldExport
{
use Exportable;

public $exportDisk = 'some_disk';

public $exportPath = 'some_path';

public $exportFilename = 'some_filename';

// ...
}
```
Expand All @@ -109,9 +115,9 @@ use PodPoint\MailExport\Contracts\ShouldExport;
class OrderShipped extends Mailable implements ShouldExport
{
use Exportable;

// ...

public function exportDisk(): string
{
return 'some_disk';
Expand Down Expand Up @@ -148,11 +154,11 @@ use Illuminate\Notifications\Notification;
class OrderShipped extends Notification
{
// ...

public function toMail($notifiable)
{
return (new Mailable($this->order))->to($notifiable->email);
}
}
}
```

Expand All @@ -175,7 +181,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Credits

- [themsaid](https://github.com/themsaid) and Spatie's [laravel-mail-preview](https://github.com/spatie/laravel-mail-preview) for some inspiration
- [Laravel Package Development](https://laravelpackage.com) documentation by [John Braun](https://github.com/Jhnbrn90)
- [Laravel Package Development](https://laravelpackage.com) documentation by [John Braun](https://github.com/Jhnbrn90)
- [Pod Point](https://github.com/pod-point)
- [All Contributors](https://github.com/pod-point/laravel-mail-export/graphs/contributors)

Expand All @@ -189,4 +195,4 @@ The MIT License (MIT). Please see [License File](LICENCE.md) for more informatio

Travel shouldn't damage the earth 🌍

Made with ❤️ at [Pod Point](https://pod-point.com)
Made with ❤️&nbsp;&nbsp;at [Pod Point](https://pod-point.com)
15 changes: 6 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
}
],
"require": {
"php": "^7.2.5|^8.0",
"nesbot/carbon": "^2.0",
"illuminate/support": "~7.0|^8.0",
"illuminate/mail": "~7.0|^8.0",
"illuminate/filesystem": "~7.0|^8.0"
"php": "^8.0",
"illuminate/filesystem": "^9.0",
"illuminate/mail": "^9.0",
"illuminate/support": "^9.0",
"nesbot/carbon": "^2.0"
},
"require-dev": {
"orchestra/testbench": "^5.0|^6.0"
"orchestra/testbench": "^7.0"
},
"autoload": {
"psr-4": {
Expand All @@ -31,9 +31,6 @@
}
},
"extra": {
"branch-alias": {
"dev-master": "0.2-dev"
},
"laravel": {
"providers": [
"PodPoint\\MailExport\\MailExportServiceProvider"
Expand Down
2 changes: 1 addition & 1 deletion config/mail-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
|
*/

'enabled' => true,
'enabled' => env('MAIL_EXPORT', true),

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/Exportable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait Exportable
*/
public function send($mailer)
{
$this->withSwiftMessage(function ($message) {
$this->withSymfonyMessage(function ($message) {
if (! $this instanceof ShouldExport) {
return;
}
Expand Down
11 changes: 6 additions & 5 deletions src/Events/MessageStored.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,35 @@

use Illuminate\Foundation\Events\Dispatchable;
use PodPoint\MailExport\StorageOptions;
use Symfony\Component\Mime\Email;

class MessageStored
{
use Dispatchable;

/**
* The Swift message instance.
* The message instance.
*
* @var \Swift_Message
* @var \Symfony\Component\Mime\Email
*/
public $message;

/**
* The filesystem storage options used to store the message including
* the disk, the path and the filename with its extension.
*
* @var StorageOptions
* @var \PodPoint\MailExport\StorageOptions
*/
public $storageOptions;

/**
* Create a new event instance.
*
* @param \Swift_Message $message
* @param Email $message
* @param StorageOptions $storageOptions
* @return void
*/
public function __construct($message, $storageOptions)
public function __construct(Email $message, StorageOptions $storageOptions)
{
$this->message = $message;
$this->storageOptions = $storageOptions;
Expand Down
30 changes: 12 additions & 18 deletions src/Listeners/ExportMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Mail\Events\MessageSent;
use PodPoint\MailExport\Events\MessageStored;
use PodPoint\MailExport\StorageOptions;
use Symfony\Component\Mime\Email;

class ExportMessage
{
Expand All @@ -14,11 +15,6 @@ class ExportMessage
*/
protected $filesystem;

/**
* @var \Swift_Message
*/
protected $message;

/**
* Create a new listener instance.
*
Expand All @@ -36,41 +32,39 @@ public function __construct(Factory $filesystem)
*/
public function handle(MessageSent $event)
{
$this->message = $event->message;

if ($this->shouldStoreMessage()) {
$this->storeMessage();
if ($this->shouldStoreMessage($event->message)) {
$this->storeMessage($event->message);
}
}

/**
* Finds out if wether we should store the mail or not.
* Finds out if whether we should store the mail or not.
*
* @return bool
*/
protected function shouldStoreMessage(): bool
protected function shouldStoreMessage(Email $message): bool
{
return property_exists($this->message, '_storageOptions')
return property_exists($message, '_storageOptions')
&& config('mail-export.enabled', false);
}

/**
* Actually stores the stringified version of the \Swift_Message including headers,
* recipients, subject and body onto the filesystem disk.
* Actually stores the stringified version of the \Symfony\Component\Mime\Email
* including headers, recipients, subject and body onto the filesystem disk.
*
* @return void
*/
private function storeMessage()
private function storeMessage(Email $message)
{
/** @var StorageOptions $storageOptions */
$storageOptions = $this->message->_storageOptions;
$storageOptions = $message->_storageOptions;

$this->filesystem
->disk($storageOptions->disk)
->put($storageOptions->fullpath(), $this->message->toString(), [
->put($storageOptions->fullpath(), $message->toString(), [
'mimetype' => $storageOptions::MIME_TYPE,
]);

event(new MessageStored($this->message, $storageOptions));
event(new MessageStored($message, $storageOptions));
}
}
Loading

0 comments on commit 26f5b21

Please sign in to comment.