From bc1e14ab53459845caca3eb3cfb73627e5a17e1a Mon Sep 17 00:00:00 2001 From: internero Date: Mon, 1 Feb 2016 16:12:08 -0200 Subject: [PATCH 1/4] Add pt_BR support, fix to only list writeable adressbooks --- recipient_to_contact/CHANGELOG | 5 ++ recipient_to_contact/README.md | 47 +++++++++++++++++++ recipient_to_contact/localization/pt_BR.inc | 23 +++++++++ recipient_to_contact/recipient_to_contact.php | 47 ++++++++++--------- 4 files changed, 100 insertions(+), 22 deletions(-) create mode 100644 recipient_to_contact/README.md create mode 100644 recipient_to_contact/localization/pt_BR.inc diff --git a/recipient_to_contact/CHANGELOG b/recipient_to_contact/CHANGELOG index 6bd6e20..88c2bf3 100644 --- a/recipient_to_contact/CHANGELOG +++ b/recipient_to_contact/CHANGELOG @@ -1,5 +1,10 @@ Recipient To Contact Changelog: +Release 0.3.1 +============================== +- Added pt_BR language support +- Bugfix: only list writeable addressbooks + Release 0.3 ============================== - New maintainer (and first release in over 2 years, sorry). diff --git a/recipient_to_contact/README.md b/recipient_to_contact/README.md new file mode 100644 index 0000000..8be0f2d --- /dev/null +++ b/recipient_to_contact/README.md @@ -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. \ No newline at end of file diff --git a/recipient_to_contact/localization/pt_BR.inc b/recipient_to_contact/localization/pt_BR.inc new file mode 100644 index 0000000..31e2484 --- /dev/null +++ b/recipient_to_contact/localization/pt_BR.inc @@ -0,0 +1,23 @@ + * Gianfelice Catini * Mat Gadd + * Eliton Claus * @copyright 2009-2013 Namesco Limited + * 2016 Eliton Claus * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 License */ @@ -23,6 +25,7 @@ * @author Vladimir Minakov * Gianfelice Catini * Mat Gadd + * Eliton Claus */ class recipient_to_contact extends rcube_plugin { @@ -95,14 +98,13 @@ 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)) { + $this->addressbooks = $this->get_addressbooks($this->rcmail->config->get('autocomplete_addressbooks')); + } else { + $this->addressbooks = $this->get_addressbooks($enabled_addressbooks); + } + } // hooks for preferences section $this->add_hook('preferences_list', array($this, 'prefs_content')); @@ -229,14 +231,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; } @@ -248,7 +250,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; } @@ -260,7 +262,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 @@ -294,16 +296,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; @@ -320,7 +323,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; @@ -360,7 +363,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); From cf5d93a7ce6a5f998b5649f9977adb3e873e4339 Mon Sep 17 00:00:00 2001 From: internero Date: Thu, 4 Feb 2016 10:00:57 -0200 Subject: [PATCH 2/4] Sanity check: only list writeable address books bugfix from last pull request --- recipient_to_contact/localization/pt_BR.inc | 2 ++ recipient_to_contact/recipient_to_contact.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/recipient_to_contact/localization/pt_BR.inc b/recipient_to_contact/localization/pt_BR.inc index 31e2484..c49d7f3 100644 --- a/recipient_to_contact/localization/pt_BR.inc +++ b/recipient_to_contact/localization/pt_BR.inc @@ -14,6 +14,8 @@ $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'; diff --git a/recipient_to_contact/recipient_to_contact.php b/recipient_to_contact/recipient_to_contact.php index dd74b26..272a5f8 100644 --- a/recipient_to_contact/recipient_to_contact.php +++ b/recipient_to_contact/recipient_to_contact.php @@ -372,7 +372,7 @@ protected function get_addressbooks(array $ids, $writable = true) 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); From 9e61e474a4028d2904aa51a4d22eb4f1b439ef62 Mon Sep 17 00:00:00 2001 From: internero Date: Thu, 4 Feb 2016 10:04:53 -0200 Subject: [PATCH 3/4] Fix translation in dialog buttons Fix translation in dialog buttons --- recipient_to_contact/CHANGELOG | 4 ++- recipient_to_contact/localization/de_DE.inc | 2 ++ recipient_to_contact/localization/en_GB.inc | 2 ++ recipient_to_contact/localization/en_US.inc | 2 ++ recipient_to_contact/localization/it_IT.inc | 2 ++ recipient_to_contact/localization/ru_RU.inc | 2 ++ recipient_to_contact/recipient_to_contact.js | 34 +++++++++++++------- 7 files changed, 36 insertions(+), 12 deletions(-) diff --git a/recipient_to_contact/CHANGELOG b/recipient_to_contact/CHANGELOG index 88c2bf3..5c3cfed 100644 --- a/recipient_to_contact/CHANGELOG +++ b/recipient_to_contact/CHANGELOG @@ -2,8 +2,10 @@ Recipient To Contact Changelog: Release 0.3.1 ============================== -- Added pt_BR language support - 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 ============================== diff --git a/recipient_to_contact/localization/de_DE.inc b/recipient_to_contact/localization/de_DE.inc index 224f45d..cf619e8 100644 --- a/recipient_to_contact/localization/de_DE.inc +++ b/recipient_to_contact/localization/de_DE.inc @@ -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'; diff --git a/recipient_to_contact/localization/en_GB.inc b/recipient_to_contact/localization/en_GB.inc index 6e2d025..74468d2 100644 --- a/recipient_to_contact/localization/en_GB.inc +++ b/recipient_to_contact/localization/en_GB.inc @@ -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'; diff --git a/recipient_to_contact/localization/en_US.inc b/recipient_to_contact/localization/en_US.inc index 19a10c1..c20d7d8 100644 --- a/recipient_to_contact/localization/en_US.inc +++ b/recipient_to_contact/localization/en_US.inc @@ -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'; diff --git a/recipient_to_contact/localization/it_IT.inc b/recipient_to_contact/localization/it_IT.inc index 05ac3ff..963997d 100644 --- a/recipient_to_contact/localization/it_IT.inc +++ b/recipient_to_contact/localization/it_IT.inc @@ -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\''; diff --git a/recipient_to_contact/localization/ru_RU.inc b/recipient_to_contact/localization/ru_RU.inc index 9212246..4dbde4b 100644 --- a/recipient_to_contact/localization/ru_RU.inc +++ b/recipient_to_contact/localization/ru_RU.inc @@ -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'] = 'Пожалуйста введите имя контакта'; diff --git a/recipient_to_contact/recipient_to_contact.js b/recipient_to_contact/recipient_to_contact.js index de88c94..bc60afc 100644 --- a/recipient_to_contact/recipient_to_contact.js +++ b/recipient_to_contact/recipient_to_contact.js @@ -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 From e7515667ad8b87e6fd1842b40411deaa27e71b06 Mon Sep 17 00:00:00 2001 From: internero Date: Fri, 19 Feb 2016 14:57:53 -0200 Subject: [PATCH 4/4] show/hide recipients in same domain as curernt user's identity Added configuration to not show recipients in the same domain as the current user's identity domain --- recipient_to_contact/CHANGELOG | 5 +++ .../config/config.inc.php.dist | 10 +++++- recipient_to_contact/recipient_to_contact.php | 31 +++++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/recipient_to_contact/CHANGELOG b/recipient_to_contact/CHANGELOG index 5c3cfed..8b00058 100644 --- a/recipient_to_contact/CHANGELOG +++ b/recipient_to_contact/CHANGELOG @@ -1,5 +1,10 @@ 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 diff --git a/recipient_to_contact/config/config.inc.php.dist b/recipient_to_contact/config/config.inc.php.dist index 68d1ee3..cbb05dc 100644 --- a/recipient_to_contact/config/config.inc.php.dist +++ b/recipient_to_contact/config/config.inc.php.dist @@ -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; \ No newline at end of file +$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; \ No newline at end of file diff --git a/recipient_to_contact/recipient_to_contact.php b/recipient_to_contact/recipient_to_contact.php index 272a5f8..40ef61d 100644 --- a/recipient_to_contact/recipient_to_contact.php +++ b/recipient_to_contact/recipient_to_contact.php @@ -100,9 +100,11 @@ public function init() // 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')); + // get only writeable addressbooks + $this->addressbooks = $this->get_addressbooks($this->rcmail->config->get('autocomplete_addressbooks'), true); } else { - $this->addressbooks = $this->get_addressbooks($enabled_addressbooks); + // get only writeable addressbooks + $this->addressbooks = $this->get_addressbooks($enabled_addressbooks, true); } } @@ -123,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) { @@ -147,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);