<commit_before><?php
namespace AcMailer\Service\Factory;

use Zend\Mail\Transport\File;
use Zend\Mail\Transport\TransportInterface;
use Zend\Mvc\Service\ViewHelperManagerFactory;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\FactoryInterface;
use Zend\Mail\Message;
use Zend\Mail\Transport\Smtp;
use AcMailer\Service\MailService;
use AcMailer\Options\MailOptions;
use AcMailer\Exception\InvalidArgumentException;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\View\HelperPluginManager;
use Zend\View\Renderer\PhpRenderer;
use Zend\View\Renderer\RendererInterface;
use Zend\View\Resolver\AggregateResolver;
use Zend\View\Resolver\TemplateMapResolver;
use Zend\View\Resolver\TemplatePathStack;

/**
 * Creates a new MailService instance
 *
 * @author <NAME>
 * @link http://www.alejandrocelaya.com
 */
class MailServiceFactory implements FactoryInterface
{
    /**
     * @var MailOptions
     */
    protected $mailOptions;

    public function createService(ServiceLocatorInterface $sm)
    {
        $this->mailOptions = $sm->get('AcMailer\Options\MailOptions');

        // Create the service
        $message        = $this->createMessage();
        $transport      = $this->createTransport($sm);
        $renderer       = $this->createRenderer($sm);
        $mailService    = new MailService($message, $transport, $renderer);

        // Set subject
        $mailService->setSubject($this->mailOptions->getMessageOptions()->getSubject());

        // Set body, either by using a template or a raw body
        $body = $this->mailOptions->getMessageOptions()->getBody();
        if ($body->getUseTemplate()) {
            $mailService->setTemplate($body->getTemplate()->toViewModel());
        } else {
            $mailService->setBody($body->getContent(), $body->getCharset());
        }

        // Attach files
        $files = $this->mailOptions->getMessageOptions()->getAttachments()->getFiles();
        $mailService->addAttachments($files);<commit_msg>Updated MailServiceFactory to set the charset when creating an email from a template<commit_after><?php
namespace AcMailer\Service\Factory;

use Zend\Mail\Transport\File;
use Zend\Mail\Transport\TransportInterface;
use Zend\Mvc\Service\ViewHelperManagerFactory;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\FactoryInterface;
use Zend\Mail\Message;
use Zend\Mail\Transport\Smtp;
use AcMailer\Service\MailService;
use AcMailer\Options\MailOptions;
use AcMailer\Exception\InvalidArgumentException;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\View\HelperPluginManager;
use Zend\View\Renderer\PhpRenderer;
use Zend\View\Renderer\RendererInterface;
use Zend\View\Resolver\AggregateResolver;
use Zend\View\Resolver\TemplateMapResolver;
use Zend\View\Resolver\TemplatePathStack;

/**
 * Creates a new MailService instance
 *
 * @author <NAME>
 * @link http://www.alejandrocelaya.com
 */
class MailServiceFactory implements FactoryInterface
{
    /**
     * @var MailOptions
     */
    protected $mailOptions;

    public function createService(ServiceLocatorInterface $sm)
    {
        $this->mailOptions = $sm->get('AcMailer\Options\MailOptions');

        // Create the service
        $message        = $this->createMessage();
        $transport      = $this->createTransport($sm);
        $renderer       = $this->createRenderer($sm);
        $mailService    = new MailService($message, $transport, $renderer);

        // Set subject
        $mailService->setSubject($this->mailOptions->getMessageOptions()->getSubject());

        // Set body, either by using a template or a raw body
        $body = $this->mailOptions->getMessageOptions()->getBody();
        if ($body->getUseTemplate()) {
            $mailService->setTemplate($body->getTemplate()->toViewModel(), ['charset' => $body->getCharset()]);
        } else {
            $mailService->setBody($body->getContent(), $body->getCharset());
        }

        // Attach files
        $files = $this->mailOptions->getMessageOptions()->getAttachments()->getFiles();
        $mailService->addAttachments($files);
{'fraction_non_alphanumeric': 0.12777115613825984, 'fraction_numerical': 0.0, 'mean_word_length': 3.7954285714285714, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4812411', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1134, 'n_words': 219}