Skip to content

Commit

Permalink
Merge pull request #110 from SparkPost/issue109
Browse files Browse the repository at this point in the history
Adding functionality for sandbox domain
  • Loading branch information
avigoldman committed Mar 16, 2017
2 parents 2df7165 + 2d2ba9e commit 77ca17a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
4 changes: 4 additions & 0 deletions mailer.http.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ protected function get_request_body()
$body['content']['attachments'] = $attachments;
}

if (isset($body['content']['from']['email']) && SparkPost::is_sandbox($body['content']['from']['email'])) {
$body['options']['sandbox'] = true;
}

$body = apply_filters( 'wpsp_request_body', $body);

return $body;
Expand Down
5 changes: 3 additions & 2 deletions mailer.smtp.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function configure_phpmailer($phpmailer) {
'options' => array (
'open_tracking' => (bool) apply_filters('wpsp_open_tracking', $tracking_enabled),
'click_tracking' => (bool) apply_filters('wpsp_click_tracking', $tracking_enabled),
'transactional' => (bool) apply_filters('wpsp_transactional', $settings['transactional'])
'transactional' => (bool) apply_filters('wpsp_transactional', $settings['transactional']),
'sandbox' => SparkPost::is_sandbox($phpmailer->From),
)
);

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

$json_x_msys_api = apply_filters('wpsp_smtp_msys_api', $x_msys_api);
$phpmailer->addCustomHeader('X-MSYS-API', json_encode($json_x_msys_api));
Expand Down
4 changes: 4 additions & 0 deletions sparkpost.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,8 @@ public function init_sp_http_mailer($args)
}
return $args;
}

static function is_sandbox($email) {
return array_slice(explode('@', $email), -1)[0] === 'sparkpostbox.com';
}
}
31 changes: 31 additions & 0 deletions tests/specs/test-sparkpost.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* @package wp-sparkpost
*/
namespace WPSparkPost;

class TestSparkPost extends \WP_UnitTestCase {
var $SparkPost;

function setUp() {
$this->SparkPost = new SparkPost();
}

function test_obfuscate_api_key() {
$original_key='my_secret_key';
$obfuscated_key=SparkPost::obfuscate_api_key($original_key);

$this->assertNotFalse(strpos($obfuscated_key, '*'));
$this->assertEquals(substr($original_key, 0, 4), substr($obfuscated_key, 0, 4));
}

function test_is_key_obfuscated() {
$this->assertTrue(SparkPost::is_key_obfuscated('my_obfuscated_***'));
$this->assertFalse(SparkPost::is_key_obfuscated('my_unobfuscated_key'));
}

function test_is_sandbox() {
$this->assertTrue(SparkPost::is_sandbox('testing@sparkpostbox.com'));
$this->assertFalse(SparkPost::is_sandbox('testing@mydoman.com'));
}
}

0 comments on commit 77ca17a

Please sign in to comment.