diff options
author | thomascube <thomas@roundcube.net> | 2011-10-19 15:28:11 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2011-10-19 15:28:11 +0000 |
commit | 5da48a95224e925f4b070f2581a121516df33829 (patch) | |
tree | fadc87888faae54cdb1efc6f7b73fbfce79e0fe7 /plugins/vcard_attachments | |
parent | b03854de3a36a322bf98c733ed9b75d996694e38 (diff) |
Copy plugins to release branch
Diffstat (limited to 'plugins/vcard_attachments')
19 files changed, 421 insertions, 0 deletions
diff --git a/plugins/vcard_attachments/localization/cs_CZ.inc b/plugins/vcard_attachments/localization/cs_CZ.inc new file mode 100644 index 000000000..11ae8c98f --- /dev/null +++ b/plugins/vcard_attachments/localization/cs_CZ.inc @@ -0,0 +1,21 @@ +<?php + +/* ++-----------------------------------------------------------------------+ +| language/cs_CZ/labels.inc | +| | +| Language file of the Roundcube Webmail client | +| Copyright (C) 2008-2010, The Roundcube Dev Team | +| Licensed under the GNU GPL | +| | ++-----------------------------------------------------------------------+ +| Author: Ales Pospichal <ales@pospichalales.info> | ++-----------------------------------------------------------------------+ + +*/ + +$labels = array(); +$labels['addvcardmsg'] = 'Přidat vCard do adresáře'; +$labels['vcardsavefailed'] = 'Nelze uložit vCard'; + +?> diff --git a/plugins/vcard_attachments/localization/de_CH.inc b/plugins/vcard_attachments/localization/de_CH.inc new file mode 100644 index 000000000..48bb90013 --- /dev/null +++ b/plugins/vcard_attachments/localization/de_CH.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = 'Kontakt im Adressbuch speichern'; +$labels['vcardsavefailed'] = 'Der Kontakt konnte nicht gespeichert werden'; + +?>
\ No newline at end of file diff --git a/plugins/vcard_attachments/localization/de_DE.inc b/plugins/vcard_attachments/localization/de_DE.inc new file mode 100644 index 000000000..48bb90013 --- /dev/null +++ b/plugins/vcard_attachments/localization/de_DE.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = 'Kontakt im Adressbuch speichern'; +$labels['vcardsavefailed'] = 'Der Kontakt konnte nicht gespeichert werden'; + +?>
\ No newline at end of file diff --git a/plugins/vcard_attachments/localization/en_US.inc b/plugins/vcard_attachments/localization/en_US.inc new file mode 100644 index 000000000..bce44d739 --- /dev/null +++ b/plugins/vcard_attachments/localization/en_US.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = 'Add vCard to addressbook'; +$labels['vcardsavefailed'] = 'Unable to save vCard'; + +?>
\ No newline at end of file diff --git a/plugins/vcard_attachments/localization/es_ES.inc b/plugins/vcard_attachments/localization/es_ES.inc new file mode 100644 index 000000000..0aba6b391 --- /dev/null +++ b/plugins/vcard_attachments/localization/es_ES.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = 'Añadir la tarjeta a la libreta de direcciones'; +$labels['vcardsavefailed'] = 'No ha sido posible guardar la tarjeta'; + +?>
\ No newline at end of file diff --git a/plugins/vcard_attachments/localization/et_EE.inc b/plugins/vcard_attachments/localization/et_EE.inc new file mode 100644 index 000000000..eb6ce230f --- /dev/null +++ b/plugins/vcard_attachments/localization/et_EE.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = 'Lisa vCard aadressiraamatusse'; +$labels['vcardsavefailed'] = 'vCard salvestamine nurjus'; + +?> diff --git a/plugins/vcard_attachments/localization/gl_ES.inc b/plugins/vcard_attachments/localization/gl_ES.inc new file mode 100644 index 000000000..4c3574a8f --- /dev/null +++ b/plugins/vcard_attachments/localization/gl_ES.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = 'Engadir a tarxeta ao caderno de enderezos'; +$labels['vcardsavefailed'] = 'Non foi posible gardar a tarxeta'; + +?>
\ No newline at end of file diff --git a/plugins/vcard_attachments/localization/it_IT.inc b/plugins/vcard_attachments/localization/it_IT.inc new file mode 100644 index 000000000..55cde3961 --- /dev/null +++ b/plugins/vcard_attachments/localization/it_IT.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = 'Aggiungi vCard alla Agenda'; +$labels['vcardsavefailed'] = 'Abilita a salvare vCard'; + +?> diff --git a/plugins/vcard_attachments/localization/ja_JP.inc b/plugins/vcard_attachments/localization/ja_JP.inc new file mode 100644 index 000000000..0b4d0d91d --- /dev/null +++ b/plugins/vcard_attachments/localization/ja_JP.inc @@ -0,0 +1,9 @@ +<?php + +// EN-Revision: 3891 + +$labels = array(); +$labels['addvardmsg'] = 'アドレス帳に vCard を追加する'; +$labels['vcardsavefailed'] = 'vCard を保存できませんでした。'; + +?>
\ No newline at end of file diff --git a/plugins/vcard_attachments/localization/pl_PL.inc b/plugins/vcard_attachments/localization/pl_PL.inc new file mode 100644 index 000000000..800e35b38 --- /dev/null +++ b/plugins/vcard_attachments/localization/pl_PL.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = 'Dodaj wizytówkę (vCard) do kontaktów'; +$labels['vcardsavefailed'] = 'Nie można zapisać wizytówki (vCard)'; + +?> diff --git a/plugins/vcard_attachments/localization/pt_BR.inc b/plugins/vcard_attachments/localization/pt_BR.inc new file mode 100644 index 000000000..263f88442 --- /dev/null +++ b/plugins/vcard_attachments/localization/pt_BR.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = 'Adicionar o vCard ao Catálogo de Endereços'; +$labels['vcardsavefailed'] = 'Impossível salvar o vCard'; + +?>
\ No newline at end of file diff --git a/plugins/vcard_attachments/localization/ru_RU.inc b/plugins/vcard_attachments/localization/ru_RU.inc new file mode 100644 index 000000000..1688c5dc8 --- /dev/null +++ b/plugins/vcard_attachments/localization/ru_RU.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = 'Добавить в контакты'; +$labels['vcardsavefailed'] = 'Не удалось сохранить vCard'; + +?>
\ No newline at end of file diff --git a/plugins/vcard_attachments/localization/sv_SE.inc b/plugins/vcard_attachments/localization/sv_SE.inc new file mode 100644 index 000000000..4c9faddf9 --- /dev/null +++ b/plugins/vcard_attachments/localization/sv_SE.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = 'Lägg till vCard i adressbok'; +$labels['vcardsavefailed'] = 'Kunde inte spara vCard'; + +?>
\ No newline at end of file diff --git a/plugins/vcard_attachments/localization/zh_TW.inc b/plugins/vcard_attachments/localization/zh_TW.inc new file mode 100644 index 000000000..361837bfc --- /dev/null +++ b/plugins/vcard_attachments/localization/zh_TW.inc @@ -0,0 +1,7 @@ +<?php + +$labels = array(); +$labels['addvcardmsg'] = '加入 vCard 到通訊錄'; +$labels['vcardsavefailed'] = '無法儲存 vCard'; + +?>
\ No newline at end of file diff --git a/plugins/vcard_attachments/package.xml b/plugins/vcard_attachments/package.xml new file mode 100644 index 000000000..e5eaf7187 --- /dev/null +++ b/plugins/vcard_attachments/package.xml @@ -0,0 +1,100 @@ +<?xml version="1.0" encoding="UTF-8"?> +<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.9.0" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 + http://pear.php.net/dtd/tasks-1.0.xsd + http://pear.php.net/dtd/package-2.0 + http://pear.php.net/dtd/package-2.0.xsd"> + <name>vcard_attachments</name> + <channel>pear.roundcube.net</channel> + <summary>vCard handler for Roundcube</summary> + <description>This plugin detects vCard attachments/bodies and shows a button(s) to add them to address book</description> + <lead> + <name>Thomas Bruederli</name> + <user>thomasb</user> + <email>roundcube@gmail.com</email> + <active>yes</active> + </lead> + <lead> + <name>Aleksander Machniak</name> + <user>alec</user> + <email>alec@alec.pl</email> + <active>yes</active> + </lead> + <date>2010-10-14</date> + <time>19:00</time> + <version> + <release>3.0</release> + <api>3.0</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.gnu.org/licenses/gpl-2.0.html">GNU GPLv2</license> + <notes> +- Exec contact_create hook when adding contact (#1486964) +- Make icons skinable +- Display vcard icon on messages list when message is of type vcard + </notes> + <contents> + <dir baseinstalldir="/" name="/"> + <file name="vcard_attachments.php" role="php"> + <tasks:replace from="@name@" to="name" type="package-info"/> + <tasks:replace from="@package_version@" to="version" type="package-info"/> + </file> + <file name="vcardattach.js" role="data"> + <tasks:replace from="@name@" to="name" type="package-info"/> + <tasks:replace from="@package_version@" to="version" type="package-info"/> + </file> + <file name="localization/cs_CZ.inc" role="data"></file> + <file name="localization/en_US.inc" role="data"></file> + <file name="localization/de_CH.inc" role="data"></file> + <file name="localization/de_DE.inc" role="data"></file> + <file name="localization/es_ES.inc" role="data"></file> + <file name="localization/et_EE.inc" role="data"></file> + <file name="localization/gl_ES.inc" role="data"></file> + <file name="localization/it_IT.inc" role="data"></file> + <file name="localization/ja_JP.inc" role="data"></file> + <file name="localization/es_ES.inc" role="data"></file> + <file name="localization/pl_PL.inc" role="data"></file> + <file name="localization/ru_RU.inc" role="data"></file> + <file name="localization/sv_SE.inc" role="data"></file> + <file name="localization/zh_TW.inc" role="data"></file> + <file name="skins/default/vcard_add_contact.png" role="data"></file> + <file name="skins/default/vcard.png" role="data"></file> + </dir> + <!-- / --> + </contents> + <dependencies> + <required> + <php> + <min>5.2.1</min> + </php> + <pearinstaller> + <min>1.7.0</min> + </pearinstaller> + </required> + </dependencies> + <phprelease/> + <changelog> + <release> + <date>2010-04-28</date> + <time>12:00:00</time> + <version> + <release>2.0</release> + <api>2.0</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.gnu.org/licenses/gpl-2.0.html">GNU GPLv2</license> + <notes> +- Added support for Content-Type: text/directory; profile=vCard +- Added handler for message bodies of type vCard (#1486683) +- Added support for more than one vCard attachment/body +- Added support for more than one contact in one vCard file +- Created package.xml + </notes> + </release> + </changelog> +</package> diff --git a/plugins/vcard_attachments/skins/default/vcard.png b/plugins/vcard_attachments/skins/default/vcard.png Binary files differnew file mode 100644 index 000000000..8bf6b1b72 --- /dev/null +++ b/plugins/vcard_attachments/skins/default/vcard.png diff --git a/plugins/vcard_attachments/skins/default/vcard_add_contact.png b/plugins/vcard_attachments/skins/default/vcard_add_contact.png Binary files differnew file mode 100644 index 000000000..478c1f3f2 --- /dev/null +++ b/plugins/vcard_attachments/skins/default/vcard_add_contact.png diff --git a/plugins/vcard_attachments/vcard_attachments.php b/plugins/vcard_attachments/vcard_attachments.php new file mode 100644 index 000000000..3fb3bf9ad --- /dev/null +++ b/plugins/vcard_attachments/vcard_attachments.php @@ -0,0 +1,184 @@ +<?php + +/** + * Detect VCard attachments and show a button to add them to address book + * + * @version @package_version@ + * @author Thomas Bruederli, Aleksander Machniak + */ +class vcard_attachments extends rcube_plugin +{ + public $task = 'mail'; + + private $message; + private $vcard_parts = array(); + private $vcard_bodies = array(); + + function init() + { + $rcmail = rcmail::get_instance(); + if ($rcmail->action == 'show' || $rcmail->action == 'preview') { + $this->add_hook('message_load', array($this, 'message_load')); + $this->add_hook('template_object_messagebody', array($this, 'html_output')); + } + else if (!$rcmail->output->framed && (!$rcmail->action || $rcmail->action == 'list')) { + $icon = 'plugins/vcard_attachments/' .$this->local_skin_path(). '/vcard.png'; + $rcmail->output->set_env('vcard_icon', $icon); + $this->include_script('vcardattach.js'); + } + + $this->register_action('plugin.savevcard', array($this, 'save_vcard')); + } + + /** + * Check message bodies and attachments for vcards + */ + function message_load($p) + { + $this->message = $p['object']; + + // handle attachments vcard attachments + foreach ((array)$this->message->attachments as $attachment) { + if ($this->is_vcard($attachment)) { + $this->vcard_parts[] = $attachment->mime_id; + } + } + // the same with message bodies + foreach ((array)$this->message->parts as $idx => $part) { + if ($this->is_vcard($part)) { + $this->vcard_parts[] = $part->mime_id; + $this->vcard_bodies[] = $part->mime_id; + } + } + + if ($this->vcard_parts) + $this->add_texts('localization'); + } + + /** + * This callback function adds a box below the message content + * if there is a vcard attachment available + */ + function html_output($p) + { + $attach_script = false; + $icon = 'plugins/vcard_attachments/' .$this->local_skin_path(). '/vcard_add_contact.png'; + + foreach ($this->vcard_parts as $part) { + $vcards = rcube_vcard::import($this->message->get_part_content($part)); + + // successfully parsed vcards? + if (empty($vcards)) + continue; + + // remove part's body + if (in_array($part, $this->vcard_bodies)) + $p['content'] = ''; + + $style = 'margin:0.5em 1em; padding:0.2em 0.5em; border:1px solid #999; ' + .'border-radius:4px; -moz-border-radius:4px; -webkit-border-radius:4px; width: auto'; + + foreach ($vcards as $idx => $vcard) { + $display = $vcard->displayname; + if ($vcard->email[0]) + $display .= ' <'.$vcard->email[0].'>'; + + // add box below messsage body + $p['content'] .= html::p(array('style' => $style), + html::a(array( + 'href' => "#", + 'onclick' => "return plugin_vcard_save_contact('".JQ($part.':'.$idx)."')", + 'title' => $this->gettext('addvcardmsg')), + html::img(array('src' => $icon, 'style' => "vertical-align:middle"))) + . ' ' . html::span(null, Q($display))); + } + + $attach_script = true; + } + + if ($attach_script) + $this->include_script('vcardattach.js'); + + return $p; + } + + /** + * Handler for request action + */ + function save_vcard() + { + $this->add_texts('localization', true); + + $uid = get_input_value('_uid', RCUBE_INPUT_POST); + $mbox = get_input_value('_mbox', RCUBE_INPUT_POST); + $mime_id = get_input_value('_part', RCUBE_INPUT_POST); + + $rcmail = rcmail::get_instance(); + + if ($uid && $mime_id) { + list($mime_id, $index) = explode(':', $mime_id); + $part = $rcmail->imap->get_message_part($uid, $mime_id); + } + + $error_msg = $this->gettext('vcardsavefailed'); + + if ($part && ($vcards = rcube_vcard::import($part)) + && ($vcard = $vcards[$index]) && $vcard->displayname && $vcard->email) { + + $contacts = $rcmail->get_address_book(null, true); + + // check for existing contacts + $existing = $contacts->search('email', $vcard->email[0], true, false); + if ($existing->count) { + $rcmail->output->command('display_message', $this->gettext('contactexists'), 'warning'); + } + else { + // add contact + $contact = array( + 'name' => $vcard->displayname, + 'firstname' => $vcard->firstname, + 'surname' => $vcard->surname, + 'email' => $vcard->email[0], + 'vcard' => $vcard->export(), + ); + + $plugin = $rcmail->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null)); + $contact = $plugin['record']; + + if (!$plugin['abort'] && ($done = $contacts->insert($contact))) + $rcmail->output->command('display_message', $this->gettext('addedsuccessfully'), 'confirmation'); + else + $rcmail->output->command('display_message', $error_msg, 'error'); + } + } + else + $rcmail->output->command('display_message', $error_msg, 'error'); + + $rcmail->output->send(); + } + + /** + * Checks if specified message part is a vcard data + * + * @param rcube_message_part Part object + * + * @return boolean True if part is of type vcard + */ + function is_vcard($part) + { + return ( + // Content-Type: text/vcard; + $part->mimetype == 'text/vcard' || + // Content-Type: text/x-vcard; + $part->mimetype == 'text/x-vcard' || + // Content-Type: text/directory; profile=vCard; + ($part->mimetype == 'text/directory' && ( + ($part->ctype_parameters['profile'] && + strtolower($part->ctype_parameters['profile']) == 'vcard') + // Content-Type: text/directory; (with filename=*.vcf) + || ($part->filename && preg_match('/\.vcf$/i', $part->filename)) + ) + ) + ); + } +} diff --git a/plugins/vcard_attachments/vcardattach.js b/plugins/vcard_attachments/vcardattach.js new file mode 100644 index 000000000..ef19190e7 --- /dev/null +++ b/plugins/vcard_attachments/vcardattach.js @@ -0,0 +1,23 @@ +/* + * vcard_attachments plugin script + * @version @package_version@ + */ +function plugin_vcard_save_contact(mime_id) +{ + var lock = rcmail.set_busy(true, 'loading'); + rcmail.http_post('plugin.savevcard', '_uid='+rcmail.env.uid+'&_mbox='+urlencode(rcmail.env.mailbox)+'&_part='+urlencode(mime_id), lock); + + return false; +} + +function plugin_vcard_insertrow(data) +{ + var ctype = data.row.ctype; + if (ctype == 'text/vcard' || ctype == 'text/x-vcard' || ctype == 'text/directory') { + $('#rcmrow'+data.uid+' > td.attachment').html('<img src="'+rcmail.env.vcard_icon+'" alt="">'); + } +} + +if (window.rcmail && rcmail.gui_objects.messagelist) { + rcmail.addEventListener('insertrow', function(data, evt) { plugin_vcard_insertrow(data); }); +} |