Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions recipient_to_contact/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
Recipient To Contact Changelog:

Release 0.3.2
==============================
- Added configuration to not show recipients in the same domain as
the current user's identity domain

Release 0.3.1
==============================
- Bugfix: only list writeable addressbooks
- Added pt_BR language support
- Added translation in 'Close' and 'Save' buttons in dialog
- TODO: translate 2 new strings - done only in en_US, en_GB and pt_BR

Release 0.3
==============================
- New maintainer (and first release in over 2 years, sorry).
Expand Down
47 changes: 47 additions & 0 deletions recipient_to_contact/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Roundcube Recipient To Contact Plugin

## About

Recipient To Contact is a plugin to quickly add new contacts to address books. When sending an email to recipients that aren't in the address book, this plugin displays a form to quickly save these contacts. Inspired by Automatic Addressbook plugin.

Features:

* Simple jQuery UI based interface.
* Parses 'To:', 'Cc:' and 'Bcc:' and automatically fills name and email address fields.
* Configurable: which address books to use for searching; default behavior; etc.
* Can be activated/deactivated through User Preferences section.
* Advanced error handling.

## Requirements

1. Plugin is maintained against Roundcube 0.7 and later.
2. jQuery UI plugin is required, which can be obtained from [http://underwa.ter.net/roundcube-plugins]() or [http://myroundcube.googlecode.com]().

## Installation

1. Download latest stable release from GitHub.
2. Extract the downloaded archive, and place the `recipient_to_contact` directory in `plugins/` folder.
3. Add `recipient_to_contact` to `$rcmail_config['plugins']` in your Roundcube config.

## Configuration

The default config file is `plugins/recipient_to_contact/config.inc.php.dist`.
Rename this to `plugins/recipient_to_contact/config.inc.php` and edit it there.

Configuration options:

`recipient_to_contact_addressbooks`

A list of address book IDs, which would be used for searching existing contacts. For example, if it contains `array('sql', 'global', 'ldap')` the plugin will look for existing contacts only in these address books. The default (an empty array) means the plugin will use address books specified in the `autocomplete_addressbooks` option in the Roundcube configuration file.

`recipient_to_contact_enabled_by_default`

Whether the plugin is enabled or disabled for users by default. If set to true, the plugin is enabled and users can disable it through settings menu.

`recipient_to_contact_use_groups`

Whether to enable contact groups (and show the UI for selecting them) or not. Defaults to false.

## License

This plugin is distributed under the GPLv3 license. Please see http://www.gnu.org/licenses/gpl-3.0.txt for the complete license.
10 changes: 9 additions & 1 deletion recipient_to_contact/config/config.inc.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ $rcmail_config['recipient_to_contact_enabled_by_default'] = true;
*
* If set to true, the contact group dropdown is shown in the dialog.
*/
$rcmail_config['recipient_to_contact_use_groups'] = false;
$rcmail_config['recipient_to_contact_use_groups'] = true;

/**
* Whether show recipients with same domain as current identity
*
* If set to true, will show all recipients, regardless of their domain
* If set to false, will skip recipients that have same domain as current identity
*/
$rcmail_config['recipient_to_contact_same_domain'] = false;
2 changes: 2 additions & 0 deletions recipient_to_contact/localization/de_DE.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ $labels['dialog_contact_surname'] = 'Nachname';
$labels['dialog_contact_addressbook'] = 'Adressbuch:';
$labels['dialog_contact_group'] = 'Gruppe: ';
$labels['dialog_email'] = 'E-Mail-Adresse';
$labels['dialog_close_button'] = 'Close';
$labels['dialog_save_button'] = 'Save';

// various response messages
$labels['response_name_empty'] = 'Bitte geben Sie einen Kontaktnamen ein';
Expand Down
2 changes: 2 additions & 0 deletions recipient_to_contact/localization/en_GB.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ $labels['dialog_contact_surname'] = 'Surname';
$labels['dialog_contact_addressbook'] = 'Address Book';
$labels['dialog_contact_group'] = 'Group';
$labels['dialog_email'] = 'Email Address';
$labels['dialog_close_button'] = 'Close';
$labels['dialog_save_button'] = 'Save';

// various response messages
$labels['response_name_empty'] = 'Please enter a contact name';
Expand Down
2 changes: 2 additions & 0 deletions recipient_to_contact/localization/en_US.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ $labels['dialog_contact_surname'] = 'Surname';
$labels['dialog_contact_addressbook'] = 'Addressbook:';
$labels['dialog_contact_group'] = 'Group: ';
$labels['dialog_email'] = 'Email address';
$labels['dialog_close_button'] = 'Close';
$labels['dialog_save_button'] = 'Save';

// various response messages
$labels['response_name_empty'] = 'Please enter a contact name';
Expand Down
2 changes: 2 additions & 0 deletions recipient_to_contact/localization/it_IT.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ $labels['dialog_contact_surname'] = 'Cognome';
$labels['dialog_contact_addressbook'] = 'Rubrica:';
$labels['dialog_contact_group'] = 'Gruppo:';
$labels['dialog_email'] = 'Email';
$labels['dialog_close_button'] = 'Close';
$labels['dialog_save_button'] = 'Save';

// various response messages
$labels['response_name_empty'] = 'Inserisci un \'nome visualizzato\'';
Expand Down
25 changes: 25 additions & 0 deletions recipient_to_contact/localization/pt_BR.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
$labels = array();

// labels used in settings view
$labels['prefs_title'] = 'Destinatários para contatos';
$labels['prefs_option'] = 'Ativar destinatários para contatos';
$labels['prefs_descr'] = 'O plugin destinatários para contatos mostra uma caixa para que você possa adicionar os destinatários de mensagens ao seu catálogo de endereços após o envio de um e-mail.';

// labels used in dialog in frontend
$labels['dialog_title'] = 'Sua mensagem foi enviada aos seguintes destinatários:';
$labels['dialog_contact_name'] = 'Nome do contato';
$labels['dialog_contact_firstname'] = 'Primeiro nome';
$labels['dialog_contact_surname'] = 'Sobrenome';
$labels['dialog_contact_addressbook'] = 'Catálogo de endereços:';
$labels['dialog_contact_group'] = 'Grupo: ';
$labels['dialog_email'] = 'Endereço de e-mail';
$labels['dialog_close_button'] = 'Fechar';
$labels['dialog_save_button'] = 'Salvar';

// various response messages
$labels['response_name_empty'] = 'Por favor entre com um nome de contato';
$labels['response_email_invalid'] = 'Por favor entre com um e-mail válido';
$labels['response_server_error'] = 'Erro de servidor';
$labels['response_contact_not_selected'] = 'Por favor selecione ao menos um contato para adicionar';
$labels['response_confirm'] = 'Contato(s) adicionado(s) com sucesso';
2 changes: 2 additions & 0 deletions recipient_to_contact/localization/ru_RU.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ $labels['dialog_contact_surname'] = 'Surname';
$labels['dialog_contact_addressbook'] = 'Addressbook:';
$labels['dialog_contact_group'] = 'Group: ';
$labels['dialog_email'] = 'Email адресс';
$labels['dialog_close_button'] = 'Close';
$labels['dialog_save_button'] = 'Save';

// various response messages
$labels['response_name_empty'] = 'Пожалуйста введите имя контакта';
Expand Down
34 changes: 23 additions & 11 deletions recipient_to_contact/recipient_to_contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,23 +285,35 @@ var recipient_to_contact = {
*/
show_dialog: function()
{

$('#new-contacts-dialog').dialog({
autoResize: true,
modal: true,
resizable: false,
width: 'auto',
title: rcmail.gettext('dialog_title', 'recipient_to_contact'),
buttons: {
Close: function() {
$(this).dialog( "close" );
// description below
rcube_event.add_listener({event:bw.opera?'keypress':'keydown', object: rcmail.message_list, method:'key_press'});
rcube_event.add_listener({event:'keydown', object:rcmail.message_list, method:'key_down'});
$('#new-contacts-dialog').remove();
recipient_to_contact.end();
},
Save: recipient_to_contact.save_contacts
}
buttons: [
{
text: rcmail.gettext('dialog_close_button', 'recipient_to_contact'),
"id": "btnClose",
click: function() {
//rcmail.gettext('dialog_close_button', 'recipient_to_contact'): function() {
$(this).dialog( "close" );
// description below
rcube_event.add_listener({event:bw.opera?'keypress':'keydown', object: rcmail.message_list, method:'key_press'});
rcube_event.add_listener({event:'keydown', object:rcmail.message_list, method:'key_down'});
$('#new-contacts-dialog').remove();
recipient_to_contact.end();
}
},
{
text: rcmail.gettext('dialog_save_button', 'recipient_to_contact'),
"id": "btnSave",
click: function() {
recipient_to_contact.save_contacts();
}
}
]
});

// pre select all checkboxes by default
Expand Down
76 changes: 52 additions & 24 deletions recipient_to_contact/recipient_to_contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* @author Vladimir Minakov <[email protected]>
* Gianfelice Catini <[email protected]>
* Mat Gadd <[email protected]>
* Eliton Claus <[email protected]>
* @copyright 2009-2013 Namesco Limited
* 2016 Eliton Claus
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 License
*/

Expand All @@ -23,6 +25,7 @@
* @author Vladimir Minakov <[email protected]>
* Gianfelice Catini <[email protected]>
* Mat Gadd <[email protected]>
* Eliton Claus <[email protected]>
*/
class recipient_to_contact extends rcube_plugin
{
Expand Down Expand Up @@ -95,14 +98,15 @@ public function init()

// fetch addressbook sources. If no addressbooks set in the config file, use the same addressbooks
// configured for autocompletition
$enabled_addressbooks = $this->rcmail->config->get('recipient_to_contact_addressbooks');
if (empty($enabled_addressbooks)) {
$this->addressbooks = $this->get_addressbooks(
$this->rcmail->config->get('autocomplete_addressbooks'));
} else {
$this->addressbooks = $this->get_addressbooks($enabled_addressbooks);
}
}
$enabled_addressbooks = $this->rcmail->config->get('recipient_to_contact_addressbooks');
if (empty($enabled_addressbooks)) {
// get only writeable addressbooks
$this->addressbooks = $this->get_addressbooks($this->rcmail->config->get('autocomplete_addressbooks'), true);
} else {
// get only writeable addressbooks
$this->addressbooks = $this->get_addressbooks($enabled_addressbooks, true);
}
}

// hooks for preferences section
$this->add_hook('preferences_list', array($this, 'prefs_content'));
Expand All @@ -121,6 +125,8 @@ public function init()
*/
public function check_recipients($args)
{
$rcmail = rcmail::get_instance();

// don't process the sent message, if it's a 'Read Receipt' response
if (isset($args['headers']['Content-Type'])
&& strpos($args['headers']['Content-Type'], 'report-type=disposition-notification') !== false) {
Expand All @@ -145,7 +151,28 @@ public function check_recipients($args)
foreach ($recipients as $recipient) {
// flag to denote if the current recipient doesn't exist in any of the address books
$is_new_contact = true;


// if we dont want to list users in same domain as us for some reason
// example: globaladdressbook plugin with all domain users inside
if (!$this->rcmail->config->get('recipient_to_contact_addressbooks')) {
// get current recipient domain
$recipient_domain = preg_replace ('/^[^@]*@(.*)$/', '$1', $recipient['mailto']);
// get identity used to send email
$identity = $rcmail->user->get_identity();
// get current identity domain
$identity_domain = preg_replace ('/^[^@]*@(.*)$/', '$1', $identity['email']);

// check if recipient domain match with this identify domain
// if match, continue loop and ignore recipient
if ($recipient_domain == $identity_domain) {
unset($recipient_domain);
unset($identity);
unset($identity_domain);
$is_new_contact = false;
continue;
}
}

// interate over over address books and search for a contact with the same email address
foreach ($this->addressbooks as $abook_id => $address_source) {
$address_book = $this->rcmail->get_address_book($abook_id);
Expand Down Expand Up @@ -229,14 +256,14 @@ public function save_contacts()
// visualization name cannot be empty
if (empty($contact['_name'])) {
$response[$key]['status'] = 'fail';
$response[$key]['message'] = Q($this->gettext('response_name_empty'));
$response[$key]['message'] = rcube::Q($this->gettext('response_name_empty'));
continue;
}

// email should be valid
if (!check_email($contact['_email'], false)) {
$response[$key]['status'] = 'fail';
$response[$key]['message'] = Q($this->gettext('response_email_invalid'));
$response[$key]['message'] = rcube::Q($this->gettext('response_email_invalid'));
continue;
}

Expand All @@ -248,7 +275,7 @@ public function save_contacts()
'firstname' => $contact['_firstname'], 'surname' => $contact['_surname']));
if ($id == false) {
$response[$key]['status'] = 'fail';
$response[$key]['message'] = Q($this->gettext('response_server_error'));
$response[$key]['message'] = rcube::Q($this->gettext('response_server_error'));
continue;
}

Expand All @@ -260,7 +287,7 @@ public function save_contacts()

// all ok
$response[$key]['status'] = 'ok';
$response[$key]['message'] = Q($this->gettext('response_confirm'));
$response[$key]['message'] = rcube::Q($this->gettext('response_confirm'));
}

// return reponse to client
Expand Down Expand Up @@ -294,16 +321,17 @@ public function prefs_content($args)
'style' => 'margin-left: -300px')
);

$args['blocks']['recipienttocontact']['options']['description'] = array(
'title' => html::div(null, Q($this->gettext('prefs_descr'))) . html::br(),
'content' => ''
);

$args['blocks']['recipienttocontact']['name'] = $this->gettext('prefs_title');
$args['blocks']['recipienttocontact']['name'] = rcube::Q($this->gettext('prefs_title'));
$args['blocks']['recipienttocontact']['options']['use_subscriptions'] = array(
'title' => html::label($field_id, Q($this->gettext('prefs_option'))),
'content' => $checkbox->show($use_recipienttocontact ? 1 : 0),
'title' => html::label($field_id, rcube::Q($this->gettext('prefs_option'))),
'content' => $checkbox->show($use_recipienttocontact ? 1 : 0)
);

$args['blocks']['recipienttocontact']['options']['description'] = array(
'title' => html::div(null, rcube::Q($this->gettext('prefs_descr'))) . html::br(),
'content' => ''
);

}

return $args;
Expand All @@ -320,7 +348,7 @@ public function prefs_section_link($args)
{
$args['list']['recipienttocontact'] = array(
'id' => 'recipienttocontact',
'section' => Q($this->gettext('prefs_title'))
'section' => rcube::Q($this->gettext('prefs_title'))
);

return $args;
Expand Down Expand Up @@ -360,7 +388,7 @@ public function prefs_save($args)
*
* @return array Addressbooks sources.
*/
protected function get_addressbooks(array $ids, $writable = false)
protected function get_addressbooks(array $ids, $writable = true)
{
$ids = array_flip($ids);

Expand All @@ -369,7 +397,7 @@ protected function get_addressbooks(array $ids, $writable = false)
unset($ids['sql']);
$ids[0] = 0;
}
$all_addresbooks = $this->rcmail->get_address_sources();
$all_addresbooks = $this->rcmail->get_address_sources($writable);

// return standard output from get_address_sources including only addressbooks specified in $ids
return array_intersect_key($all_addresbooks, $ids);
Expand Down