mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°3169 - Add feature to connect Gsuite mail box with OAuth
N°2504 - Add feature to connect Office mail box with OAuth2 for Microsoft Graph * Fix legacy mailboxes compatibility
This commit is contained in:
@@ -43,7 +43,7 @@ class EMail implements iEMail
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oMailer = EmailFactory::GetMailer($this);
|
||||
$this->oMailer = EmailFactory::GetMailer();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,20 +2,19 @@
|
||||
|
||||
namespace Combodo\iTop\Core\Email;
|
||||
|
||||
use EMail;
|
||||
use EMailLaminas;
|
||||
use EmailSwiftMailer;
|
||||
use utils;
|
||||
|
||||
class EmailFactory
|
||||
{
|
||||
public static function GetMailer(EMail $oEMail)
|
||||
public static function GetMailer()
|
||||
{
|
||||
$sTransport = utils::GetConfig()->Get('email_transport');
|
||||
if ($sTransport == 'SMTP_OAuth') {
|
||||
return EMailLaminas::GetMailer($oEMail);
|
||||
return EMailLaminas::GetMailer();
|
||||
}
|
||||
|
||||
return EmailSwiftMailer::GetMailer($oEMail);
|
||||
return EmailSwiftMailer::GetMailer();
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,6 @@
|
||||
@include APPROOT."/core/oauth.php";
|
||||
|
||||
use Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory;
|
||||
use Combodo\iTop\Core\Email\iEMail;
|
||||
use Laminas\Mail\Header\ContentType;
|
||||
use Laminas\Mail\Message;
|
||||
use Laminas\Mail\Transport\File;
|
||||
@@ -39,7 +38,7 @@ use Pelago\Emogrifier\CssInliner;
|
||||
use Pelago\Emogrifier\HtmlProcessor\CssToAttributeConverter;
|
||||
use Pelago\Emogrifier\HtmlProcessor\HtmlPruner;
|
||||
|
||||
class EMailLaminas implements iEMail
|
||||
class EMailLaminas extends Email
|
||||
{
|
||||
// Serialization formats
|
||||
const ORIGINAL_FORMAT = 1; // Original format, consisting in serializing the whole object, inculding the Swift Mailer's object.
|
||||
@@ -57,11 +56,10 @@ class EMailLaminas implements iEMail
|
||||
}
|
||||
|
||||
protected $m_oMessage;
|
||||
protected $oEMail;
|
||||
|
||||
public function __construct(EMail $oEMail)
|
||||
/** @noinspection PhpMissingParentConstructorInspection */
|
||||
public function __construct()
|
||||
{
|
||||
$this->oEMail = $oEMail;
|
||||
$this->m_aData = array();
|
||||
$this->m_oMessage = new Message();
|
||||
$this->m_oMessage->setEncoding('UTF-8');
|
||||
@@ -141,7 +139,7 @@ class EMailLaminas implements iEMail
|
||||
protected function SendAsynchronous(&$aIssues, $oLog = null)
|
||||
{
|
||||
try {
|
||||
AsyncSendEmail::AddToQueue($this->oEMail, $oLog);
|
||||
AsyncSendEmail::AddToQueue($this, $oLog);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$aIssues = array($e->GetMessage());
|
||||
@@ -153,9 +151,9 @@ class EMailLaminas implements iEMail
|
||||
return EMAIL_SEND_PENDING;
|
||||
}
|
||||
|
||||
public static function GetMailer(EMail $oEMail)
|
||||
public static function GetMailer()
|
||||
{
|
||||
return new EMailLaminas($oEMail);
|
||||
return new EMailLaminas();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,14 +24,13 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Core\Email\iEMail;
|
||||
use Pelago\Emogrifier\CssInliner;
|
||||
use Pelago\Emogrifier\HtmlProcessor\CssToAttributeConverter;
|
||||
use Pelago\Emogrifier\HtmlProcessor\HtmlPruner;
|
||||
|
||||
Swift_Preferences::getInstance()->setCharset('UTF-8');
|
||||
|
||||
class EmailSwiftMailer implements iEMail
|
||||
class EmailSwiftMailer extends EMail
|
||||
{
|
||||
protected static $m_oConfig = null;
|
||||
protected $m_aData; // For storing data to serialize
|
||||
@@ -45,11 +44,10 @@ class EmailSwiftMailer implements iEMail
|
||||
}
|
||||
|
||||
protected $m_oMessage;
|
||||
protected $oEMail;
|
||||
|
||||
public function __construct(EMail $oEMail)
|
||||
/** @noinspection PhpMissingParentConstructorInspection */
|
||||
public function __construct()
|
||||
{
|
||||
$this->oEMail = $oEMail;
|
||||
$this->m_aData = array();
|
||||
$this->m_oMessage = new Swift_Message();
|
||||
$this->SetRecipientFrom(MetaModel::GetConfig()->Get('email_default_sender_address'), MetaModel::GetConfig()->Get('email_default_sender_label'));
|
||||
@@ -137,7 +135,7 @@ class EmailSwiftMailer implements iEMail
|
||||
{
|
||||
try
|
||||
{
|
||||
AsyncSendEmail::AddToQueue($this->oEMail, $oLog);
|
||||
AsyncSendEmail::AddToQueue($this, $oLog);
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
@@ -148,9 +146,9 @@ class EmailSwiftMailer implements iEMail
|
||||
return EMAIL_SEND_PENDING;
|
||||
}
|
||||
|
||||
public static function GetMailer(EMail $oEMail)
|
||||
public static function GetMailer()
|
||||
{
|
||||
return new EmailSwiftMailer($oEMail);
|
||||
return new EmailSwiftMailer();
|
||||
}
|
||||
|
||||
protected function SendSynchronous(&$aIssues, $oLog = null)
|
||||
@@ -183,7 +181,7 @@ class EmailSwiftMailer implements iEMail
|
||||
break;
|
||||
|
||||
case 'LogFile':
|
||||
$oTransport = new Swift_LogFileTransport();
|
||||
$oTransport = new Swift_LogFileTransport(new Swift_Events_SimpleEventDispatcher());
|
||||
$oTransport->setLogFile(APPROOT.'log/mail.log');
|
||||
break;
|
||||
|
||||
@@ -543,6 +541,6 @@ class Swift_LogFileTransport extends Swift_Transport_LogFileTransport
|
||||
*/
|
||||
public static function newInstance()
|
||||
{
|
||||
return new self();
|
||||
return new self(new Swift_Events_SimpleEventDispatcher());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user