Changeset 840b4db in github


Ignore:
Timestamp:
Jul 10, 2012 2:30:34 PM (11 months ago)
Author:
Aleksander Machniak <alec@…>
Children:
1c079c1
Parents:
2b21b97
Message:

Simplified method of getting default addressbook.
Make sure to use the same source when adding contact and checking
if message is safe (sender is in addressbook).
Small code improvements.

Location:
program
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcmail.php

    r7c8fd80 r840b4db  
    172172   * Return instance of the internal address book class 
    173173   * 
    174    * @param string  Address book identifier 
     174   * @param string  Address book identifier (-1 for default addressbook) 
    175175   * @param boolean True if the address book needs to be writeable 
    176176   * 
     
    181181    $contacts    = null; 
    182182    $ldap_config = (array)$this->config->get('ldap_public'); 
    183     $abook_type  = strtolower($this->config->get('address_book_type')); 
    184183 
    185184    // 'sql' is the alias for '0' used by autocomplete 
    186185    if ($id == 'sql') 
    187         $id = '0'; 
     186      $id = '0'; 
     187    else if ($id == -1) { 
     188      $id = $this->config->get('default_addressbook'); 
     189      $default = true; 
     190    } 
    188191 
    189192    // use existing instance 
    190     if (isset($this->address_books[$id]) && is_object($this->address_books[$id]) 
    191       && is_a($this->address_books[$id], 'rcube_addressbook') 
    192       && (!$writeable || !$this->address_books[$id]->readonly) 
    193     ) { 
     193    if (isset($this->address_books[$id]) && ($this->address_books[$id] instanceof rcube_addressbook)) { 
    194194      $contacts = $this->address_books[$id]; 
    195195    } 
     
    207207        $contacts = $plugin['instance']; 
    208208      } 
    209       // get first source from the list 
    210       else if (!$id) { 
    211         $source = reset($this->get_address_sources($writeable)); 
    212         if (!empty($source)) { 
    213           $contacts = $this->get_address_book($source['id']); 
    214           if ($contacts) 
    215             $id = $source['id']; 
    216         } 
     209    } 
     210 
     211    // Get first addressbook from the list if configured default doesn't exist 
     212    // This can happen when user deleted the addressbook (e.g. Kolab folder) 
     213    if (!$contacts && (!$id || $default)) { 
     214      $source = reset($this->get_address_sources($writeable)); 
     215      if (!empty($source)) { 
     216        $contacts = $this->get_address_book($source['id']); 
     217        if ($contacts) 
     218          $id = $source['id']; 
    217219      } 
    218220    } 
     
    224226        'message' => "Addressbook source ($id) not found!"), 
    225227        true, true); 
     228    } 
     229 
     230    if ($writeable && $contacts->readonly) { 
     231      return null; 
    226232    } 
    227233 
  • program/steps/mail/addcontact.inc

    r041c93c r840b4db  
    2424  return; 
    2525 
    26 $abook = $RCMAIL->config->get('default_addressbook'); 
    27  
    28 // Get configured addressbook 
    29 $CONTACTS = $RCMAIL->get_address_book($abook, true); 
    30  
    31 // Get first writeable addressbook if the configured doesn't exist 
    32 // This can happen when user deleted the addressbook (e.g. Kolab folder) 
    33 if ($abook == null || !is_object($CONTACTS)) { 
    34   $source = reset($RCMAIL->get_address_sources(true)); 
    35   $CONTACTS = $RCMAIL->get_address_book($source['id'], true); 
    36 } 
     26// Get default addressbook 
     27$CONTACTS = $RCMAIL->get_address_book(-1, true); 
    3728 
    3829if (!empty($_POST['_address']) && is_object($CONTACTS)) 
  • program/steps/mail/func.inc

    r8749e94 r840b4db  
    519519  global $RCMAIL; 
    520520 
    521   $show_images = $RCMAIL->config->get('show_images'); 
    522521  if (!$message->is_safe 
    523     && !empty($show_images) 
    524     && $message->has_html_part()) 
    525   { 
    526     switch($show_images) { 
    527       case '1': // known senders only 
    528         $CONTACTS = new rcube_contacts($RCMAIL->db, $_SESSION['user_id']); 
    529         if ($CONTACTS->search('email', $message->sender['mailto'], true, false)->count) { 
    530           $message->set_safe(true); 
     522    && ($show_images = $RCMAIL->config->get('show_images')) 
     523    && $message->has_html_part() 
     524  ) { 
     525    switch ($show_images) { 
     526      case 1: // known senders only 
     527        // get default addressbook, like in addcontact.inc 
     528        $CONTACTS = $RCMAIL->get_address_book(-1, true); 
     529 
     530        if ($CONTACTS) { 
     531          $result = $CONTACTS->search('email', $message->sender['mailto'], 1, false); 
     532          if ($result->count) { 
     533            $message->set_safe(true); 
     534          } 
    531535        } 
    532       break; 
    533       case '2': // always 
     536        break; 
     537 
     538      case 2: // always 
    534539        $message->set_safe(true); 
    535       break; 
     540        break; 
    536541    } 
    537542  } 
Note: See TracChangeset for help on using the changeset viewer.