PathHeader example


    public function addIdHeader(string $name, string|array $ids)static
    {
        return $this->add(new IdentificationHeader($name$ids));
    }

    /** * @return $this */
    public function addPathHeader(string $name, Address|string $path)static
    {
        return $this->add(new PathHeader($name$path instanceof Address ? $path : new Address($path)));
    }

    /** * @return $this */
    public function addDateHeader(string $name, \DateTimeInterface $dateTime)static
    {
        return $this->add(new DateHeader($name$dateTime));
    }

    /** * @return $this */
$headers = new Headers();
        $headers->addMailboxListHeader('From', [$from = new Address('from@symfony.com', 'from'), 'some@symfony.com']);
        $headers->addMailboxListHeader('To', ['to@symfony.com']);
        $e = Envelope::create(new Message($headers));
        $this->assertEquals($from$e->getSender());
    }

    public function testSenderFromHeadersFailsWithNonAsciiCharactersInLocalPart()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Invalid sender "fabièn@symfony.com": non-ASCII characters not supported in local-part of email.');
        $message = new Message(new Headers(new PathHeader('Return-Path', new Address('fabièn@symfony.com'))));
        Envelope::create($message)->getSender();
    }

    public function testSenderFromHeadersWithoutFrom()
    {
        $headers = new Headers();
        $headers->addMailboxListHeader('To', ['to@symfony.com']);
        $e = Envelope::create($message = new Message($headers));
        $message->getHeaders()->addMailboxListHeader('From', [$from = new Address('from@symfony.com', 'from')]);
        $this->assertEquals($from$e->getSender());
    }

    
namespace Symfony\Component\Mime\Tests\Header;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Header\PathHeader;

class PathHeaderTest extends TestCase
{
    public function testSingleAddressCanBeSetAndFetched()
    {
        $header = new PathHeader('Return-Path', $address = new Address('chris@swiftmailer.org'));
        $this->assertEquals($address$header->getAddress());
    }

    public function testAddressMustComplyWithRfc2822()
    {
        $this->expectException(\Exception::class);
        new PathHeader('Return-Path', new Address('chr is@swiftmailer.org'));
    }

    public function testValueIsAngleAddrWithValidAddress()
    {
        

    public function addIdHeader(string $name, string|array $ids)static
    {
        return $this->add(new IdentificationHeader($name$ids));
    }

    /** * @return $this */
    public function addPathHeader(string $name, Address|string $path)static
    {
        return $this->add(new PathHeader($name$path instanceof Address ? $path : new Address($path)));
    }

    /** * @return $this */
    public function addDateHeader(string $name, \DateTimeInterface $dateTime)static
    {
        return $this->add(new DateHeader($name$dateTime));
    }

    /** * @return $this */
Home | Imprint | This part of the site doesn't use cookies.