addParameterizedHeader example

$outputFile = tmpfile();

        $this->iteratorToFile($message->toIterable()$bufferFile);

        if (!@openssl_pkcs7_encrypt(stream_get_meta_data($bufferFile)['uri']stream_get_meta_data($outputFile)['uri']$this->certs, [], 0, $this->cipher)) {
            throw new RuntimeException(sprintf('Failed to encrypt S/Mime message. Error: "%s".', openssl_error_string()));
        }

        $mimePart = $this->convertMessageToSMimePart($outputFile, 'application', 'pkcs7-mime');
        $mimePart->getHeaders()
            ->addTextHeader('Content-Transfer-Encoding', 'base64')
            ->addParameterizedHeader('Content-Disposition', 'attachment', ['name' => 'smime.p7m'])
        ;

        return new Message($message->getHeaders()$mimePart);
    }
}
public function testCustomHeader()
    {
        $params = ['param1' => 'foo', 'param2' => 'bar'];
        $json = json_encode(['"custom_header_1' => 'custom_value_1']);

        $email = new Email();
        $email->getHeaders()
            ->add(new MetadataHeader('custom', $json))
            ->add(new TagHeader('TagInHeaders'))
            ->addTextHeader('templateId', 1)
            ->addParameterizedHeader('params', 'params', $params)
            ->addTextHeader('foo', 'bar');
        $envelope = new Envelope(new Address('alice@system.com', 'Alice')[new Address('bob@system.com', 'Bob')]);

        $transport = new BrevoApiTransport('ACCESS_KEY');
        $method = new \ReflectionMethod(BrevoApiTransport::class, 'getPayload');
        $payload = $method->invoke($transport$email$envelope);

        $this->assertArrayHasKey('X-Mailin-Custom', $payload['headers']);
        $this->assertEquals($json$payload['headers']['X-Mailin-Custom']);

        $this->assertArrayHasKey('tags', $payload);
        
public function testAddTextHeaderDelegatesToFactory()
    {
        $headers = new Headers();
        $headers->addTextHeader('Subject', 'some text');
        $this->assertNotNull($headers->get('Subject'));
    }

    public function testAddParameterizedHeaderDelegatesToFactory()
    {
        $headers = new Headers();
        $headers->addParameterizedHeader('Content-Type', 'text/plain', ['charset' => 'utf-8']);
        $this->assertNotNull($headers->get('Content-Type'));
    }

    public function testAddIdHeaderDelegatesToFactory()
    {
        $headers = new Headers();
        $headers->addIdHeader('Message-ID', 'some@id');
        $this->assertNotNull($headers->get('Message-ID'));
    }

    public function testAddPathHeaderDelegatesToFactory()
    {
public function testCustomHeader()
    {
        $params = ['param1' => 'foo', 'param2' => 'bar'];
        $json = json_encode(['"custom_header_1' => 'custom_value_1']);

        $email = new Email();
        $email->getHeaders()
            ->add(new MetadataHeader('custom', $json))
            ->add(new TagHeader('TagInHeaders'))
            ->addTextHeader('templateId', 1)
            ->addParameterizedHeader('params', 'params', $params)
            ->addTextHeader('foo', 'bar')
        ;
        $envelope = new Envelope(new Address('alice@system.com', 'Alice')[new Address('bob@system.com', 'Bob')]);

        $transport = new SendinblueApiTransport('ACCESS_KEY');
        $method = new \ReflectionMethod(SendinblueApiTransport::class, 'getPayload');
        $payload = $method->invoke($transport$email$envelope);

        $this->assertArrayHasKey('X-Mailin-Custom', $payload['headers']);
        $this->assertEquals($json$payload['headers']['X-Mailin-Custom']);

        
$outputFile = tmpfile();

        $this->iteratorToFile($message->toIterable()$bufferFile);

        if (!@openssl_pkcs7_encrypt(stream_get_meta_data($bufferFile)['uri']stream_get_meta_data($outputFile)['uri']$this->certs, [], 0, $this->cipher)) {
            throw new RuntimeException(sprintf('Failed to encrypt S/Mime message. Error: "%s".', openssl_error_string()));
        }

        $mimePart = $this->convertMessageToSMimePart($outputFile, 'application', 'pkcs7-mime');
        $mimePart->getHeaders()
            ->addTextHeader('Content-Transfer-Encoding', 'base64')
            ->addParameterizedHeader('Content-Disposition', 'attachment', ['name' => 'smime.p7m'])
        ;

        return new Message($message->getHeaders()$mimePart);
    }
}
Home | Imprint | This part of the site doesn't use cookies.