4

I found this global address book plugin for RoundCube with iRedMail. I'm using hMailServer as my e-mail server though since I'm working with Windows. I still tried this plugin and works fine with the default fields (name, email and domain). I added vcard field in the table though you can't find it in the documentation. I also tweaked the sql_global_backend.php and add some codes coming originally from rcube_contacts.php:

public function get_record($id, $assoc=false) {
    $db = rcube::get_instance()->db;
    $db->query('SELECT * FROM global_addressbook WHERE `ID`=?', $id);
    if ($sql_arr = $db->fetch_assoc()) {
        // $sql_arr['email'] = explode(',', $sql_arr['email']); // edited
        $record = $this->convert_db_data($sql_arr);             // edited
        $this->result = new rcube_result_set(1);
        $this->result->add($record);                            // edited
    }

    return $assoc && $record ? $record : $this->result;

}

/**
* Convert data stored in the database into output format
* Note: this code is originally from rcube_contacts.php
*/
private function convert_db_data($sql_arr)
{

  $record = array();
  $record['ID'] = $sql_arr[$this->primary_key];

  if ($sql_arr['vcard']) {
      unset($sql_arr['email']);
      $vcard = new rcube_vcard($sql_arr['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap);
      $record += $vcard->get_assoc() + $sql_arr;
  }
  else {
      $record += $sql_arr;
      $record['email'] = explode(self::SEPARATOR, $record['email']);
      $record['email'] = array_map('trim', $record['email']);
  }

  return $record;
}

This code enables the view(template of roundcube) to read the vcard field. But it can't read all.

BEGIN:VCARD
VERSION:3.0
N:John;Doe;;;                                // can read
FN:John Doe                                  // can read
EMAIL;TYPE=INTERNET;TYPE=WORK:john@doe.com   // can read
TITLE:Programmer                             // can't read
ORG:John Doe Org                             // can't read
X-DEPARTMENT:Management System Department    // can't read
TEL:09123456789                              // can't read
END:VCARD

UPDATED

My table global_addressbook look like this:

_______________________________________________________________________________________________________________
|    |          |              |           |         |         |                                               |
| ID |   name   |    email     | firstname | surname | domain  |  vcard                                        |
|____|__________|______________|___________|_________|_________|_______________________________________________|
|    |          |              |           |         |         |                                               |
| 1  | John Doe | john@doe.com |    John   |   doe   | doe.com |  BEGIN:VCARD                                  |
|    |          |              |           |         |         |  VERSION:3.0                                  |
                                                               |  N:John;Doe;;;                                |
                                                               |  FN:John Doe                                  |
                                                               |  EMAIL;TYPE=INTERNET;TYPE=WORK:john@doe.com   |
                                                               |  TITLE:Programmer                             |
                                                               |  ORG:John Doe Org                             |
                                                               |  X-DEPARTMENT:Management System Department    |
                                                               |  TEL:09123456789                              |
                                                               |  END:VCARD                                    |

And it look like this in the RoundCube view:

enter image description here

Lekz Flores
  • 468
  • 10
  • 27
  • Can you post the function rcube_vcard() used in convert_db_data() function? – Ketan Malhotra Feb 18 '17 at 11:52
  • @KetanMalhotra. The code is almost thousands of lines. I've just downloaded my `RoundCube` last week and I didn't re-code it. You can see the same if you could download it. – Lekz Flores Feb 20 '17 at 08:02

1 Answers1

0

Try this way by extracting vcard as string using the export method.

private function convert_db_data($sql_arr) {   
  if ($sql_arr['vcard']) {
      unset($sql_arr['email']);
      $vcard = new rcube_vcard($sql_arr['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap);
      $sql_arr['vcard'] = $vcard->export();
  } else {
      unset($sql_arr['vcard']);
  }

  return $sql_arr;
}
  • Now it only shows the `Groups` tab. `Name` and `Display Name` is now missing. Is there other block codes that I need to re-configure? – Lekz Flores Feb 20 '17 at 07:56
  • @LekzFlores I think my edited answer must be what you need...! –  Feb 20 '17 at 15:40