Files
espocrm/application/Espo/Entities/EmailAccount.php
Yuri Kuznetsov abca847e5a type fixes
2022-03-18 13:37:53 +02:00

149 lines
3.8 KiB
PHP

<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2022 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Entities;
use Espo\Core\ORM\Entity;
use Espo\Core\Field\Date;
use Espo\Core\Field\Link;
use Espo\Core\Field\LinkMultiple;
use stdClass;
class EmailAccount extends Entity
{
public const ENTITY_TYPE = 'EmailAccount';
public function isAvailableForFetching(): bool
{
return $this->get('status') === 'Active' && $this->get('useImap');
}
public function getEmailAddress(): ?string
{
return $this->get('emailAddress');
}
public function getAssignedUser(): ?Link
{
/** @var ?Link */
return $this->getValueObject('assignedUser');
}
public function getTeams(): LinkMultiple
{
/** @var LinkMultiple */
return LinkMultiple::create();
}
public function keepFetchedEmailsUnread(): bool
{
return (bool) $this->get('keepFetchedEmailsUnread');
}
public function getFetchData(): stdClass
{
$data = $this->get('fetchData') ?? (object) [];
if (!property_exists($data, 'lastUID')) {
$data->lastUID = (object) [];
}
if (!property_exists($data, 'lastDate')) {
$data->lastDate = (object) [];
}
if (!property_exists($data, 'byDate')) {
$data->byDate = (object) [];
}
return $data;
}
public function getFetchSince(): ?Date
{
/** @var ?Date */
return $this->getValueObject('fetchSince');
}
public function getEmailFolder(): ?Link
{
/** @var ?Link */
return $this->getValueObject('emailFolder');
}
/**
* @return string[]
*/
public function getMonitoredFolderList(): array
{
return $this->get('monitoredFolders') ?? [];
}
public function getHost(): ?string
{
return $this->get('host');
}
public function getPort(): ?int
{
return $this->get('port');
}
public function getUsername(): ?string
{
return $this->get('username');
}
public function getPassword(): ?string
{
return $this->get('password');
}
public function getSecurity(): ?string
{
return $this->get('security');
}
/**
* @return ?class-string<object>
*/
public function getImapHandlerClassName(): ?string
{
/** @var ?class-string<object> */
return $this->get('imapHandler');
}
public function getSentFolder(): ?string
{
return $this->get('sentFolder');
}
}