- md5
- 0aebe9874598c6c2b4a16d3d7fd4f0e4
- sha1
- 1b895411caf523bd6ae76e01b1c183a6c32c03cb
- sha256
- a5f97c9a9bdd552cc073357a7c0dd1b96647c35e8233512e8efed19f052b6181
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
<?php
/**
* @package Joomla.Site
* @subpackage com_mailto
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Mailto\Site\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\Component\Mailto\Site\Helper\MailtoHelper;
/**
* Mailer Component Controller.
*
* @package Joomla.Site
* @subpackage com_mailto
* @since 1.5
*/
class DisplayController extends BaseController
{
/**
* Show the form so that the user can send the link to someone.
*
* @return void
*
* @since 1.5
*/
public function mailto()
{
$this->app->getSession()->set('com_mailto.formtime', time());
$this->input->set('view', 'mailto');
$this->display();
}
/**
* Send the message and display a notice
*
* @return void
*
* @since 1.5
*/
public function send()
{
// Check for request forgeries
$this->checkToken();
$session = $this->app->getSession();
$timeout = $session->get('com_mailto.formtime', 0);
if ($timeout == 0 || time() - $timeout < 20)
{
$this->setMessage(\JText::_('COM_MAILTO_EMAIL_NOT_SENT'), 'notice');
return $this->mailto();
}
$SiteName = $this->app->get('sitename');
$link = MailtoHelper::validateHash($this->input->get('link', '', 'post'));
// Verify that this is a local link
if (!$link || !\JUri::isInternal($link))
{
// Non-local url...
$this->setMessage(\JText::_('COM_MAILTO_EMAIL_NOT_SENT'), 'notice');
return $this->mailto();
}
// An array of email headers we do not want to allow as input
$headers = array (
'Content-Type:',
'MIME-Version:',
'Content-Transfer-Encoding:',
'bcc:',
'cc:'
);
// An array of the input fields to scan for injected headers
$fields = array(
'mailto',
'sender',
'from',
'subject',
);
/*
* Here is the meat and potatoes of the header injection test. We
* iterate over the array of form input and check for header strings.
* If we find one, send an unauthorized header and die.
*/
foreach ($fields as $field)
{
foreach ($headers as $header)
{
if (strpos($this->input->post->getString($field), $header) !== false)
{
throw new \Exception('', 403);
}
}
}
/*
* Free up memory
*/
unset($headers, $fields);
$email = $this->input->post->getString('mailto', '');
$sender = $this->input->post->getString('sender', '');
$from = $this->input->post->getString('from', '');
$subject_default = \JText::sprintf('COM_MAILTO_SENT_BY', $sender);
$subject = $this->input->post->getString('subject', $subject_default);
// Check for a valid to address
$error = false;
if (!$email || !\JMailHelper::isEmailAddress($email))
{
$error = \JText::sprintf('COM_MAILTO_EMAIL_INVALID', $email);
$this->app->enqueueMessage($error, 'warning');
}
// Check for a valid from address
if (!$from || !\JMailHelper::isEmailAddress($from))
{
$error = \JText::sprintf('COM_MAILTO_EMAIL_INVALID', $from);
$this->app->enqueueMessage($error, 'warning');
}
if ($error)
{
return $this->mailto();
}
// Build the message to send
$msg = \JText::_('COM_MAILTO_EMAIL_MSG');
$body = sprintf($msg, $SiteName, $sender, $from, $link);
// Clean the email data
$subject = \JMailHelper::cleanSubject($subject);
$body = \JMailHelper::cleanBody($body);
// To send we need to use punycode.
$from = \JStringPunycode::emailToPunycode($from);
$from = \JMailHelper::cleanAddress($from);
$email = \JStringPunycode::emailToPunycode($email);
// Send the email
if (\JFactory::getMailer()->sendMail($from, $sender, $email, $subject, $body) !== true)
{
$this->setMessage(\JText::_('COM_MAILTO_EMAIL_NOT_SENT'), 'notice');
return $this->mailto();
}
$this->input->set('view', 'sent');
$this->display();
}
}
No other release has this exact content. See every version of this file.