Hello everybody,

I use roundcube for my emails but I think the adressbook is lacking a lot of interesting features.
 1) Ability to store multiple email adresses, phones numbers, pictures and other info about my contacts
 2) Ability to share contacts (eg : my contacts could be seen by my wife, since we have  some friends in common ;)
 3) Ability to import/export from csv files or other adequate format
 4) Ability to display pictures of my contacts when I receive mail from them (can anyone remember of the "picons" idea? see http://www.cs.indiana.edu/picons/ftp/faq.html#what)


So I propose the following:
 1) see the code below to implement an extended version of the contacts.
At the moment it can :
- eidt, save and display multiple info about your contacts
- mailto links working with the various emails of the contact
- I chose not to store the image in the db itself but only a link to it, since it was simpler; but it means cross-linking between your roudcube web site and the site hosting the image
Todo :
- when auto-completing recipient address only the first email of the contacts can be matched
- when adding a new contact, only the first email address is checked for redundancy

2) Not implemented yet
To share contacts, I have included a "global" attribute in the contact profile. When set to True this will make the contact visible to everybody, but editable only by the user who created it.
There will be a config attribute to disable this behaviour.

3) Not implemented yet, but should'nt be hard

4) I really like this idea (try gmail to see how it could work). I think I will add :
- mouse-over info box that displays the contact profile when the mouse is over a mail
- when displaying a message, show at the top the picture and some info from the addressbook



Please tell me if you think this can be included in roundcube 'official' version, and in that case I will send you the future updates.

If you find bugs, please send them to me. It seems to work ok for me. If you prefer to work with cvs, I can do so, but on the web site it is said to propose code by mail.

Bye
Paul



Code to implement feature 1)

A/ DB modification (I use mysql, so this is the code to update the db scheme).

ALTER TABLE `contacts` ADD `email2` VARCHAR( 128 ) NOT NULL ,
ADD `email3` VARCHAR( 128 ) NOT NULL ,
ADD `email4` VARCHAR( 128 ) NOT NULL ,
ADD `im` VARCHAR( 128 ) NOT NULL ,
ADD `homephone` VARCHAR( 128 ) NOT NULL ,
ADD `mobilephone` VARCHAR( 128 ) NOT NULL ,
ADD `workphone` VARCHAR( 128 ) NOT NULL ,
ADD `sip` VARCHAR( 128 ) NOT NULL ,
ADD `webpage` VARCHAR( 256 ) NOT NULL ,
ADD `birthdate` DATE NOT NULL ,
ADD `pgppublickey` TEXT NOT NULL ,
ADD `homeaddress` TEXT NOT NULL ,
ADD `workaddress` TEXT NOT NULL ,
ADD `company` VARCHAR( 128 ) NOT NULL ,
ADD `comments` TEXT NOT NULL ,
ADD `picture` VARCHAR( 256 ) NOT NULL ,
ADD `globalcontact` BOOL NOT NULL ;




B/ Localization files updates (done only for US and fr files)
US file: program/localization/en_US/labels.inc.php
// address boook
$labels['name']      = 'Display name';
$labels['firstname'] = 'First name';
$labels['surname']   = 'Last name';
$labels['email']     = 'E-Mail';
//new labels
$labels[email2]      = 'E-Mail 2';
$labels[email3]      = 'E-Mail 3';
$labels[email4]      = 'E-Mail 4';
$labels[im]          = 'Instant messaging';
$labels[homephone]   = 'Home phone';
$labels[mobilephone] = 'Mobile phone';
$labels[workphone]   = 'Work phone';
$labels[sip]         = 'SIP';
$labels[webpage]     = 'Web page';
$labels[birthdate]   = 'Birth date';
$labels[pgppublickey]= 'PGP public key';
$labels[homeaddress] = 'Home address';
$labels[workaddress] = 'Work address';
$labels[company]     = 'Company';
$labels[comments]    = 'Comments';
$labels[picture]     = 'Picture';
$labels[globalcontact]= 'Global contact';


 
fr file: program/localization/fr/labels.inc.php
// address boook
$labels['name']      = 'Nom à afficher';
$labels['firstname'] = 'Prénom';
$labels['surname']   = 'Nom';
$labels['email']     = 'e-Mail';
//new labels
$labels[email2]      = 'e-Mail 2';
$labels[email3]      = 'e-Mail 3';
$labels[email4]      = 'e-Mail 4';
$labels[im]          = 'Messagerie instantanée';
$labels[homephone]   = 'Téléphone domicile';
$labels[mobilephone] = 'Téléphone mobile';
$labels[workphone]   = 'Téléphone professionnel';
$labels[sip]         = 'SIP';
$labels[webpage]     = 'Page web';
$labels[birthdate]   = 'Date de naissance';
$labels[pgppublickey]= 'Clé publique PGP';
$labels[homeaddress] = 'Adresse domicile';
$labels[workaddress] = 'Adresse professionnelle';
$labels[company]     = 'Société';
$labels[comments]    = 'Commentaires';
$labels[picture]     = 'Image';
$labels[globalcontact]= 'Contact global';




C/ New config options
To be appended at the end of the file: config/main.inc.php
// addressbook configuration
// chose which columns in the addressbook to enable, the columns are displayed in the specified order
$rcmail_config['addressbook_show_cols'] = array('picture', 'name', 'firstname', 'surname', 'email', 'email2', 'email3', 'email4', 'im', 'homephone', 'mobilephone', 'workphone', 'sip', 'webpage', 'birthdate', 'pgppublickey', 'homeaddress', 'workaddress', 'company', 'comments', 'globalcontact');

// image size in address book
$rcmail_config['addressbook_image_width'] = '100';
$rcmail_config['addressbook _image_height'] = '100';

// enable global contacts
$rcmail_config['adressbook_enable_global_contacts'] = 'true';





D/ Show contact update
Update the rcmail_contact_details function in the file: program/steps/addressbook/show.inc
function rcmail_contact_details($attrib)
  {
  global $CONFIG, $CONTACT_RECORD, $JS_OBJECT_NAME;

  if (!$CONTACT_RECORD)
    return show_message('contactnotfound' );

  // a specific part is requested
  if ($attrib['part'])
    return rep_specialchars_output($CONTACT_RECORD[$attrib['part' ]]);


  // return the complete address record as table
  $out = "<table>\n\n";

  $a_show_cols = $CONFIG['addressbook_show_cols'];
  foreach ($a_show_cols as $col)
    {
    if (substr($col,0,5)=='email' && $CONTACT_RECORD[$col])
      $value = sprintf('<a href="#compose" onclick="%s.command(\'compose\ ', \'%d_%s\')" title="%s">%s</a>',
                       $JS_OBJECT_NAME,
                       $CONTACT_RECORD['contact_id'],
                       $col,
                       rcube_label('composeto'),
                       $CONTACT_RECORD[$col]);
    elseif ($col=="picture" && $CONTACT_RECORD[$col])
      $value = sprintf('<img height="%s" width="%s" src="%s" />',
                       $CONFIG['addressbook_image _height'],
                       $CONFIG['addressbook_image_width'],
                       $CONTACT_RECORD[$col]);
    else
      $value = rep_specialchars_output($CONTACT_RECORD[$col]);

    $title = rcube_label($col);
    $out .= sprintf("<tr><td class=\"title\">%s</td><td>%s< /td></tr>\n", $title, $value);
    }


  $out .= "\n</table>";

  return $out;
  }




E/ Edit contact update
Update the rcmail_contact_editform function in the file: program/steps/addressbook/edit.inc
function rcmail_contact_editform($attrib)
  {
  global $CONFIG, $CONTACT_RECORD, $JS_OBJECT_NAME;

  if (!$CONTACT_RECORD && $GLOBALS['_action']!='add')
    return rcube_label('contactnotfound');

  // add some labels to client
  rcube_add_label('noemailwarning');
  rcube_add_label('nonamewarning');

  list($form_start, $form_end) = get_form_tags($attrib);
  unset($attrib['form']);


  // a specific part is requested
  if ($attrib['part'])
    {
    $out = $form_start;
    $out .= rcmail_get_edit_field($attrib[ 'part'], $CONTACT_RECORD[$attrib['part']], $attrib);
    return $out;
    }


  // return the complete address edit form as table
  $out = "$form_start<table>\n\n";

  #$a_show_cols = array('name', 'firstname', 'surname', 'email');
  $a_show_cols = $CONFIG['addressbook_show_cols'];
  foreach ($a_show_cols as $col)
    {
    $attrib['id'] = 'rcmfd_'.$col;
    $title = rcube_label($col);
    if (($col=='homeaddress' || $col=='workaddress' || $col=='comments') && $CONTACT_RECORD[$col])
      $value = rcmail_get_edit_field($col, $CONTACT_RECORD[$col], $attrib, 'textarea');
    else
      $value = rcmail_get_edit_field($col, $CONTACT_RECORD[$col], $attrib);

    $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td> %s</td></tr>\n",
                    $attrib['id'],
                    $title,
                    $value);
    }

  $out .= "\n</table>$form_end";

  return $out;
  }



F/ Save contact update
Replace the line
$a_save_cols = array('name', 'firstname', 'surname', 'email');
by
$a_save_cols = $CONFIG['addressbook_show_cols'];
in the file: program/steps/addressbook/save.inc




G/ Compose mail update (to to chose not only the first email, but also one of the others depending on which link was clicked in the contact profile)
Update the "case 'to'" in the compose action, in the file: program/steps/mail/compose.inc
case 'to':
      $fname = '_to';
      $header = 'to';

      // we have contact id's as get parameters
      if (!empty($_GET['_to']) && preg_match('/^[0-9]+(,[0-9]+)*$/', $_GET['_to']))
        {
        $a_recipients = array();
        $sql_result = $DB->query("SELECT name, email
                                   FROM ".get_table_name('contacts')."
                                   WHERE user_id=?
                                  AND    del<>1
                                  AND    contact_id IN (".$_GET['_to'].")",
                                  $_SESSION['user_id']);

        while ($sql_arr = $DB->fetch_assoc($sql_result))
          $a_recipients[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);

        if (sizeof($a_recipients))
          $fvalue = join(', ', $a_recipients);
        }
      else if (!empty($_GET['_to']) && preg_match('/^[0-9]+_email[0-9 ]*$/', $_GET['_to']))
        {
        $a_recipients = array();
        preg_match('/^([0-9])+_(email[0-9]*)$/', $_GET['_to'], $matches);
        $sql_result = $DB->query("SELECT name, ".$matches[2]."
                                   FROM ".get_table_name('contacts')."
                                  WHERE user_id=?
                                  AND    del<>1
                                   AND    contact_id IN (".$matches[1].")",
                                  $_SESSION['user_id']);

        while ($sql_arr = $DB->fetch_assoc($sql_result))
          $a_recipients[] = format_email_recipient($sql_arr[$matches[2]], $sql_arr['name']);

        if (sizeof($a_recipients))
          $fvalue = join(', ', $a_recipients);
        }

      else if (!empty($_GET['_to']))
        $fvalue = $_GET['_to'];