Skip to content

Commit

Permalink
Intégration Wamailer 3
Browse files Browse the repository at this point in the history
  • Loading branch information
bobe17 committed Mar 15, 2015
1 parent 6094655 commit c447b2d
Show file tree
Hide file tree
Showing 34 changed files with 405 additions and 401 deletions.
42 changes: 19 additions & 23 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
}
}

if (!Mailer::validate_email($new_email)) {
if (!Mailer::checkMailSyntax($new_email)) {
$error = true;
$msg_error[] = $lang['Message']['Invalid_email'];
}
Expand All @@ -71,32 +71,28 @@

$db->insert(ADMIN_TABLE, $sql_data);

$mailer = new Mailer(WA_ROOTDIR . '/language/email_' . $nl_config['language'] . '/');
$mailer->signature = WA_X_MAILER;

if ($nl_config['use_smtp']) {
$mailer->use_smtp(
$nl_config['smtp_host'],
$nl_config['smtp_port'],
$nl_config['smtp_user'],
$nl_config['smtp_pass']
);
}

$mailer->set_charset('UTF-8');
$mailer->set_format(FORMAT_TEXTE);
$mailer->set_from($admindata['admin_email'], $admindata['admin_login']);
$mailer->set_address($new_email);
$mailer->set_subject(sprintf($lang['Subject_email']['New_admin'], $nl_config['sitename']));

$mailer->use_template('new_admin', array(
$tpl = new Template(WA_ROOTDIR . '/language/email_' . $nl_config['language'] . '/');
$tpl->set_filenames(array('mail' => 'new_admin.txt'));
$tpl->assign_vars(array(
'PSEUDO' => $new_login,
'SITENAME' => $nl_config['sitename'],
'INIT_PASS_URL' => wan_build_url('login.php?mode=cp')
));
$message = $tpl->pparse('mail', true);

$email = new Email('UTF-8');
$email->setFrom($admindata['admin_email'], $admindata['admin_login']);
$email->addRecipient($new_email);
$email->setSubject(sprintf($lang['Subject_email']['New_admin'], $nl_config['sitename']));
$email->setTextBody($message);

if (!$mailer->send()) {
trigger_error(sprintf($lang['Message']['Failed_sending2'], $mailer->msg_error), E_USER_ERROR);
try {
wan_sendmail($email);
}
catch (Exception $e) {
trigger_error(sprintf($lang['Message']['Failed_sending2'],
wan_htmlspecialchars($e->getMessage())
), E_USER_ERROR);
}

$output->redirect('./admin.php', 6);
Expand Down Expand Up @@ -227,7 +223,7 @@
}
}

if (!Mailer::validate_email($email)) {
if (!Mailer::checkMailSyntax($email)) {
$error = true;
$msg_error[] = $lang['Message']['Invalid_email'];
}
Expand Down
40 changes: 20 additions & 20 deletions admin/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,27 @@
$new_config['smtp_pass'] = $old_config['smtp_pass'];
}

if ($new_config['use_smtp'] && function_exists('fsockopen')) {
preg_match('/^http(s)?:\/\/(.*?)\/?$/i', $new_config['urlsite'], $match);

$smtp = new Smtp();

$result = $smtp->connect(
$new_config['smtp_host'],
$new_config['smtp_port'],
$new_config['smtp_user'],
$new_config['smtp_pass'],
$match[2]
);

if (!$result) {
if ($new_config['use_smtp'] && function_exists('stream_socket_client')) {
$smtp = new Mailer_SMTP();

try {
if (!$smtp->connect(
$new_config['smtp_host'],
$new_config['smtp_port'],
$new_config['smtp_user'],
$new_config['smtp_pass']
)) {
throw new Exception(sprintf("SMTP server response: '%s'", $smtp->responseData));
}
}
catch (Exception $e) {
$error = true;
$msg_error[] = sprintf(nl2br($lang['Message']['bad_smtp_param']),
wan_htmlspecialchars($smtp->msg_error));
}
else {
$smtp->quit();
wan_htmlspecialchars($e->getMessage())
);
}

$smtp->quit();
}
else {
$new_config['use_smtp'] = 0;
Expand Down Expand Up @@ -307,8 +307,8 @@
'SMTP_ROW_CLASS' => ($new_config['use_smtp']) ? '' : 'inactive',
'CHECKED_USE_SMTP_ON' => $output->getBoolAttr('checked', $new_config['use_smtp']),
'CHECKED_USE_SMTP_OFF' => $output->getBoolAttr('checked', !$new_config['use_smtp']),
'DISABLED_SMTP' => $output->getBoolAttr('disabled', !function_exists('fsockopen')),
'WARNING_SMTP' => (!function_exists('fsockopen')) ? ' <span style="color: red;">[not available]</span>' : '',
'DISABLED_SMTP' => $output->getBoolAttr('disabled', !function_exists('stream_socket_client')),
'WARNING_SMTP' => (!function_exists('stream_socket_client')) ? ' <span style="color: red;">[not available]</span>' : '',
'SMTP_HOST' => $new_config['smtp_host'],
'SMTP_PORT' => $new_config['smtp_port'],
'SMTP_USER' => $new_config['smtp_user'],
Expand Down
2 changes: 1 addition & 1 deletion admin/envoi.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@
$supp_address = array_map('trim', $supp_address);
$supp_address = array_unique($supp_address);
$supp_address = array_filter($supp_address, function ($email) {
return Mailer::validate_email($email);
return Mailer::checkMailSyntax($email);
});
}

Expand Down
2 changes: 1 addition & 1 deletion admin/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ function ($parser, $data) use (&$depth, &$tagname, &$emails) {
//
$emails = array_filter($emails,
function ($email) use (&$lang, &$report) {
if (Mailer::validate_email($email)) {
if (Mailer::checkMailSyntax($email)) {
return true;
}
else {
Expand Down
10 changes: 5 additions & 5 deletions admin/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
);
}
else {
$body = Mailer::word_wrap(trim($body), false);
$body = Mime::wordwrap(trim($body));
$body = active_urls(wan_htmlspecialchars($body, ENT_NOQUOTES));
$body = preg_replace('/(?<=^|\s)(\*[^\r\n]+?\*)(?=\s|$)/', '<strong>\\1</strong>', $body);
$body = preg_replace('/(?<=^|\s)(\/[^\r\n]+?\/)(?=\s|$)/', '<em>\\1</em>', $body);
Expand Down Expand Up @@ -398,7 +398,7 @@
if (isset($_POST['submit'])) {
$email = (!empty($_POST['email'])) ? trim($_POST['email']) : '';

if (!Mailer::validate_email($email)) {
if (!Mailer::checkMailSyntax($email)) {
$error = true;
$msg_error[] = $lang['Message']['Invalid_email'];
}
Expand Down Expand Up @@ -914,17 +914,17 @@
$msg_error[] = $lang['Unknown_format'];
}

if (!Mailer::validate_email($sender_email)) {
if (!Mailer::checkMailSyntax($sender_email)) {
$error = true;
$msg_error[] = $lang['Message']['Invalid_email'];
}

if (!empty($return_email) && !Mailer::validate_email($return_email)) {
if (!empty($return_email) && !Mailer::checkMailSyntax($return_email)) {
$error = true;
$msg_error[] = $lang['Message']['Invalid_email'];
}

if (!empty($liste_alias) && !Mailer::validate_email($liste_alias)) {
if (!empty($liste_alias) && !Mailer::checkMailSyntax($liste_alias)) {
$error = true;
$msg_error[] = $lang['Message']['Invalid_email'];
}
Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@
"php": ">=5.3.7",
"patchwork/utf8": "~1.2@dev",
"ircmaxell/password-compat": "1.0.4",
"wascripts/wamailer": "dev-master",
"guiguiboy/PHP-CLI-Progress-Bar": "dev-master#7d3eb61c1f0c164b9c3139af694b2d38171e4d04"
},
"require-dev": {
"squizlabs/php_codesniffer": "~1.0"
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wascripts/wamailer"
}
]
}
2 changes: 1 addition & 1 deletion contrib/wanewsletter
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ else if ($import_mail) {
//
$emails = array_filter($emails,
function ($email) use (&$lang) {
if (Mailer::validate_email($email)) {
if (Mailer::checkMailSyntax($email)) {
return true;
}
else {
Expand Down
15 changes: 10 additions & 5 deletions includes/class.attach.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,14 @@ public function upload_file($upload_mode, $log_id, $filename, $tmp_filename, $fi
if (!$result) {
$error = true;
$msg_error[] = $errstr;
fclose($fw);
$this->remove_file($tmp_filename);

return;
}

fwrite($fw, $result['data']);
fclose($fw);
$filesize = strlen($result['data']);
$filetype = $result['type'];
}
Expand All @@ -317,6 +319,7 @@ public function upload_file($upload_mode, $log_id, $filename, $tmp_filename, $fi
$lang['Message']['Unaccess_host'],
wan_htmlspecialchars($part['host'])
);
fclose($fw);
$this->remove_file($tmp_filename);

return;
Expand All @@ -330,28 +333,30 @@ public function upload_file($upload_mode, $log_id, $filename, $tmp_filename, $fi
if (!ftp_fget($cid, $fw, $path, FTP_BINARY)) {
$error = true;
$msg_error[] = $lang['Message']['Not_found_at_url'];
fclose($fw);
$this->remove_file($tmp_filename);

return;
}
ftp_close($cid);
fclose($fw);

$filetype = Mailer::mime_type($extension);
$filetype = Mime::getType($tmp_filename);
}

fclose($fw);
}

//
// Fichier uploadé manuellement sur le serveur
//
else if ($upload_mode == 'local') {
$filetype = Mailer::mime_type($extension);

//
// On verifie si le fichier est bien présent sur le serveur
//
$filesize = $this->joined_file_exists($tmp_filename, $error, $msg_error);

if (!$error) {
$filetype = Mime::getType($this->upload_path . $tmp_filename);
}
}
}
else {
Expand Down
Loading

0 comments on commit c447b2d

Please sign in to comment.