Skip to content

Commit

Permalink
Fetch emails sent to multiple mailboxes on a per mailbox basis - closes
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Apr 22, 2024
1 parent 7a6cbab commit 8c5dbb4
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions app/Console/Commands/FetchEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public function handle()

$this->line('['.date('Y-m-d H:i:s').'] Fetching '.($this->option('unseen') ? 'UNREAD' : 'ALL').' emails for the last '.$this->option('days').' days.');

$this->extra_import = [];

if (Mailbox::getInProtocols() === Mailbox::$in_protocols) {
$this->mailboxes = Mailbox::get();
} else {
Expand Down Expand Up @@ -124,24 +122,25 @@ function ($mailboxId) {
$this->info('['.date('Y-m-d H:i:s').'] Mailbox: '.$mailbox->name);

$this->mailbox = $mailbox;

$this->extra_import = [];

try {
$this->fetch($mailbox);
} catch (\Exception $e) {
$successfully = false;
$this->logError('Error: '.$e->getMessage().'; File: '.$e->getFile().' ('.$e->getLine().')').')';
}

usleep($sleep);
}

// Import emails sent to several mailboxes at once.
if (count($this->extra_import)) {
$this->line('['.date('Y-m-d H:i:s').'] Importing emails sent to several mailboxes at once: '.count($this->extra_import));
foreach ($this->extra_import as $i => $extra_import) {
$this->line('['.date('Y-m-d H:i:s').'] '.($i+1).') '.$extra_import['message']->getSubject());
$this->processMessage($extra_import['message'], $extra_import['message_id'], $extra_import['mailbox'], [], true);
// Import emails sent to several mailboxes at once.
if (count($this->extra_import)) {
$this->line('['.date('Y-m-d H:i:s').'] Importing emails sent to several mailboxes at once: '.count($this->extra_import));
foreach ($this->extra_import as $i => $extra_import) {
$this->line('['.date('Y-m-d H:i:s').'] '.($i+1).') '.$extra_import['message']->getSubject());
$this->processMessage($extra_import['message'], $extra_import['message_id'], $extra_import['mailbox'], [], true);
}
}

usleep($sleep);
}

if ($successfully && count($this->mailboxes)) {
Expand Down

0 comments on commit 8c5dbb4

Please sign in to comment.