1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Helpers/Mail/Mailbox/Imap/ImapMailbox.php

55 lines
1.4 KiB
PHP
Raw Normal View History

2023-12-10 16:06:33 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Helpers\Mail;
use Ddeboer\Imap\MessageInterface;
use Ddeboer\Imap\Server;
use Ddeboer\Imap\SearchExpression;
use Ddeboer\Imap\Search\Date\Since;
2023-12-14 10:33:49 +01:00
class ImapMailbox
2023-12-10 16:06:33 +01:00
{
private $server;
public $connection;
2023-12-14 08:32:15 +01:00
public function __construct(string $server, string $port, string $user, string $password)
2023-12-10 16:06:33 +01:00
{
2023-12-14 10:33:49 +01:00
$this->server = new Server($server, $port != '' ? $port : null);
2023-12-10 16:06:33 +01:00
$this->connection = $this->server->authenticate($user, $password);
}
public function getUnprocessedEmails()
{
$mailbox = $this->connection->getMailbox('INBOX');
$search = new SearchExpression();
// not older than 30days
$today = new \DateTimeImmutable();
$thirtyDaysAgo = $today->sub(new \DateInterval('P30D'));
$search->addCondition(new Since($thirtyDaysAgo));
return $mailbox->getMessages($search);
}
public function moveProcessed(MessageInterface $mail)
{
return $mail->move($this->connection->getMailbox('PROCESSED'));
}
2023-12-14 10:33:49 +01:00
public function moveFailed(MessageInterface $mail)
{
return $mail->move($this->connection->getMailbox('FAILED'));
}
2023-12-10 16:06:33 +01:00
}