parseAddresses() public method

Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. Note that quotes in the name part are removed.
public parseAddresses ( string $addrstr, boolean $useimap = true ) : array
$addrstr string The address list string
$useimap boolean Whether to use the IMAP extension to parse the list
return array
 /**
  * Test RFC822 address splitting.
  */
 public function testAddressSplitting()
 {
     //Test built-in address parser
     $this->assertCount(2, $this->Mail->parseAddresses('Joe User <*****@*****.**>, Jill User <*****@*****.**>'), 'Failed to recognise address list (IMAP parser)');
     //Test simple address parser
     $this->assertCount(2, $this->Mail->parseAddresses('Joe User <*****@*****.**>, Jill User <*****@*****.**>', false), 'Failed to recognise address list');
     //Test single address
     $this->assertNotEmpty($this->Mail->parseAddresses('Joe User <*****@*****.**>', false), 'Failed to recognise single address');
     //Test quoted name IMAP
     $this->assertNotEmpty($this->Mail->parseAddresses('Tim "The Book" O\'Reilly <*****@*****.**>'), 'Failed to recognise quoted name (IMAP)');
     //Test quoted name
     $this->assertNotEmpty($this->Mail->parseAddresses('Tim "The Book" O\'Reilly <*****@*****.**>', false), 'Failed to recognise quoted name');
     //Test single address IMAP
     $this->assertNotEmpty($this->Mail->parseAddresses('Joe User <*****@*****.**>'), 'Failed to recognise single address (IMAP)');
     //Test unnamed address
     $this->assertNotEmpty($this->Mail->parseAddresses('*****@*****.**', false), 'Failed to recognise unnamed address');
     //Test unnamed address IMAP
     $this->assertNotEmpty($this->Mail->parseAddresses('*****@*****.**'), 'Failed to recognise unnamed address (IMAP)');
     //Test invalid addresses
     $this->assertEmpty($this->Mail->parseAddresses('Joe User <joe@example.com.>, Jill User <*****@*****.**>'), 'Failed to recognise invalid addresses (IMAP)');
     //Test invalid addresses
     $this->assertEmpty($this->Mail->parseAddresses('Joe User <joe@example.com.>, Jill User <*****@*****.**>', false), 'Failed to recognise invalid addresses');
 }
Example #2
0
 /**
  * Test RFC822 address splitting.
  */
 public function testAddressSplitting()
 {
     //Test built-in address parser
     $this->assertCount(2, PHPMailer::parseAddresses('Joe User <*****@*****.**>, Jill User <*****@*****.**>'), 'Failed to recognise address list (IMAP parser)');
     $this->assertEquals(array(array("name" => 'Joe User', 'address' => '*****@*****.**'), array("name" => 'Jill User', 'address' => '*****@*****.**'), array("name" => '', 'address' => '*****@*****.**')), $this->Mail->parseAddresses('Joe User <*****@*****.**>,' . 'Jill User <*****@*****.**>,' . 'frank@example.com,'), 'Parsed addresses');
     //Test simple address parser
     $this->assertCount(2, PHPMailer::parseAddresses('Joe User <*****@*****.**>, Jill User <*****@*****.**>', false), 'Failed to recognise address list');
     //Test single address
     $this->assertNotEmpty(PHPMailer::parseAddresses('Joe User <*****@*****.**>', false), 'Failed to recognise single address');
     //Test quoted name IMAP
     $this->assertNotEmpty(PHPMailer::parseAddresses('Tim "The Book" O\'Reilly <*****@*****.**>'), 'Failed to recognise quoted name (IMAP)');
     //Test quoted name
     $this->assertNotEmpty(PHPMailer::parseAddresses('Tim "The Book" O\'Reilly <*****@*****.**>', false), 'Failed to recognise quoted name');
     //Test single address IMAP
     $this->assertNotEmpty(PHPMailer::parseAddresses('Joe User <*****@*****.**>'), 'Failed to recognise single address (IMAP)');
     //Test unnamed address
     $this->assertNotEmpty(PHPMailer::parseAddresses('*****@*****.**', false), 'Failed to recognise unnamed address');
     //Test unnamed address IMAP
     $this->assertNotEmpty(PHPMailer::parseAddresses('*****@*****.**'), 'Failed to recognise unnamed address (IMAP)');
     //Test invalid addresses
     $this->assertEmpty(PHPMailer::parseAddresses('Joe User <joe@example.com.>, Jill User <*****@*****.**>'), 'Failed to recognise invalid addresses (IMAP)');
     //Test invalid addresses
     $this->assertEmpty(PHPMailer::parseAddresses('Joe User <joe@example.com.>, Jill User <*****@*****.**>', false), 'Failed to recognise invalid addresses');
 }