diff --git a/app/Console/Commands/FetchEmailCommand.php b/app/Console/Commands/FetchEmailCommand.php
index c734ef1..789991d 100644
--- a/app/Console/Commands/FetchEmailCommand.php
+++ b/app/Console/Commands/FetchEmailCommand.php
@@ -97,13 +97,15 @@ public function handle(): void
}
// Get document number
- $this->line('- Processing message '.$headers['Subject']);
+ $subject = $headers['Subject'];
+ $this->line('- Processing message '.$subject);
+ $subject = str_replace(['Copy of ', 'สำเนา '], '', $subject);
$list = [];
- if (preg_match('/(?:สพจ|SMCU)(?:\.|\s){1,2}(\d+)-(25\d\d)\s.+/i', $headers['Subject'], $list, PREG_UNMATCHED_AS_NULL)) {
+ if (preg_match('/(?:สพจ|SMCU)(?:\.|\s|-){1,2}(\d+)(?:_|-)(25\d\d)(?:\s|-).+/i', $subject, $list, PREG_UNMATCHED_AS_NULL)) {
$document = Document::where('number', $list[1])->where('year', $list[2])->first();
if ($document) {
$this->line('- Found update of document '.$document->id.' ('.$document->number.'/'.$document->year.') '.$document->title);
- if (str_starts_with($headers['Subject'], 'FINALIZED:')) {
+ if (str_starts_with($subject, 'FINALIZED:')) {
// Skip if document is already approved
if ($document->status == Document::STATUS_APPROVED and $document->approved_path and Carbon::parse($headers['Date'])
->isBefore($document->updated_at)) {
@@ -125,9 +127,12 @@ public function handle(): void
break;
}
}
- } elseif (str_starts_with($headers['Subject'], 'REJECTED:') and $document->status != Document::STATUS_REJECTED) {
+ } elseif (str_starts_with($subject, 'REJECTED:') and $document->status != Document::STATUS_REJECTED) {
$document->status = Document::STATUS_REJECTED;
$document->save();
+ } elseif (str_starts_with($subject, 'Email delivery failure:') and $document->status != Document::STATUS_UNDELIVERED) {
+ $document->status = Document::STATUS_UNDELIVERED;
+ $document->save();
}
}
}
diff --git a/app/Models/Document.php b/app/Models/Document.php
index 1ca153c..3371cf8 100644
--- a/app/Models/Document.php
+++ b/app/Models/Document.php
@@ -33,6 +33,7 @@ class Document extends Model {
public const STATUS_APPROVED = 'APPROVED';
public const STATUS_REJECTED = 'REJECTED';
+ public const STATUS_UNDELIVERED = 'UNDELIVERED'; // Email delivery failure
public function department(): BelongsTo {
return $this->belongsTo(Department::class)->select('id', 'name');
diff --git a/resources/js/Pages/DocumentIndex.vue b/resources/js/Pages/DocumentIndex.vue
index f1edc08..d2efca8 100644
--- a/resources/js/Pages/DocumentIndex.vue
+++ b/resources/js/Pages/DocumentIndex.vue
@@ -42,6 +42,7 @@
ไม่พบไฟล์