Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MailjetBundle/DependencyInjection/DekaleeMailjetExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Dekalee\MailjetBundle\DependencyInjection;

use Dekalee\MailjetBundle\Guesser\Strategy\SimpleTemplateGuesser;
use Dekalee\MailjetBundle\Guesser\TemplateIdGuesserInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand Down Expand Up @@ -42,6 +43,9 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('repository.yml');
$loader->load('manager.yml');
}
if (3 < Kernel::MAJOR_VERSION || (3 === Kernel::MAJOR_VERSION && 3 <= Kernel::MINOR_VERSION)) {
$container->registerForAutoconfiguration(TemplateIdGuesserInterface::CLASS)->addTag('dekalee_mailjet.guesser.template_id.strategy');
}

foreach ($config['simple_template_choice'] as $class => $templateId) {
$container
Expand Down
5 changes: 5 additions & 0 deletions MailjetBundle/Resources/config/manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ services:
arguments:
- '@dekalee_mailjet.convertor.contact_list'
- '@dekalee_mailjet.client'

Dekalee\MailjetBundle\Manager\ContactListSubscriber:
alias: dekalee_mailet.subscriber.contact_list
Dekalee\MailjetBundle\Manager\ContactListUnsubscriber:
alias: dekalee_mailjet.unsubscriber.contact_list
2 changes: 2 additions & 0 deletions MailjetBundle/Transport/MailjetSendApiTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul
$vars = $message->getVars();
}

unset($headers['Content-Type']);

$body = [
'FromEmail' => key($from),
'Subject' => $message->getSubject(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ function it_should_send_mail(
\Swift_Events_EventDispatcher $dispatcher,
\Swift_Events_SendEvent $event,
\Swift_Mime_SimpleHeaderSet $headers,
\Swift_Attachment $attachment
\Swift_Attachment $attachment,
\Swift_Mime_Header $mailHeader
) {
$manager->guess($message)->willReturn('foo');
$message->getFrom()->willReturn(['test@foo.com' => null]);
Expand All @@ -64,8 +65,10 @@ function it_should_send_mail(
$attachment->getFilename()->willReturn('foo.bar');
$attachment->getContentType()->willReturn('application/bar');
$attachment->getBody()->willReturn('baz');

$headers->getAll()->willReturn([]);

$mailHeader->getFieldName()->willReturn('Content-Type');
$mailHeader->getFieldBody()->willReturn('application/bar');
$headers->getAll()->willReturn([$mailHeader]);

$response->success()->willReturn(true);
$client->post(Argument::any(), Argument::any())->willReturn($response);
Expand Down Expand Up @@ -162,6 +165,68 @@ function it_should_send_mail_with_custom_vars(
]])->shouldBeCalled();
}

function it_should_send_mail_with_no_multipart_data(
Swift_Mime_SimpleMessage $message,
Client $client,
Response $response,
TemplateIdGuesserManager $manager,
\Swift_Events_EventDispatcher $dispatcher,
\Swift_Events_SendEvent $event,
\Swift_Mime_SimpleHeaderSet $headers,
\Swift_Attachment $attachment,
\Swift_Mime_Header $mailHeader
) {
$manager->guess($message)->willReturn('foo');
$message->getFrom()->willReturn(['test@foo.com' => null]);
$message->getTo()->willReturn(['to@foo.com' => null, 'bar@baz.com' => null]);
$message->getSubject()->willReturn('Mail subject');
$message->getBody()->willReturn('Mail body');
$message->getHeaders()->willReturn($headers);
$message->getChildren()->willReturn([$attachment]);

$attachment->getFilename()->willReturn('foo.bar');
$attachment->getContentType()->willReturn('multipart/alternative');
$attachment->getBody()->willReturn('baz');

$mailHeader->getFieldName()->willReturn('Content-Type');
$mailHeader->getFieldBody()->willReturn('multipart/alternative');
$headers->getAll()->willReturn([]);

$response->success()->willReturn(true);
$client->post(Argument::any(), Argument::any())->willReturn($response);

$dispatcher->createSendEvent(Argument::any(), Argument::any())->willReturn($event);
$dispatcher->dispatchEvent($event, 'beforeSendPerformed')->shouldBeCalled();
$event->bubbleCancelled()->willReturn(false);
$event->setResult(\Swift_Events_SendEvent::RESULT_SUCCESS)->shouldBeCalled();
$dispatcher->dispatchEvent($event, 'sendPerformed')->shouldBeCalled();

$this->send($message)->shouldBeEqualTo(2);

$client->post(Resources::$Email, ['body' => [
'FromEmail' => 'test@foo.com',
'Subject' => 'Mail subject',
'Vars' => ['content' => 'Mail body'],
'Recipients' => [
['Email' => 'to@foo.com', 'Name' => 'to@foo.com'],
['Email' => 'bar@baz.com', 'Name' => 'bar@baz.com'],
],
'MJ-TemplateID' => 'foo',
'MJ-TemplateLanguage' => 'True',
'Headers' => [
'MJ-TemplateErrorReporting' => 'foo@bar.com',
'MJ-TemplateErrorDeliver' => 'deliver',
],
'Attachments' => [
[
'Content-type' => 'multipart/alternative',
'Filename' => 'foo.bar',
'content' => base64_encode('baz')
],
],
]])->shouldBeCalled();
}

function it_should_send_mail_and_dispatch_failed_message(
Swift_Mime_SimpleMessage $message,
Client $client,
Expand Down