Virtual Business Card Roundcube-SQL-Global-Address-Books

I found this global address book for RoundCube with iRedMail . I use hMailServer as my email server, though, since I work with Windows. I have tried this plugin so far and works great with default fields (name, email address and domain). I added the vcard field to the table, although you cannot find it in the documentation. I also changed sql_global_backend.phpand added some codes coming 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 allows you to view (roundcube pattern) to read the vcard field. But he cannot read everything.

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_addressbooklooks 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                                    |

RoundCube:

enter image description here

+4
1

, vcard , export.

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;
}
0

Source: https://habr.com/ru/post/1669211/


All Articles