function index(Request $request, Application $app)
 {
     $sendemail = new SendEmailModel();
     $sendemail->setSiteId($app['currentSite']->getId());
     $sendemail->setTimezone($app['currentTimeZone']);
     $form = $app['form.factory']->create(new SendEmailNewForm(), $sendemail);
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         $sendemail->setSendTo($request->request->get('send_to') == 'other' ? $request->request->get('send_to_other') : $request->request->get('send_to'));
         if (!filter_var($sendemail->getSendTo(), FILTER_VALIDATE_EMAIL)) {
             $form->addError(new FormError('Please enter an email address'));
         }
         if ($form->isValid()) {
             $sendemail->buildEvents($app);
             $repository = new SendEmailRepository();
             $repository->create($sendemail, $app['currentSite'], $app['currentUser']);
             return $app->redirect("/admin/sendemail/" . $sendemail->getSlug());
         }
     }
     $emails = array($app['currentUser']->getEmail());
     $rb = new SendEmailRepositoryBuilder();
     $rb->setSite($app['currentSite']);
     $rb->setUserCreatedBy($app['currentUser']);
     foreach ($rb->fetchAll() as $sendemail) {
         if (!in_array($sendemail->getSendTo(), $emails)) {
             $emails[] = $sendemail->getSendTo();
         }
     }
     return $app['twig']->render('site/sendemailnew/index.html.twig', array('form' => $form->createView(), 'emails' => $emails));
 }
 function show($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Email does not exist.");
     }
     if ($request->request->get('actionSend') && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) {
         $this->parameters['sendemail']->send($app, $app['currentUser']);
         $sec = new SendEmailRepository();
         $sec->markSent($this->parameters['sendemail'], $app['currentUser']);
         return $app->redirect("/admin/sendemail/" . $this->parameters['sendemail']->getSlug());
     }
     if ($request->request->get('actionDiscard') && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) {
         // TODO
     }
     return $app['twig']->render('site/sendemail/show.html.twig', $this->parameters);
 }