Source for file controller.php

Documentation is available at controller.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_mailto
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * @package     Joomla.Site
  14.  * @subpackage  com_mailto
  15.  * @since       1.5
  16.  */
  17. {
  18.     /**
  19.      * Show the form so that the user can send the link to someone
  20.      *
  21.      * @access public
  22.      * @since 1.5
  23.      */
  24.     public function mailto()
  25.     {
  26.         $session JFactory::getSession();
  27.         $session->set('com_mailto.formtime'time());
  28.         $this->input->set('view''mailto');
  29.         $this->display();
  30.     }
  31.  
  32.     /**
  33.      * Send the message and display a notice
  34.      *
  35.      * @access public
  36.      * @since 1.5
  37.      */
  38.     public function send()
  39.     {
  40.         // Check for request forgeries
  41.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  42.  
  43.         $app     JFactory::getApplication();
  44.         $session JFactory::getSession();
  45.  
  46.         $timeout $session->get('com_mailto.formtime'0);
  47.         if ($timeout == || time($timeout 20)
  48.         {
  49.             JError::raiseNotice(500JText::_('COM_MAILTO_EMAIL_NOT_SENT'));
  50.             return $this->mailto();
  51.         }
  52.  
  53.         $SiteName $app->getCfg('sitename');
  54.  
  55.         $link     MailtoHelper::validateHash($this->input->get('link''''post'));
  56.  
  57.         // Verify that this is a local link
  58.         if (!$link || !JUri::isInternal($link))
  59.         {
  60.             //Non-local url...
  61.             JError::raiseNotice(500JText::_('COM_MAILTO_EMAIL_NOT_SENT'));
  62.             return $this->mailto();
  63.         }
  64.  
  65.         // An array of email headers we do not want to allow as input
  66.         $headers array (    'Content-Type:',
  67.                             'MIME-Version:',
  68.                             'Content-Transfer-Encoding:',
  69.                             'bcc:',
  70.                             'cc:');
  71.  
  72.         // An array of the input fields to scan for injected headers
  73.         $fields array(
  74.             'mailto',
  75.             'sender',
  76.             'from',
  77.             'subject',
  78.         );
  79.  
  80.         /*
  81.          * Here is the meat and potatoes of the header injection test.  We
  82.          * iterate over the array of form input and check for header strings.
  83.          * If we find one, send an unauthorized header and die.
  84.          */
  85.         foreach ($fields as $field)
  86.         {
  87.             foreach ($headers as $header)
  88.             {
  89.                 if (strpos($_POST[$field]$header!== false)
  90.                 {
  91.                     JError::raiseError(403'');
  92.                 }
  93.             }
  94.         }
  95.  
  96.         /*
  97.          * Free up memory
  98.          */
  99.         unset ($headers$fields);
  100.  
  101.         $email           $this->input->post->getString('mailto''');
  102.         $sender          $this->input->post->getString('sender''');
  103.         $from            $this->input->post->getString('from''');
  104.         $subject_default JText::sprintf('COM_MAILTO_SENT_BY'$sender);
  105.         $subject         $this->input->post->getString('subject'$subject_default);
  106.  
  107.         // Check for a valid to address
  108.         $error    false;
  109.         if ($email  || JMailHelper::isEmailAddress($email))
  110.         {
  111.             $error    JText::sprintf('COM_MAILTO_EMAIL_INVALID'$email);
  112.             JError::raiseWarning(0$error);
  113.         }
  114.  
  115.         // Check for a valid from address
  116.         if ($from || JMailHelper::isEmailAddress($from))
  117.         {
  118.             $error    JText::sprintf('COM_MAILTO_EMAIL_INVALID'$from);
  119.             JError::raiseWarning(0$error);
  120.         }
  121.  
  122.         if ($error)
  123.         {
  124.             return $this->mailto();
  125.         }
  126.  
  127.         // Build the message to send
  128.         $msg    JText::_('COM_MAILTO_EMAIL_MSG');
  129.  
  130.         $link $link;
  131.         $body    sprintf($msg$SiteName$sender$from$link);
  132.  
  133.         // Clean the email data
  134.         $subject JMailHelper::cleanSubject($subject);
  135.         $body     JMailHelper::cleanBody($body);
  136.  
  137.         // To send we need to use punycode.
  138.         $from JStringPunycode::emailToPunycode($from);
  139.         $from     JMailHelper::cleanAddress($from);
  140.         $email JStringPunycode::emailToPunycode($email);
  141.  
  142.         // Send the email
  143.         if (JFactory::getMailer()->sendMail($from$sender$email$subject$body!== true)
  144.         {
  145.             JError::raiseNotice(500JText::_('COM_MAILTO_EMAIL_NOT_SENT'));
  146.             return $this->mailto();
  147.         }
  148.  
  149.         $this->input->set('view''sent');
  150.         $this->display();
  151.     }
  152. }

Documentation generated on Tue, 19 Nov 2013 14:57:31 +0100 by phpDocumentor 1.4.3