From 66a8110d5855cc7022a302d0ee27d62e5ad9013c Mon Sep 17 00:00:00 2001
From: Marick van Tuil
Date: Sun, 30 Dec 2018 21:25:55 +0100
Subject: [PATCH 1/7] Remove closure and make config file cacheable
---
config/laravel-database-emails.php | 6 +-----
tests/ConfigCacheTest.php | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 5 deletions(-)
create mode 100644 tests/ConfigCacheTest.php
diff --git a/config/laravel-database-emails.php b/config/laravel-database-emails.php
index c35a229..61d9164 100644
--- a/config/laravel-database-emails.php
+++ b/config/laravel-database-emails.php
@@ -42,11 +42,7 @@
'email' => 'test@email.com',
- 'enabled' => function () {
- return false;
- // ...or...
- // return app()->environment('local', 'staging');
- },
+ 'enabled' => env('LARAVEL_DATABASE_EMAILS_TESTING_ENABLED', true),
],
diff --git a/tests/ConfigCacheTest.php b/tests/ConfigCacheTest.php
new file mode 100644
index 0000000..30077e0
--- /dev/null
+++ b/tests/ConfigCacheTest.php
@@ -0,0 +1,26 @@
+fail('Configuration file cannot be serialized');
+ } else {
+ $this->assertTrue(true);
+ }
+ }
+}
\ No newline at end of file
From 33a7d3a577ceee6eb94cc53bee3b8a2ea7cd7739 Mon Sep 17 00:00:00 2001
From: Marick van Tuil
Date: Sun, 30 Dec 2018 21:32:44 +0100
Subject: [PATCH 2/7] Move readme back into repository
---
README.md | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 188 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index d8b8b01..1d993bf 100644
--- a/README.md
+++ b/README.md
@@ -7,8 +7,193 @@
-## Introduction
+# Package Documentation
-This package allows you to easily send e-mails using a database table.
+This package allows you to store and send e-mails using a database.
-Official documentation, changelog and more [is located here](https://stackkit.github.io/laravel-database-emails/).
+## Contribution
+
+The package is MIT licenced, meaning it's open source and you are free to copy or fork it and modify it any way you wish.
+
+We feel the package is currently feature complete, but feel free to send a pull request or help improve existing code.
+
+
+# Installation
+
+Require the package using composer.
+
+```bash
+composer require stackkit/laravel-database-emails
+```
+
+If you're running Laravel 5.5 or later you may skip this step. Add the service provider to your application.
+
+```
+Stackkit\LaravelDatabaseEmails\LaravelDatabaseEmailsServiceProvider::class,
+```
+
+Publish the configuration files.
+
+```bash
+php artisan vendor:publish --provider=Stackkit\\LaravelDatabaseEmails\\LaravelDatabaseEmailsServiceProvider
+```
+
+Create the database table required for this package.
+
+```bash
+php artisan migrate
+```
+
+Add the e-mail cronjob to your scheduler
+
+```php
+command('email:send')->everyMinute()->withoutOverlapping(5);
+}
+```
+
+
+# Usage
+
+### Send an email
+
+```php
+label('welcome')
+ ->recipient('john@doe.com')
+ ->subject('This is a test')
+ ->view('emails.welcome')
+ ->variables([
+ 'name' => 'John Doe',
+ ])
+ ->send();
+```
+
+### Specify multiple recipients
+
+```php
+recipient([
+ 'john@doe.com',
+ 'jane@doe.com'
+ ]);
+```
+
+### CC and BCC
+
+```php
+cc('john@doe.com')
+ ->cc(['john@doe.com', 'jane@doe.com'])
+ ->bcc('john@doe.com')
+ ->bcc(['john@doe.com', 'jane@doe.com']);
+```
+
+### Using mailables
+
+You may also pass a mailable to the e-mail composer.
+
+```php
+mailable(new OrderShipped())
+ ->send();
+```
+
+### Attachments
+
+```php
+attach('/path/to/file');
+```
+
+Or for in-memory attachments:
+
+```php
+attachData('Your order has shipped!
', 'order.html');
+```
+
+### Custom Sender
+
+```php
+from('john@doe.com', 'John Doe');
+```
+
+### Scheduling
+
+You may schedule an e-mail by calling `later` instead of `send`. You must provide a Carbon instance or a strtotime valid date.
+
+```php
+later('+2 hours');
+```
+
+### Encryption (Optional)
+
+If you wish to encrypt your e-mails, please enable the `encrypt` option in the configuration file. This is disabled by default. Encryption and decryption will be handled by Laravel's built-in encryption mechanism. Please note that by encrypting the e-mail it takes more disk space.
+
+```text
+Without encryption
+
+7 bytes (label)
+16 bytes (recipient)
+20 bytes (subject)
+48 bytes (view name)
+116 bytes (variables)
+1874 bytes (e-mail content)
+4 bytes (attempts, sending, failed, encrypted)
+57 bytes (created_at, updated_at, deleted_at)
+... x 10.000 rows = ± 21.55 MB
+
+With encryption the table size is ± 50.58 MB.
+```
+
+### Test mode (Optional)
+
+When enabled, all newly created e-mails will be sent to the specified test e-mail address. This is turned off by default.
+
+### E-mails to send per minute
+
+To configure how many e-mails should be sent each command, please check the `limit` option. The default is `20` e-mails every command.
\ No newline at end of file
From c70df736d2a338dd52b3b21b0c21017f88a419d8 Mon Sep 17 00:00:00 2001
From: Marick van Tuil
Date: Sun, 30 Dec 2018 21:34:12 +0100
Subject: [PATCH 3/7] Move changelog back into repository
---
CHANGELOG.md | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 110 insertions(+)
create mode 100644 CHANGELOG.md
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..58d4c8d
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,110 @@
+# Releases
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
+and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
+
+## 3.0.3 - 2018-07-24
+
+**Fixed**
+
+- Transforming an `Email` object to JSON would cause the encrpyted attributes to stay encrypted. This is now fixed.
+
+## 3.0.2 - 2018-03-22
+
+**Changed**
+
+- Updated README.md
+
+**Added**
+
+- Support for process time limit
+
+---
+
+## 3.0.1 - 2018-03-18
+
+**Changed**
+
+- Updated README.md
+- Deprecated `email:retry`, please use `email:resend`
+
+---
+
+## 3.0.0 - 2017-12-22
+
+**Added**
+
+- Support for a custom sender per e-mail.
+
+**Upgrade from 2.x to 3.x**
+
+3.0.0 added support for a custom sender per e-mail. To update please run the following command:
+
+```bash
+php artisan migrate
+```
+
+---
+
+## 2.0.0 - 2017-12-14
+
+**Added**
+
+- Support for multiple recipients, cc and bcc addresses.
+- Support for mailables (*)
+- Support for attachments
+- New method `later`
+
+*= Only works for Laravel versions 5.5 and up because 5.5 finally introduced a method to read the mailable body.
+
+**Fixed**
+- Bug causing failed e-mails not to be resent
+
+**Upgrade from 1.x to 2.x**
+Because 2.0.0 introduced support for attachments, the database needs to be updated. Simply run the following two commands after updating your dependencies and running composer update:
+
+```bash
+php artisan migrate
+```
+
+---
+
+## 1.1.3 - 2017-12-07
+
+**Fixed**
+
+- Created a small backwards compatibility fix for Laravel versions 5.4 and below.
+
+---
+
+## 1.1.2 - 2017-11-18
+
+**Fixed**
+
+- Incorrect auto discovery namespace for Laravel 5.5
+
+---
+
+## 1.1.1 - 2017-08-02
+
+**Changed**
+
+- Only dispatch `before.send` event during unit tests
+
+---
+
+## 1.1.0 - 2017-07-01
+
+**Added**
+
+- PHPUnit tests
+- Support for CC and BCC
+
+---
+
+## 1.0.0 - 2017-06-29
+
+**Added**
+
+- Initial release of the package
\ No newline at end of file
From 3c7b4fae81139c2070f4509fa5ae0028371c0680 Mon Sep 17 00:00:00 2001
From: Marick van Tuil
Date: Mon, 31 Dec 2018 13:13:57 +0100
Subject: [PATCH 4/7] Build mailable before extracting data from it
---
src/MailableReader.php | 7 ++++++-
tests/MailableReaderTest.php | 25 +++++++++----------------
2 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/src/MailableReader.php b/src/MailableReader.php
index 0497bd2..a8f35da 100644
--- a/src/MailableReader.php
+++ b/src/MailableReader.php
@@ -4,6 +4,7 @@
use Exception;
use function call_user_func_array;
+use Illuminate\Container\Container;
class MailableReader
{
@@ -14,6 +15,8 @@ class MailableReader
*/
public function read(EmailComposer $composer)
{
+ Container::getInstance()->call([$composer->getData('mailable'), 'build']);
+
$this->readRecipient($composer);
$this->readFrom($composer);
@@ -123,7 +126,9 @@ private function readBody(EmailComposer $composer)
$composer->setData('view', '');
- $composer->setData('body', $composer->getData('mailable')->render());
+ $mailable = $composer->getData('mailable');
+
+ $composer->setData('body', view($mailable->view, $mailable->buildViewData()));
}
/**
diff --git a/tests/MailableReaderTest.php b/tests/MailableReaderTest.php
index 34aa814..3f14408 100644
--- a/tests/MailableReaderTest.php
+++ b/tests/MailableReaderTest.php
@@ -20,7 +20,9 @@ public function it_extracts_the_recipient()
(new TestMailable())->to(['jane@doe.com'])
);
- $this->assertEquals(['john@doe.com', 'jane@doe.com'], $composer->getData('recipient'));
+ $this->assertCount(2, $composer->getData('recipient'));
+ $this->assertContains('john@doe.com', $composer->getData('recipient'));
+ $this->assertContains('jane@doe.com', $composer->getData('recipient'));
}
/** @test */
@@ -107,29 +109,20 @@ public function it_extracts_the_from_address_and_or_name()
class TestMailable extends Mailable
{
/**
- * Create a new message instance.
+ * Build the message.
*
- * @return void
+ * @return $this
*/
- public function __construct()
+ public function build()
{
- $this->to('john@doe.com')
+ return $this->to('john@doe.com')
->cc(['john+cc@doe.com', 'john+cc2@doe.com'])
->bcc(['john+bcc@doe.com', 'john+bcc2@doe.com'])
->subject('Your order has shipped!')
->attach(__DIR__ . '/files/pdf-sample.pdf', [
'mime' => 'application/pdf',
])
- ->attachData('Thanks for your oder
', 'order.html');
- }
-
- /**
- * Build the message.
- *
- * @return $this
- */
- public function build()
- {
- return $this->view('tests::dummy', ['name' => 'John Doe']);
+ ->attachData('Thanks for your oder
', 'order.html')
+ ->view('tests::dummy', ['name' => 'John Doe']);
}
}
From 420a9fd1401e54951581014f6483b2519c3128db Mon Sep 17 00:00:00 2001
From: Marick van Tuil
Date: Mon, 31 Dec 2018 13:25:07 +0100
Subject: [PATCH 5/7] Added additional recipient validation check
---
src/Validator.php | 4 ++++
tests/ValidatorTest.php | 12 ++++++++++++
2 files changed, 16 insertions(+)
diff --git a/src/Validator.php b/src/Validator.php
index 2a3113a..0dfc946 100644
--- a/src/Validator.php
+++ b/src/Validator.php
@@ -67,6 +67,10 @@ private function validateRecipient(EmailComposer $composer)
$recipients = (array) $composer->getData('recipient');
+ if (count($recipients) == 0) {
+ throw new InvalidArgumentException('No recipient specified');
+ }
+
foreach ($recipients as $recipient) {
if (! filter_var($recipient, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException('E-mail address [' . $recipient . '] is invalid');
diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php
index 2aab662..beca390 100644
--- a/tests/ValidatorTest.php
+++ b/tests/ValidatorTest.php
@@ -30,6 +30,18 @@ public function a_recipient_is_required()
->send();
}
+ /**
+ * @test
+ * @expectedException InvalidArgumentException
+ * @expectedExceptionMessage No recipient specified
+ */
+ public function a_recipient_cannot_be_empty()
+ {
+ Email::compose()
+ ->recipient([])
+ ->send();
+ }
+
/**
* @test
* @expectedException InvalidArgumentException
From a2deb4b1357b7ea0d1fe2916d1b496812c486351 Mon Sep 17 00:00:00 2001
From: Marick van Tuil
Date: Mon, 31 Dec 2018 12:26:52 +0000
Subject: [PATCH 6/7] Apply fixes from StyleCI
---
tests/ConfigCacheTest.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/ConfigCacheTest.php b/tests/ConfigCacheTest.php
index 30077e0..2851e6b 100644
--- a/tests/ConfigCacheTest.php
+++ b/tests/ConfigCacheTest.php
@@ -7,7 +7,7 @@
class ConfigCacheTest extends TestCase
{
/** @test */
- function the_configuration_file_can_be_cached()
+ public function the_configuration_file_can_be_cached()
{
$failed = false;
@@ -23,4 +23,4 @@ function the_configuration_file_can_be_cached()
$this->assertTrue(true);
}
}
-}
\ No newline at end of file
+}
From 4ac2573b8f5b12ff9afcfec73586b24662909683 Mon Sep 17 00:00:00 2001
From: Marick van Tuil
Date: Mon, 31 Dec 2018 13:40:05 +0100
Subject: [PATCH 7/7] Update badges
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 1d993bf..3324a47 100644
--- a/README.md
+++ b/README.md
@@ -3,8 +3,8 @@
-
-
+
+
# Package Documentation