]> wagnertech.de Git - timetracker.git/commitdiff
Refactored Mailer.class.php.
authoranuko <support@anuko.com>
Sun, 5 Feb 2017 00:40:45 +0000 (00:40 +0000)
committeranuko <support@anuko.com>
Sun, 5 Feb 2017 00:40:45 +0000 (00:40 +0000)
WEB-INF/lib/mail/Mailer.class.php
WEB-INF/templates/footer.tpl

index eb4e7f9a6b840e1a501101ee2b313cc9c7e355a1..6b301be1604382ba81484c3a161c268a322e0760 100644 (file)
 <?php
-// License here
+// +----------------------------------------------------------------------+
+// | Anuko Time Tracker
+// +----------------------------------------------------------------------+
+// | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
+// +----------------------------------------------------------------------+
+// | LIBERAL FREEWARE LICENSE: This source code document may be used
+// | by anyone for any purpose, and freely redistributed alone or in
+// | combination with other software, provided that the license is obeyed.
+// |
+// | There are only two ways to violate the license:
+// |
+// | 1. To redistribute this code in source form, with the copyright
+// |    notice or license removed or altered. (Distributing in compiled
+// |    forms without embedded copyright notices is permitted).
+// |
+// | 2. To redistribute modified versions of this code in *any* form
+// |    that bears insufficient indications that the modifications are
+// |    not the work of the original author(s).
+// |
+// | This license applies to this document only, not any other software
+// | that it may be combined with.
+// |
+// +----------------------------------------------------------------------+
+// | Contributors:
+// | https://www.anuko.com/time_tracker/credits.htm
+// +----------------------------------------------------------------------+
 
 class Mailer {
-       var $mSendType;
-       var $mCharSet = "iso-8859-1";
-       var $mContentType = "text/plain";
-       var $mSender;
-       var $mReceiver;
-       var $mReceiverCC;
-
-    function __construct($type='standard') {
-       $this->mSendType = $type;
+  var $mMailMode;
+  var $mCharSet = 'iso-8859-1';
+  var $mContentType = 'text/plain';
+  var $mSender;
+  var $mReceiver;
+  var $mReceiverCC;
+
+  function __construct($type='mail') {
+    $this->mMailMode = $type;
+  }
+
+  function setSendType($value) {
+    $this->mMailMode = $value;
+  }
+
+  function setCharSet($value) {
+    $this->mCharSet = $value;
+  }
+
+  function setContentType($value) {
+    $this->mContentType = $value;
+  }
+
+  function setReceiver($value) {
+    $this->mReceiver = $value;
+  }
+
+  function setReceiverCC($value) {
+    $this->mReceiverCC = $value;
+  }
+
+  function setSender($value) {
+    $this->mSender = $value;
+  }
+
+  function send($subject, $data) {
+    $data = chunk_split(base64_encode($data));
+    $subject = Mailer::mimeEncode($subject, $this->mCharSet);
+
+    $headers = array('From' => $this->mSender, 'To' => $this->mReceiver);
+    if (isset($this->mReceiverCC)) $headers = array_merge($headers, array('CC' => $this->mReceiverCC));
+    $headers = array_merge($headers, array(
+      'Subject' => $subject,
+      'MIME-Version' => '1.0',
+      'Content-Type' => $this->mContentType.'; charset='.$this->mCharSet,
+      'Content-Transfer-Encoding' => 'BASE64'));
+
+    // PEAR::Mail
+    require_once('Mail.php');
+
+    $recipients = $this->mReceiver;
+    switch ($this->mMailMode) {
+      case 'mail':
+        $mail = Mail::factory('mail');
+        break;
+
+    case 'smtp':
+        // Mail_smtp does not do CC -> recipients conversion
+        if (!empty($this->mReceiverCC)) {
+          // make exactly one space after a comma
+          $recipients .= ', ' . preg_replace('/,[[:space:]]+/', ', ', $this->mReceiverCC);
+        }
+
+        $host = defined('MAIL_SMTP_HOST') ? MAIL_SMTP_HOST : 'localhost';
+        $port = defined('MAIL_SMTP_PORT') ? MAIL_SMTP_PORT : '25';
+        $username = defined('MAIL_SMTP_USER') ? MAIL_SMTP_USER : null;
+        $password = defined('MAIL_SMTP_PASSWORD') ? MAIL_SMTP_PASSWORD : null;
+        $auth = (defined('MAIL_SMTP_AUTH') && isTrue(MAIL_SMTP_AUTH)) ? true : false;
+        $debug = (defined('MAIL_SMTP_DEBUG') && isTrue(MAIL_SMTP_DEBUG)) ? true : false;
+
+        $mail = Mail::factory('smtp', array ('host' => $host,
+          'port' => $port,
+          'username' => $username,
+          'password' => $password,
+          'auth' => $auth,
+          'debug' => $debug));
+        break;
     }
 
-    function setSendType($value) {
-       $this->mSendType = $value;
-    }
-
-    function setCharSet($value) {
-       $this->mCharSet = $value;
-    }
+    if (defined('MAIL_SMTP_DEBUG') && isTrue(MAIL_SMTP_DEBUG))
+      PEAR::setErrorHandling(PEAR_ERROR_PRINT);
 
-    function setContentType($value) {
-       $this->mContentType = $value;
-    }
-
-    function setReceiver($value) {
-       $this->mReceiver = $value;
-    }
+    $res = $mail->send($recipients, $headers, $data);
+    return (!is_a($res, 'PEAR_Error'));
+  }
 
-    function setReceiverCC($value) {
-       $this->mReceiverCC = $value;
+  function mimeEncode($in_str, $charset) {
+    $out_str = $in_str;
+    if ($out_str && $charset) {
+      $start = '=?'.strtoupper($charset).'?B?';
+      $end = '?=';
+      $out_str = base64_encode($out_str);
+      $out_str = $start . $out_str . $end;
     }
-
-    function setSender($value) {
-       $this->mSender = $value;
-    }
-
-    function send($subject, $data) {
-       $data = chunk_split(base64_encode($data));
-       $subject = Mailer::mimeEncode($subject, $this->mCharSet);
-
-       $headers = array(
-               'From' => $this->mSender,
-               'To' => $this->mReceiver);
-       if (isset($this->mReceiverCC)) $headers = array_merge($headers, array(
-               'CC' => $this->mReceiverCC));
-       $headers = array_merge($headers, array(
-               'Subject' => $subject,
-               'MIME-Version' => '1.0',
-               'Content-Type' => $this->mContentType.'; charset='.$this->mCharSet,
-               'Content-Transfer-Encoding' => 'BASE64',
-       ));
-
-       // PEAR::Mail
-       require_once('Mail.php');
-
-       $recipients = $this->mReceiver;
-       switch ($this->mSendType) {
-               case 'mail':
-                                       $mail = Mail::factory('mail');
-                       break;
-
-               case "smtp":
-                       // Mail_smtp does not do CC -> recipients conversion
-                       if (!empty($this->mReceiverCC)) {
-                               // make exactly one space after a comma
-                               $recipients .= ', ' . preg_replace('/,[[:space:]]+/', ', ', $this->mReceiverCC);;
-                       }
-                       
-                       $host = defined('MAIL_SMTP_HOST') ? MAIL_SMTP_HOST : 'localhost';
-                       $port = defined('MAIL_SMTP_PORT') ? MAIL_SMTP_PORT : '25';
-                       $username = defined('MAIL_SMTP_USER') ? MAIL_SMTP_USER : null;
-                       $password = defined('MAIL_SMTP_PASSWORD') ? MAIL_SMTP_PASSWORD : null;
-                       $auth = (defined('MAIL_SMTP_AUTH') && isTrue(MAIL_SMTP_AUTH)) ? true : false;
-                       $debug = (defined('MAIL_SMTP_DEBUG') && isTrue(MAIL_SMTP_DEBUG)) ? true : false;
-                                               
-                       $mail = Mail::factory('smtp', array ('host' => $host,
-                         'port' => $port,
-                         'username' => $username,
-                         'password' => $password,
-                         'auth' => $auth,
-                         'debug' => $debug));
-                       break;
-       }
-       
-       if (defined('MAIL_SMTP_DEBUG') && isTrue(MAIL_SMTP_DEBUG))
-          PEAR::setErrorHandling(PEAR_ERROR_PRINT);
-       $res = $mail->send($recipients, $headers, $data);
-       return (!is_a($res, 'PEAR_Error'));
-    }
-
-    /**
-     * convert to base64-string
-     *
-     * @param string $in_str
-     * @param string $charset
-     * @return string
-     */
-    function mimeEncode($in_str, $charset) {
-          $out_str = $in_str;
-          if ($out_str && $charset) {
-
-              $end = "?=";
-              $start = "=?" . strtoupper($charset) . "?B?";
-              $spacer = $end . "\r\n " . $start;
-
-              $length = 75 - strlen($start) - strlen($end);
-              $length = floor($length/2) * 2;
-
-              $out_str = base64_encode($out_str);
-              //$out_str = Mail::encodemime($out_str,"base64");
-              //$out_str = chunk_split($out_str, $length, $spacer);
-
-              //$spacer = preg_quote($spacer);
-              //$out_str = preg_replace("/" . $spacer . "$/", "", $out_str);
-              $out_str = $start . $out_str . $end;
-          }
-          return $out_str;
-       }
-}
\ No newline at end of file
+    return $out_str;
+  }
+}
index 97662f41b08b0a8a3b3ce3e77c295be721cd780f..e787236f84710433ada268b8c401c5873bbb2b9a 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.9.36.3559 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.9.36.3560 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>