mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01: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:
@@ -25,13 +25,14 @@
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Core\Email\EmailFactory;
|
||||
use Combodo\iTop\Core\Email\iEMail;
|
||||
|
||||
|
||||
define ('EMAIL_SEND_OK', 0);
|
||||
define ('EMAIL_SEND_PENDING', 1);
|
||||
define ('EMAIL_SEND_ERROR', 2);
|
||||
|
||||
class EMail
|
||||
class EMail implements iEMail
|
||||
{
|
||||
protected $oMailer;
|
||||
|
||||
@@ -42,7 +43,7 @@ class EMail
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oMailer = EmailFactory::GetMailer();
|
||||
$this->oMailer = EmailFactory::GetMailer($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -161,6 +161,7 @@ return array(
|
||||
'Combodo\\iTop\\Core\\Authentication\\Client\\OAuth\\OAuthClientProviderGoogle' => $baseDir . '/sources/Core/Authentication/Client/OAuth/OAuthClientProviderGoogle.php',
|
||||
'Combodo\\iTop\\Core\\Authentication\\Client\\OAuth\\OAuthClientResultDisplayConf' => $baseDir . '/sources/Core/Authentication/Client/OAuth/OAuthClientResultDisplayConf.php',
|
||||
'Combodo\\iTop\\Core\\Email\\EmailFactory' => $baseDir . '/sources/Core/Email/EmailFactory.php',
|
||||
'Combodo\\iTop\\Core\\Email\\iEMail' => $baseDir . '/sources/Core/Email/iEMail.php',
|
||||
'Combodo\\iTop\\DesignDocument' => $baseDir . '/core/designdocument.class.inc.php',
|
||||
'Combodo\\iTop\\DesignElement' => $baseDir . '/core/designdocument.class.inc.php',
|
||||
'Combodo\\iTop\\TwigExtension' => $baseDir . '/application/twigextension.class.inc.php',
|
||||
|
||||
@@ -529,6 +529,7 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b
|
||||
'Combodo\\iTop\\Core\\Authentication\\Client\\OAuth\\OAuthClientProviderGoogle' => __DIR__ . '/../..' . '/sources/Core/Authentication/Client/OAuth/OAuthClientProviderGoogle.php',
|
||||
'Combodo\\iTop\\Core\\Authentication\\Client\\OAuth\\OAuthClientResultDisplayConf' => __DIR__ . '/../..' . '/sources/Core/Authentication/Client/OAuth/OAuthClientResultDisplayConf.php',
|
||||
'Combodo\\iTop\\Core\\Email\\EmailFactory' => __DIR__ . '/../..' . '/sources/Core/Email/EmailFactory.php',
|
||||
'Combodo\\iTop\\Core\\Email\\iEMail' => __DIR__ . '/../..' . '/sources/Core/Email/iEMail.php',
|
||||
'Combodo\\iTop\\DesignDocument' => __DIR__ . '/../..' . '/core/designdocument.class.inc.php',
|
||||
'Combodo\\iTop\\DesignElement' => __DIR__ . '/../..' . '/core/designdocument.class.inc.php',
|
||||
'Combodo\\iTop\\TwigExtension' => __DIR__ . '/../..' . '/application/twigextension.class.inc.php',
|
||||
|
||||
@@ -2,19 +2,20 @@
|
||||
|
||||
namespace Combodo\iTop\Core\Email;
|
||||
|
||||
use EMail;
|
||||
use EMailLaminas;
|
||||
use EmailSwiftMailer;
|
||||
use utils;
|
||||
|
||||
class EmailFactory
|
||||
{
|
||||
public static function GetMailer()
|
||||
public static function GetMailer(EMail $oEMail)
|
||||
{
|
||||
$sTransport = utils::GetConfig()->Get('email_transport');
|
||||
if ($sTransport == 'SMTP_OAuth') {
|
||||
return EMailLaminas::GetMailer();
|
||||
return EMailLaminas::GetMailer($oEMail);
|
||||
}
|
||||
|
||||
return EmailSwiftMailer::GetMailer();
|
||||
return EmailSwiftMailer::GetMailer($oEMail);
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
@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;
|
||||
@@ -38,7 +39,7 @@ use Pelago\Emogrifier\CssInliner;
|
||||
use Pelago\Emogrifier\HtmlProcessor\CssToAttributeConverter;
|
||||
use Pelago\Emogrifier\HtmlProcessor\HtmlPruner;
|
||||
|
||||
class EMailLaminas
|
||||
class EMailLaminas implements iEMail
|
||||
{
|
||||
// Serialization formats
|
||||
const ORIGINAL_FORMAT = 1; // Original format, consisting in serializing the whole object, inculding the Swift Mailer's object.
|
||||
@@ -56,9 +57,11 @@ class EMailLaminas
|
||||
}
|
||||
|
||||
protected $m_oMessage;
|
||||
protected $oEMail;
|
||||
|
||||
public function __construct()
|
||||
public function __construct(EMail $oEMail)
|
||||
{
|
||||
$this->oEMail = $oEMail;
|
||||
$this->m_aData = array();
|
||||
$this->m_oMessage = new Message();
|
||||
$this->m_oMessage->setEncoding('UTF-8');
|
||||
@@ -138,7 +141,7 @@ class EMailLaminas
|
||||
protected function SendAsynchronous(&$aIssues, $oLog = null)
|
||||
{
|
||||
try {
|
||||
AsyncSendEmail::AddToQueue($this, $oLog);
|
||||
AsyncSendEmail::AddToQueue($this->oEMail, $oLog);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$aIssues = array($e->GetMessage());
|
||||
@@ -150,9 +153,9 @@ class EMailLaminas
|
||||
return EMAIL_SEND_PENDING;
|
||||
}
|
||||
|
||||
public static function GetMailer()
|
||||
public static function GetMailer(EMail $oEMail)
|
||||
{
|
||||
return new EMailLaminas();
|
||||
return new EMailLaminas($oEMail);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,14 +337,7 @@ class EMailLaminas
|
||||
|
||||
if (strlen($sValue) > 0) {
|
||||
$oHeaders = $this->m_oMessage->getHeaders();
|
||||
switch (strtolower($sKey)) {
|
||||
case 'return-path':
|
||||
$this->m_oMessage->setReturnPath($sValue);
|
||||
break;
|
||||
|
||||
default:
|
||||
$oHeaders->addHeaderLine($sKey, $sValue);
|
||||
}
|
||||
$oHeaders->addHeaderLine($sKey, $sValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,7 +383,7 @@ class EMailLaminas
|
||||
* @throws \CoreException
|
||||
* @throws \Symfony\Component\CssSelector\Exception\SyntaxErrorException
|
||||
*/
|
||||
public function SetBody($sBody, string $sMimeType = Mime::TYPE_HTML, $sCustomStyles = null)
|
||||
public function SetBody($sBody, $sMimeType = Mime::TYPE_HTML, $sCustomStyles = null)
|
||||
{
|
||||
$oBody = new Laminas\Mime\Message();
|
||||
$aAdditionalParts = [];
|
||||
@@ -439,7 +435,7 @@ class EMailLaminas
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function AddPart($sText, string $sMimeType = Mime::TYPE_HTML)
|
||||
public function AddPart($sText, $sMimeType = Mime::TYPE_HTML)
|
||||
{
|
||||
if (!array_key_exists('parts', $this->m_aData)) {
|
||||
$this->m_aData['parts'] = array();
|
||||
|
||||
@@ -24,13 +24,14 @@
|
||||
* @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
|
||||
class EmailSwiftMailer implements iEMail
|
||||
{
|
||||
protected static $m_oConfig = null;
|
||||
protected $m_aData; // For storing data to serialize
|
||||
@@ -44,9 +45,11 @@ class EmailSwiftMailer
|
||||
}
|
||||
|
||||
protected $m_oMessage;
|
||||
protected $oEMail;
|
||||
|
||||
public function __construct()
|
||||
public function __construct(EMail $oEMail)
|
||||
{
|
||||
$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'));
|
||||
@@ -134,7 +137,7 @@ class EmailSwiftMailer
|
||||
{
|
||||
try
|
||||
{
|
||||
AsyncSendEmail::AddToQueue($this, $oLog);
|
||||
AsyncSendEmail::AddToQueue($this->oEMail, $oLog);
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
@@ -145,9 +148,9 @@ class EmailSwiftMailer
|
||||
return EMAIL_SEND_PENDING;
|
||||
}
|
||||
|
||||
public static function GetMailer()
|
||||
public static function GetMailer(EMail $oEMail)
|
||||
{
|
||||
return new EmailSwiftMailer();
|
||||
return new EmailSwiftMailer($oEMail);
|
||||
}
|
||||
|
||||
protected function SendSynchronous(&$aIssues, $oLog = null)
|
||||
|
||||
51
sources/Core/Email/iEMail.php
Normal file
51
sources/Core/Email/iEMail.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Core\Email;
|
||||
|
||||
interface iEMail
|
||||
{
|
||||
public function SerializeV2();
|
||||
|
||||
/**
|
||||
* Custom de-serialization method
|
||||
*
|
||||
* @param string $sSerializedMessage The serialized representation of the message
|
||||
*
|
||||
* @return \Email
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreException
|
||||
* @throws \Symfony\Component\CssSelector\Exception\SyntaxErrorException
|
||||
*/
|
||||
static public function UnSerializeV2($sSerializedMessage);
|
||||
|
||||
public function Send(&$aIssues, $bForceSynchronous = false, $oLog = null);
|
||||
|
||||
public function AddToHeader($sKey, $sValue);
|
||||
|
||||
public function SetMessageId($sId);
|
||||
|
||||
public function SetReferences($sReferences);
|
||||
|
||||
public function SetBody($sBody, $sMimeType = 'text/html', $sCustomStyles = null);
|
||||
|
||||
public function AddPart($sText, $sMimeType = 'text/html');
|
||||
|
||||
public function AddAttachment($data, $sFileName, $sMimeType);
|
||||
|
||||
public function SetSubject($sSubject);
|
||||
|
||||
public function GetSubject();
|
||||
|
||||
public function SetRecipientTO($sAddress);
|
||||
|
||||
public function GetRecipientTO($bAsString = false);
|
||||
|
||||
public function SetRecipientCC($sAddress);
|
||||
|
||||
public function SetRecipientBCC($sAddress);
|
||||
|
||||
public function SetRecipientFrom($sAddress, $sLabel = '');
|
||||
|
||||
public function SetRecipientReplyTo($sAddress);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user