AddressStructure.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * AddressStructure.class.php
  4. *
  5. * This file contains functions needed to extract email address headers from
  6. * mime messages.
  7. *
  8. * @copyright &copy; 2003-2007 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id$
  11. * @package squirrelmail
  12. * @subpackage mime
  13. * @since 1.3.2
  14. */
  15. /**
  16. * Class used to work with email address headers
  17. * @package squirrelmail
  18. * @subpackage mime
  19. * @since 1.3.2
  20. */
  21. class AddressStructure {
  22. /**
  23. * Personal information
  24. * @var string
  25. */
  26. var $personal = '';
  27. /**
  28. * @todo check use of this variable. var is not used in class.
  29. * @var string
  30. */
  31. var $adl = '';
  32. /**
  33. * Mailbox name.
  34. * @var string
  35. */
  36. var $mailbox = '';
  37. /**
  38. * Server address.
  39. * @var string
  40. */
  41. var $host = '';
  42. /**
  43. * @todo check use of this variable. var is not used in class.
  44. * @var string
  45. */
  46. var $group = '';
  47. /**
  48. * Return address information from mime headers.
  49. * @param boolean $full return full address (true) or only personal if it exists, otherwise email (false)
  50. * @param boolean $encoded (since 1.4.0) return rfc2047 encoded address (true) or plain text (false).
  51. * @return string
  52. */
  53. function getAddress($full = true, $encoded = false) {
  54. $result = '';
  55. if (is_object($this)) {
  56. $email = ($this->host ? $this->mailbox.'@'.$this->host
  57. : $this->mailbox);
  58. $personal = trim($this->personal);
  59. $is_encoded = false;
  60. if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$personal,$reg)) {
  61. $is_encoded = true;
  62. }
  63. if ($personal) {
  64. if ($encoded && !$is_encoded) {
  65. $personal_encoded = encodeHeader($personal);
  66. if ($personal !== $personal_encoded) {
  67. $personal = $personal_encoded;
  68. } else {
  69. $personal = '"'.$this->personal.'"';
  70. }
  71. } else {
  72. if (!$is_encoded) {
  73. $personal = '"'.$this->personal.'"';
  74. }
  75. }
  76. $addr = ($email ? $personal . ' <' .$email.'>'
  77. : $this->personal);
  78. $best_dpl = $this->personal;
  79. } else {
  80. $addr = $email;
  81. $best_dpl = $email;
  82. }
  83. $result = ($full ? $addr : $best_dpl);
  84. }
  85. return $result;
  86. }
  87. /**
  88. * Shorter version of getAddress() function
  89. * Returns full encoded address.
  90. * @return string
  91. * @since 1.4.0
  92. */
  93. function getEncodedAddress() {
  94. return $this->getAddress(true, true);
  95. }
  96. /**
  97. * Return just the email portion of this address
  98. * @return string
  99. * @since 1.5.2
  100. */
  101. function getEmail () {
  102. $r = '';
  103. if (is_object($this)) {
  104. $r = $this->host ? $this->mailbox.'@'.$this->host : $this->mailbox;
  105. }
  106. return $r;
  107. }
  108. }