public function emailSendingAction()

in pp3/module/Application/src/Application/Controller/AdminController.php [347:469]


    public function emailSendingAction() {
        $this->_checkAdminUser();
        $req = $this->request;
        $successMessage = false;

        $onlyVerified = false;
        $nbVersionId = [];
        $subject = '[NetBeans PluginPortal] Check your plugin with the new Apache NetBeans <version>!';
        $emailText = '
<html>
<head><title></title></head>
<body>
<p>Hey %1$s,</p>

<p>
have you heard of the new Apache NetBeans version on the horizon?
Yes, the NetBeans community is going to release version <version> soon!
In order to have your great plugin(s) available on the NetBeans Update
Center also for users of the new version please consider testing the
plugin(s) with the latest RC build and possibly submit new verification
request(s) via the Plugin Portal website.
</p>

<p>
Your plugins:<br />
%3$s
</p>

<p>Direct link to the list of your plugins:<br />
<a href="%2$s/plugin/list">%2$s/plugin/list</a>
</p>

<p>
Thanks for your contribution and ongoing support!<br />
Apache NetBeans Plugin Portal Administrator
</p>

<p>P.S.: Please contact dev@netbeans.apache.org mailing list for any questions.</p>
</body>
</html>';

        if ($req->isPost() && ($this->params()->fromPost('sendEmail') || $this->params()->fromPost('sendPreview'))) {
            $successMessage = '';
            $onlyVerified = $this->params()->fromPost('onlyVerified');
            $nbVersionId = $this->params()->fromPost('nbVersionId');
            $subject = $this->params()->fromPost('subject');
            $emailText = $this->params()->fromPost('emailText');

            $users = [];

            $plugins = $this->_pluginRepository
                    ->getPluginsByNetBeansVersion($nbVersionId, $onlyVerified);

            foreach ($plugins as $plugin) {
                foreach ($plugin->getAuthors() as $author) {
                    $email = $author->getEmail();
                    if (!array_key_exists($email, $users)) {
                        $users[$email] = [
                            'email' => $email,
                            'name' => $author->getName(),
                            'plugins' => []
                        ];
                    }
                    if (!in_array($plugin->getName(), $users[$email]['plugins'])) {
                        $users[$email]['plugins'][] = $plugin->getName();
                    }
                }
            }

            $successMessage .= sprintf("Generating E-Mails for %d plugins and %d users<br>\n",
                    count($plugins),
                    count($users));

            if ($this->params()->fromPost('sendPreview')) {
                $successMessage .= "Only sending preview email!<br>\n";

                /**
                 * @var \Application\Entity\User
                 */
                $user = $this->_userRepository->find($this->getAuthenticatedUserId());
                $users = [$user->getEmail() => [
                    'email' => $user->getEmail(),
                    'name' => $user->getName(),
                    'plugins' => ['Demo plugin 1', 'Demo plugin 2']
                ]];
            }

            $transport = new Mail\Transport\Sendmail();

            $emailCount = 0;
            foreach (array_values(($users)) as $entry) {
                $emailCount++;
                $list = "<ul>";
                foreach($entry['plugins'] as $pluginName) {
                    $list .= sprintf("<li>%s</li>", htmlspecialchars($pluginName));
                }
                $list .= "</ul>";

                $mail = new Mail\Message();
                $mail->setFrom('noreply@netbeans.apache.org', 'NetBeans webmaster');
                $mail->setSubject($subject);
                $mail->getHeaders()->addHeader(ContentType::fromString('Content-Type: text/html; charset=utf-8'));
                $htmlBody = str_replace(
                    ['%1$s', '%2$s', '%3$s'],
                    [htmlspecialchars($entry['name']), htmlspecialchars($this->getHomeUrl()), $list],
                    $emailText
                );
                $mail->setBody($htmlBody);
                $mail->addTo($entry['email']);
                $transport->send($mail);
            }

            $successMessage .= "E-Mails were successfully sent: " . $emailCount;
        }
        return new ViewModel([
            'onlyVerified' => $onlyVerified,
            'nbVersionId' => $nbVersionId === null ? [] : $nbVersionId,
            'subject' => $subject,
            'emailText' => $emailText,
            'successMessage' => $successMessage,
            'nbVersions' => $this->_nbVersionRepository->findAll()
        ]);
    }