*/ if (php_sapi_name() != 'cli') { echo "
\n";
}
else
{
	chdir(__DIR__);
}

include '../inc/common_functions.inc.php';

$addresses = array(
	'Joe Doe ',
	'"Doe, Joe" ',
	'"\\\'Joe Doe\\\'" ',	// "\'Joe Doe\'" 
	'postmaster@example.com',
	'root',
	'"Joe on its way Down Under :-\)" ',
	'"Giant; \\"Big\\" Box" ',		// "Giant; \"Big\" Box" 
	'"sysservices@example.net" ',
);
$addresses[] = implode(', ', $addresses);

$default_host = 'default.host';

foreach($addresses as $address)
{
	echo "\n\n$address:\n";
	$parsed = my_imap_rfc822_parse_adrlist($address, $default_host);
	print_r($parsed);
	echo my_imap_rfc822_write_address($parsed[0]->mailbox,
		$parsed[0]->host !== $default_host ? $parsed[0]->host : '',
		!empty($parsed[0]->personal) ? $parsed[0]->personal : '')."\n";
}