[FIX] Remove unused functions and add new Config conditionals

- Also replace hardcoded paths
This commit is contained in:
Marcus Müller 2019-04-01 19:04:51 +02:00
parent 9a39bcf15b
commit 1494f2b5d3

View file

@ -3,7 +3,7 @@
* Name: PHP Mailer SMTP * Name: PHP Mailer SMTP
* Description: Connects to a SMTP server based on the config * Description: Connects to a SMTP server based on the config
* Version: 0.1 * Version: 0.1
* Author: Marcus Mueller <http://mat.exon.name> * Author: Marcus Mueller
*/ */
use Friendica\App; use Friendica\App;
@ -15,7 +15,7 @@ function phpmailer_install()
{ {
Addon::registerHook( Addon::registerHook(
'emailer_send_prepare', 'emailer_send_prepare',
'addon/phpmailer/phpmailer.php', __FILE__,
'phpmailer_emailer_send_prepare' 'phpmailer_emailer_send_prepare'
); );
} }
@ -24,15 +24,11 @@ function phpmailer_uninstall()
{ {
Addon::unregisterHook( Addon::unregisterHook(
'emailer_send_prepare', 'emailer_send_prepare',
'addon/phpmailer/phpmailer.php', __FILE__,
'phpmailer_emailer_send_prepare' 'phpmailer_emailer_send_prepare'
); );
} }
function phpmailer_module()
{
}
/** /**
* @param App $a * @param App $a
* @param array $b * @param array $b
@ -46,7 +42,7 @@ function phpmailer_emailer_send_prepare(App $a, array &$b)
// Passing `true` enables exceptions // Passing `true` enables exceptions
$mail = new PHPMailer(true); $mail = new PHPMailer(true);
try { try {
if (!empty($a->config['system']['smtp']) && (bool)$a->config['system']['smtp'] === true) { if (Config::get('phpmailer', 'smtp')) {
// Set mailer to use SMTP // Set mailer to use SMTP
$mail->isSMTP(); $mail->isSMTP();
/* /*
@ -54,22 +50,22 @@ function phpmailer_emailer_send_prepare(App $a, array &$b)
$mail->SMTPDebug = 2; $mail->SMTPDebug = 2;
*/ */
// Specify main and backup SMTP servers // Specify main and backup SMTP servers
$mail->Host = $a->config['system']['smtp_server']; $mail->Host = Config::get('phpmailer', 'smtp_server');
$mail->Port = $a->config['system']['smtp_port']; $mail->Port = Config::get('phpmailer', 'smtp_port');
if (!empty($a->config['system']['smtp_secure']) && (bool)$a->config['system']['smtp_secure'] !== '') { if (Config::get('system', 'smtp_secure') && Config::get('phpmailer', 'smtp_port_s')) {
$mail->SMTPSecure = $a->config['system']['smtp_secure']; $mail->SMTPSecure = Config::get('phpmailer', 'smtp_secure');
$mail->Port = $a->config['system']['smtp_port_s']; $mail->Port = Config::get('phpmailer', 'smtp_port_s');
} }
if (!empty($a->config['system']['smtp_username']) && !empty($a->config['system']['smtp_password'])) { if (Config::get('phpmailer', 'smtp_username') && Config::get('phpmailer', 'smtp_password')) {
$mail->SMTPAuth = true; $mail->SMTPAuth = true;
$mail->Username = $a->config['system']['smtp_username']; $mail->Username = Config::get('phpmailer', 'smtp_username');
$mail->Password = $a->config['system']['smtp_password']; $mail->Password = Config::get('phpmailer', 'smtp_password');
} }
if (!empty($a->config['system']['smtp_from']) && !empty($a->config['system']['smtp_domain'])) { if (Config::get('phpmailer', 'smtp_from')) {
$mail->setFrom($a->config['system']['smtp_from'], $a->config['sitename']); $mail->setFrom(Config::get('phpmailer', 'smtp_from'), Config::get('sitename'));
} }
} }