Message example

$headerCanonData .= rtrim($this->canonicalizeHeader($header->toString()."\r\n b=", $options['header_canon']));
        if (self::ALGO_SHA256 === $options['algorithm']) {
            if (!openssl_sign($headerCanonData$signature$this->key, \OPENSSL_ALGO_SHA256)) {
                throw new RuntimeException('Unable to sign DKIM hash: '.openssl_error_string());
            }
        } else {
            throw new \RuntimeException(sprintf('The "%s" DKIM signing algorithm is not supported yet.', self::ALGO_ED25519));
        }
        $header->setValue($value.' b='.trim(chunk_split(base64_encode($signature), 73, ' ')));
        $headers->add($header);

        return new Message($headers$message->getBody());
    }

    private function canonicalizeHeader(string $header, string $headerCanon): string
    {
        if (self::CANON_RELAXED !== $headerCanon) {
            return $header."\r\n";
        }

        $exploded = explode(':', $header, 2);
        $name = strtolower(trim($exploded[0]));
        $value = str_replace("\r\n", '', $exploded[1]);
        
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);
    }
}
$headerCanonData .= rtrim($this->canonicalizeHeader($header->toString()."\r\n b=", $options['header_canon']));
        if (self::ALGO_SHA256 === $options['algorithm']) {
            if (!openssl_sign($headerCanonData$signature$this->key, \OPENSSL_ALGO_SHA256)) {
                throw new RuntimeException('Unable to sign DKIM hash: '.openssl_error_string());
            }
        } else {
            throw new \RuntimeException(sprintf('The "%s" DKIM signing algorithm is not supported yet.', self::ALGO_ED25519));
        }
        $header->setValue($value.' b='.trim(chunk_split(base64_encode($signature), 73, ' ')));
        $headers->add($header);

        return new Message($headers$message->getBody());
    }

    private function canonicalizeHeader(string $header, string $headerCanon): string
    {
        if (self::CANON_RELAXED !== $headerCanon) {
            return $header."\r\n";
        }

        $exploded = explode(':', $header, 2);
        $name = strtolower(trim($exploded[0]));
        $value = str_replace("\r\n", '', $exploded[1]);
        

        $this->assertConversion((clone $email)
            ->text('text content')
            ->addPart((new DataPart($file, 'test_attached.jpg', 'image/gif'))->asInline())
        );
    }

    private function assertConversion(Email $expected)
    {
        $r = new \ReflectionMethod($expected, 'generateBody');

        $message = new Message($expected->getHeaders()$r->invoke($expected));
        $converted = MessageConverter::toEmail($message);
        if ($expected->getHtmlBody()) {
            $this->assertStringMatchesFormat(str_replace('cid:test.jpg', 'cid:%s', $expected->getHtmlBody())$converted->getHtmlBody());
            $expected->html('HTML content');
            $converted->html('HTML content');
        }

        $r = new \ReflectionProperty($expected, 'cachedBody');
        $r->setValue($expected, null);
        $r->setValue($converted, null);

        
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);
    }
}
/** * {@inheritdoc} */
  public static function getSubscribedEvents() {
    return [
      ScriptEvents::POST_CREATE_PROJECT_CMD => 'displayPostCreateMessage',
      ScriptEvents::POST_INSTALL_CMD => 'displayPostCreateMessage',
    ];
  }

  public function displayPostCreateMessage(Event $event) {
    $message = new Message($this->composer->getPackage()$event->getName());
    if ($message = $message->getText()) {
      $this->io->write($message);
    }
  }

}


    public function testKeepGettingPendingMessages()
    {
        $client = $this->createMock(SqsClient::class);
        $client->expects($this->any())
            ->method('getQueueUrl')
            ->with(['QueueName' => 'queue', 'QueueOwnerAWSAccountId' => 123])
            ->willReturn(ResultMockFactory::create(GetQueueUrlResult::class['QueueUrl' => 'https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue']));

        $firstResult = ResultMockFactory::create(ReceiveMessageResult::class['Messages' => [
            new Message(['MessageId' => 1, 'Body' => 'this is a test']),
            new Message(['MessageId' => 2, 'Body' => 'this is a test']),
            new Message(['MessageId' => 3, 'Body' => 'this is a test']),
        ]]);
        $secondResult = ResultMockFactory::create(ReceiveMessageResult::class['Messages' => []]);

        $series = [
            [[['QueueUrl' => 'https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue',
                'VisibilityTimeout' => null,
                'MaxNumberOfMessages' => 9,
                'MessageAttributeNames' => ['All'],
                'WaitTimeSeconds' => 20]]$firstResult],
            [[[
public function sign(Message $message): Message
    {
        $bufferFile = tmpfile();
        $outputFile = tmpfile();

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

        if (!@openssl_pkcs7_sign(stream_get_meta_data($bufferFile)['uri']stream_get_meta_data($outputFile)['uri']$this->signCertificate, $this->signPrivateKey, []$this->signOptions, $this->extraCerts)) {
            throw new RuntimeException(sprintf('Failed to sign S/Mime message. Error: "%s".', openssl_error_string()));
        }

        return new Message($message->getHeaders()$this->convertMessageToSMimePart($outputFile, 'multipart', 'signed'));
    }
}

    public function testDefaultTransport()
    {
        $transport = new Transports([
            'foo' => $foo = $this->createMock(TransportInterface::class),
            'bar' => $bar = $this->createMock(TransportInterface::class),
        ]);

        $foo->expects($this->once())->method('send');
        $bar->expects($this->never())->method('send');

        $email = new Message(new Headers()new TextPart('...'));
        $transport->send($email);
    }

    public function testOverrideTransport()
    {
        $transport = new Transports([
            'foo' => $foo = $this->createMock(TransportInterface::class),
            'bar' => $bar = $this->createMock(TransportInterface::class),
        ]);

        $foo->expects($this->never())->method('send');
        
public function testConstructorWithWrongRecipients()
    {
        $this->expectException(\InvalidArgumentException::class);
        new Envelope(new Address('fabien@symfony.com')['lucas@symfony.com']);
    }

    public function testSenderFromHeaders()
    {
        $headers = new Headers();
        $headers->addPathHeader('Return-Path', $return = new Address('return@symfony.com', 'return'));
        $headers->addMailboxListHeader('To', ['to@symfony.com']);
        $e = Envelope::create(new Message($headers));
        $this->assertEquals($return$e->getSender());

        $headers = new Headers();
        $headers->addMailboxHeader('Sender', $sender = new Address('sender@symfony.com', 'sender'));
        $headers->addMailboxListHeader('To', ['to@symfony.com']);
        $e = Envelope::create(new Message($headers));
        $this->assertEquals($sender$e->getSender());

        $headers = new Headers();
        $headers->addMailboxListHeader('From', [$from = new Address('from@symfony.com', 'from'), 'some@symfony.com']);
        $headers->addMailboxListHeader('To', ['to@symfony.com']);
        
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\TextPart;

/** * @requires extension openssl */
class SMimeSignerTest extends SMimeTestCase
{
    public function testSignedMessage()
    {
        $message = new Message(
            (new Headers())
                ->addDateHeader('Date', new \DateTimeImmutable('2019-04-07 10:36:30', new \DateTimeZone('Europe/Paris')))
                ->addMailboxListHeader('From', ['fabien@symfony.com']),
            new TextPart('content')
        );

        $signer = new SMimeSigner($this->samplesDir.'sign.crt', $this->samplesDir.'sign.key');
        $signedMessage = $signer->sign($message);

        $this->assertMessageSignatureIsValid($signedMessage$message);
    }

    
use Symfony\Component\Clock\MockClock;
use Symfony\Component\Scheduler\RecurringMessage;
use Symfony\Component\Scheduler\Schedule;
use Symfony\Component\Scheduler\Scheduler;

class SchedulerTest extends TestCase
{
    public function testCanRunAndStop()
    {
        $handler = new Handler();
        $handler->clock = $clock = new MockClock();
        $schedule = (new Schedule())->add(RecurringMessage::every('1 second', new Message()));
        $scheduler = new Scheduler([Message::class => $handler][$schedule]$clock);
        $handler->scheduler = $scheduler;

        $scheduler->run(['sleep' => 100]);

        $this->assertSame(3, $handler->count);
    }
}

class Message
{
}
use Symfony\Component\Mime\Header\MailboxListHeader;
use Symfony\Component\Mime\Header\UnstructuredHeader;
use Symfony\Component\Mime\Message;

class MessageListenerTest extends TestCase
{
    /** * @dataProvider provideHeaders */
    public function testHeaders(Headers $initialHeaders, Headers $defaultHeaders, Headers $expectedHeaders, array $rules = MessageListener::DEFAULT_RULES)
    {
        $message = new Message($initialHeaders);
        $listener = new MessageListener($defaultHeaders, null, $rules);
        $event = new MessageEvent($messagenew Envelope(new Address('sender@example.com')[new Address('recipient@example.com')]), 'smtp');
        $listener->onMessage($event);

        $this->assertEquals($expectedHeaders$event->getMessage()->getHeaders());
    }

    public static function provideHeaders(): iterable
    {
        $initialHeaders = new Headers();
        $defaultHeaders = (new Headers())
            
namespace Symfony\Component\Mime\Tests\Part\Multipart;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\Part\MessagePart;
use Symfony\Component\Mime\Part\Multipart\DigestPart;

class DigestPartTest extends TestCase
{
    public function testConstructor()
    {
        $r = new DigestPart($a = new MessagePart(new Message())$b = new MessagePart(new Message()));
        $this->assertEquals('multipart', $r->getMediaType());
        $this->assertEquals('digest', $r->getMediaSubtype());
        $this->assertEquals([$a$b]$r->getParts());
    }
}

  public function testGetMessageText($expected$config) {
    // Root package has our config.     $root = $this->getMockBuilder(RootPackageInterface::class)
      ->onlyMethods(['getExtra'])
      ->getMockForAbstractClass();
    $root->expects($this->once())
      ->method('getExtra')
      ->willReturn($config);

    $message = new Message($root, 'event-name');

    $this->assertSame($expected$message->getText());
  }

  /** * @covers ::getText */
  public function testDefaultFile() {
    // Root package has no extra field.     $root = $this->getMockBuilder(RootPackageInterface::class)
      ->onlyMethods(['getExtra'])
      
Home | Imprint | This part of the site doesn't use cookies.