-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce new "identity" option. (#51)
This option defines whether identity name & signature should be included when composing outgoing e-mail, or is anonymous data (name from recipient & no signature) should be used instead for privacy.
- Loading branch information
Showing
7 changed files
with
323 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,44 @@ final class CustomFromTest extends TestCase | |
{ | ||
const CONTAINS = 'custom_from_compose_contains'; | ||
const DISABLE = 'custom_from_preference_disable'; | ||
const IDENTITY = 'custom_from_compose_identity'; | ||
const RULES = 'custom_from_header_rules'; | ||
const SUBJECT = 'custom_from_compose_subject'; | ||
|
||
public static function identity_select_should_select_matched_identity_provider(): array | ||
{ | ||
return array( | ||
array('1', 0), | ||
array('2', 1), | ||
array('3', null) | ||
); | ||
} | ||
|
||
#[DataProvider('identity_select_should_select_matched_identity_provider')] | ||
public function test_identity_select_should_select_matched_identity($identity, $expected): void | ||
{ | ||
$rcmail = rcmail::mock(); | ||
$rcmail->mock_config(array()); | ||
$rcmail->mock_user(array(), array()); | ||
|
||
$plugin = self::create_plugin(); | ||
|
||
rcube_utils::mock_input_value('_id', '42'); | ||
|
||
self::set_state($plugin, '42', $identity, null); | ||
|
||
$params = $plugin->identity_select(array('identities' => array( | ||
array('identity_id' => '1'), | ||
array('identity_id' => '2') | ||
))); | ||
|
||
if ($expected !== null) { | ||
$this->assertSame($params['selected'], $expected); | ||
} else { | ||
$this->assertSame(isset($params['selected']), false); | ||
} | ||
} | ||
|
||
public static function storage_init_should_fetch_headers_provider(): array | ||
{ | ||
return array( | ||
|
@@ -69,90 +104,142 @@ public static function message_compose_should_set_state_provider(): array | |
array('to' => '[email protected]'), | ||
array(self::RULES => 'to=e'), | ||
array(), | ||
array('email' => null, 'id' => '1') | ||
'1', | ||
null | ||
), | ||
// Subject rule "exact" shouldn't match suffix | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::RULES => 'to=e'), | ||
array(), | ||
null, | ||
null, | ||
), | ||
// Subject rule "prefix" should match address exactly | ||
array( | ||
array('to' => '[email protected]'), | ||
array(), | ||
array(), | ||
array('email' => null, 'id' => '1') | ||
'1', | ||
null | ||
), | ||
// Subject rule "prefix" should match address by prefix | ||
array( | ||
array('to' => '[email protected]'), | ||
array(), | ||
array(), | ||
array('email' => '[email protected]', 'id' => '1') | ||
'1', | ||
'Alice <[email protected]>' | ||
), | ||
// Subject rule "prefix" should not match different user | ||
array( | ||
array('to' => '[email protected]'), | ||
array(), | ||
array(), | ||
null, | ||
null, | ||
), | ||
// Subject rule "domain" on custom header should match address by domain | ||
array( | ||
array('to' => '[email protected]', 'x-custom' => '[email protected]'), | ||
array(self::RULES => 'x-custom=d'), | ||
array(), | ||
array('email' => '[email protected]', 'id' => '3') | ||
'3', | ||
'Carl <[email protected]>' | ||
), | ||
// Subject rule "domain" should not match different domain | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::RULES => 'to=d'), | ||
array(), | ||
null, | ||
null, | ||
), | ||
// Subject rule "other" should match anything | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::RULES => 'to=o'), | ||
array(), | ||
array('email' => '[email protected]', 'id' => '2') | ||
'2', | ||
'Bob <[email protected]>' | ||
), | ||
// Subject rule is overridden by user prefrences | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::RULES => 'to=e'), | ||
array(self::SUBJECT => 'domain'), | ||
array('email' => '[email protected]', 'id' => '3') | ||
'3', | ||
'Carl <[email protected]>' | ||
), | ||
// Contains constraint in configuration options matches address | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::CONTAINS => 'match'), | ||
array(self::SUBJECT => 'domain'), | ||
array('email' => '[email protected]', 'id' => '1') | ||
'1', | ||
'Alice <[email protected]>' | ||
), | ||
// Contains constraint in configuration options rejects no match | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::CONTAINS => 'match'), | ||
array(self::SUBJECT => 'domain'), | ||
null, | ||
null | ||
), | ||
// Contains constraint in user preferences rejects no match | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::CONTAINS => 'other'), | ||
array(self::CONTAINS => 'match', self::SUBJECT => 'always'), | ||
null, | ||
null | ||
), | ||
// Identity behavior "default" returns matched identity with no sender on exact match | ||
array( | ||
array('to' => '[email protected]'), | ||
array(), | ||
array(self::SUBJECT => 'always'), | ||
'3', | ||
null | ||
), | ||
// Identity behavior "default" returns matched identity and sender with identity name on domain match | ||
array( | ||
array('to' => '[email protected]'), | ||
array(), | ||
array(self::SUBJECT => 'domain'), | ||
'3', | ||
'Carl <[email protected]>' | ||
), | ||
// Identity behavior "loose" returns matched identity and sender with identity name on prefix match | ||
array( | ||
array('to' => 'SomeName <[email protected]>'), | ||
array(), | ||
array(self::IDENTITY => 'loose', self::SUBJECT => 'prefix'), | ||
'3', | ||
'Carl <[email protected]>' | ||
), | ||
// Identity behavior "exact" returns matched identity with no sender on exact match | ||
array( | ||
array('to' => '[email protected]'), | ||
array(self::IDENTITY => 'exact'), | ||
array(self::SUBJECT => 'always'), | ||
'3', | ||
null | ||
), | ||
// Identity behavior "exact" returns no identity and sender with recipient name on prefix match | ||
array( | ||
array('to' => 'SomeName <[email protected]>'), | ||
array(), | ||
array(self::IDENTITY => 'exact', self::SUBJECT => 'prefix'), | ||
null, | ||
'SomeName <[email protected]>' | ||
) | ||
); | ||
} | ||
|
||
#[DataProvider('message_compose_should_set_state_provider')] | ||
public function test_message_compose_should_set_state($message, $config_values, $user_prefs, $expected): void | ||
public function test_message_compose_should_set_state($message, $config_values, $user_prefs, $expected_identity, $expected_sender): void | ||
{ | ||
$identity1 = array('identity_id' => '1', 'email' => '[email protected]', 'name' => 'Alice', 'standard' => '0'); | ||
$identity2 = array('identity_id' => '2', 'email' => '[email protected]', 'name' => 'Bob', 'standard' => '1'); | ||
|
@@ -168,7 +255,9 @@ public function test_message_compose_should_set_state($message, $config_values, | |
$plugin = self::create_plugin(); | ||
$plugin->message_compose(array('id' => $compose_id, 'param' => array('uid' => $message_id))); | ||
|
||
$this->assertSame($_SESSION["custom_from_$compose_id"], $expected); | ||
$state = self::get_state($plugin, $compose_id); | ||
|
||
$this->assertSame($state, array($expected_identity, $expected_sender)); | ||
} | ||
|
||
private static function create_plugin() | ||
|
@@ -178,4 +267,20 @@ private static function create_plugin() | |
|
||
return $plugin; | ||
} | ||
|
||
private static function get_state($plugin, $compose_id) | ||
{ | ||
$class = new ReflectionClass($plugin); | ||
$method = $class->getMethod('get_state'); | ||
|
||
return $method->invokeArgs(null, array($compose_id)); | ||
} | ||
|
||
private static function set_state($plugin, $compose_id, $identity, $sender) | ||
{ | ||
$class = new ReflectionClass($plugin); | ||
$method = $class->getMethod('set_state'); | ||
|
||
return $method->invokeArgs(null, array($compose_id, $identity, $sender)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters