Skip to content

Commit

Permalink
De 982 got unknown content type multipart alternative revisited 157 m…
Browse files Browse the repository at this point in the history
…ailgun (#159)

* Changed `Tested Up` version of WP

* Changed `Tested Up` version of WP

* Fix bug with wp_mail filter. release new version

* = 1.9.1 (2023-03-26): =
- Remove not needed error logging.
- Fixed bug with Override param for Woocommerce
  • Loading branch information
oleksandr-mykhailenko committed Mar 26, 2023
1 parent 06259aa commit 996610f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
14 changes: 12 additions & 2 deletions includes/mg-filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function mg_detect_from_name($from_name_header = null)
}

$filter_from_name = null;

if ((!isset($mg_override_from) || $mg_override_from == '0') && has_filter('wp_mail_from_name')) {
$filter_from_name = apply_filters(
'wp_mail_from_name',
Expand Down Expand Up @@ -165,7 +166,7 @@ function mg_detect_from_address($from_addr_header = null): string
}

$filter_from_addr = null;
if (has_filter('wp_mail_from')) {
if ((!isset($mg_override_from) || $mg_override_from == '0') && has_filter('wp_mail_from')) {
$filter_from_addr = apply_filters(
'wp_mail_from',
$from_addr
Expand Down Expand Up @@ -234,7 +235,7 @@ function mg_parse_headers($headers = []): array
}

// Explode the header
list($name, $value) = explode(':', trim($header), 2);
[$name, $value] = explode(':', trim($header), 2);

// Clean up the values
$name = trim($name);
Expand Down Expand Up @@ -330,3 +331,12 @@ function mg_smtp_get_region($getRegion)
return false;
}
}

/**
* @return false|mixed
*/
function isReplyToOverride()
{
$mg_opts = get_option('mailgun');
return (bool)($mg_opts['override-from'] ?? false);
}
16 changes: 9 additions & 7 deletions includes/wp-mail-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
// Mainly for legacy -- process a From: header if it's there
case 'from':
if (strpos($content, '<') !== false) {
// So... making my life hard again?
$from_name = substr($content, 0, strpos($content, '<') - 1);
$from_name = str_replace('"', '', $from_name);
$from_name = trim($from_name);
Expand Down Expand Up @@ -246,12 +245,17 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())

$from_name = mg_detect_from_name($from_name);
$from_email = mg_detect_from_address($from_email);
$fromString = "{$from_name} <{$from_email}>";
if (isReplyToOverride()) {
$headers['Reply-to'] = $fromString;
}

$body = array(
'from' => "{$from_name} <{$from_email}>",
$body = [
'from' => $fromString,
'to' => $to,
'subject' => $subject,
);
];


$rcpt_data = apply_filters('mg_mutate_to_rcpt_vars', $to);
if (!is_null($rcpt_data['rcpt_vars'])) {
Expand Down Expand Up @@ -332,8 +336,6 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
} else if ('text/html' === $content_type) {
$body['html'] = $message;
} else {
// Unknown Content-Type??
error_log('[mailgun] Got unknown Content-Type: ' . $content_type);
$body['text'] = $message;
$body['html'] = $message;
}
Expand Down Expand Up @@ -454,7 +456,7 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
}

// Not sure there is any additional checking that needs to be done here, but why not?
if ($response_body->message != 'Queued. Thank you.') {
if ($response_body->message !== 'Queued. Thank you.') {
mg_api_last_error($response_body->message);

return false;
Expand Down
2 changes: 1 addition & 1 deletion mailgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Mailgun
* Plugin URI: http://wordpress.org/extend/plugins/mailgun/
* Description: Mailgun integration for WordPress
* Version: 1.9
* Version: 1.9.1
* Tested up to: 6.1
* Author: Mailgun
* Author URI: http://www.mailgun.com/
Expand Down
9 changes: 7 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Contributors: mailgun, sivel, lookahead.io, m35dev
Tags: mailgun, smtp, http, api, mail, email
Requires at least: 3.3
Tested up to: 6.1.1
Stable tag: 1.9
Stable tag: 1.9.1
Requires PHP: 5.6
License: GPLv2 or later

Expand Down Expand Up @@ -130,7 +130,12 @@ MAILGUN_FROM_ADDRESS Type: string


== Changelog ==
= 1.9 (2023-01-18): =

= 1.9.1 (2023-03-26): =
- Remove not needed error logging.
- Fixed bug with Override param for Woocommerce

- = 1.9 (2023-01-18): =
- Sanitizing and escaping vars. Possible security issues

= 1.8.10 (2022-12-26): =
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Contributors: mailgun, sivel, lookahead.io, m35dev
Tags: mailgun, smtp, http, api, mail, email
Requires at least: 4.4
Tested up to: 6.1.1
Stable tag: 1.9
Stable tag: 1.9.1
Requires PHP: 5.6
License: GPLv2 or later

Expand Down Expand Up @@ -128,6 +128,11 @@ MAILGUN_FROM_ADDRESS Type: string


== Changelog ==

= 1.9.1 (2023-03-26): =
- Remove not needed error logging.
- Fixed bug with Override param for Woocommerce

= 1.9 (2023-01-18): =
- Sanitizing and escaping vars. Possible security issues

Expand Down

0 comments on commit 996610f

Please sign in to comment.