Skip to content

Commit

Permalink
Merge pull request #69 from OPUS4/emailauth66
Browse files Browse the repository at this point in the history
#66 Support auth options for mail
  • Loading branch information
j3nsch authored Aug 15, 2022
2 parents 37522a3 + f313bc1 commit 261c917
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Mail/MailException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright Copyright (c) 2009-2020, OPUS 4 development team
* @copyright Copyright (c) 2009, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

Expand All @@ -34,7 +34,7 @@
use Exception;

/**
* Extends default Exception class.
* Exception for mail related problems.
*/
class MailException extends Exception
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mail/SendMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright Copyright (c) 2011-2018, OPUS 4 development team
* @copyright Copyright (c) 2011, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

Expand Down
34 changes: 27 additions & 7 deletions src/Mail/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright Copyright (c) 2011-2018, OPUS 4 development team
* @copyright Copyright (c) 2011, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

Expand All @@ -35,8 +35,14 @@
use Zend_Config;
use Zend_Mail_Transport_Smtp;

use function array_flip;
use function array_intersect_key;

/**
* Override
* mail.opus.auth = ;
* mail.opus.username = ;
* main.opus.password = ;
* main.opus.ssl = ;
*/
class Transport extends Zend_Mail_Transport_Smtp
{
Expand All @@ -57,14 +63,28 @@ public function __construct($config = null)
$smtp = '127.0.0.1';
}

$port = 25;
if ($config !== null) {
$options = $config->toArray();
} else {
$options = [];
}

if (isset($config->port)) {
$port = $config->port;
if (! isset($options['port'])) {
$options['port'] = 25;
}

Log::get()->info(self::class . " Using mail server {$smtp}:{$port}");
$allowedOptions = [
'port',
'auth',
'username',
'password',
'ssl',
];

$options = array_intersect_key($options, array_flip($allowedOptions));

Log::get()->info(self::class . " Using mail server {$smtp}:{$options['port']}");

parent::__construct($smtp, ['port' => $port]);
parent::__construct($smtp, $options);
}
}
7 changes: 6 additions & 1 deletion test/Mail/TransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function tearDown()
{
}

public function testConstructorWoConfig()
public function testConstructorWithoutConfig()
{
$transport = new Transport();
}
Expand All @@ -75,4 +75,9 @@ public function testConstructorWithConfig()

$transport = new Transport($config);
}

public function testAuthConfig()
{
$this->markTestIncomplete('not tested');
}
}

0 comments on commit 261c917

Please sign in to comment.