PageRenderTime 25ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/rucrm/log4php.debug/appenders/LoggerAppenderMailEvent.php

https://code.google.com/p/vtiger-ru-fork/
PHP | 170 lines | 68 code | 25 blank | 77 comment | 7 complexity | a41231a3433964e4215c71bc13dfa2b6 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * log4php is a PHP port of the log4j java logging package.
  4. *
  5. * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
  6. * <p>Design, strategies and part of the methods documentation are developed by log4j team
  7. * (Ceki Gülcü as log4j project founder and
  8. * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
  9. *
  10. * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
  11. * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
  12. *
  13. * <p>This software is published under the terms of the LGPL License
  14. * a copy of which has been included with this distribution in the LICENSE file.</p>
  15. *
  16. * @package log4php
  17. * @subpackage appenders
  18. */
  19. /**
  20. * @ignore
  21. */
  22. if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  23. /**
  24. */
  25. require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  26. require_once(LOG4PHP_DIR . '/LoggerLog.php');
  27. /**
  28. * Log events to an email address. It will be created an email for each event.
  29. *
  30. * <p>Parameters are
  31. * {@link $smtpHost} (optional),
  32. * {@link $port} (optional),
  33. * {@link $from} (optional),
  34. * {@link $to},
  35. * {@link $subject} (optional).</p>
  36. * <p>A layout is required.</p>
  37. *
  38. * @author Domenico Lordi <lordi@interfree.it>
  39. * @author VxR <vxr@vxr.it>
  40. * @version $Revision: 1.10 $
  41. * @package log4php
  42. * @subpackage appenders
  43. */
  44. class LoggerAppenderMailEvent extends LoggerAppenderSkeleton {
  45. /**
  46. * @var string 'from' field
  47. */
  48. var $from = null;
  49. /**
  50. * @var integer 'from' field
  51. */
  52. var $port = 25;
  53. /**
  54. * @var string hostname.
  55. */
  56. var $smtpHost = null;
  57. /**
  58. * @var string 'subject' field
  59. */
  60. var $subject = '';
  61. /**
  62. * @var string 'to' field
  63. */
  64. var $to = null;
  65. /**
  66. * @access private
  67. */
  68. var $requiresLayout = true;
  69. /**
  70. * Constructor.
  71. *
  72. * @param string $name appender name
  73. */
  74. function LoggerAppenderMailEvent($name)
  75. {
  76. $this->LoggerAppenderSkeleton($name);
  77. }
  78. function activateOptions()
  79. {
  80. $this->closed = false;
  81. }
  82. function close()
  83. {
  84. $this->closed = true;
  85. }
  86. /**
  87. * @return string
  88. */
  89. function getFrom() { return $this->from; }
  90. /**
  91. * @return integer
  92. */
  93. function getPort() { return $this->port; }
  94. /**
  95. * @return string
  96. */
  97. function getSmtpHost() { return $this->smtpHost; }
  98. /**
  99. * @return string
  100. */
  101. function getSubject() { return $this->subject; }
  102. /**
  103. * @return string
  104. */
  105. function getTo() { return $this->to; }
  106. function setFrom($from) { $this->from = $from; }
  107. function setPort($port) { $this->port = (int)$port; }
  108. function setSmtpHost($smtphost) { $this->smtpHost = $smtpHost; }
  109. function setSubject($subject) { $this->subject = $subject; }
  110. function setTo($to) { $this->to = $to; }
  111. function append($event)
  112. {
  113. $from = $this->getFrom();
  114. $to = $this->getTo();
  115. if (empty($from) or empty($to))
  116. return;
  117. $smtpHost = $this->getSmtpHost();
  118. $prevSmtpHost = ini_get('SMTP');
  119. if (!empty($smtpHost)) {
  120. ini_set('SMTP', $smtpHost);
  121. } else {
  122. $smtpHost = $prevSmtpHost;
  123. }
  124. $smtpPort = $this->getPort();
  125. $prevSmtpPort= ini_get('smtp_port');
  126. if ($smtpPort > 0 and $smtpPort < 65535) {
  127. ini_set('smtp_port', $smtpPort);
  128. } else {
  129. $smtpPort = $prevSmtpPort;
  130. }
  131. LoggerLog::debug(
  132. "LoggerAppenderMailEvent::append()" .
  133. ":from=[{$from}]:to=[{$to}]:smtpHost=[{$smtpHost}]:smtpPort=[{$smtpPort}]"
  134. );
  135. if (!@mail( $to, $this->getSubject(),
  136. $this->layout->getHeader() . $this->layout->format($event) . $this->layout->getFooter($event),
  137. "From: {$from}\r\n"
  138. )) {
  139. LoggerLog::debug("LoggerAppenderMailEvent::append() mail error");
  140. }
  141. ini_set('SMTP', $prevSmtpHost);
  142. ini_set('smtp_port', $prevSmtpPort);
  143. }
  144. }
  145. ?>