wpMandrill - Version 1.29

Version Description

  • ADDED: wp_mail, wp_mail_from, and wp_mail_from_name filters. ** Thanks Mike Little! **
  • ADDED: Support for "important" emails.
  • UPDATED: Wordpress wp_mail function code.
  • ADDED: wpMandrill User-Agent
Download this release

Release Info

Developer MC_Will
Plugin Icon wp plugin wpMandrill
Version 1.29
Comparing to
See all releases

Code changes from version 1.28 to 1.29

legacy/function.wp_mail.php CHANGED
@@ -11,7 +11,7 @@
11
  if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
12
  require_once ABSPATH . WPINC . '/class-phpmailer.php';
13
  require_once ABSPATH . WPINC . '/class-smtp.php';
14
- $phpmailer = new PHPMailer();
15
  }
16
 
17
  // Headers
@@ -26,7 +26,9 @@
26
  $tempheaders = $headers;
27
  }
28
  $headers = array();
29
-
 
 
30
  // If it's actually got contents
31
  if ( !empty( $tempheaders ) ) {
32
  // Iterate through the raw headers
@@ -94,10 +96,7 @@
94
  $phpmailer->ClearAddresses();
95
  $phpmailer->ClearAllRecipients();
96
  $phpmailer->ClearAttachments();
97
- $phpmailer->ClearBCCs();
98
- $phpmailer->ClearCCs();
99
- $phpmailer->ClearCustomHeaders();
100
- $phpmailer->ClearReplyTos();
101
 
102
  // From email and name
103
  // If we don't have a name from the input headers
@@ -130,7 +129,19 @@
130
  $to = explode( ',', $to );
131
 
132
  foreach ( (array) $to as $recipient ) {
133
- $phpmailer->AddAddress( trim( $recipient ) );
 
 
 
 
 
 
 
 
 
 
 
 
134
  }
135
 
136
  // Set mail's subject and body
@@ -140,13 +151,37 @@
140
  // Add any CC and BCC recipients
141
  if ( !empty( $cc ) ) {
142
  foreach ( (array) $cc as $recipient ) {
143
- $phpmailer->AddCc( trim($recipient) );
 
 
 
 
 
 
 
 
 
 
 
 
144
  }
145
  }
146
 
147
  if ( !empty( $bcc ) ) {
148
  foreach ( (array) $bcc as $recipient) {
149
- $phpmailer->AddBcc( trim($recipient) );
 
 
 
 
 
 
 
 
 
 
 
 
150
  }
151
  }
152
 
@@ -185,14 +220,22 @@
185
 
186
  if ( !empty( $attachments ) ) {
187
  foreach ( $attachments as $attachment ) {
188
- $phpmailer->AddAttachment($attachment);
 
 
 
 
189
  }
190
  }
191
 
192
  do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
193
 
194
  // Send!
195
- $result = @$phpmailer->Send();
 
 
 
 
196
 
197
- return $result;
198
  ?>
11
  if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
12
  require_once ABSPATH . WPINC . '/class-phpmailer.php';
13
  require_once ABSPATH . WPINC . '/class-smtp.php';
14
+ $phpmailer = new PHPMailer( true );
15
  }
16
 
17
  // Headers
26
  $tempheaders = $headers;
27
  }
28
  $headers = array();
29
+ $cc = array();
30
+ $bcc = array();
31
+
32
  // If it's actually got contents
33
  if ( !empty( $tempheaders ) ) {
34
  // Iterate through the raw headers
96
  $phpmailer->ClearAddresses();
97
  $phpmailer->ClearAllRecipients();
98
  $phpmailer->ClearAttachments();
99
+ $phpmailer->ClearBCCs();/* $phpmailer->ClearCCs(); $phpmailer->ClearCustomHeaders(); $phpmailer->ClearReplyTos(); */
 
 
 
100
 
101
  // From email and name
102
  // If we don't have a name from the input headers
129
  $to = explode( ',', $to );
130
 
131
  foreach ( (array) $to as $recipient ) {
132
+ try {
133
+ // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
134
+ $recipient_name = '';
135
+ if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
136
+ if ( count( $matches ) == 3 ) {
137
+ $recipient_name = $matches[1];
138
+ $recipient = $matches[2];
139
+ }
140
+ }
141
+ $phpmailer->AddAddress( $recipient, $recipient_name);
142
+ } catch ( phpmailerException $e ) {
143
+ continue;
144
+ }
145
  }
146
 
147
  // Set mail's subject and body
151
  // Add any CC and BCC recipients
152
  if ( !empty( $cc ) ) {
153
  foreach ( (array) $cc as $recipient ) {
154
+ try {
155
+ // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
156
+ $recipient_name = '';
157
+ if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
158
+ if ( count( $matches ) == 3 ) {
159
+ $recipient_name = $matches[1];
160
+ $recipient = $matches[2];
161
+ }
162
+ }
163
+ $phpmailer->AddCc( $recipient, $recipient_name );
164
+ } catch ( phpmailerException $e ) {
165
+ continue;
166
+ }
167
  }
168
  }
169
 
170
  if ( !empty( $bcc ) ) {
171
  foreach ( (array) $bcc as $recipient) {
172
+ try {
173
+ // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
174
+ $recipient_name = '';
175
+ if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
176
+ if ( count( $matches ) == 3 ) {
177
+ $recipient_name = $matches[1];
178
+ $recipient = $matches[2];
179
+ }
180
+ }
181
+ $phpmailer->AddBcc( $recipient, $recipient_name );
182
+ } catch ( phpmailerException $e ) {
183
+ continue;
184
+ }
185
  }
186
  }
187
 
220
 
221
  if ( !empty( $attachments ) ) {
222
  foreach ( $attachments as $attachment ) {
223
+ try {
224
+ $phpmailer->AddAttachment($attachment);
225
+ } catch ( phpmailerException $e ) {
226
+ continue;
227
+ }
228
  }
229
  }
230
 
231
  do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
232
 
233
  // Send!
234
+ try {
235
+ $phpmailer->Send();
236
+ } catch ( phpmailerException $e ) {
237
+ return false;
238
+ }
239
 
240
+ return true;
241
  ?>
lib/mandrill.class.php CHANGED
@@ -416,6 +416,8 @@ class Mandrill {
416
  ini_set("arg_separator.output", $orig_sep);
417
  }
418
 
 
 
419
  if( function_exists('curl_init') && function_exists('curl_exec') ) {
420
 
421
  if( !ini_get('safe_mode') ){
@@ -430,8 +432,8 @@ class Mandrill {
430
  curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
431
 
432
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // @Bruno Braga:
433
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Thanks for the hack!
434
-
435
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
436
  curl_setopt($ch, CURLOPT_HEADER, false);
437
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -479,6 +481,7 @@ class Mandrill {
479
  $payload = "$method $path HTTP/1.0\r\n" .
480
  "Host: $host\r\n" .
481
  "Connection: close\r\n" .
 
482
  "Content-type: application/x-www-form-urlencoded\r\n" .
483
  "Content-length: " . strlen($params) . "\r\n" .
484
  "Connection: close\r\n\r\n" .
416
  ini_set("arg_separator.output", $orig_sep);
417
  }
418
 
419
+ $useragent = wpMandrill::getUserAgent();
420
+
421
  if( function_exists('curl_init') && function_exists('curl_exec') ) {
422
 
423
  if( !ini_get('safe_mode') ){
432
  curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
433
 
434
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // @Bruno Braga:
435
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Thanks for the hack!
436
+ curl_setopt($ch, CURLOPT_USERAGENT,$useragent);
437
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
438
  curl_setopt($ch, CURLOPT_HEADER, false);
439
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
481
  $payload = "$method $path HTTP/1.0\r\n" .
482
  "Host: $host\r\n" .
483
  "Connection: close\r\n" .
484
+ "User-Agent: $useragent\r\n" .
485
  "Content-type: application/x-www-form-urlencoded\r\n" .
486
  "Content-length: " . strlen($params) . "\r\n" .
487
  "Connection: close\r\n\r\n" .
readme.txt CHANGED
@@ -99,6 +99,12 @@ If your account has more than 20 senders registered or more than 40 tags used, t
99
  4. Dashboard widget Settings
100
 
101
  == Changelog ==
 
 
 
 
 
 
102
  = 1.28 =
103
  * ADDED: If you want to fall back some of your emails to the native wp_mail function, now you can do it by using the mandrill_payload filter and setting a parameter called 'force_native' to true.
104
  * REMOVED: Mime type checking on attachments.
99
  4. Dashboard widget Settings
100
 
101
  == Changelog ==
102
+ = 1.29 =
103
+ * ADDED: wp_mail, wp_mail_from, and wp_mail_from_name filters. ** Thanks Mike Little! **
104
+ * ADDED: Support for "important" emails.
105
+ * UPDATED: Wordpress wp_mail function code.
106
+ * ADDED: wpMandrill User-Agent
107
+
108
  = 1.28 =
109
  * ADDED: If you want to fall back some of your emails to the native wp_mail function, now you can do it by using the mandrill_payload filter and setting a parameter called 'force_native' to true.
110
  * REMOVED: Mime type checking on attachments.
wpmandrill.php CHANGED
@@ -5,7 +5,7 @@ Description: wpMandrill sends emails, generated by WordPress using Mandrill.
5
  Author: Mandrill
6
  Author URI: http://mandrillapp.com/
7
  Plugin URI: http://connect.mailchimp.com/integrations/wpmandrill
8
- Version: 1.28
9
  Text Domain: wpmandrill
10
  */
11
  /* Copyright 2012 MailChimp (email : will@mailchimp.com )
@@ -29,7 +29,6 @@ wpMandrill::on_load();
29
 
30
  class wpMandrill {
31
  const DEBUG = false;
32
-
33
  static $settings;
34
  static $report;
35
  static $stats;
@@ -1619,18 +1618,21 @@ JS;
1619
  $merge_vars = array(),
1620
  $google_analytics_domains = array(),
1621
  $google_analytics_campaign = array(),
1622
- $meta_data = array()
 
1623
 
1624
  ) {
1625
  try {
1626
- $message = compact('html', 'text', 'subject', 'from_name', 'from_email', 'to', 'headers', 'attachments',
 
1627
  'url_strip_qs',
1628
  'merge',
1629
  'global_merge_vars',
1630
  'merge_vars',
1631
  'google_analytics_domains',
1632
  'google_analytics_campaign',
1633
- 'meta_data'
 
1634
  );
1635
  return self::sendEmail($message, $tags, $template_name, $track_opens, $track_clicks);
1636
  } catch ( Exception $e ) {
@@ -1715,7 +1717,7 @@ JS;
1715
  break;
1716
 
1717
  case 'bcc':
1718
- // TODO: Mandrill's API only accept one BCC address. The other addresses supplied will be silently discarted
1719
  $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
1720
 
1721
  $message['bcc_address'] = $bcc[0];
@@ -1724,7 +1726,11 @@ JS;
1724
  case 'reply-to':
1725
  $message['headers'][trim( $name )] = trim( $content );
1726
  break;
1727
-
 
 
 
 
1728
  default:
1729
  if ( substr($name,0,2) == 'x-' ) {
1730
  $message['headers'][trim( $name )] = trim( $content );
@@ -1812,6 +1818,8 @@ JS;
1812
  }
1813
 
1814
  // Letting the user filter/change the message payload
 
 
1815
  $message = apply_filters('mandrill_payload', $message);
1816
 
1817
  if ( isset($message['force_native']) && $message['force_native'] ) throw new Exception('Manually falling back to native wp_mail()');
@@ -1855,7 +1863,22 @@ JS;
1855
 
1856
  return $attachments;
1857
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1858
  }
 
1859
  function wpMandrill_transformJSArray(&$value, $key, $params = 0) {
1860
  if ( is_array($params) ) {
1861
  $format = isset($params[0]) ? $params[0] : 0;
5
  Author: Mandrill
6
  Author URI: http://mandrillapp.com/
7
  Plugin URI: http://connect.mailchimp.com/integrations/wpmandrill
8
+ Version: 1.29
9
  Text Domain: wpmandrill
10
  */
11
  /* Copyright 2012 MailChimp (email : will@mailchimp.com )
29
 
30
  class wpMandrill {
31
  const DEBUG = false;
 
32
  static $settings;
33
  static $report;
34
  static $stats;
1618
  $merge_vars = array(),
1619
  $google_analytics_domains = array(),
1620
  $google_analytics_campaign = array(),
1621
+ $meta_data = array(),
1622
+ $important = false
1623
 
1624
  ) {
1625
  try {
1626
+ extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'html', 'headers', 'attachments' ) ) );
1627
+ $message = compact('html', 'subject', 'from_name', 'from_email', 'to', 'headers', 'attachments',
1628
  'url_strip_qs',
1629
  'merge',
1630
  'global_merge_vars',
1631
  'merge_vars',
1632
  'google_analytics_domains',
1633
  'google_analytics_campaign',
1634
+ 'meta_data',
1635
+ 'important'
1636
  );
1637
  return self::sendEmail($message, $tags, $template_name, $track_opens, $track_clicks);
1638
  } catch ( Exception $e ) {
1717
  break;
1718
 
1719
  case 'bcc':
1720
+ // TODO: Mandrill's API only accept one BCC address. Other addresses will be silently discarted
1721
  $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
1722
 
1723
  $message['bcc_address'] = $bcc[0];
1726
  case 'reply-to':
1727
  $message['headers'][trim( $name )] = trim( $content );
1728
  break;
1729
+ case 'importance':
1730
+ case 'x-priority':
1731
+ case 'x-msmail-priority':
1732
+ if ( !$message['important'] ) $message['important'] = ( strpos(strtolower($content),'high') !== false ) ? true : false;
1733
+ break;
1734
  default:
1735
  if ( substr($name,0,2) == 'x-' ) {
1736
  $message['headers'][trim( $name )] = trim( $content );
1818
  }
1819
 
1820
  // Letting the user filter/change the message payload
1821
+ $message['from_email'] = apply_filters('wp_mail_from', $message['from_email']);
1822
+ $message['from_name'] = apply_filters('wp_mail_from_name', $message['from_name']);
1823
  $message = apply_filters('mandrill_payload', $message);
1824
 
1825
  if ( isset($message['force_native']) && $message['force_native'] ) throw new Exception('Manually falling back to native wp_mail()');
1863
 
1864
  return $attachments;
1865
  }
1866
+
1867
+ static function getUserAgent() {
1868
+ global $wp_version;
1869
+
1870
+ if ( ! function_exists( 'get_plugins' ) ) require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
1871
+ $plugin_folder = get_plugins( '/' . plugin_basename( dirname( __FILE__ ) ) );
1872
+ $plugin_file = basename( ( __FILE__ ) );
1873
+
1874
+ $me = $plugin_folder[$plugin_file]['Version'];
1875
+ $php = phpversion();
1876
+ $wp = $wp_version;
1877
+
1878
+ return "wpMandrill/$me (PHP/$php; WP/$wp)";
1879
+ }
1880
  }
1881
+
1882
  function wpMandrill_transformJSArray(&$value, $key, $params = 0) {
1883
  if ( is_array($params) ) {
1884
  $format = isset($params[0]) ? $params[0] : 0;