diff --git a/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php b/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php index 95e1519d7a085ea8b1924d13de25d4fda9887b99..d516bc7025f98c32baf7731aa7cfec5062ad6551 100644 --- a/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php +++ b/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php @@ -30,9 +30,10 @@ namespace finc\Controller; //use ZfcRbac\Service\AuthorizationServiceAwareInterface as AuthorizationServiceAwareInterface; //use ZfcRbac\Service\AuthorizationServiceAwareTrait as AuthorizationServiceAwareTrait; -use finc\Exception\DDS as DDSException; -use finc\Mailer\Mailer as Mailer; -use Zend\Validator as Validator; +use finc\Exception\DDS as DDSException, + finc\Mailer\Mailer as Mailer, + Zend\Mail\Address as Address, + Zend\Validator as Validator; /** * Controller for Document Delivery Service @@ -55,7 +56,7 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase * @var $config * @access protected */ - protected $config = array(); + protected $config = []; /** * Departments @@ -63,7 +64,7 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase * @var $department * @access protected */ - protected $department = array(); + protected $department = []; /** * Divisions @@ -71,7 +72,7 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase * @var $division * @access protected */ - protected $division = array(); + protected $division = []; /** * HTTP client @@ -107,7 +108,7 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase * @var $content * @access protected */ - protected $content = array(); + protected $content = []; /** * Build department taxonomy for options of select box. @@ -225,8 +226,7 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase $mailer->sendTextHtml( $email['to'], $email['from'], - $email['reply'], - $email['replyname'], + new Address($email['reply'], $email['replyname']), $email['subject'], '', //$bodyHtml, $email['body'] diff --git a/module/finc/src/finc/Controller/EmailHoldTrait.php b/module/finc/src/finc/Controller/EmailHoldTrait.php index 7b06d4146e36ea15feff7c850194bb65670b6ca7..159eefdd2c3a27df6118392ac75707031e083014 100644 --- a/module/finc/src/finc/Controller/EmailHoldTrait.php +++ b/module/finc/src/finc/Controller/EmailHoldTrait.php @@ -28,7 +28,8 @@ * @link https://vufind.org Main Site */ namespace finc\Controller; -use finc\Mailer\Mailer as Mailer; +use finc\Mailer\Mailer as Mailer, + Zend\Mail\Address as Address; /** * Email Hold trait (for subclasses of AbstractRecord) @@ -159,8 +160,12 @@ trait EmailHoldTrait $details['patron']['firstname'] . " | Signatur: " . $details['callnumber']; - $from = (isset($details['patron']['email'])) ? $details['patron']['email'] : $emailProfile->from ; - $to = $emailProfile->to; + $from = $reply = (isset($details['patron']['email'])) + ? new Address( + $details['patron']['email'], + $details['patron']['firstname'] . ' ' . $details['patron']['lastname'] + ) : new Address($emailProfile->from) ; + $to = new Address($emailProfile->to); // Get mailer $mailer = new Mailer( $this->getServiceLocator() @@ -170,8 +175,7 @@ trait EmailHoldTrait $mailer->sendTextHtml( $to, $from, - $from, - '', + $reply, $subject, $bodyHtml, $bodyPlain diff --git a/module/finc/src/finc/Controller/MyResearchController.php b/module/finc/src/finc/Controller/MyResearchController.php index 4f0885961f1b20b3c73788f92683d9446614e302..9b5233cc3cf5214fc812df0f475ae61d2ea544a0 100644 --- a/module/finc/src/finc/Controller/MyResearchController.php +++ b/module/finc/src/finc/Controller/MyResearchController.php @@ -27,9 +27,11 @@ */ namespace finc\Controller; -use Zend\Validator\StringLength, +use finc\Mailer\Mailer, + VuFind\Exception\Mail as MailException, Zend\I18n\Validator\IsInt, - finc\Mailer\Mailer; + Zend\Mail\Address, + Zend\Validator\StringLength; /** * Controller for the user account area. @@ -168,25 +170,26 @@ class MyResearchController extends \VuFind\Controller\MyResearchController ) : $this->translate('PDA::pda_form_title') ); + $from_unknown = (isset($config->Acquisition->from_unknown) ? $config->Acquisition->from_unknown : ''); - $from = (isset($user->email) - ? $user->email : $from_unknown); - $to = (isset($config->Acquisition->to) - ? $config->Acquisition->to : ''); + $from = $reply = (isset($user->email)) + ? new Address($user->email, $user->firstname . ' ' . $user->lastname) + : new Address($from_unknown); + + $to = (isset($config->Acquisition->to)) + ? new Address($config->Acquisition->to) + : ''; + $mailer = new Mailer( $this->getServiceLocator() ->get('VuFind\Mailer')->getTransport() ); - - $reply_to = $from; - $reply_to_name = $user->firstname . ' ' . $user->lastname; - + $mailer->sendTextHtml( $to, $from, - $reply_to, - $reply_to_name, + $reply, $subject, $message_html, $message_text diff --git a/module/finc/src/finc/Controller/PdaTrait.php b/module/finc/src/finc/Controller/PdaTrait.php index 1110c535e53de21bd132136192724bdf92e8ca36..afe96d669ccb485db254990369d3c0877c7aee11 100644 --- a/module/finc/src/finc/Controller/PdaTrait.php +++ b/module/finc/src/finc/Controller/PdaTrait.php @@ -30,6 +30,7 @@ */ namespace finc\Controller; use VuFind\Exception\Mail as MailException, + Zend\Mail\Address, Zend\Validator\StringLength, Zend\Validator\Identical, finc\Mailer\Mailer; @@ -221,11 +222,9 @@ trait PdaTrait ) : $this->translate('PDA::Acquisition'); // Set reply address and name if available - $replyTo = isset($params['email']) ? $params['email'] : ''; - $replyToName - = (isset($params['firstname']) && isset($params['lastname'])) && !empty($replyTo) - ? $params['firstname'] . ' ' . $params['lastname'] - : ''; + $reply = (isset($params['email'], $params['firstname'], $params['lastname'])) + ? new Address($params['email'], $params['firstname'] . ' ' . $params['lastname']) + : null; // Get mailer $mailer = new Mailer( @@ -235,10 +234,9 @@ trait PdaTrait // Send the email $mailer->sendTextHtml( - $emailProfile->to, - $emailProfile->from, - $replyTo, - $replyToName, + new Address($emailProfile->to), + new Address($emailProfile->from), + $reply, $subject, $bodyHtml, $bodyPlain diff --git a/module/finc/src/finc/Mailer/Mailer.php b/module/finc/src/finc/Mailer/Mailer.php index 3c823d40f6fbd2e35048c96b10a718d437147745..6e85383393221092239d421f6d7961a468e94931 100644 --- a/module/finc/src/finc/Mailer/Mailer.php +++ b/module/finc/src/finc/Mailer/Mailer.php @@ -27,6 +27,8 @@ */ namespace finc\Mailer; use VuFind\Exception\Mail as MailException, + Zend\Mail\Address, + Zend\Mail\AddressList, Zend\Mail\Message, Zend\Mime\Message as MimeMessage, Zend\Mime\Part as MimePart, @@ -59,26 +61,49 @@ class Mailer extends \VuFind\Mailer\Mailer /** * Send an email message. * - * @param string $to Recipient email address - * @param string $from Sender email address - * @param string $reply reply email address - * @param string $subject Subject line for message - * @param string $body Message body + * @param string|Address|AddressList $to Recipient email address (or + * delimited list) + * @param string|Address $from Sender name and email address + * @param string|Address $reply Reply name and email address + * @param string $subject Subject line for message + * @param string $body_html HTML message body + * @param string $body_text Plain text message body * * @throws MailException * @return void */ - public function sendTextHtml($to, $from, $reply, $reply_name, $subject, $body_html, $body_text) - { - // Validate sender and recipient + public function sendTextHtml($to, $from, $reply, $subject, $body_html, + $body_text + ) { + if ($to instanceof AddressList) { + $recipients = $to; + } else if ($to instanceof Address) { + $recipients = new AddressList(); + $recipients->add($to); + } else { + $recipients = $this->stringToAddressList($to); + } + + // Validate email addresses: $validator = new \Zend\Validator\EmailAddress(); - if (!$validator->isValid($to)) { + if (count($recipients) == 0) { throw new MailException('Invalid Recipient Email Address'); } - if (!$validator->isValid($from)) { + foreach ($recipients as $current) { + if (!$validator->isValid($current->getEmail())) { + throw new MailException('Invalid Recipient Email Address'); + } + } + + $fromEmail = ($from instanceof Address) + ? $from->getEmail() : $from; + if (!$validator->isValid($fromEmail)) { throw new MailException('Invalid Sender Email Address'); } - if (!empty($reply) && !$validator->isValid($reply)) { + + $replyEmail = ($reply instanceof Address) + ? $reply->getEmail() : $reply; + if (!empty($reply) && !$validator->isValid($replyEmail)) { throw new MailException('Invalid Reply Email Address'); } @@ -105,12 +130,12 @@ class Mailer extends \VuFind\Mailer\Mailer $message = $this->getNewTextHtmlMessage() ->addFrom($from) - ->addTo($to) + ->addTo($recipients) ->setBody($mimeBody) ->setSubject($subject); if (!empty($reply)) { - $message->addReplyTo($reply, !empty($reply_name) ? $reply_name : null); + $message->addReplyTo($reply); } $message->getHeaders()