AddressStructure.class.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * AddressStructure.class.php
  4. *
  5. * Copyright (c) 2003-2004 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * This contains functions needed to handle mime messages.
  9. *
  10. * @version $Id$
  11. * @package squirrelmail
  12. */
  13. /**
  14. * Undocumented class
  15. * @package squirrelmail
  16. */
  17. class AddressStructure {
  18. var $personal = '',
  19. $adl = '',
  20. $mailbox = '',
  21. $host = '',
  22. $group = '';
  23. function getAddress($full = true, $encoded = false) {
  24. $result = '';
  25. if (is_object($this)) {
  26. $email = ($this->host ? $this->mailbox.'@'.$this->host
  27. : $this->mailbox);
  28. $personal = trim($this->personal);
  29. $is_encoded = false;
  30. if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$personal,$reg)) {
  31. $is_encoded = true;
  32. }
  33. if ($personal) {
  34. if ($encoded && !$is_encoded) {
  35. $personal_encoded = encodeHeader($personal);
  36. if ($personal !== $personal_encoded) {
  37. $personal = $personal_encoded;
  38. } else {
  39. $personal = '"'.$this->personal.'"';
  40. }
  41. } else {
  42. if (!$is_encoded) {
  43. $personal = '"'.$this->personal.'"';
  44. }
  45. }
  46. $addr = ($email ? $personal . ' <' .$email.'>'
  47. : $this->personal);
  48. $best_dpl = $this->personal;
  49. } else {
  50. $addr = $email;
  51. $best_dpl = $email;
  52. }
  53. $result = ($full ? $addr : $best_dpl);
  54. }
  55. return $result;
  56. }
  57. function getEncodedAddress() {
  58. return $this->getAddress(true, true);
  59. }
  60. }
  61. ?>