From 08662c1595f38b7ca8b8e3a5d64decf2036ab6a4 Mon Sep 17 00:00:00 2001 From: paulwer Date: Mon, 18 Dec 2023 17:24:59 +0100 Subject: [PATCH] renaming and minor changes --- .../IngresEmail/IngresEmailEngine.php | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/app/Services/IngresEmail/IngresEmailEngine.php b/app/Services/IngresEmail/IngresEmailEngine.php index 328a98d6c9f4..f0891df1faaa 100644 --- a/app/Services/IngresEmail/IngresEmailEngine.php +++ b/app/Services/IngresEmail/IngresEmailEngine.php @@ -62,7 +62,7 @@ class IngresEmailEngine implements ShouldQueue continue; $this->isUnknownRecipent = false; - if (!$this->validateExpenseActive()) + if (!$this->validateExpenseShouldProcess()) continue; $this->createExpense(); @@ -71,41 +71,6 @@ class IngresEmailEngine implements ShouldQueue $this->saveMeta(); } - // MAIN-PROCESSORS - protected function createExpense() - { - if (!$this->validateExpenseSender()) { - nlog('invalid sender of an ingest email to company: ' . $this->company->id . ' from: ' . $this->email->from); - return; - } - - $expense = ExpenseFactory::create($this->company->id, $this->company->owner()->id); - - $expense->public_notes = $this->email->subject; - $expense->private_notes = $this->email->text_body; - $expense->date = $this->email->date; - - // handle vendor assignment - $expense_vendor = $this->getExpenseVendor(); - if ($expense_vendor) - $expense->vendor_id = $expense_vendor->id; - - // handle documents - $this->processHtmlBodyToDocument(); - $documents = []; - array_push($documents, ...$this->email->documents); - if ($this->email->body_document) - $documents[] = $this->email->body_document; - $this->saveDocuments($documents, $expense); - - $expense->saveQuietly(); - - event(new ExpenseWasCreated($expense, $expense->company, Ninja::eventVars(null))); // @turbo124 please check, I copied from API - event('eloquent.created: App\Models\Expense', $expense); // @turbo124 please check, I copied from API - - return $expense; - } - // SPAM Protection private function isInvalidOrBlocked() { @@ -166,7 +131,7 @@ class IngresEmailEngine implements ShouldQueue Cache::add('ingresEmailBlockedSender:' . $this->email->from, true, now()->addHours(12)); $this->saveMeta(); - // TODO: ignore, when known sender + // TODO: ignore, when known sender (for heavy email-usage mostly on isHosted()) // TODO: handle external blocking } private function saveMeta() @@ -185,15 +150,52 @@ class IngresEmailEngine implements ShouldQueue } } } - // PARSING + + // MAIL-PARSING private function processHtmlBodyToDocument() { if (!$this->email->body_document && property_exists($this->email, "body")) { $this->email->body_document = TempFile::UploadedFileFromRaw($this->email->body, "E-Mail.html", "text/html"); } } + + // MAIN-PROCESSORS + protected function createExpense() + { + if (!$this->validateExpenseSender()) { + nlog('invalid sender of an ingest email to company: ' . $this->company->id . ' from: ' . $this->email->from); + return; + } + + $expense = ExpenseFactory::create($this->company->id, $this->company->owner()->id); + + $expense->public_notes = $this->email->subject; + $expense->private_notes = $this->email->text_body; + $expense->date = $this->email->date; + + // handle vendor assignment + $expense_vendor = $this->getExpenseVendor(); + if ($expense_vendor) + $expense->vendor_id = $expense_vendor->id; + + // handle documents + $this->processHtmlBodyToDocument(); + $documents = []; + array_push($documents, ...$this->email->documents); + if ($this->email->body_document) + $documents[] = $this->email->body_document; + $this->saveDocuments($documents, $expense); + + $expense->saveQuietly(); + + event(new ExpenseWasCreated($expense, $expense->company, Ninja::eventVars(null))); // @turbo124 please check, I copied from API + event('eloquent.created: App\Models\Expense', $expense); // @turbo124 please check, I copied from API + + return $expense; + } + // HELPERS - private function validateExpenseActive() + private function validateExpenseShouldProcess() { return $this->company?->expense_mailbox_active ?: false; }