Skip to content

Commit 77ca17a

Browse files
authored
Merge pull request #110 from SparkPost/issue109
Adding functionality for sandbox domain
2 parents 2df7165 + 2d2ba9e commit 77ca17a

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

mailer.http.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ protected function get_request_body()
136136
$body['content']['attachments'] = $attachments;
137137
}
138138

139+
if (isset($body['content']['from']['email']) && SparkPost::is_sandbox($body['content']['from']['email'])) {
140+
$body['options']['sandbox'] = true;
141+
}
142+
139143
$body = apply_filters( 'wpsp_request_body', $body);
140144

141145
return $body;

mailer.smtp.class.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public function configure_phpmailer($phpmailer) {
2929
'options' => array (
3030
'open_tracking' => (bool) apply_filters('wpsp_open_tracking', $tracking_enabled),
3131
'click_tracking' => (bool) apply_filters('wpsp_click_tracking', $tracking_enabled),
32-
'transactional' => (bool) apply_filters('wpsp_transactional', $settings['transactional'])
32+
'transactional' => (bool) apply_filters('wpsp_transactional', $settings['transactional']),
33+
'sandbox' => SparkPost::is_sandbox($phpmailer->From),
3334
)
3435
);
3536

@@ -40,7 +41,7 @@ public function configure_phpmailer($phpmailer) {
4041
$phpmailer->SMTPAuth = true;
4142
$phpmailer->Username = 'SMTP_Injection';
4243
$phpmailer->Password = apply_filters('wpsp_api_key', $settings['password']);
43-
$phpmailer->XMailer = $xmailer;
44+
$phpmailer->XMailer = $xmailer;
4445

4546
$json_x_msys_api = apply_filters('wpsp_smtp_msys_api', $x_msys_api);
4647
$phpmailer->addCustomHeader('X-MSYS-API', json_encode($json_x_msys_api));

sparkpost.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,8 @@ public function init_sp_http_mailer($args)
120120
}
121121
return $args;
122122
}
123+
124+
static function is_sandbox($email) {
125+
return array_slice(explode('@', $email), -1)[0] === 'sparkpostbox.com';
126+
}
123127
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* @package wp-sparkpost
4+
*/
5+
namespace WPSparkPost;
6+
7+
class TestSparkPost extends \WP_UnitTestCase {
8+
var $SparkPost;
9+
10+
function setUp() {
11+
$this->SparkPost = new SparkPost();
12+
}
13+
14+
function test_obfuscate_api_key() {
15+
$original_key='my_secret_key';
16+
$obfuscated_key=SparkPost::obfuscate_api_key($original_key);
17+
18+
$this->assertNotFalse(strpos($obfuscated_key, '*'));
19+
$this->assertEquals(substr($original_key, 0, 4), substr($obfuscated_key, 0, 4));
20+
}
21+
22+
function test_is_key_obfuscated() {
23+
$this->assertTrue(SparkPost::is_key_obfuscated('my_obfuscated_***'));
24+
$this->assertFalse(SparkPost::is_key_obfuscated('my_unobfuscated_key'));
25+
}
26+
27+
function test_is_sandbox() {
28+
$this->assertTrue(SparkPost::is_sandbox('[email protected]'));
29+
$this->assertFalse(SparkPost::is_sandbox('[email protected]'));
30+
}
31+
}

0 commit comments

Comments
 (0)