Author Topic: Compose to alternate email addresses  (Read 8356 times)

Offline richardt

  • Jr. Member
  • **
  • Posts: 22
Compose to alternate email addresses
« on: August 01, 2006, 07:31:22 PM »
Following on from the previous address book extension post, I have made a small tweak that will allow me to send mail to an alternate email address for a contact. I have added another field "otheremail" to my contacts table, and as per instructions in the previous post I have also modified the address book code to allow access to this field when adding/modifying contacts.

There are probably other places to consider, but to simply add this alternate email address to my compose lists I modified program\steps\mail\compose.inc as follows:

Original compose.inc (from line 779)

Code: [Select]
/****** get contacts for this user and add them to client scripts ********/

$sql_result = $DB->query("SELECT name, email
             FROM ".get_table_name('contacts')." WHERE user_id=?
             AND del<>1&quot;,$_SESSION['user_id']);
                 
if ($DB->num_rows($sql_result))
 {    
 $a_contacts = array();
 while ($sql_arr = $DB->fetch_assoc($sql_result))
  if ($sql_arr['email'])
   $a_contacts&#91;] = format_email_recipient($sql_arr['email'], rep_specialchars_output($sql_arr['name'], 'js'));
 
 $OUTPUT->add_script(sprintf(&quot;$JS_OBJECT_NAME.set_env('contacts', %s);&quot;, array2js($a_contacts)));
 }

Modified compose.inc (line 779)

Code: [Select]
/****** get contacts for this user and add them to client scripts ********/

$sql_result = $DB->query("SELECT name, email, otheremail
             FROM ".get_table_name('contacts')." WHERE user_id=?
             AND del<>1",$_SESSION['user_id']);
                 
if ($DB->num_rows($sql_result))
 {    
 $a_contacts = array();
 while ($sql_arr = $DB->fetch_assoc($sql_result)) {
  if ($sql_arr['email'])
   $a_contacts[] = format_email_recipient($sql_arr['email'], rep_specialchars_output($sql_arr['name'], 'js'));
  if ($sql_arr['otheremail'])
   $a_contacts[] = format_email_recipient($sql_arr['otheremail'], rep_specialchars_output($sql_arr['name'] . ' (2)', 'js'));
}
 
 $OUTPUT->add_script(sprintf("$JS_OBJECT_NAME.set_env('contacts', %s);", array2js($a_contacts)));
 }

This will add a contacts alternate email with a '(2)' after the name, as attached.

Cheers!!
Richard

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,876
    • SKaero - Custom Roundcube development
Re: Compose to alternate email addresses
« Reply #1 on: August 05, 2006, 05:07:01 AM »
I good idea, I don't know if I will use this but it has some good code! 8)