[ Index ]
 

Code source de IMP H3 (4.1.5)

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/lib/MIME/ -> Headers.php (source)

   1  <?php
   2  
   3  require_once 'Horde/MIME/Headers.php';
   4  require_once  IMP_BASE . '/lib/version.php';
   5  
   6  /**
   7   * The description of the IMP program to use in the 'User-Agent:' header.
   8   */
   9  define('IMP_AGENT_HEADER', 'Internet Messaging Program (IMP) ' . IMP_VERSION);
  10  
  11  /**
  12   * The IMP_Headers:: class contains all functions related to handling
  13   * the headers of mail messages in IMP.
  14   *
  15   * $Horde: imp/lib/MIME/Headers.php,v 1.92.2.22 2007/01/02 13:54:59 jan Exp $
  16   *
  17   * Copyright 2002-2007 Michael Slusarz <slusarz@bigworm.colorado.edu>
  18   *
  19   * See the enclosed file COPYING for license information (GPL). If you
  20   * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  21   *
  22   * @author  Michael Slusarz <slusarz@bigworm.colorado.edu>
  23   * @since   IMP 4.0
  24   * @package IMP
  25   */
  26  class IMP_Headers extends MIME_Headers {
  27  
  28      /**
  29       * The User-Agent string to use.
  30       *
  31       * @var string
  32       */
  33      var $_agent = IMP_AGENT_HEADER;
  34  
  35      /**
  36       * Returns a reference to a currently open IMAP stream.
  37       *
  38       * @see MIME_Headers::_getStream()
  39       */
  40      function &_getStream()
  41      {
  42          return $GLOBALS['imp']['stream'];
  43      }
  44  
  45      /**
  46       * Parse all of the available mailing list headers.
  47       */
  48      function parseAllListHeaders()
  49      {
  50          foreach ($this->listHeaders() as $val => $str) {
  51              $this->parseListHeaders($val);
  52          }
  53      }
  54  
  55      /**
  56       * Parse the information in the mailing list headers.
  57       *
  58       * @param string $header  The header to process.
  59       * @param boolean $raw    Should the raw URL be returned instead of setting
  60       *                        the header value?
  61       *
  62       * @return string  The header value (if $raw == true).
  63       */
  64      function parseListHeaders($header, $raw = false)
  65      {
  66          if (!($data = $this->getValue($header))) {
  67              return;
  68          }
  69  
  70          $output = '';
  71  
  72          require_once 'Horde/Text.php';
  73  
  74          /* Split the incoming data by the ',' character. */
  75          foreach (preg_split("/,/", $data) as $entry) {
  76              /* Get the data inside of the brackets. If there is no brackets,
  77                 then return the raw text. */
  78              if (!preg_match("/\<([^\>]+)\>/", $entry, $matches)) {
  79                  return trim($entry);
  80              }
  81  
  82              /* Remove all whitespace from between brackets (RFC 2369 [2]). */
  83              $match = preg_replace("/\s+/", '', $matches[1]);
  84  
  85              /* Determine if there is any comments. */
  86              preg_match("/(\(.+\))/", $entry, $comments);
  87  
  88              /* RFC 2369 [2] states that we should only show the *FIRST* URL
  89                 that appears in a header that we can adequately handle. */
  90              if (stristr($match, 'mailto:') !== false) {
  91                  $match = substr($match, strpos($match, ':') + 1);
  92                  if ($raw) {
  93                      return $match;
  94                  }
  95                  $output = Horde::link(IMP::composeLink($match)) . $match . '</a>';
  96                  if (!empty($comments[1])) {
  97                      $output .= '&nbsp;' . $comments[1];
  98                  }
  99                  break;
 100              } else {
 101                  require_once 'Horde/Text/Filter.php';
 102                  if ($url = Text_Filter::filter($match, 'linkurls', array('callback' => 'Horde::externalUrl'))) {
 103                      if ($raw) {
 104                          return $match;
 105                      }
 106                      $output = $url;
 107                      if (!empty($comments[1])) {
 108                          $output .= '&nbsp;' . $comments[1];
 109                      }
 110                      break;
 111                  } else {
 112                      /* Use this entry unless we can find a better one. */
 113                      $output = $match;
 114                  }
 115              }
 116          }
 117  
 118          $this->setValue($header, $output);
 119      }
 120  
 121      /**
 122       * Add any site-specific headers defined in config/header.php to
 123       * the internal header array.
 124       */
 125      function addSiteHeaders()
 126      {
 127          /* Add the 'User-Agent' header. */
 128          $this->addAgentHeader();
 129  
 130          /* Tack on any site-specific headers. */
 131          if (!empty($GLOBALS['conf']['msg']['prepend_header']) &&
 132              @is_readable(IMP_BASE . '/config/header.php')) {
 133              require_once IMP_BASE . '/config/header.php';
 134              foreach ($_header as $key => $val) {
 135                  $this->addHeader(trim($key), trim($val));
 136              }
 137          }
 138      }
 139  
 140      /**
 141       * Builds a string containing a list of addresses.
 142       *
 143       * @param string $field    The address field to parse.
 144       * @param integer $addURL  The self URL.
 145       * @param boolean $set     Set the associated header with the return
 146       *                         string?
 147       * @param boolean $link    Link each address to the compose screen?
 148       *
 149       * @return string  String containing the formatted address list.
 150       */
 151      function buildAddressLinks($field, $addURL, $set = false, $link = true)
 152      {
 153          global $prefs, $registry;
 154  
 155          $add_link = null;
 156  
 157          /* Make sure this is a valid object address field. */
 158          $array = $this->myGetOb($field);
 159          if (empty($array) || !is_array($array)) {
 160              return null;
 161          }
 162  
 163          /* Set up the add address icon link if contact manager is
 164             available. */
 165          if ($link &&
 166              $registry->hasMethod('contacts/import') &&
 167              $prefs->getValue('add_source')) {
 168              $add_link = Util::addParameter($addURL, 'actionID', 'add_address');
 169          }
 170  
 171          $addr_array = array();
 172  
 173          foreach ($this->getAddressesFromObject($array) as $ob) {
 174              if (!empty($ob->address) && !empty($ob->inner)) {
 175                  $ret = '';
 176  
 177                  /* If this is an incomplete e-mail address, don't link
 178                     to anything. */
 179                  if (stristr($ob->host, 'UNKNOWN') !== false) {
 180                      $ret = $ob->address;
 181                  } else {
 182                      $ret = htmlspecialchars(str_replace('\"', '"', $ob->address));
 183                      if ($link) {
 184                          $ret = Horde::link(IMP::composeLink(array('to' => addslashes($ob->address))), sprintf(_("New Message to %s"), $ob->inner)) . $ret . '</a>';
 185                      }
 186  
 187                      /* Append the add address icon to every address if
 188                         contact manager is available. */
 189                      if ($add_link) {
 190                          $curr_link = Util::addParameter($add_link, array('name' => $ob->personal,
 191                                                                           'address' => $ob->inner));
 192                          $ret .= Horde::link($curr_link, sprintf(_("Add %s to my Address Book"), $ob->inner)) .
 193                              Horde::img('addressbook_add.png', sprintf(_("Add %s to my Address Book"), $ob->inner)) . '</a>';
 194                      }
 195                  }
 196  
 197                  $addr_array[] = $ret;
 198              }
 199          }
 200  
 201          /* If left with an empty address list ($ret), inform the user that
 202             the recipient list is purposely "undisclosed". */
 203          if (empty($addr_array)) {
 204              $ret = _("Undisclosed Recipients");
 205          } else {
 206              /* Build the address line. */
 207              if (count($addr_array) > 20) {
 208                  Horde::addScriptFile('hideable.js', 'horde', true);
 209                  Horde::addScriptFile('addressesBlocks.js', 'imp');
 210              
 211                  $ret = '<div id="at_' . $field . '">' .
 212                      Horde::link('#', '', 'widget', '', 'toggleAddressesBlock(\'' . $field . '\', \'' . count($addr_array) . '\'); return false;', '', '') .
 213                      sprintf(_("[Show addresses - %s recipients]"), count($addr_array)) . '</a></div>' .
 214                      '<div id="ab_' . $field . '" style="display:none;"><span class="nowrap">' . implode(',</span> <span class="nowrap">', $addr_array) . '</span></div>';
 215              } else {
 216                  $ret = '<span class="nowrap">' . implode(',</span> <span class="nowrap">', $addr_array) . '</span>';
 217              }
 218          }
 219  
 220          /* Set the header value, if requested. */
 221          if (!empty($set)) {
 222              $this->setValue($field, $ret);
 223          }
 224  
 225          return $ret;
 226      }
 227  
 228      /**
 229       * Add the local time string to the date header.
 230       *
 231       * @param string $date  The date string.
 232       *
 233       * @return string  The date string with the local time added on.
 234       */
 235      function addLocalTime($date)
 236      {
 237          if (empty($date)) {
 238              $ltime = false;
 239          } else {
 240              $date = preg_replace('/\s+\(\w+\)$/', '', $date);
 241              $ltime = strtotime($date);
 242          }
 243          if ($ltime !== false && $ltime !== -1) {
 244              $date_str = strftime($GLOBALS['prefs']->getValue('date_format'), $ltime);
 245              $time_str = strftime($GLOBALS['prefs']->getValue('time_format'), $ltime);
 246              $tz = strftime('%Z');
 247              if ((date('Y') != @date('Y', $ltime)) ||
 248                  (date('M') != @date('M', $ltime)) ||
 249                  (date('d') != @date('d', $ltime))) {
 250                  /* Not today, use the date. */
 251                  $date .= sprintf(' <small>[%s %s %s]</small>', $date_str, $time_str, $tz);
 252              } else {
 253                  /* Else, it's today, use the time only. */
 254                  $date .= sprintf(' <small>[%s %s]</small>', $time_str, $tz);
 255              }
 256          }
 257  
 258          return $date;
 259      }
 260  
 261      /**
 262       * Get a header from the header object.
 263       *
 264       * @since IMP 4.1
 265       *
 266       * @param string $field  The header to return as an object.
 267       *
 268       * @return mixed  The field requested.
 269       */
 270      function myGetOb($field)
 271      {
 272          if (!isset($this->_obCache[$field])) {
 273              $value = $this->getValue($field);
 274              $this->_obCache[$field] = IMP::parseAddressList($value);
 275          }
 276          return $this->_obCache[$field];
 277      }
 278  
 279  }


Généré le : Thu Nov 29 12:30:07 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics