Changeset 2358 in subversion


Ignore:
Timestamp:
Mar 17, 2009 5:40:43 PM (4 years ago)
Author:
thomasb
Message:

Add hooks to fetch and display additional headers + use html wrapper functions

Location:
branches/devel-api
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-api/plugins/additional_message_headers/additional_message_headers.php

    r2290 r2358  
    2323class additional_message_headers extends rcube_plugin 
    2424{ 
    25  
     25    public $task = 'mail'; 
     26     
    2627    function init() 
    2728    { 
  • branches/devel-api/program/include/rcube_imap.php

    r2329 r2358  
    5555  var $default_folders = array('INBOX'); 
    5656  var $default_folders_lc = array('inbox'); 
     57  var $fetch_add_headers = ''; 
    5758  var $cache = array(); 
    5859  var $cache_keys = array();   
     
    782783     
    783784    // fetch reuested headers from server 
    784     $a_header_index = iil_C_FetchHeaders($this->conn, $mailbox, $msgs); 
     785    $a_header_index = iil_C_FetchHeaders($this->conn, $mailbox, $msgs, false, $this->fetch_add_headers); 
    785786    $deleted_count = 0; 
    786787     
     
    836837          $this->search('', $this->search_string, $this->search_charset, $this->sort_field); 
    837838 
    838         if ($this->sort_order == 'DESC') 
     839        if ($this->sort_order == 'DESC') 
    839840          $this->cache[$key] = array_reverse($this->search_set); 
    840         else 
    841           $this->cache[$key] = $this->search_set; 
     841        else 
     842          $this->cache[$key] = $this->search_set; 
    842843        } 
    843844      else 
    844845        { 
    845         $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, join(',', $this->search_set), $this->sort_field); 
     846        $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, join(',', $this->search_set), $this->sort_field, false); 
    846847 
    847848        if ($this->sort_order=="ASC") 
     
    930931 
    931932      // fetch complete headers and add to cache 
    932       $headers = iil_C_FetchHeader($this->conn, $mailbox, $id); 
     933      $headers = iil_C_FetchHeader($this->conn, $mailbox, $id, false, $this->fetch_add_headers); 
    933934      $this->add_message_cache($cache_key, $headers->id, $headers); 
    934935      } 
     
    10671068      return $headers; 
    10681069 
    1069     $headers = iil_C_FetchHeader($this->conn, $mailbox, $id, $is_uid); 
     1070    $headers = iil_C_FetchHeader($this->conn, $mailbox, $id, $is_uid, $this->fetch_add_headers); 
    10701071 
    10711072    // write headers cache 
     
    22242225      { 
    22252226      // get highest index 
    2226       $header = iil_C_FetchHeader($this->conn, $mailbox, "$msg_count"); 
     2227      $header = iil_C_FetchHeader($this->conn, $mailbox, "$msg_count", false, $this->fetch_add_headers); 
    22272228      $cache_uid = array_pop($cache_index); 
    22282229       
     
    22742275        // featch headers if unserialize failed 
    22752276        if (empty($this->cache[$cache_key][$uid])) 
    2276           $this->cache[$cache_key][$uid] = iil_C_FetchHeader($this->conn, preg_replace('/.msg$/', '', $key), $uid, true); 
     2277          $this->cache[$cache_key][$uid] = iil_C_FetchHeader($this->conn, preg_replace('/.msg$/', '', $key), $uid, true, $this->fetch_add_headers); 
    22772278        } 
    22782279      } 
  • branches/devel-api/program/include/rcube_plugin_api.php

    r2354 r2358  
    3333  public $output; 
    3434   
    35   private $handlers = array(); 
     35  public $handlers = array(); 
    3636  private $plugins = array(); 
    3737  private $actions = array(); 
     
    143143     
    144144    // maybe also register a shudown function which triggers shutdown functions of all plugin objects 
     145     
     146     
     147    // call imap_init right now 
     148    // (should actually be done in rcmail::imap_init() but plugins are not initialized then) 
     149    if ($rcmail->imap) { 
     150      $hook = $this->exec_hook('imap_init', array('fetch_headers' => $rcmail->imap->fetch_add_headers)); 
     151      if ($hook['fetch_headers']) 
     152        $rcmail->imap->fetch_add_headers = $hook['fetch_headers']; 
     153    } 
    145154  } 
    146155   
  • branches/devel-api/program/lib/imap.inc

    r2185 r2358  
    177177        var $junk = false; 
    178178        var $flagged = false; 
     179        var $others = array(); 
    179180} 
    180181 
     
    16181619} 
    16191620 
    1620 function iil_C_FetchHeaders(&$conn, $mailbox, $message_set, $uidfetch=false) 
     1621function iil_C_FetchHeaders(&$conn, $mailbox, $message_set, $uidfetch=false, $add='') 
    16211622{ 
    16221623        global $IMAP_USE_INTERNAL_DATE; 
     
    16651666        $request .= "(DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC BCC "; 
    16661667        $request .= "CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID "; 
    1667         $request .= "REFERENCES DISPOSITION-NOTIFICATION-TO X-PRIORITY)])"; 
     1668        $request .= "REFERENCES DISPOSITION-NOTIFICATION-TO X-PRIORITY ".strtoupper($add).")])"; 
    16681669 
    16691670        if (!iil_PutLine($fp, $request)) { 
     
    18131814                                         
    18141815                                        $field  = strtolower($field); 
    1815                                         $string = ereg_replace("\n[[:space:]]*"," ",$string);  
     1816                                        $string = ereg_replace("\n[[:space:]]*"," ",$string); 
    18161817                                         
    18171818                                        switch ($field) { 
     
    18711872                                                        $result[$id]->priority = intval($matches[1]); 
    18721873                                                break; 
     1874                                        default: 
     1875                                                if (strlen($field) > 2) 
     1876                                                        $result[$id]->others[$field] = $string; 
     1877                                                break; 
    18731878                                        } // end switch () 
    18741879                                } // end while () 
     
    18881893} 
    18891894 
    1890 function iil_C_FetchHeader(&$conn, $mailbox, $id, $uidfetch=false) { 
    1891  
    1892         $a  = iil_C_FetchHeaders($conn, $mailbox, $id, $uidfetch); 
     1895function iil_C_FetchHeader(&$conn, $mailbox, $id, $uidfetch=false, $add='') { 
     1896 
     1897        $a  = iil_C_FetchHeaders($conn, $mailbox, $id, $uidfetch, $add); 
    18931898        if (is_array($a)) { 
    18941899                return array_shift($a); 
  • branches/devel-api/program/steps/mail/func.inc

    r2336 r2358  
    815815function rcmail_message_headers($attrib, $headers=NULL) 
    816816  { 
    817   global $IMAP, $OUTPUT, $MESSAGE, $PRINT_MODE, $CONFIG; 
     817  global $IMAP, $OUTPUT, $MESSAGE, $PRINT_MODE, $RCMAIL; 
    818818  static $sa_attrib; 
    819819   
     
    824824    $attrib = $sa_attrib; 
    825825   
    826    
    827826  if (!isset($MESSAGE)) 
    828827    return FALSE; 
     
    832831    $headers = is_object($MESSAGE->headers) ? get_object_vars($MESSAGE->headers) : $MESSAGE->headers; 
    833832     
    834   $header_count = 0; 
    835    
    836   // allow the following attributes to be added to the <table> tag 
    837   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary')); 
    838   $out = '<table' . $attrib_str . ">\n"; 
    839  
    840833  // show these headers 
    841834  $standard_headers = array('subject', 'from', 'to', 'cc', 'bcc', 'replyto', 'date'); 
    842  
    843   foreach ($standard_headers as $hkey) 
    844     { 
     835  $output_headers = array(); 
     836 
     837  foreach ($standard_headers as $hkey) { 
    845838    if (!$headers[$hkey]) 
    846839      continue; 
    847840 
    848     if ($hkey == 'date') 
    849       { 
     841    if ($hkey == 'date') { 
    850842      if ($PRINT_MODE) 
    851         $header_value = format_date($headers[$hkey], $CONFIG['date_long'] ? $CONFIG['date_long'] : 'x'); 
     843        $header_value = format_date($headers[$hkey], $RCMAIL->config->get('date_long', 'x')); 
    852844      else 
    853845        $header_value = format_date($headers[$hkey]); 
    854       } 
    855     else if ($hkey == 'replyto') 
    856       { 
     846    } 
     847    else if ($hkey == 'replyto') { 
    857848      if ($headers['replyto'] != $headers['from']) 
    858         $header_value = Q(rcmail_address_string($headers['replyto'], null, true, $attrib['addicon']), 'show'); 
     849        $header_value = rcmail_address_string($headers['replyto'], null, true, $attrib['addicon']); 
    859850      else 
    860851        continue; 
    861       } 
     852    } 
    862853    else if (in_array($hkey, array('from', 'to', 'cc', 'bcc'))) 
    863       $header_value = Q(rcmail_address_string($headers[$hkey], null, true, $attrib['addicon']), 'show'); 
     854      $header_value = rcmail_address_string($headers[$hkey], null, true, $attrib['addicon']); 
    864855    else if ($hkey == 'subject' && empty($headers[$hkey])) 
    865       $header_value = Q(rcube_label('nosubject')); 
     856      $header_value = rcube_label('nosubject'); 
    866857    else 
    867       $header_value = Q(trim($IMAP->decode_header($headers[$hkey]))); 
    868  
    869     $out .= "\n<tr>\n"; 
    870     $out .= '<td class="header-title">'.Q(rcube_label($hkey)).":&nbsp;</td>\n"; 
    871     $out .= '<td class="'.$hkey.'" width="90%">'.$header_value."</td>\n</tr>"; 
    872     $header_count++; 
    873     } 
     858      $header_value = trim($IMAP->decode_header($headers[$hkey])); 
     859       
     860    $output_headers[$hkey] = array('title' => rcube_label($hkey), 'value' => $header_value, 'raw' => $headers[$hkey]); 
     861  } 
     862     
     863  $plugin = $RCMAIL->plugins->exec_hook('message_headers_output', array('output' => $output_headers, 'headers' => $MESSAGE->headers)); 
     864   
     865  // compose html table 
     866  $table = new html_table(array('cols' => 2)); 
     867   
     868  foreach ($plugin['output'] as $hkey => $row) { 
     869    $table->add(array('class' => 'header-title'), Q($row['title'])); 
     870    $table->add(array('class' => $hkey, 'width' => "90%"), Q($row['value'], ($hkey == 'subject' ? 'strict' : 'show'))); 
     871  } 
    874872 
    875873  // all headers division 
    876   $out .= "\n".'<tr><td colspan="2" class="more-headers show-headers" 
    877         onclick="return '.JS_OBJECT_NAME.'.command(\'load-headers\', \'\', this)"></td></tr>'; 
    878   $out .= "\n".'<tr id="all-headers"><td colspan="2" class="all"><div id="headers-source"></div></td></tr>'; 
    879  
     874  $table->add(array('colspan' => 2, 'class' => "more-headers show-headers", 'onclick' => "return ".JS_OBJECT_NAME.".command('load-headers','',this)"), ''); 
     875  $table->add_row(array('id' => "all-headers")); 
     876  $table->add(array('colspan' => 2, 'class' => "all"), html::div(array('id' => 'headers-source'), '')); 
     877   
    880878  $OUTPUT->add_gui_object('all_headers_row', 'all-headers'); 
    881879  $OUTPUT->add_gui_object('all_headers_box', 'headers-source'); 
    882880 
    883   $out .= "\n</table>\n\n"; 
    884  
    885   return $header_count ? $out : '';   
     881  return $table->show($attrib); 
    886882  } 
    887883 
Note: See TracChangeset for help on using the changeset viewer.