Source for file AddressStructure.class.php

Documentation is available at AddressStructure.class.php

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

Documentation generated on Sat, 07 Oct 2006 16:08:50 +0300 by phpDocumentor 1.3.0RC6