<commit_before><?php

require_once(__DIR__ . '/../../vendor/autoload.php');
require_once(__DIR__ . '/../../src/Email/Parse.php');

use Email\Parse;

class InflectTest extends PHPUnit_Framework_TestCase
{
	function testParseEmailAddresses()
	{
		$emails = "<EMAIL>";
		$result = serialize(Parse::getInstance()->parse($emails));
		$this->assertEquals('a:3:{s:7:"success";b:1;s:6:"reason";N;s:15:"email_addresses";a:1:{i:0;a:12:{s:7:"address";s:21:"<EMAIL>";s:14:"simple_address";s:21:"<EMAIL>";s:16:"original_address";s:21:"<EMAIL>";s:4:"name";s:0:"";s:11:"name_parsed";s:0:"";s:10:"local_part";s:6:"t.name";s:17:"local_part_parsed";s:6:"t.name";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}}}', $result);

		$emails = "<EMAIL>";
		$result = serialize(Parse::getInstance()->parse($emails));
		$this->assertEquals('a:3:{s:7:"success";b:1;s:6:"reason";N;s:15:"email_addresses";a:1:{i:0;a:12:{s:7:"address";s:20:"<EMAIL>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:20:"<EMAIL>@asdf.ghjkl.com";s:4:"name";s:0:"";s:11:"name_parsed";s:0:"";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}}}', $result);

		// Test as single address
		$result = serialize(Parse::getInstance()->parse($emails, false));
		$this->assertEquals('a:12:{s:7:"address";s:20:"<EMAIL>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:20:"<EMAIL>";s:4:"name";s:0:"";s:11:"name_parsed";s:0:"";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}', $result);

		$emails = "Testing Name <<EMAIL>>";
		$result = serialize(Parse::getInstance()->parse($emails));
		$this->assertEquals('a:3:{s:7:"success";b:1;s:6:"reason";N;s:15:"email_addresses";a:1:{i:0;a:12:{s:7:"address";s:35:"Testing Name <<EMAIL>>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:35:"Testing Name <<EMAIL>>";s:4:"name";s:12:"Testing Name";s:11:"name_parsed";s:12:"Testing Name";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}}}', $result);

		// Test as single address
		$result = serialize(Parse::getInstance()->parse($emails, false));
		$this->assertEquals('a:12:{s:7:"address";s:35:"Testing Name <<EMAIL>>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:35:"Testing Name <<EMAIL>>";s:4:"name";s:12:"Testing Name";s:11:"name_parsed";s:12:"Testing Name";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}', $result);

		$emails = "Testing D Name <<EMAIL>>";
		$result = serialize(Parse::getInstance()->parse($emails));
		$this->assertEquals('a:3:{s:7:"success";b:1;s:6:"reason";N;s:15:"email_addresses";a:1:{i:0;a:12:{s:7:"address";s:37:"Testing D Name <<EMAIL>>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:37:"Testing D Name <<EMAIL>>";s:4:"name";s:14:"Testing D Name";s:11:"name_parsed";s:14:"Testing D Name";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.<EMAIL>";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}}}', $result);

		// Test as single address
		$result = serialize(Parse::getInstance()->parse($emails, false));
		$this->assertEquals('a:12:{s:7:"address";s:37:"Testing D Name <<EMAIL>>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:37:"Testing D Name <<EMAIL>>";s:4:"name";s:14:"Testing D Name";s:11:"name_parsed";s:14:"Testing D Name";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}', $result);

		$emails = "Testing D. Name  <<EMAIL>>";
		$result = serialize(Parse::getInstance()->parse($emails));
		$this->assertEquals('a:3:{s:7:"success";b:0;s:6:"reason";s:21:"Invalid email address";s:15:"email_addresses";a:2:{i:0;a:12:{s:7:"address";s:0:"";s:14:"simple_address";s:0:"";s:16:"original_address";s:15:"Testing D. Name";s:4:"name";s:10:"Testing D.";s:11:"name_parsed";s:10:"Testing D.";s:10:"local_part";s:0:"";s:17:"local_part_parsed";s:0:"";s:11:"domain_part";s:0:"";s:6:"domain";s:0:"";s:2:"ip";s:0:"";s:7:"invalid";b:1;s:14:"invalid_reason";s:110:"Periods within the name of an email address must appear in quotes, such as "<NAME>" <<EMAIL>>";}i:1;a:12:{s:7:"address";s:20:"<EMAIL>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:22:"<<EMAIL>>";s:4:"name";s:0:"";s:11:"name_parsed";s:0:"";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}}}', $result);

		// Test as single address
		$result = serialize(Parse::getInstance()->parse($emails, false));
		$this->assertEquals('a:12:{s:7:"address";s:0:"";s:14:"simple_address";s:0:"";s:16:"original_address";s:39:"Testing D. Name  <<EMAIL>>";s:4:"name";s:10:"Testing D.";s:11:"name_parsed";s:10:"Testing D.";s:10:"local_part";s:0:"";s:17:"local_part_parsed";s:0:"";s:11:"domain_part";s:0:"";s:6:"domain";s:0:"";s:2:"ip";s:0:"";s:7:"invalid";b:1;s:14:"invalid_reason";s:110:"Periods within the name of an email address must appear in quotes, such as "<NAME>" <<EMAIL>>";}', $result);
			
		$emails = "<EMAIL> <EMAIL>";
		$result = json_encode(Parse::getInstance()->parse($emails));
		$this->assertEquals('{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"test.testing","local_part_parsed":"test.testing","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"test.testing2","local_part_parsed":"test.testing2","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}', $result);
			
		$emails = array(
				"\"Testing D. Name\" <<EMAIL>>",
				"<<EMAIL>>",
				"<.<EMAIL>>",
				"\"test .s set .set\"@<EMAIL>",
				"<<EMAIL>>",
				"<<EMAIL>>",
				"<EMAIL>, <EMAIL>, <EMAIL>",
				"tnam e@asdf.g asdfa hjkl.com, <EMAIL>, <EMAIL>",
				"Testing D Name <<EMAIL>> <EMAIL> <EMAIL>",
				"Testing D Name <<EMAIL>> (comment) tn(comment1)<EMAIL>(comment2)jkl.com tname-test1(comment3)@<EMAIL>",
				"Tes!@#$@$&*&%(*ti)ng D Name <<EMAIL>> (comment) tna(m!@#($(!(^)$)#)!^%#&*%^#)mment<EMAIL>(comment2)jkl.com tname-test1(comment3)@<EMAIL>",
				"tname@[10.0.10.45] <EMAIL>, <EMAIL>",
				"t\"na\"me@[10.0.10.45] <EMAIL>, <EMAIL>",
				"t(comment with spaces !!!)name@[10.0.10.45] <EMAIL>, <EMAIL>",
				"<EMAIL>",
				"<EMAIL>",
				"<EMAIL>",
				"testing@192.168.0.1",
				"testing@256.26.52.5",
				"testing@[256.26.52.5]",
				"testing@[299.236.532.265]",
				"testing@[172.16.58.35]",
				"testing@192.168.127.12");


		$results1 = array('{"success":true,"reason":null,"email_addresses":[{"address":"\"Testing <NAME>\" <<EMAIL>>","simple_address":"<EMAIL>","original_address":"\"Testing D. Name\" <<EMAIL>>","name":"\"<NAME>\"","name_parsed":"Testing D. Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"<.<EMAIL>>","name":"","name_parsed":"","local_part":"","local_part_parsed":"","domain_part":"","domain":"","ip":"","invalid":true,"invalid_reason":"Email address can not start with \'.\'"}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"\"test .s set .set\"@asdf.<EMAIL>","simple_address":"\"test .s set .set\"@<EMAIL>","original_address":"\"test .s set .set\"@<EMAIL>","name":"","name_parsed":"","local_part":"\"test .s set .set\"","local_part_parsed":"test .s set .set","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"t.name","local_part_parsed":"t.name","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"t.name.","local_part_parsed":"t.name.","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>@asdf.ghjkl.com","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname-test1","local_part_parsed":"tname-test1","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"tnam <e<EMAIL>>","simple_address":"e@asdf.g","original_address":"tnam e@asdf.g","name":"tnam","name_parsed":"tnam","local_part":"e","local_part_parsed":"e","domain_part":"asdf.g","domain":"asdf.g","ip":"","invalid":false,"invalid_reason":null},{"address":"","simple_address":"","original_address":"asdfa hjkl.com","name":"asdfa","name_parsed":"asdfa","local_part":"","local_part_parsed":"","domain_part":"","domain":"","ip":"","invalid":true,"invalid_reason":"Misplaced Comma or missing \"@\" symbol"},{"address":"tn\'\'\'<EMAIL>","simple_address":"tn\'\'\'<EMAIL>","original_address":"tn\'\'\'<EMAIL>","name":"","name_parsed":"","local_part":"tn\'\'\'ame","local_part_parsed":"tn\'\'\'ame","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>.com","name":"","name_parsed":"","local_part":"tname-test1","local_part_parsed":"tname-test1","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"Testing D Name <<EMAIL>>","simple_address":"<EMAIL>","original_address":"Testing D Name <<EMAIL>>","name":"Testing D Name","name_parsed":"Testing D Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname-test1","local_part_parsed":"tname-test1","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"Testing D Name <<EMAIL>>","simple_address":"<EMAIL>","original_address":"Testing D Name <<EMAIL>> (comment)","name":"Testing D Name","name_parsed":"Testing D Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"tn(comment1)<EMAIL>(comment2)<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"tname-test1(comment3)@<EMAIL>","name":"","name_parsed":"","local_part":"tname-test1","local_part_parsed":"tname-test1","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"Tes!@#$@$&*&%(*ti)ng","name":"","name_parsed":"","local_part":"","local_part_parsed":"","domain_part":"","domain":"","ip":"","invalid":true,"invalid_reason":"This character is not allowed in email addresses submitted (please put in quotes if needed): \'!\'"},{"address":"D Name <<EMAIL>>","simple_address":"<EMAIL>","original_address":"D Name <<EMAIL>> (comment)","name":"D Name","name_parsed":"D Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"tna(m!@#($(!(^)$)#)!^%#&*%^#)m<EMAIL>1e@<EMAIL>(comment2)jkl.<EMAIL>","name":"","name_parsed":"","local_part":"tnamment1e","local_part_parsed":"tnamment1e","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"tname-test1(comment3)@<EMAIL>","name":"","name_parsed":"","local_part":"tname-test1","local_part_parsed":"tname-test1","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"tname@[10.0.10.45]","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname-test2","local_part_parsed":"tname-test2","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"t\"na\"me@[10.0.10.45]","name":"","name_parsed":"","local_part":"\"tname\"","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname-test2","local_part_parsed":"tname-test2","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"t(comment with spaces !!!)name@[10.0.10.45]","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname-test2","local_part_parsed":"tname-test2","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"testing@t\u016bdali\u0146.lv","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"xn--tdali-d8a8w.lv","domain":"xn--tdali-d8a8w.lv","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"xn--tdali-d8a8w.lv","domain":"xn--tdali-d8a8w.lv","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"-bad-domain.com","domain":"-bad-domain.com","ip":"","invalid":true,"invalid_reason":"Domain invalid: Parts of the domain name \'-bad-domain.com\' can not start or end with \'-\'.  This part does: -bad-domain"}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"testing@192.168.0.1","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[192.168.0.1]","domain":null,"ip":"192.168.0.1","invalid":true,"invalid_reason":"IP address invalid (private): 192.168.0.1"}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"testing@256.26.52.5","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[25172.16.17.32]","domain":null,"ip":"256.26.52.5","invalid":true,"invalid_reason":"IP address invalid: \'256.26.52.5\' does not appear to be a valid IP address"}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"testing@[256.26.52.5]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[256.26.52.5]","domain":"","ip":"256.26.52.5","invalid":true,"invalid_reason":"IP address invalid: \'256.26.52.5\' does not appear to be a valid IP address"}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"testing@[299.236.532.265]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[299.236.532.265]","domain":"","ip":"299.236.532.265","invalid":true,"invalid_reason":"IP address invalid: \'299.236.532.265\' does not appear to be a valid IP address"}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"testing@[192.168.127.12]","simple_address":"testing@[80.67.66.65]","original_address":"testing@[80.67.66.65]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[80.67.66.65]","domain":"","ip":"192.168.127.12","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"testing@[80.67.66.65]","simple_address":"testing@[80.67.66.65]","original_address":"testing@192.168.127.12","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[80.67.66.65]","domain":null,"ip":"192.168.127.12","invalid":false,"invalid_reason":null}]}',
		);

		$results2 = array('{"address":"\"Testing D. Name\" <<EMAIL>>","simple_address":"<EMAIL>","original_address":"\"Testing D. Name\" <<EMAIL>>","name":"\"Testing D. Name\"","name_parsed":"Testing D. Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.<EMAIL>","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"","simple_address":"","original_address":"<.<EMAIL>>","name":"","name_parsed":"","local_part":"","local_part_parsed":"","domain_part":"","domain":"","ip":"","invalid":true,"invalid_reason":"Email address can not start with \'.\'"}',
'{"address":"\"test .s set .set\"@<EMAIL>","simple_address":"\"test .s set .set\"@<EMAIL>","original_address":"\"test .s set .set\"@<EMAIL>","name":"","name_parsed":"","local_part":"\"test .s set .set\"","local_part_parsed":"test .s set .set","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"t.name","local_part_parsed":"t.name","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"t.name.","local_part_parsed":"t.name.","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"","simple_address":"","original_address":"<EMAIL>, <EMAIL>, <EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":true,"invalid_reason":"Comma not permitted - only one email address allowed"}',
'{"address":"tnam <<EMAIL>>","simple_address":"e@asdf.g","original_address":"tnam e@asdf.g","name":"tnam","name_parsed":"tnam","local_part":"e","local_part_parsed":"e","domain_part":"asdf.g","domain":"asdf.g","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"Testing D Name <<EMAIL>>","simple_address":"<EMAIL>","original_address":"Testing D Name <<EMAIL>>","name":"Testing D Name","name_parsed":"Testing D Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"Testing D Name <<EMAIL>>","simple_address":"<EMAIL>","original_address":"Testing D Name <<EMAIL>> (comment)","name":"Testing D Name","name_parsed":"Testing D Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"","simple_address":"","original_address":"Tes!@#$@$&*&%(*ti)ng <NAME> <<EMAIL>> (comment) tna(m!@#($(!(^)$)#)!^%#&*%^#)<EMAIL>(comment2)jkl.com tname-test1(comment3)<EMAIL>","name":"","name_parsed":"","local_part":"","local_part_parsed":"","domain_part":"","domain":"","ip":"","invalid":true,"invalid_reason":"This character is not allowed in email addresses submitted (please put in quotes if needed): \'!\'"}',
'{"address":"","simple_address":"","original_address":"tname@[10.0.10.45]","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"}',
'{"address":"","simple_address":"","original_address":"t\"na\"me@[10.0.10.45]","name":"","name_parsed":"","local_part":"\"tname\"","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"}',
'{"address":"","simple_address":"","original_address":"t(comment with spaces !!!)name@[10.0.10.45]","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"}',
'{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>@t\u016bdali\u0146.lv","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"xn--tdali-d8a8w.lv","domain":"xn--tdali-d8a8w.lv","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"xn--tdali-d8a8w.lv","domain":"xn--tdali-d8a8w.lv","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"","simple_address":"","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"-bad-domain.com","domain":"-bad-domain.com","ip":"","invalid":true,"invalid_reason":"Domain invalid: Parts of the domain name \'-bad-domain.com\' can not start or end with \'-\'.  This part does: -bad-domain"}',
'{"address":"","simple_address":"","original_address":"testing@192.168.0.1","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[192.168.0.1]","domain":null,"ip":"192.168.0.1","invalid":true,"invalid_reason":"IP address invalid (private): 192.168.0.1"}',
'{"address":"","simple_address":"","original_address":"testing@256.26.52.5","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[256.26.52.5]","domain":null,"ip":"256.26.52.5","invalid":true,"invalid_reason":"IP address invalid: \'256.26.52.5\' does not appear to be a valid IP address"}',
'{"address":"","simple_address":"","original_address":"testing@[256.26.52.5]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[256.26.52.5]","domain":"","ip":"256.26.52.5","invalid":true,"invalid_reason":"IP address invalid: \'256.26.52.5\' does not appear to be a valid IP address"}',
'{"address":"","simple_address":"","original_address":"testing@[299.236.532.265]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[299.236.532.265]","domain":"","ip":"299.236.532.265","invalid":true,"invalid_reason":"IP address invalid: \'299.236.532.265\' does not appear to be a valid IP address"}',
'{"address":"testing@[80.67.66.65]","simple_address":"testing@[80.67.66.65]","original_address":"testing@[80.67.66.65]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[80.67.66.65]","domain":"","ip":"192.168.127.12","invalid":false,"invalid_reason":null}',
'{"address":"testing@[80.67.66.65]","simple_address":"testing@[80.67.66.65]","original_address":"testing@192.168.127.12","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[80.67.66.65]","domain":null,"ip":"192.168.127.12","invalid":false,"invalid_reason":null}',
		);

		for($i = 0 ; $i < count($emails) ; $i++)
		{			
			$a = Parse::getInstance()->parse($emails[$i]);
			$b = Parse::getInstance()->parse($emails[$i], false);
			
			$this->assertEquals($results1[$i], json_encode($a));
			$this->assertEquals($results2[$i], json_encode($b));
		}
	}
}<commit_msg>update tabs -> spaces<commit_after><?php

require_once(__DIR__ . '/../../vendor/autoload.php');
require_once(__DIR__ . '/../../src/Email/Parse.php');

use Email\Parse;

class InflectTest extends PHPUnit_Framework_TestCase
{
    function testParseEmailAddresses()
    {
        $emails = "<EMAIL>";
        $result = serialize(Parse::getInstance()->parse($emails));
        $this->assertEquals('a:3:{s:7:"success";b:1;s:6:"reason";N;s:15:"email_addresses";a:1:{i:0;a:12:{s:7:"address";s:21:"<EMAIL>";s:14:"simple_address";s:21:"<EMAIL>";s:16:"original_address";s:21:"<EMAIL>";s:4:"name";s:0:"";s:11:"name_parsed";s:0:"";s:10:"local_part";s:6:"t.name";s:17:"local_part_parsed";s:6:"t.name";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}}}', $result);

        $emails = "<EMAIL>";
        $result = serialize(Parse::getInstance()->parse($emails));
        $this->assertEquals('a:3:{s:7:"success";b:1;s:6:"reason";N;s:15:"email_addresses";a:1:{i:0;a:12:{s:7:"address";s:20:"<EMAIL>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:20:"<EMAIL>";s:4:"name";s:0:"";s:11:"name_parsed";s:0:"";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}}}', $result);

        // Test as single address
        $result = serialize(Parse::getInstance()->parse($emails, false));
        $this->assertEquals('a:12:{s:7:"address";s:20:"<EMAIL>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:20:"<EMAIL>";s:4:"name";s:0:"";s:11:"name_parsed";s:0:"";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}', $result);

        $emails = "Testing Name <t<EMAIL>>";
        $result = serialize(Parse::getInstance()->parse($emails));
        $this->assertEquals('a:3:{s:7:"success";b:1;s:6:"reason";N;s:15:"email_addresses";a:1:{i:0;a:12:{s:7:"address";s:35:"Testing Name <<EMAIL>>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:35:"Testing Name <<EMAIL>>";s:4:"name";s:12:"Testing Name";s:11:"name_parsed";s:12:"Testing Name";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}}}', $result);

        // Test as single address
        $result = serialize(Parse::getInstance()->parse($emails, false));
        $this->assertEquals('a:12:{s:7:"address";s:35:"Testing Name <<EMAIL>>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:35:"Testing Name <<EMAIL>>";s:4:"name";s:12:"Testing Name";s:11:"name_parsed";s:12:"Testing Name";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}', $result);

        $emails = "Testing D Name <<EMAIL>>";
        $result = serialize(Parse::getInstance()->parse($emails));
        $this->assertEquals('a:3:{s:7:"success";b:1;s:6:"reason";N;s:15:"email_addresses";a:1:{i:0;a:12:{s:7:"address";s:37:"Testing D Name <<EMAIL>>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:37:"Testing D Name <<EMAIL>>";s:4:"name";s:14:"Testing D Name";s:11:"name_parsed";s:14:"Testing D Name";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}}}', $result);

        // Test as single address
        $result = serialize(Parse::getInstance()->parse($emails, false));
        $this->assertEquals('a:12:{s:7:"address";s:37:"Testing D Name <<EMAIL>>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:37:"Testing D Name <<EMAIL>>";s:4:"name";s:14:"Testing D Name";s:11:"name_parsed";s:14:"Testing D Name";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}', $result);

        $emails = "Testing D. Name  <<EMAIL>>";
        $result = serialize(Parse::getInstance()->parse($emails));
        $this->assertEquals('a:3:{s:7:"success";b:0;s:6:"reason";s:21:"Invalid email address";s:15:"email_addresses";a:2:{i:0;a:12:{s:7:"address";s:0:"";s:14:"simple_address";s:0:"";s:16:"original_address";s:15:"Testing D. Name";s:4:"name";s:10:"Testing D.";s:11:"name_parsed";s:10:"Testing D.";s:10:"local_part";s:0:"";s:17:"local_part_parsed";s:0:"";s:11:"domain_part";s:0:"";s:6:"domain";s:0:"";s:2:"ip";s:0:"";s:7:"invalid";b:1;s:14:"invalid_reason";s:110:"Periods within the name of an email address must appear in quotes, such as "<NAME>" <<EMAIL>>";}i:1;a:12:{s:7:"address";s:20:"<EMAIL>";s:14:"simple_address";s:20:"<EMAIL>";s:16:"original_address";s:22:"<<EMAIL>>";s:4:"name";s:0:"";s:11:"name_parsed";s:0:"";s:10:"local_part";s:5:"tname";s:17:"local_part_parsed";s:5:"tname";s:11:"domain_part";s:14:"asdf.ghjkl.com";s:6:"domain";s:14:"asdf.ghjkl.com";s:2:"ip";s:0:"";s:7:"invalid";b:0;s:14:"invalid_reason";N;}}}', $result);

        // Test as single address
        $result = serialize(Parse::getInstance()->parse($emails, false));
        $this->assertEquals('a:12:{s:7:"address";s:0:"";s:14:"simple_address";s:0:"";s:16:"original_address";s:39:"Testing D. Name  <<EMAIL>>";s:4:"name";s:10:"Testing D.";s:11:"name_parsed";s:10:"Testing D.";s:10:"local_part";s:0:"";s:17:"local_part_parsed";s:0:"";s:11:"domain_part";s:0:"";s:6:"domain";s:0:"";s:2:"ip";s:0:"";s:7:"invalid";b:1;s:14:"invalid_reason";s:110:"Periods within the name of an email address must appear in quotes, such as "<NAME>" <<EMAIL>>";}', $result);
            
        $emails = "<EMAIL> <EMAIL>";
        $result = json_encode(Parse::getInstance()->parse($emails));
        $this->assertEquals('{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"test.testing","local_part_parsed":"test.testing","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"test.testing2","local_part_parsed":"test.testing2","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}', $result);
            
        $emails = array(
                "\"Testing D. Name\" <<EMAIL>>",
                "<<EMAIL>>",
                "<.<EMAIL>>",
                "\"test .s set .set\"@<EMAIL>",
                "<<EMAIL>>",
                "<<EMAIL>>",
                "<EMAIL>, <EMAIL>, <EMAIL>",
                "tnam <EMAIL> asdfa hjkl.com, <EMAIL>, <EMAIL>",
                "Testing D Name <<EMAIL>> <EMAIL> <EMAIL>",
                "Testing D Name <<EMAIL>> (comment) tn(comment1)<EMAIL>(comment2)jkl.com tname-<EMAIL>(comment3)<EMAIL>",
                "Tes!@#$@$&*&%(*ti)ng D Name <<EMAIL>> (comment) tna(m!@#($(!(^)$)#)!^%#&*%^#)<EMAIL>@<EMAIL>(comment2)jkl.com tname-<EMAIL>(comment3)<EMAIL>",
                "tname@[10.0.10.45] <EMAIL>, <EMAIL>",
                "t\"na\"me@[10.0.10.45] <EMAIL>, <EMAIL>",
                "t(comment with spaces !!!)name@[10.0.10.45] <EMAIL>, <EMAIL>",
                "<EMAIL>",
                "<EMAIL>",
                "<EMAIL>@-bad-<EMAIL>",
                "testing@192.168.0.1",
                "testing@256.26.52.5",
                "testing@[256.26.52.5]",
                "testing@[299.236.532.265]",
                "testing@[192.168.127.12]",
                "testing@192.168.127.12");


        $results1 = array('{"success":true,"reason":null,"email_addresses":[{"address":"\"Testing D. Name\" <<EMAIL>>","simple_address":"<EMAIL>","original_address":"\"Testing D. Name\" <<EMAIL>>","name":"\"Testing D. Name\"","name_parsed":"Testing D. Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"<.<EMAIL>>","name":"","name_parsed":"","local_part":"","local_part_parsed":"","domain_part":"","domain":"","ip":"","invalid":true,"invalid_reason":"Email address can not start with \'.\'"}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"\"test .s set .set\"@<EMAIL>","simple_address":"\"test .s set .set\"@<EMAIL>","original_address":"\"test .s set .set\"@<EMAIL>","name":"","name_parsed":"","local_part":"\"test .s set .set\"","local_part_parsed":"test .s set .set","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"t.name","local_part_parsed":"t.name","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"t.name.","local_part_parsed":"t.name.","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"tname-<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname-test1","local_part_parsed":"tname-test1","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"tnam <e@asdf.g>","simple_address":"e@asdf.g","original_address":"tnam e@asdf.g","name":"tnam","name_parsed":"tnam","local_part":"e","local_part_parsed":"e","domain_part":"asdf.g","domain":"asdf.g","ip":"","invalid":false,"invalid_reason":null},{"address":"","simple_address":"","original_address":"asdfa hjkl.com","name":"asdfa","name_parsed":"asdfa","local_part":"","local_part_parsed":"","domain_part":"","domain":"","ip":"","invalid":true,"invalid_reason":"Misplaced Comma or missing \"@\" symbol"},{"address":"tn\'\'\'<EMAIL>","simple_address":"tn\'\'\'<EMAIL>","original_address":"tn\'\'\'<EMAIL>","name":"","name_parsed":"","local_part":"tn\'\'\'ame","local_part_parsed":"tn\'\'\'ame","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname-test1","local_part_parsed":"tname-test1","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"Testing D Name <<EMAIL>>","simple_address":"<EMAIL>","original_address":"Testing D Name <<EMAIL>>","name":"Testing D Name","name_parsed":"Testing D Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname-test1","local_part_parsed":"tname-test1","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"Testing D Name <<EMAIL>>","simple_address":"<EMAIL>","original_address":"Testing D Name <<EMAIL>> (comment)","name":"Testing D Name","name_parsed":"Testing D Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"tn(comment1)ame<EMAIL>(comment2)jkl.com","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"tname-test1(comment3)@<EMAIL>","name":"","name_parsed":"","local_part":"tname-test1","local_part_parsed":"tname-test1","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"Tes!@#$@$&*&%(*ti)ng","name":"","name_parsed":"","local_part":"","local_part_parsed":"","domain_part":"","domain":"","ip":"","invalid":true,"invalid_reason":"This character is not allowed in email addresses submitted (please put in quotes if needed): \'!\'"},{"address":"D Name <<EMAIL>>","simple_address":"<EMAIL>","original_address":"D Name <<EMAIL>> (comment)","name":"D Name","name_parsed":"D Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"tna(m!@#($(!(^)$)#)!^%#&*%^#)mment1e@asdf.gh(comment2)jkl.com","name":"","name_parsed":"","local_part":"tnamment1e","local_part_parsed":"tnamment1e","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"tname-test1(comment3)@<EMAIL>","name":"","name_parsed":"","local_part":"tname-test1","local_part_parsed":"tname-test1","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"tname@[10.0.10.45]","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"t<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname-test2","local_part_parsed":"tname-test2","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"t\"na\"me@[10.0.10.45]","name":"","name_parsed":"","local_part":"\"tname\"","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname-test2","local_part_parsed":"tname-test2","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"t(comment with spaces !!!)name@[10.0.10.45]","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null},{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"tname-test2","local_part_parsed":"tname-test2","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>@t\u016bdali\u0146.lv","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"xn--tdali-d8a8w.lv","domain":"xn--tdali-d8a8w.lv","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"xn--tdali-d8a8w.lv","domain":"xn--tdali-d8a8w.lv","ip":"","invalid":false,"invalid_reason":null}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"-bad-domain.com","domain":"-bad-domain.com","ip":"","invalid":true,"invalid_reason":"Domain invalid: Parts of the domain name \'-bad-domain.com\' can not start or end with \'-\'.  This part does: -bad-domain"}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"testing@192.168.0.1","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[192.168.0.1]","domain":null,"ip":"192.168.0.1","invalid":true,"invalid_reason":"IP address invalid (private): 192.168.0.1"}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"testing@256.26.52.5","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[256.26.52.5]","domain":null,"ip":"256.26.52.5","invalid":true,"invalid_reason":"IP address invalid: \'256.26.52.5\' does not appear to be a valid IP address"}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"testing@[25172.16.17.32]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[25172.16.17.32]","domain":"","ip":"256.26.52.5","invalid":true,"invalid_reason":"IP address invalid: \'256.26.52.5\' does not appear to be a valid IP address"}]}',
'{"success":false,"reason":"Invalid email address","email_addresses":[{"address":"","simple_address":"","original_address":"testing@[299.236.532.265]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[299.236.532.265]","domain":"","ip":"299.236.532.265","invalid":true,"invalid_reason":"IP address invalid: \'299.236.532.265\' does not appear to be a valid IP address"}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"testing@[80.67.66.65]","simple_address":"testing@[80.67.66.65]","original_address":"testing@[80.67.66.65]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[80.67.66.65]","domain":"","ip":"192.168.127.12","invalid":false,"invalid_reason":null}]}',
'{"success":true,"reason":null,"email_addresses":[{"address":"testing@[80.67.66.65]","simple_address":"testing@[80.67.66.65]","original_address":"testing@192.168.127.12","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[80.67.66.65]","domain":null,"ip":"192.168.127.12","invalid":false,"invalid_reason":null}]}',
        );

        $results2 = array('{"address":"\"Testing D. Name\" <<EMAIL>>","simple_address":"<EMAIL>","original_address":"\"<NAME>\" <<EMAIL>>","name":"\"<NAME>\"","name_parsed":"<NAME>","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"","simple_address":"","original_address":"<.<EMAIL>>","name":"","name_parsed":"","local_part":"","local_part_parsed":"","domain_part":"","domain":"","ip":"","invalid":true,"invalid_reason":"Email address can not start with \'.\'"}',
'{"address":"\"test .s set .set\"@<EMAIL>","simple_address":"\"test .s set .set\"@<EMAIL>","original_address":"\"test .s set .set\"@<EMAIL>","name":"","name_parsed":"","local_part":"\"test .s set .set\"","local_part_parsed":"test .s set .set","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"t.name","local_part_parsed":"t.name","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<<EMAIL>>","name":"","name_parsed":"","local_part":"t.name.","local_part_parsed":"t.name.","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"","simple_address":"","original_address":"<EMAIL>, <EMAIL>, <EMAIL>","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":true,"invalid_reason":"Comma not permitted - only one email address allowed"}',
'{"address":"tnam <<EMAIL>>","simple_address":"<EMAIL>","original_address":"tnam <EMAIL>","name":"tnam","name_parsed":"tnam","local_part":"e","local_part_parsed":"e","domain_part":"asdf.g","domain":"asdf.g","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"Testing D Name <<EMAIL>>","simple_address":"<EMAIL>","original_address":"Testing D Name <<EMAIL>>","name":"Testing D Name","name_parsed":"Testing D Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"Testing D Name <<EMAIL>>","simple_address":"<EMAIL>","original_address":"Testing D Name <<EMAIL>> (comment)","name":"Testing D Name","name_parsed":"Testing D Name","local_part":"tname","local_part_parsed":"tname","domain_part":"asdf.ghjkl.com","domain":"asdf.ghjkl.com","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"","simple_address":"","original_address":"Tes!@#$@$&*&%(*ti)ng D Name <<EMAIL>> (comment) tna(m!@#($(!(^)$)#)!^%#&*%^#)mment1e@asdf.gh(comment2)jkl.com tname-test1(comment3)<EMAIL>","name":"","name_parsed":"","local_part":"","local_part_parsed":"","domain_part":"","domain":"","ip":"","invalid":true,"invalid_reason":"This character is not allowed in email addresses submitted (please put in quotes if needed): \'!\'"}',
'{"address":"","simple_address":"","original_address":"tname@[10.0.10.45]","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"}',
'{"address":"","simple_address":"","original_address":"t\"na\"me@[10.0.10.45]","name":"","name_parsed":"","local_part":"\"tname\"","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"}',
'{"address":"","simple_address":"","original_address":"t(comment with spaces !!!)name@[10.0.10.45]","name":"","name_parsed":"","local_part":"tname","local_part_parsed":"tname","domain_part":"[10.0.10.45]","domain":"","ip":"10.0.10.45","invalid":true,"invalid_reason":"IP address invalid (private): 10.0.10.45"}',
'{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"testing@t\u016bdali\u0146.lv","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"xn--tdali-d8a8w.lv","domain":"xn--tdali-d8a8w.lv","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"<EMAIL>","simple_address":"<EMAIL>","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"xn--tdali-d8a8w.lv","domain":"xn--tdali-d8a8w.lv","ip":"","invalid":false,"invalid_reason":null}',
'{"address":"","simple_address":"","original_address":"<EMAIL>","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"-bad-domain.com","domain":"-bad-domain.com","ip":"","invalid":true,"invalid_reason":"Domain invalid: Parts of the domain name \'-bad-domain.com\' can not start or end with \'-\'.  This part does: -bad-domain"}',
'{"address":"","simple_address":"","original_address":"testing@192.168.0.1","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[192.168.0.1]","domain":null,"ip":"192.168.0.1","invalid":true,"invalid_reason":"IP address invalid (private): 192.168.0.1"}',
'{"address":"","simple_address":"","original_address":"testing@256.26.52.5","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[256.26.52.5]","domain":null,"ip":"256.26.52.5","invalid":true,"invalid_reason":"IP address invalid: \'256.26.52.5\' does not appear to be a valid IP address"}',
'{"address":"","simple_address":"","original_address":"testing@[256.26.52.5]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[256.26.52.5]","domain":"","ip":"256.26.52.5","invalid":true,"invalid_reason":"IP address invalid: \'256.26.52.5\' does not appear to be a valid IP address"}',
'{"address":"","simple_address":"","original_address":"testing@[299.236.532.265]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[299.236.532.265]","domain":"","ip":"299.236.532.265","invalid":true,"invalid_reason":"IP address invalid: \'299.236.532.265\' does not appear to be a valid IP address"}',
'{"address":"testing@[80.67.66.65]","simple_address":"testing@[80.67.66.65]","original_address":"testing@[80.67.66.65]","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[80.67.66.65]","domain":"","ip":"192.168.127.12","invalid":false,"invalid_reason":null}',
'{"address":"testing@[80.67.66.65]","simple_address":"testing@[80.67.66.65]","original_address":"testing@192.168.127.12","name":"","name_parsed":"","local_part":"testing","local_part_parsed":"testing","domain_part":"[192.168.127.12]","domain":null,"ip":"192.168.127.12","invalid":false,"invalid_reason":null}',
        );

        for($i = 0 ; $i < count($emails) ; $i++)
        {            
            $a = Parse::getInstance()->parse($emails[$i]);
            $b = Parse::getInstance()->parse($emails[$i], false);
            
            $this->assertEquals($results1[$i], json_encode($a));
            $this->assertEquals($results2[$i], json_encode($b));
        }
    }
}
{'fraction_non_alphanumeric': 0.29949416274307317, 'fraction_numerical': 0.04253233682810285, 'mean_word_length': 13.995800524934383, 'pattern_counts': {'":': 1728, '<': 498, '<?xml version=': 0, '>': 543, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 154, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5254913', 'n_tokens_mistral': 21575, 'n_tokens_neox': 20543, 'n_words': 1234}