Skip to content

Commit 1ca7093

Browse files
committedMay 26, 2021
Email processing completed
1 parent c6a050e commit 1ca7093

35 files changed

+11945
-12009
lines changed
 

‎email copy.txt

+11,667
Large diffs are not rendered by default.

‎email.txt

+13-11,661
Large diffs are not rendered by default.

‎packages/Webkul/Admin/publishable/assets/css/admin.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Loading
Loading
Loading
Loading

‎packages/Webkul/Admin/publishable/assets/mix-manifest.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"/js/admin.js": "/js/admin.js?id=373c7d185b2823978adb",
3-
"/css/admin.css": "/css/admin.css?id=1bd3a82bf67c413b520c",
3+
"/css/admin.css": "/css/admin.css?id=bca1e0925b0cf77b5337",
44
"/images/avatar-icon.svg": "/images/avatar-icon.svg?id=138110db59ab81030a21",
55
"/images/dashboard-active-icon.svg": "/images/dashboard-active-icon.svg?id=0a8aa85a7bf837ce0ec6",
66
"/images/dashboard-icon.svg": "/images/dashboard-icon.svg?id=00efeb765d72f3fd86d4",
@@ -12,5 +12,9 @@
1212
"/images/products-active-icon.svg": "/images/products-active-icon.svg?id=a7a4f47ff4f77e073eda",
1313
"/images/products-icon.svg": "/images/products-icon.svg?id=8fde4922886ec4f1fcad",
1414
"/images/settings-active-icon.svg": "/images/settings-active-icon.svg?id=6997c8791cbeea4bf76a",
15-
"/images/settings-icon.svg": "/images/settings-icon.svg?id=55afb93247c656e5ecd7"
15+
"/images/settings-icon.svg": "/images/settings-icon.svg?id=55afb93247c656e5ecd7",
16+
"/images/activities-active-icon.svg": "/images/activities-active-icon.svg?id=f7887e3fdcddf68567ce",
17+
"/images/activities-icon.svg": "/images/activities-icon.svg?id=323f3f274df979c3ac21",
18+
"/images/emails-active-icon.svg": "/images/emails-active-icon.svg?id=419a405cc6a99593c02c",
19+
"/images/emails-icon.svg": "/images/emails-icon.svg?id=f3c561cf1bbc740dc2ff"
1620
}

‎packages/Webkul/Admin/src/Config/menu.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@
1313
'route' => 'admin.leads.index',
1414
'sort' => 2,
1515
'icon-class' => 'leads-icon',
16+
], [
17+
'key' => 'emails',
18+
'name' => 'admin::app.layouts.emails',
19+
'route' => 'admin.emails.index',
20+
'sort' => 3,
21+
'icon-class' => 'emails-icon',
1622
], [
1723
'key' => 'activities',
1824
'name' => 'admin::app.layouts.activities',
1925
'route' => 'admin.activities.index',
20-
'sort' => 3,
26+
'sort' => 4,
2127
'icon-class' => 'activities-icon',
2228
], [
2329
'key' => 'contacts',
2430
'name' => 'admin::app.layouts.contacts',
2531
'route' => 'admin.contacts.persons.index',
26-
'sort' => 4,
32+
'sort' => 5,
2733
'icon-class' => 'phone-icon',
2834
], [
2935
'key' => 'contacts.persons',
@@ -39,13 +45,13 @@
3945
'key' => 'products',
4046
'name' => 'admin::app.layouts.products',
4147
'route' => 'admin.products.index',
42-
'sort' => 5,
48+
'sort' => 6,
4349
'icon-class' => 'products-icon',
4450
], [
4551
'key' => 'settings',
4652
'name' => 'admin::app.layouts.settings',
4753
'route' => 'admin.settings.users.index',
48-
'sort' => 6,
54+
'sort' => 7,
4955
'icon-class' => 'settings-icon',
5056
], [
5157
'key' => 'settings.roles',

‎packages/Webkul/Admin/src/Http/Controllers/Email/EmailController.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public function store($id)
7474
*/
7575
public function inboundParse()
7676
{
77-
$this->emailRepository->parseEmailAddress();
77+
$emailContent = file_get_contents(base_path('email.txt'));
78+
79+
$this->emailRepository->processInboundParseMail($emailContent);
7880

7981
return response()->json([], 200);
8082
}

‎packages/Webkul/Admin/src/Http/routes.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
Route::post('reset-password', 'Webkul\Admin\Http\Controllers\User\ResetPasswordController@store')->name('admin.reset_password.store');
2323

24-
Route::post('emails/inbound-parse', 'EmailController@inboundParse')->name('admin.emails.inbound_parse');
24+
Route::get('emails/inbound-parse', 'Webkul\Admin\Http\Controllers\Email\EmailController@inboundParse')->name('admin.emails.inbound_parse');
2525

2626
// Admin Routes
2727
Route::group(['middleware' => ['user']], function () {
@@ -100,6 +100,8 @@
100100
'prefix' => 'emails',
101101
'namespace' => 'Webkul\Admin\Http\Controllers\Email',
102102
], function () {
103+
Route::get('', 'EmailController@index')->name('admin.emails.index');
104+
103105
Route::post('create/{id}', 'EmailController@store')->name('admin.emails.store');
104106

105107
Route::delete('{id?}', 'EmailController@destroy')->name('admin.emails.delete');
Loading
Loading

‎packages/Webkul/Admin/src/Resources/assets/sass/icons.scss

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
background-image: url("../images/leads-icon.svg");
1515
}
1616

17+
.emails-icon {
18+
width: 20px;
19+
height: 18px;
20+
background-image: url("../images/emails-icon.svg");
21+
}
22+
1723
.activities-icon {
1824
width: 17px;
1925
height: 21px;
@@ -49,6 +55,10 @@
4955
background-image: url("../images/leads-active-icon.svg");
5056
}
5157

58+
.emails-icon {
59+
background-image: url("../images/emails-active-icon.svg");
60+
}
61+
5262
.activities-icon {
5363
background-image: url("../images/activities-active-icon.svg");
5464
}

‎packages/Webkul/Admin/src/Resources/lang/en/app.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@
130130
'file-added' => 'File added',
131131
],
132132

133+
'emails' => [
134+
'title' => 'Emails',
135+
'create-success' => 'Email sent successfully.',
136+
'delete-success' => 'Email deleted successfully.',
137+
'delete-failed' => 'Email can not be deleted.',
138+
],
139+
133140
'activities' => [
134141
'title' => 'Activities',
135142
'create-success' => 'Activity created successfully.',
@@ -283,7 +290,6 @@
283290
'email' => 'Email',
284291
'subject' => 'Subject',
285292
'emails' => 'Emails',
286-
'emails' => 'Emails',
287293
'stage' => 'Stage',
288294
'status' => 'Status',
289295
'active' => 'Active',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@extends('admin::layouts.master')
2+
3+
@section('page_title')
4+
{{ __('admin::app.emails.title') }}
5+
@stop
6+
7+
@section('content-wrapper')
8+
<div class="content full-page dashboard">
9+
<h1>{{ __('admin::app.emails.title') }}</h1>
10+
11+
12+
</div>
13+
@stop

‎packages/Webkul/Email/src/Contracts/Thread.php

-8
This file was deleted.

‎packages/Webkul/Email/src/Database/Migrations/2021_05_24_075618_create_emails_table.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@ public function up()
1717
$table->increments('id');
1818
$table->string('subject')->nullable();
1919
$table->string('source');
20+
$table->string('user_type');
21+
$table->string('name')->nullable();
22+
$table->text('reply')->nullable();
23+
$table->boolean('is_trashed')->default(0);
24+
$table->json('from')->nullable();
25+
$table->json('sender')->nullable();
26+
$table->json('reply_to')->nullable();
27+
$table->json('cc')->nullable();
28+
$table->json('bcc')->nullable();
29+
$table->string('unique_id')->nullable()->unique();
2030
$table->string('message_id')->unique();
2131
$table->json('reference_ids')->nullable();
22-
$table->boolean('is_trashed')->default(0);
2332

2433
$table->integer('user_id')->unsigned()->nullable();
2534
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@@ -29,6 +38,11 @@ public function up()
2938

3039
$table->timestamps();
3140
});
41+
42+
Schema::table('emails', function (Blueprint $table) {
43+
$table->integer('parent_id')->unsigned()->nullable();
44+
$table->foreign('parent_id')->references('id')->on('emails')->onDelete('cascade');
45+
});
3246
}
3347

3448
/**

‎packages/Webkul/Email/src/Database/Migrations/2021_05_24_075624_create_email_threads_table.php

-52
This file was deleted.

‎packages/Webkul/Email/src/Database/Migrations/2021_05_25_072700_create_email_thread_attachments_table.php ‎packages/Webkul/Email/src/Database/Migrations/2021_05_25_072700_create_email_attachments_table.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
class CreateEmailThreadAttachmentsTable extends Migration
7+
class CreateEmailAttachmentsTable extends Migration
88
{
99
/**
1010
* Run the migrations.
@@ -13,16 +13,16 @@ class CreateEmailThreadAttachmentsTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('email_thread_attachments', function (Blueprint $table) {
16+
Schema::create('email_attachments', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->string('name')->nullable();
1919
$table->string('path');
2020
$table->integer('size')->nullable();
2121
$table->string('content_type')->nullable();
2222
$table->string('content_id')->nullable();
2323

24-
$table->integer('email_thread_id')->unsigned();
25-
$table->foreign('email_thread_id')->references('id')->on('email_threads')->onDelete('cascade');
24+
$table->integer('email_id')->unsigned();
25+
$table->foreign('email_id')->references('id')->on('emails')->onDelete('cascade');
2626

2727
$table->timestamps();
2828
});
@@ -35,6 +35,6 @@ public function up()
3535
*/
3636
public function down()
3737
{
38-
Schema::dropIfExists('email_thread_attachments');
38+
Schema::dropIfExists('email_attachments');
3939
}
4040
}

‎packages/Webkul/Email/src/Helpers/Parser.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function extractMultipartMIMEText($part, $source, $encodingType)
278278

279279
list($relations, $content_types, $boundaries) = $matches;
280280

281-
$messageToProcess = substr($source, strpos($source, $content_delimeter) + strlen($content_delimeter));
281+
$messageToProcess = substr($source, stripos($source, (string)$content_delimeter) + strlen($content_delimeter));
282282

283283
array_unshift($boundaries, $boundary);
284284

@@ -521,7 +521,7 @@ public function extractMultipartMIMEAttachments()
521521
$content_delimeter = end($delimeter);
522522

523523
list($relations, $content_types, $boundaries) = $matches;
524-
$messageToProcess = substr($this->data, strpos($this->data, $content_delimeter) + strlen($content_delimeter));
524+
$messageToProcess = substr($this->data, stripos($this->data, (string)$content_delimeter) + strlen($content_delimeter));
525525

526526
array_unshift($boundaries, $boundary);
527527

‎packages/Webkul/Email/src/Mails/Email.php

+19-19
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,27 @@
55
use Illuminate\Bus\Queueable;
66
use Illuminate\Mail\Mailable;
77
use Illuminate\Queue\SerializesModels;
8-
use Webkul\Email\Contracts\Thread;
98

109
class Email extends Mailable
1110
{
1211
use Queueable, SerializesModels;
1312

1413
/**
15-
* The thread instance.
14+
* The email instance.
1615
*
17-
* @var \Webkul\Email\Contracts\Thread $thread
16+
* @var \Webkul\Email\Contracts\Email $email
1817
*/
19-
public $thread;
18+
public $email;
2019

2120
/**
22-
* Create a new thread instance.
21+
* Create a new email instance.
2322
*
24-
* @param \Webkul\Email\Contracts\Thread $thread
23+
* @param \Webkul\Email\Contracts\Email $email
2524
* @return void
2625
*/
27-
public function __construct(Thread $thread)
26+
public function __construct($email)
2827
{
29-
$this->thread = $thread;
28+
$this->email = $email;
3029
}
3130

3231
/**
@@ -36,22 +35,23 @@ public function __construct(Thread $thread)
3635
*/
3736
public function build()
3837
{
39-
$this->to($this->thread->reply_to)
40-
->replyTo($this->thread->email->message_id)
41-
->cc($this->thread->cc)
42-
->bcc($this->thread->bcc)
43-
->subject($this->thread->email->subject)
44-
->html($this->thread->reply);
38+
$this->to($this->email->reply_to)
39+
->replyTo($this->email->parent_id ? $this->email->parent->unique_id : $this->email->unique_id)
40+
->cc($this->email->cc)
41+
->bcc($this->email->bcc)
42+
->subject($this->email->subject)
43+
->html($this->email->reply);
4544

4645
$this->withSwiftMessage(function ($message) {
47-
$message->getHeaders()->addTextHeader('Message-ID', $this->thread->message_id);
46+
$message->getHeaders()->addTextHeader('Message-ID', $this->email->message_id);
4847

49-
$message->getHeaders()->addTextHeader('References', implode(' ', array_merge($this->thread->email->reference_ids ?? [], [
50-
$this->thread->message_id
51-
])));
48+
$message->getHeaders()->addTextHeader('References', $this->email->parent_id
49+
? implode(' ', $this->email->parent->reference_ids)
50+
: implode(' ', $this->email->reference_ids)
51+
);
5252
});
5353

54-
foreach ($this->thread->attachments as $attachment) {
54+
foreach ($this->email->attachments as $attachment) {
5555
$this->attachFromStorage($attachment->path);
5656
}
5757

‎packages/Webkul/Email/src/Models/Attachment.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class Attachment extends Model implements AttachmentContract
99
{
10-
protected $table = 'email_thread_attachments';
10+
protected $table = 'email_attachments';
1111

1212
/**
1313
* The attributes that are mass assignable.
@@ -20,14 +20,14 @@ class Attachment extends Model implements AttachmentContract
2020
'size',
2121
'content_type',
2222
'content_id',
23-
'email_thread_id',
23+
'email_id',
2424
];
2525

2626
/**
27-
* Get the thread.
27+
* Get the email.
2828
*/
29-
public function thread()
29+
public function email()
3030
{
31-
return $this->belongsTo(ThreadProxy::modelClass());
31+
return $this->belongsTo(EmailProxy::modelClass());
3232
}
3333
}

‎packages/Webkul/Email/src/Models/Email.php

+35-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class Email extends Model implements EmailContract
1212
protected $table = 'emails';
1313

1414
protected $casts = [
15+
'sender' => 'array',
16+
'from' => 'array',
17+
'reply_to' => 'array',
18+
'cc' => 'array',
19+
'bcc' => 'array',
1520
'reference_ids' => 'array',
1621
];
1722

@@ -23,19 +28,37 @@ class Email extends Model implements EmailContract
2328
protected $fillable = [
2429
'subject',
2530
'source',
31+
'name',
32+
'user_type',
33+
'is_trashed',
34+
'sender',
35+
'from',
36+
'reply_to',
37+
'cc',
38+
'bcc',
39+
'unique_id',
2640
'message_id',
2741
'reference_ids',
28-
'is_trashed',
42+
'reply',
2943
'user_id',
3044
'person_id',
45+
'parent_id',
3146
];
3247

3348
/**
34-
* Get the threads.
49+
* Get the parent email.
50+
*/
51+
public function parent()
52+
{
53+
return $this->belongsTo(EmailProxy::modelClass(), 'parent_id');
54+
}
55+
56+
/**
57+
* Get the emails.
3558
*/
36-
public function threads()
59+
public function emails()
3760
{
38-
return $this->hasMany(ThreadProxy::modelClass());
61+
return $this->hasMany(EmailProxy::modelClass(), 'parent_id');
3962
}
4063

4164
/**
@@ -53,4 +76,12 @@ public function person()
5376
{
5477
return $this->belongsTo(PersonProxy::modelClass());
5578
}
79+
80+
/**
81+
* Get the attachments.
82+
*/
83+
public function attachments()
84+
{
85+
return $this->hasMany(AttachmentProxy::modelClass(), 'email_id');
86+
}
5687
}

‎packages/Webkul/Email/src/Models/Thread.php

-75
This file was deleted.

‎packages/Webkul/Email/src/Models/ThreadProxy.php

-10
This file was deleted.

‎packages/Webkul/Email/src/Providers/ModuleServiceProvider.php

-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ class ModuleServiceProvider extends BaseModuleServiceProvider
99
protected $models = [
1010
\Webkul\Email\Models\Attachment::class,
1111
\Webkul\Email\Models\Email::class,
12-
\Webkul\Email\Models\Thread::class,
1312
];
1413
}

‎packages/Webkul/Email/src/Repositories/AttachmentRepository.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ public function setEmailParser($emailParser)
3636
}
3737

3838
/**
39-
* @param \Webkul\Email\Contracts\Thread $thread
39+
* @param \Webkul\Email\Contracts\Email $email
4040
* @param array $data
4141
* @return void
4242
*/
43-
public function uploadAttachments($thread, array $data)
43+
public function uploadAttachments($email, array $data)
4444
{
4545
if ($data['source'] == 'email') {
4646
foreach ($this->emailParser->getAttachments() as $attachment) {
47-
$fileName = 'emails/' . $thread->email_id . '/' . $thread->id . '/' . $attachment->getFilename();
47+
Storage::put($path = 'emails/' . $email->id . '/' . $attachment->getFilename(), $attachment->getContent());
4848

4949
$this->create([
50-
'path' => $path = Storage::put($fileName, $attachment->getContent()),
51-
'name' => $attachment->getFileName(),
52-
'content_type' => $attachment->contentType,
53-
'content_id' => $attachment->contentId,
54-
'size' => Storage::size($path),
55-
'email_thread_id' => $thread->id,
50+
'path' => $path,
51+
'name' => $attachment->getFileName(),
52+
'content_type' => $attachment->contentType,
53+
'content_id' => $attachment->contentId,
54+
'size' => Storage::size($path),
55+
'email_id' => $email->id,
5656
]);
5757
}
5858
} else {
@@ -62,11 +62,11 @@ public function uploadAttachments($thread, array $data)
6262

6363
foreach ($data['attachments'] as $index => $attachment) {
6464
$this->create([
65-
'path' => $path = request()->file('attachments.' . $index)->store('emails/' . $thread->email_id . '/' . $thread->id),
66-
'name' => $attachment->getClientOriginalName(),
67-
'content_type' => $attachment->getClientMimeType(),
68-
'size' => Storage::size($path),
69-
'email_thread_id' => $thread->id,
65+
'path' => $path = request()->file('attachments.' . $index)->store('emails/' . $email->id),
66+
'name' => $attachment->getClientOriginalName(),
67+
'content_type' => $attachment->getClientMimeType(),
68+
'size' => Storage::size($path),
69+
'email_id' => $email->id,
7070
]);
7171
}
7272
}

‎packages/Webkul/Email/src/Repositories/EmailRepository.php

+84-42
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44

55
use Illuminate\Container\Container;
66
use Illuminate\Support\Facades\Event;
7-
use Webkul\Core\Eloquent\Repository;
7+
use Illuminate\Support\Facades\Mail;
8+
use Webkul\Email\Mails\Email;
89
use Webkul\Email\Helpers\Parser;
10+
use Webkul\Email\Helpers\Htmlfilter;
11+
use Webkul\Core\Eloquent\Repository;
912

1013
class EmailRepository extends Repository
1114
{
1215
/**
13-
* ThreadRepository object
16+
* AttachmentRepository object
1417
*
15-
* @var \Webkul\Attribute\Repositories\ThreadRepository
18+
* @var \Webkul\Email\Repositories\AttachmentRepository
1619
*/
17-
protected $threadRepository;
20+
protected $attachmentRepository;
1821

1922
/**
2023
* Parser object
@@ -23,24 +26,35 @@ class EmailRepository extends Repository
2326
*/
2427
protected $emailParser;
2528

29+
/**
30+
* Htmlfilter object
31+
*
32+
* @var \Webkul\Email\Helpers\Htmlfilter
33+
*/
34+
protected $htmlFilter;
35+
2636
/**
2737
* Create a new repository instance.
2838
*
29-
* @param \Webkul\Attribute\Repositories\ThreadRepository $threadRepository
39+
* @param \Webkul\Email\Repositories\AttachmentRepository $attachmentRepository
3040
* @param \Webkul\Email\Helpers\Parser $emailParser
41+
* @param \Webkul\Email\Helpers\Htmlfilter $htmlFilter
3142
* @param \Illuminate\Container\Container $container
3243
* @return void
3344
*/
3445
public function __construct(
35-
ThreadRepository $threadRepository,
46+
AttachmentRepository $attachmentRepository,
3647
Parser $emailParser,
48+
Htmlfilter $htmlFilter,
3749
Container $container
3850
)
3951
{
40-
$this->threadRepository = $threadRepository;
52+
$this->attachmentRepository = $attachmentRepository;
4153

4254
$this->emailParser = $emailParser;
4355

56+
$this->htmlFilter = $htmlFilter;
57+
4458
parent::__construct($container);
4559
}
4660

@@ -60,15 +74,14 @@ function model()
6074
*/
6175
public function create(array $data)
6276
{
63-
$email = parent::create(array_merge($data, [
77+
$email = parent::create(array_merge($this->sanitizeEmails($data), [
78+
'unique_id' => ! isset($data['parent_id']) ? time() . '@example.com' : null,
6479
'message_id' => $data['message_id'] ?? time() . '@example.com',
6580
]));
6681

67-
$thread = $this->threadRepository->create(array_merge($data, [
68-
'type' => 'create',
69-
'message_id' => $email->message_id,
70-
'email_id' => $email->id,
71-
]));
82+
$this->attachmentRepository->setEmailParser($this->emailParser)->uploadAttachments($email, $data);
83+
84+
Mail::send(new Email($email));
7285

7386
return $email;
7487
}
@@ -81,6 +94,16 @@ public function processInboundParseMail($content)
8194
{
8295
$this->emailParser->setText($content);
8396

97+
$email = $this->findOneWhere(['message_id' => $this->emailParser->getHeader('message-id')]);
98+
99+
if ($email) {
100+
return;
101+
}
102+
103+
if (! $fromNameParts = mailparse_rfc822_parse_addresses($this->emailParser->getHeader('from'))) {
104+
$fromNameParts = mailparse_rfc822_parse_addresses($this->emailParser->getHeader('sender'));
105+
}
106+
84107
$headers = [
85108
'from' => $this->parseEmailAddress('from'),
86109
'sender' => $this->parseEmailAddress('sender'),
@@ -89,56 +112,60 @@ public function processInboundParseMail($content)
89112
'bcc' => $this->parseEmailAddress('bcc'),
90113
'subject' => $this->emailParser->getHeader('subject'),
91114
'source' => 'email',
92-
'name' => $headers['from'] == $from[0]['display']
93-
? current(explode('@', $from[0]['display']))
94-
: $from[0]['display'],
115+
'name' => $fromNameParts[0]['display'] == $fromNameParts[0]['address']
116+
? current(explode('@', $fromNameParts[0]['display']))
117+
: $fromNameParts[0]['display'],
95118
'user_type' => 'person',
96119
'message_id' => $this->emailParser->getHeader('message-id') ?? time() . '@example.com',
97120
'reference_ids' => htmlspecialchars_decode($this->emailParser->getHeader('references')),
98121
'in_reply_to' => htmlspecialchars_decode($this->emailParser->getHeader('in-reply-to')),
99122
];
100123

101-
foreach ($toAdress as $to) {
124+
foreach ($headers['reply_to'] as $to) {
102125
if ($email = $this->findOneWhere(['message_id' => $to])) {
103126
break;
104127
}
105128
}
106129

107130
if (! isset($email) && $headers['in_reply_to']) {
108-
$email = $this->threadRepository->findOneWhere([['reference_ids', 'like', $headers['in_reply_to']]]);
131+
$email = $this->findOneWhere(['message_id' => $headers['in_reply_to']]);
132+
133+
if (! $email) {
134+
$email = $this->findOneWhere([['reference_ids', 'like', '%' . $headers['in_reply_to'] . '%']]);
135+
}
109136
}
110137

111138
if (! isset($email) && $headers['reference_ids']) {
112139
$referenceIds = explode(' ', $headers['reference_ids']);
113140

114141
foreach ($referenceIds as $referenceId) {
115-
if ($email = $this->threadRepository->findOneWhere([['reference_ids', 'like', $referenceId]])) {
142+
if ($email = $this->findOneWhere([['reference_ids', 'like', '%' . $referenceId . '%']])) {
116143
break;
117144
}
118145
}
119146
}
120147

148+
if (! $reply = $this->emailParser->getMessageBody('text')) {
149+
$reply = $this->emailParser->getTextMessageBody();
150+
}
151+
121152
if (! isset($email)) {
122153
$email = $this->create(array_merge($headers, [
123-
'reference_ids' => $headers['message_id'],
124-
]));
125-
126-
$thread = $this->threadRepository->setEmailParser($this->emailParser)->create(array_merge($headers, [
127-
'type' => 'create',
154+
'reply' => $this->htmlFilter->HTMLFilter($reply, ''),
155+
'reference_ids' => [$headers['message_id']],
128156
'user_type' => 'person',
129-
'reference_ids' => $headers['message_id'],
130157
]));
131158
} else {
132-
$thread = $this->threadRepository->findOneWhere(['message_id' => $headers['message_id']]);
133-
134-
if ($thread) {
135-
return;
136-
}
137-
138159
// Create person or admin if both are note exists (Optional)
139160

140-
$this->threadRepository->setEmailParser($this->emailParser)->create(array_merge($headers, [
141-
'type' => 'reply',
161+
$this->update([
162+
'reference_ids' => array_merge($email->reference_ids ?? [], [$headers['message_id']]),
163+
], $email->id);
164+
165+
$this->create(array_merge($headers, [
166+
'reply' => $this->htmlFilter->HTMLFilter($reply, ''),
167+
'parent_id' => $email->id,
168+
'user_type' => 'person',
142169
]));
143170
}
144171
}
@@ -149,20 +176,35 @@ public function processInboundParseMail($content)
149176
*/
150177
public function parseEmailAddress($type)
151178
{
152-
$addresses = mailparse_rfc822_parse_addresses($this->emailParser->getHeader($type));
153-
154-
if (count($addresses) <= 1) {
155-
return [$addresses[0]['address']];
156-
}
157-
158179
$emails = [];
159180

160-
foreach ($addresses as $address) {
161-
if (filter_var($address['address'], FILTER_VALIDATE_EMAIL)) {
162-
$emails[] = $address['address'];
181+
$addresses = mailparse_rfc822_parse_addresses($this->emailParser->getHeader($type));
182+
183+
if (count($addresses) > 1) {
184+
foreach ($addresses as $address) {
185+
if (filter_var($address['address'], FILTER_VALIDATE_EMAIL)) {
186+
$emails[] = $address['address'];
187+
}
163188
}
189+
} else if ($addresses) {
190+
$emails[] = $addresses[0]['address'];
164191
}
165192

166193
return $emails;
167194
}
195+
196+
/**
197+
* @param array $data
198+
* @return array
199+
*/
200+
public function sanitizeEmails(array $data)
201+
{
202+
$data['reply_to'] = array_values(array_filter($data['reply_to']));
203+
204+
$data['cc'] = array_values(array_filter($data['cc']));
205+
206+
$data['bcc'] = array_values(array_filter($data['bcc']));
207+
208+
return $data;
209+
}
168210
}

‎packages/Webkul/Email/src/Repositories/ThreadRepository.php

-95
This file was deleted.

‎packages/Webkul/UI/publishable/assets/css/ui.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Loading

‎packages/Webkul/UI/publishable/assets/js/ui.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/Webkul/UI/publishable/assets/mix-manifest.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"/js/ui.js": "/js/ui.js?id=632998789bfb445cead6",
3-
"/css/ui.css": "/css/ui.css?id=56fc2ce8d1c7b5ad586c",
2+
"/js/ui.js": "/js/ui.js?id=2fe55eb59727be5cf344",
3+
"/css/ui.css": "/css/ui.css?id=733e72d33a3ad3d371d0",
44
"/images/align-justify-icon.svg": "/images/align-justify-icon.svg?id=ee8d48e636b80417a884",
55
"/images/arrow-down-icon.svg": "/images/arrow-down-icon.svg?id=7b5c03f96be72c9a0bef",
66
"/images/arrow-left-icon.svg": "/images/arrow-left-icon.svg?id=61cff1417c6e047d76f6",
@@ -31,5 +31,6 @@
3131
"/images/plus-black-icon.svg": "/images/plus-black-icon.svg?id=9135b4e0e1c239c36981",
3232
"/images/add-icon.svg": "/images/add-icon.svg?id=9135b4e0e1c239c36981",
3333
"/images/time-icon.svg": "/images/time-icon.svg?id=57cfdb5c9d4c46e2ec1c",
34-
"/images/trash-icon.svg": "/images/trash-icon.svg?id=985e370d9ceea2f05b82"
34+
"/images/trash-icon.svg": "/images/trash-icon.svg?id=985e370d9ceea2f05b82",
35+
"/images/attachment-icon.svg": "/images/attachment-icon.svg?id=7f8975406eb4b7e497e7"
3536
}

‎public/phpinfo.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
phpinfo();
4+
5+
?>

0 commit comments

Comments
 (0)
Please sign in to comment.