AbstractTransport.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Abstract send email
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package cake.libs.email
  16. * @since CakePHP(tm) v 2.0.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. /**
  20. * Abstract class
  21. *
  22. * @package cake.libs.email
  23. */
  24. abstract class AbstractTransport {
  25. /**
  26. * Configurations
  27. *
  28. * @var array
  29. */
  30. protected $_config = array();
  31. /**
  32. * Send mail
  33. *
  34. * @params object $email CakeEmail
  35. * @return boolean
  36. */
  37. abstract public function send(CakeEmail $email);
  38. /**
  39. * Set the config
  40. *
  41. * @param array $config
  42. * @return object $this
  43. */
  44. public function config($config = array()) {
  45. if (!empty($config)) {
  46. $this->_config = $config;
  47. }
  48. }
  49. /**
  50. * Help to convert headers in string
  51. *
  52. * @param array $headers Headers in format key => value
  53. * @param string $eol
  54. * @return string
  55. */
  56. protected function _headersToString($headers, $eol = "\r\n") {
  57. $out = '';
  58. foreach ($headers as $key => $value) {
  59. if ($value === false || $value === null || $value === '') {
  60. continue;
  61. }
  62. $out .= $key . ': ' . $value . $eol;
  63. }
  64. if (!empty($out)) {
  65. $out = substr($out, 0, -1 * strlen($eol));
  66. }
  67. return $out;
  68. }
  69. }