PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/ASTRA_Demo_Server/udrive/www/astra/interact/includes/pear/Mail.php

https://github.com/shafiqissani/ASTRA-College-Website
PHP | 197 lines | 71 code | 19 blank | 107 comment | 9 complexity | 2e771c6cdb992de8ea33c751cd742eac MD5 | raw file
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Chuck Hagenbuch <chuck@horde.org> |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Mail.php,v 1.2 2005/03/21 01:04:46 websterb4 Exp $
  20. require_once $CONFIG['INCLUDES_PATH'].'/pear/PEAR.php';
  21. /**
  22. * PEAR's Mail:: interface. Defines the interface for implementing
  23. * mailers under the PEAR hierarchy, and provides supporting functions
  24. * useful in multiple mailer backends.
  25. *
  26. * @access public
  27. * @version $Revision: 1.2 $
  28. * @package Mail
  29. */
  30. class Mail
  31. {
  32. /**
  33. * Line terminator used for separating header lines.
  34. * @var string
  35. */
  36. var $sep = "\r\n";
  37. /**
  38. * Provides an interface for generating Mail:: objects of various
  39. * types
  40. *
  41. * @param string $driver The kind of Mail:: object to instantiate.
  42. * @param array $params The parameters to pass to the Mail:: object.
  43. * @return object Mail a instance of the driver class or if fails a PEAR Error
  44. * @access public
  45. */
  46. function factory($driver, $params = array())
  47. {
  48. global $CONFIG;
  49. $driver = strtolower($driver);
  50. @include_once $CONFIG['INCLUDES_PATH'].'/pear/Mail/' . $driver . '.php';
  51. $class = 'Mail_' . $driver;
  52. if (class_exists($class)) {
  53. return new $class($params);
  54. } else {
  55. return PEAR::raiseError('Unable to find class for driver ' . $driver);
  56. }
  57. }
  58. /**
  59. * Implements Mail::send() function using php's built-in mail()
  60. * command.
  61. *
  62. * @param mixed $recipients Either a comma-seperated list of recipients
  63. * (RFC822 compliant), or an array of recipients,
  64. * each RFC822 valid. This may contain recipients not
  65. * specified in the headers, for Bcc:, resending
  66. * messages, etc.
  67. *
  68. * @param array $headers The array of headers to send with the mail, in an
  69. * associative array, where the array key is the
  70. * header name (ie, 'Subject'), and the array value
  71. * is the header value (ie, 'test'). The header
  72. * produced from those values would be 'Subject:
  73. * test'.
  74. *
  75. * @param string $body The full text of the message body, including any
  76. * Mime parts, etc.
  77. *
  78. * @return mixed Returns true on success, or a PEAR_Error
  79. * containing a descriptive error message on
  80. * failure.
  81. * @access public
  82. * @deprecated use Mail_mail::send instead
  83. */
  84. function send($recipients, $headers, $body)
  85. {
  86. // if we're passed an array of recipients, implode it.
  87. if (is_array($recipients)) {
  88. $recipients = implode(', ', $recipients);
  89. }
  90. // get the Subject out of the headers array so that we can
  91. // pass it as a seperate argument to mail().
  92. $subject = '';
  93. if (isset($headers['Subject'])) {
  94. $subject = $headers['Subject'];
  95. unset($headers['Subject']);
  96. }
  97. // flatten the headers out.
  98. list(,$text_headers) = Mail::prepareHeaders($headers);
  99. return mail($recipients, $subject, $body, $text_headers);
  100. }
  101. /**
  102. * Take an array of mail headers and return a string containing
  103. * text usable in sending a message.
  104. *
  105. * @param array $headers The array of headers to prepare, in an associative
  106. * array, where the array key is the header name (ie,
  107. * 'Subject'), and the array value is the header
  108. * value (ie, 'test'). The header produced from those
  109. * values would be 'Subject: test'.
  110. *
  111. * @return mixed Returns false if it encounters a bad address,
  112. * otherwise returns an array containing two
  113. * elements: Any From: address found in the headers,
  114. * and the plain text version of the headers.
  115. * @access private
  116. */
  117. function prepareHeaders($headers)
  118. {
  119. global $CONFIG;
  120. $lines = array();
  121. $from = null;
  122. foreach ($headers as $key => $value) {
  123. if ($key === 'From') {
  124. include_once $CONFIG['INCLUDES_PATH'].'/pear/Mail/RFC822.php';
  125. $addresses = Mail_RFC822::parseAddressList($value, 'localhost',
  126. false);
  127. $from = $addresses[0]->mailbox . '@' . $addresses[0]->host;
  128. // Reject envelope From: addresses with spaces.
  129. if (strstr($from, ' ')) {
  130. return false;
  131. }
  132. $lines[] = $key . ': ' . $value;
  133. } elseif ($key === 'Received') {
  134. // Put Received: headers at the top. Spam detectors often
  135. // flag messages with Received: headers after the Subject:
  136. // as spam.
  137. array_unshift($lines, $key . ': ' . $value);
  138. } else {
  139. $lines[] = $key . ': ' . $value;
  140. }
  141. }
  142. return array($from, join($this->sep, $lines) . $this->sep);
  143. }
  144. /**
  145. * Take a set of recipients and parse them, returning an array of
  146. * bare addresses (forward paths) that can be passed to sendmail
  147. * or an smtp server with the rcpt to: command.
  148. *
  149. * @param mixed Either a comma-seperated list of recipients
  150. * (RFC822 compliant), or an array of recipients,
  151. * each RFC822 valid.
  152. *
  153. * @return array An array of forward paths (bare addresses).
  154. * @access private
  155. */
  156. function parseRecipients($recipients)
  157. {
  158. global $CONFIG;
  159. include_once $CONFIG['INCLUDES_PATH'].'/pear/Mail/RFC822.php';
  160. // if we're passed an array, assume addresses are valid and
  161. // implode them before parsing.
  162. if (is_array($recipients)) {
  163. $recipients = implode(', ', $recipients);
  164. }
  165. // Parse recipients, leaving out all personal info. This is
  166. // for smtp recipients, etc. All relevant personal information
  167. // should already be in the headers.
  168. $addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false);
  169. $recipients = array();
  170. if (is_array($addresses)) {
  171. foreach ($addresses as $ob) {
  172. $recipients[] = $ob->mailbox . '@' . $ob->host;
  173. }
  174. }
  175. return $recipients;
  176. }
  177. }
  178. ?>