Skip to content

Commit 5e88328

Browse files
first commit
0 parents  commit 5e88328

21 files changed

+1450
-0
lines changed

composer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "effectra/laravel-email",
3+
"description": "laravel package for handling internal/external emails",
4+
"type": "library",
5+
"license": "mit",
6+
"authors": [
7+
{
8+
"name": "Effectra",
9+
"email": "[email protected]"
10+
},
11+
{
12+
"name": "Mohammed Taha [BMT]",
13+
"email": "[email protected]"
14+
}
15+
],
16+
"autoload": {
17+
"psr-4": {
18+
"Effectra\\LaravelEmail\\": "src/",
19+
"Effectra\\LaravelEmail\\Tests\\": "tests/"
20+
},
21+
"files": [
22+
"src/Helpers/functions.php"
23+
]
24+
},
25+
"minimum-stability": "stable",
26+
"require": {},
27+
"extra": {
28+
"laravel": {
29+
"providers": [
30+
"Effectra\\LaravelEmail\\Provider\\LaravelEmailServiceProvider"
31+
]
32+
}
33+
}
34+
}

composer.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/email-message.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
use Effectra\LaravelEmail\Models\EmailTemplate;
4+
5+
return [
6+
'models'=>[
7+
'template' => EmailTemplate::class
8+
]
9+
];

src/Enums/EmailTypeEnum.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Effectra\LaravelStatus\Enums;
4+
5+
6+
enum EmailTypeEnum: int
7+
{
8+
case INTERNAL = 1;
9+
case EXTERNAL = 2;
10+
case UNKNOWN = 3;
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Effectra\LaravelEmail\Exception;
4+
5+
class EmailFetchException extends \Exception
6+
{
7+
8+
}

src/Models/EmailMessage.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Effectra\LaravelEmail\Models;
4+
5+
use Effectra\LaravelStatus\Enums\EmailTypeEnum;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class EmailMessage extends Model
9+
{
10+
/**
11+
* The table associated with the model.
12+
*
13+
* @var string
14+
*/
15+
protected $table = 'email_messages';
16+
/**
17+
* The attributes that are mass assignable.
18+
*
19+
* @var array<int, string>
20+
*/
21+
protected $fillable = [
22+
'subject',
23+
'body',
24+
'attachments',
25+
'to',
26+
'from',
27+
'cc',
28+
'bb',
29+
'template_id',
30+
'type'
31+
];
32+
33+
/**
34+
* The attributes that should be cast to native types.
35+
*
36+
* @var array<string, string>
37+
*/
38+
protected $casts = [
39+
'attachments' => 'array',
40+
'type' => EmailTypeEnum::class,
41+
];
42+
43+
public function template()
44+
{
45+
return $this->belongsTo(config('email-message.models.template'));
46+
}
47+
48+
public function scopeInternalType($query)
49+
{
50+
return $query->where('type', EmailTypeEnum::INTERNAL);
51+
}
52+
53+
public function scopeExternalType($query)
54+
{
55+
return $query->where('type', EmailTypeEnum::EXTERNAL);
56+
}
57+
}

src/Models/EmailTemplate.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Effectra\LaravelEmail\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class EmailTemplate extends Model
8+
{
9+
/**
10+
* The table associated with the model.
11+
*
12+
* @var string
13+
*/
14+
protected $table = 'email_templates';
15+
/**
16+
* The attributes that are mass assignable.
17+
*
18+
* @var array<int, string>
19+
*/
20+
protected $fillable = [
21+
'subject',
22+
'body',
23+
'attachments',
24+
'to',
25+
'from',
26+
'cc',
27+
'bb',
28+
];
29+
30+
/**
31+
* The attributes that should be cast to native types.
32+
*
33+
* @var array<string, string>
34+
*/
35+
protected $casts = [
36+
'attachments' => 'array',
37+
];
38+
39+
public function emails()
40+
{
41+
return $this->hasMany(config('email-message.models.template'));
42+
}
43+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Effectra\LaravelEmail\Provider;
6+
7+
use Spatie\LaravelPackageTools\Commands\InstallCommand;
8+
use Spatie\LaravelPackageTools\Package;
9+
use Spatie\LaravelPackageTools\PackageServiceProvider;
10+
11+
final class LaravelEmailServiceProvider extends PackageServiceProvider
12+
{
13+
public function configurePackage(Package $package): void
14+
{
15+
$package->name('laravel-blog')
16+
->hasConfigFile('blog')
17+
->hasMigrations([
18+
'create_email_messages_table',
19+
'create_email_templates_table',
20+
])
21+
->hasInstallCommand(function (InstallCommand $command): void {
22+
$command
23+
->publishConfigFile()
24+
->publishMigrations()
25+
->askToStarRepoOnGitHub('effectra/email-message');
26+
});
27+
}
28+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Effectra\LaravelEmail\Services;
4+
5+
use Carbon\Carbon;
6+
use Effectra\LaravelEmail\Exception\EmailFetchException;
7+
use Effectra\LaravelEmail\Models\EmailMessage;
8+
use Effectra\LaravelStatus\Enums\EmailTypeEnum;
9+
10+
class EmailMessageService
11+
{
12+
public function __construct(protected EmailMessage $article)
13+
{
14+
15+
}
16+
17+
public static function defaultData(): array
18+
{
19+
return [
20+
'attachments' => [],
21+
'cc' => null,
22+
'bb' => null,
23+
'template_id' => null,
24+
'type' => EmailTypeEnum::INTERNAL
25+
];
26+
}
27+
28+
public function send(?Carbon $sendDate = null): bool
29+
{
30+
return true;
31+
}
32+
33+
/**
34+
* @return EmailMessage[]
35+
*/
36+
public function saveEmailsFetchedFromExternalSource(): array
37+
{
38+
try {
39+
$emails = [];
40+
return array_map(function ($email) {
41+
return EmailMessage::create($this->parseExternalEmailDataToModelAttributes($email));
42+
}, $emails);
43+
44+
} catch (\Throwable $th) {
45+
throw new EmailFetchException("Error Processing Fetch");
46+
}
47+
}
48+
49+
public function parseExternalEmailDataToModelAttributes(array $email): array
50+
{
51+
return [
52+
'subject',
53+
'body',
54+
'attachments',
55+
'to',
56+
'from',
57+
'cc',
58+
'bb',
59+
'template_id'=>null,
60+
'type'=>EmailTypeEnum::EXTERNAL
61+
];
62+
}
63+
}

vendor/autoload.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer
4+
5+
if (PHP_VERSION_ID < 50600) {
6+
if (!headers_sent()) {
7+
header('HTTP/1.1 500 Internal Server Error');
8+
}
9+
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
10+
if (!ini_get('display_errors')) {
11+
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
12+
fwrite(STDERR, $err);
13+
} elseif (!headers_sent()) {
14+
echo $err;
15+
}
16+
}
17+
throw new RuntimeException($err);
18+
}
19+
20+
require_once __DIR__ . '/composer/autoload_real.php';
21+
22+
return ComposerAutoloaderInitdbbd3255a3aa90598be589ee758c4cf0::getLoader();

0 commit comments

Comments
 (0)