1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-18 19:23:10 +01:00
openstamanager/modules/smtp/actions.php
Thomas Zilio 85d5ee692e Fix #550
2019-04-11 16:11:32 -07:00

88 lines
2.7 KiB
PHP

<?php
include_once __DIR__.'/../../core.php';
switch (post('op')) {
case 'add':
$dbo->insert('zz_smtps', [
'name' => post('name'),
'from_name' => post('from_name'),
'from_address' => post('from_address'),
]);
$id_record = $dbo->lastInsertedID();
flash()->info(tr('Nuovo account email aggiunto!'));
break;
case 'update':
$predefined = post('predefined');
if (!empty($predefined)) {
$dbo->query('UPDATE zz_smtps SET predefined = 0');
}
$dbo->update('zz_smtps', [
'name' => post('name'),
'note' => post('note'),
'server' => post('server'),
'port' => post('port'),
'username' => post('username'),
'password' => post('password'),
'from_name' => post('from_name'),
'from_address' => post('from_address'),
'encryption' => post('encryption'),
'pec' => post('pec'),
'ssl_no_verify' => post('ssl_no_verify'),
'predefined' => $predefined,
], ['id' => $id_record]);
flash()->info(tr('Informazioni salvate correttamente!'));
// Validazione indirizzo email mittente
$check_email = Validate::isValidEmail(post('from_address'));
// Se $check_email non è null e la riposta è negativa --> mostro il messaggio di avviso.
if (!empty($check_email)) {
flash()->info(tr('Sintassi email verificata'));
if (is_object($check_email) && $check_email->smtp) {
if ($check_email->smtp_check) {
flash()->info(tr('SMTP email verificato'));
} elseif (!$check_email->smtp_check) {
flash()->warning(tr('SMTP email non verificato'));
} else {
flash()->error(tr("Attenzione: l'SMTP email _EMAIL_ sembra non essere valido", [
'_EMAIL_' => $check_email->email,
]));
}
}
} else {
flash()->error(tr("Attenzione: l'indirizzo email _EMAIL_ sembra non essere valido", [
'_EMAIL_' => $check_email->email,
]));
if (is_object($check_email) && !empty($check_email->error->info)) {
flash()->error($check_email->error->info);
}
}
break;
case 'test':
$mail = new Mail($id_record);
echo json_encode([
'test' => $mail->testSMTP(),
]);
break;
case 'delete':
$dbo->query('UPDATE zz_smtps SET deleted_at = NOW() WHERE id='.prepare($id_record));
flash()->info(tr('Account email eliminato!'));
break;
}