Commit 01a9c9d7 authored by Seamus Lee's avatar Seamus Lee

dev/mailing#59 Add in provider option IMAP_XOAUTH2 to assist with google's changes to imap access

Apply PHP Syntax fix patch and update tests

Bump up to 1.9.1 of zetacomponents/mail to fix syntax issue
parent 4f0806fd
......@@ -39,7 +39,7 @@ class CRM_Mailing_MailStore {
throw new Exception("Could not find entry named $name in civicrm_mail_settings");
}
$protocols = CRM_Core_PseudoConstant::get('CRM_Core_DAO_MailSettings', 'protocol');
$protocols = CRM_Core_PseudoConstant::get('CRM_Core_DAO_MailSettings', 'protocol', [], 'validate');
if (empty($protocols[$dao->protocol])) {
throw new Exception("Empty mail protocol");
}
......@@ -48,6 +48,9 @@ class CRM_Mailing_MailStore {
case 'IMAP':
return new CRM_Mailing_MailStore_Imap($dao->server, $dao->username, $dao->password, (bool) $dao->is_ssl, $dao->source);
case 'IMAP_XOAUTH2':
return new CRM_Mailing_MailStore_Imap($dao->server, $dao->username, $dao->password, (bool) $dao->is_ssl, $dao->source, TRUE);
case 'POP3':
return new CRM_Mailing_MailStore_Pop3($dao->server, $dao->username, $dao->password, (bool) $dao->is_ssl);
......
......@@ -33,10 +33,12 @@ class CRM_Mailing_MailStore_Imap extends CRM_Mailing_MailStore {
* Whether to use IMAP or IMAPS.
* @param string $folder
* Name of the inbox folder.
* @param bool $useXOAUTH2
* Use XOAUTH2 authentication method
*
* @return \CRM_Mailing_MailStore_Imap
*/
public function __construct($host, $username, $password, $ssl = TRUE, $folder = 'INBOX') {
public function __construct($host, $username, $password, $ssl = TRUE, $folder = 'INBOX', $useXOAUTH2 = FALSE) {
// default to INBOX if an empty string
if (!$folder) {
$folder = 'INBOX';
......@@ -54,7 +56,12 @@ class CRM_Mailing_MailStore_Imap extends CRM_Mailing_MailStore {
'uidReferencing' => TRUE,
];
$this->_transport = new ezcMailImapTransport($host, NULL, $options);
$this->_transport->authenticate($username, $password);
if (useXOAUTH2) {
$this->_transport->authenticate($username, $password, ezcMailImapTransport::AUTH_XOAUTH2);
}
else {
$this->_transport->authenticate($username, $password);
}
$this->_transport->selectMailbox($folder);
$this->_ignored = implode($this->_transport->getHierarchyDelimiter(), [$folder, 'CiviMail', 'ignored']);
......
......@@ -73,6 +73,20 @@ class CRM_Upgrade_Incremental_php_FiveTwentyThree extends CRM_Upgrade_Incrementa
public function upgrade_5_23_alpha1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Remove Google + location option', 'removeGooglePlusOption');
$this->addTask('dev/mailing#59 Add in IMAP_XOAUTH2 protocol option for mailbox access', 'addXoauth2ProtocolOption');
}
/**
* Add in the IMAP XOAUTH2 mailing protocol option
*/
public static function addXoauth2ProtocolOption(CRM_Queue_TaskContext $ctx) {
CRM_Core_BAO_OptionValue::ensureOptionValueExists([
'option_group_id' => 'mail_protocol',
'name' => 'IMAP_XOAUTH2',
'label' => 'IMAP XOAUTH2',
'is_active' => TRUE,
]);
return TRUE;
}
/**
......
......@@ -2441,16 +2441,16 @@
},
{
"name": "zetacomponents/mail",
"version": "1.9.0",
"version": "1.9.1",
"source": {
"type": "git",
"url": "https://github.com/zetacomponents/Mail.git",
"reference": "fa879c688b1142b9b9088f7f3216684e4b903725"
"reference": "4dc71ccbcc8b67951a2efe47d3fcc2aeaa7f530d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zetacomponents/Mail/zipball/fa879c688b1142b9b9088f7f3216684e4b903725",
"reference": "fa879c688b1142b9b9088f7f3216684e4b903725",
"url": "https://api.github.com/repos/zetacomponents/Mail/zipball/4dc71ccbcc8b67951a2efe47d3fcc2aeaa7f530d",
"reference": "4dc71ccbcc8b67951a2efe47d3fcc2aeaa7f530d",
"shasum": ""
},
"require": {
......@@ -2517,7 +2517,7 @@
],
"description": "The component allows you construct and/or parse Mail messages conforming to the mail standard. It has support for attachments, multipart messages and HTML mail. It also interfaces with SMTP to send mail or IMAP, POP3 or mbox to retrieve e-mail.",
"homepage": "https://github.com/zetacomponents",
"time": "2020-01-16T12:26:10+00:00"
"time": "2020-01-17T11:18:01+00:00"
}
],
"packages-dev": [
......
This diff is collapsed.
......@@ -138,11 +138,12 @@ class api_v3_ConstantTest extends CiviUnitTestCase {
];
$result = $this->callAPIAndDocument('mail_settings', 'getoptions', $params, __FUNCTION__, __FILE__);
$this->assertEquals(4, $result['count'], "In line " . __LINE__);
$this->assertEquals(5, $result['count'], "In line " . __LINE__);
$this->assertContains('IMAP', $result['values'], "In line " . __LINE__);
$this->assertContains('Maildir', $result['values'], "In line " . __LINE__);
$this->assertContains('POP3', $result['values'], "In line " . __LINE__);
$this->assertContains('Localdir', $result['values'], "In line " . __LINE__);
$this->assertContains('IMAP XOAUTH2', $result['values'], "In line " . __LINE__);
}
}
......@@ -707,6 +707,7 @@ VALUES
(@option_group_id_mp, 'Maildir', 2, 'Maildir', NULL, 0, NULL, 2, NULL, 0, 0, 1, NULL, NULL , NULL),
(@option_group_id_mp, 'POP3', 3, 'POP3', NULL, 0, NULL, 3, NULL, 0, 0, 1, NULL, NULL , NULL),
(@option_group_id_mp, 'Localdir', 4, 'Localdir', NULL, 0, NULL, 4, NULL, 0, 0, 1, NULL, NULL , NULL),
(@option_group_id_mp, 'IMAP XOAUTH2', 5, 'IMAP_XOAUTH2', NULL, 0, NULL, 5, NULL, 0, 0, 1, NULL, NULL , NULL),
-- priority
(@option_group_id_priority, '{ts escape="sql"}Urgent{/ts}', 1, 'Urgent', NULL, 0, NULL, 1, NULL, 0, 0, 1, NULL, NULL, NULL),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment