Skip to content

Commit 33a7a3e

Browse files
committed
Fix SwiftMailer use
1 parent 8970578 commit 33a7a3e

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

src/Controller/DAVController.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Symfony\Component\HttpFoundation\Response;
1313
use Symfony\Component\Routing\Annotation\Route;
1414
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
15+
use Twig\Environment as TwigEnvironment;
1516

1617
class DAVController extends AbstractController
1718
{
@@ -74,6 +75,20 @@ class DAVController extends AbstractController
7475
*/
7576
protected $em;
7677

78+
/**
79+
* The Twig engine.
80+
*
81+
* @var Twig\Environment
82+
*/
83+
protected $twig;
84+
85+
/**
86+
* The Swift_Mailer mailer service.
87+
*
88+
* @var \Swift_Mailer
89+
*/
90+
protected $mailer;
91+
7792
/**
7893
* Base URI of the server.
7994
*
@@ -95,7 +110,7 @@ class DAVController extends AbstractController
95110
*/
96111
protected $server;
97112

98-
public function __construct(BasicAuth $basicAuthBackend, UrlGeneratorInterface $router, EntityManagerInterface $entityManager, bool $calDAVEnabled = true, bool $cardDAVEnabled = true, bool $webDAVEnabled = false, ?string $inviteAddress, ?string $authMethod, ?string $authRealm, ?string $publicDir, ?string $tmpDir)
113+
public function __construct(\Swift_Mailer $mailer, TwigEnvironment $twig, BasicAuth $basicAuthBackend, UrlGeneratorInterface $router, EntityManagerInterface $entityManager, bool $calDAVEnabled = true, bool $cardDAVEnabled = true, bool $webDAVEnabled = false, ?string $inviteAddress, ?string $authMethod, ?string $authRealm, ?string $publicDir, ?string $tmpDir)
99114
{
100115
$this->calDAVEnabled = $calDAVEnabled;
101116
$this->cardDAVEnabled = $cardDAVEnabled;
@@ -109,6 +124,8 @@ public function __construct(BasicAuth $basicAuthBackend, UrlGeneratorInterface $
109124
$this->tmpDir = $tmpDir;
110125

111126
$this->em = $entityManager;
127+
$this->twig = $twig;
128+
$this->mailer = $mailer;
112129
$this->baseUri = $router->generate('dav', ['path' => '']);
113130

114131
$this->basicAuthBackend = $basicAuthBackend;
@@ -199,7 +216,7 @@ private function initServer()
199216
$this->server->addPlugin(new \Sabre\CalDAV\SharingPlugin());
200217
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
201218
if ($this->inviteAddress) {
202-
$this->server->addPlugin(new DavisIMipPlugin($this->inviteAddress));
219+
$this->server->addPlugin(new DavisIMipPlugin($this->twig, $this->mailer, $this->inviteAddress));
203220
}
204221
}
205222

src/Plugins/DavisIMipPlugin.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Sabre\CalDAV\Schedule\IMipPlugin as SabreBaseIMipPlugin;
66
use Sabre\DAV;
77
use Sabre\VObject\ITip;
8+
use Twig\Environment as TwigEnvironment;
89

910
/**
1011
* iMIP handler.
@@ -13,6 +14,20 @@ class DavisIMipPlugin extends SabreBaseIMipPlugin
1314
{
1415
const MESSAGE_ORIGIN_INDICATOR = '(via Davis)';
1516

17+
/**
18+
* The Twig engine.
19+
*
20+
* @var Twig\Environment
21+
*/
22+
protected $twig;
23+
24+
/**
25+
* The Swift_Mailer mailer service.
26+
*
27+
* @var \Swift_Mailer
28+
*/
29+
protected $mailer;
30+
1631
/**
1732
* Creates the email handler.
1833
*
@@ -21,8 +36,10 @@ class DavisIMipPlugin extends SabreBaseIMipPlugin
2136
* generally be some kind of no-reply email
2237
* address you own.
2338
*/
24-
public function __construct($senderEmail)
39+
public function __construct(TwigEnvironment $twig, \Swift_Mailer $mailer, $senderEmail)
2540
{
41+
$this->twig = $twig;
42+
$this->mailer = $mailer;
2643
$this->senderEmail = $senderEmail;
2744
}
2845

@@ -157,7 +174,7 @@ public function schedule(ITip\Message $itip)
157174
$zoom = 16;
158175
$width = 500;
159176
$height = 220;
160-
$locationImage = Swift_Image::fromPath(
177+
$locationImage = \Swift_Image::fromPath(
161178
'http://api.tiles.mapbox.com/v4'.
162179
'/mapbox.streets'.
163180
'/pin-m-star+285A98'.
@@ -212,33 +229,30 @@ public function schedule(ITip\Message $itip)
212229
];
213230

214231
$message->setBody(
215-
$this->renderView(
232+
$this->twig->render(
216233
'mails/scheduling.html.twig',
217234
$params
218235
),
219236
'text/html'
220237
)
221238
->addPart(
222-
$this->renderView(
239+
$this->twig->render(
223240
'mails/scheduling.txt.twig',
224241
$params
225242
),
226243
'text/plain'
227244
);
228245

229246
if (false === $deliveredLocally) {
230-
$bodyAsStream = new Stringbuffer\Read();
231-
$bodyAsStream->initializeWith($itip->message->serialize());
232-
233247
// Attach the event file (invite.ics)
234-
$attachment = (new Swift_Attachment())
248+
$attachment = (new \Swift_Attachment())
235249
->setFilename('invite.ics')
236250
->setContentType('text/calendar; method='.(string) $itip->method.'; charset=UTF-8')
237-
->setBody($bodyAsStream);
251+
->setBody($itip->message->serialize());
238252
$message->attach($attachment);
239253
}
240254

241-
$mailer->send($message);
255+
$this->mailer->send($message);
242256

243257
if (false === $deliveredLocally) {
244258
$itip->scheduleStatus = '1.1;Scheduling message is sent via iMip.';

0 commit comments

Comments
 (0)