summaryrefslogtreecommitdiff
path: root/plugins/vcard_attachments
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2010-09-29 10:00:48 +0000
committerthomascube <thomas@roundcube.net>2010-09-29 10:00:48 +0000
commit2baa16ae6d8355e0dfb38e400fd4115057b0680d (patch)
tree0e5790c0ff37980bfcdca26b1bfe4c392cf211b6 /plugins/vcard_attachments
parent717815c9a88222fc19989d6545134bb4d1df62c9 (diff)
Copy plugins into 0.4.1 release branch
Diffstat (limited to 'plugins/vcard_attachments')
-rw-r--r--plugins/vcard_attachments/localization/cs_CZ.inc21
-rw-r--r--plugins/vcard_attachments/localization/de_CH.inc7
-rw-r--r--plugins/vcard_attachments/localization/de_DE.inc7
-rw-r--r--plugins/vcard_attachments/localization/en_US.inc7
-rw-r--r--plugins/vcard_attachments/localization/es_ES.inc7
-rw-r--r--plugins/vcard_attachments/localization/et_EE.inc7
-rw-r--r--plugins/vcard_attachments/localization/ja_JP.inc9
-rw-r--r--plugins/vcard_attachments/localization/pl_PL.inc7
-rw-r--r--plugins/vcard_attachments/localization/ru_RU.inc7
-rw-r--r--plugins/vcard_attachments/localization/sv_SE.inc7
-rw-r--r--plugins/vcard_attachments/localization/zh_TW.inc7
-rw-r--r--plugins/vcard_attachments/package.xml89
-rw-r--r--plugins/vcard_attachments/vcard_add_contact.pngbin0 -> 1361 bytes
-rw-r--r--plugins/vcard_attachments/vcard_attachments.php179
-rw-r--r--plugins/vcard_attachments/vcardattach.js13
15 files changed, 374 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..5d7c9c4c2
--- /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, RoundQube Dev. - Switzerland |
+| 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..c00b4990b
--- /dev/null
+++ b/plugins/vcard_attachments/localization/es_ES.inc
@@ -0,0 +1,7 @@
+<?php
+
+$labels = array();
+$labels['addvcardmsg'] = 'Añadir tarjeta a la libreta de direcciones';
+$labels['vcardsavefailed'] = 'Imposible 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/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/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..64a92defb
--- /dev/null
+++ b/plugins/vcard_attachments/package.xml
@@ -0,0 +1,89 @@
+<?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></date>
+ <time></time>
+ <version>
+ <release></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>
+- Exec contact_create hook when adding contact (#1486964)
+ </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/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/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="vcard_add_contact.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/vcard_add_contact.png b/plugins/vcard_attachments/vcard_add_contact.png
new file mode 100644
index 000000000..478c1f3f2
--- /dev/null
+++ b/plugins/vcard_attachments/vcard_add_contact.png
Binary files differ
diff --git a/plugins/vcard_attachments/vcard_attachments.php b/plugins/vcard_attachments/vcard_attachments.php
new file mode 100644
index 000000000..a4c1795b7
--- /dev/null
+++ b/plugins/vcard_attachments/vcard_attachments.php
@@ -0,0 +1,179 @@
+<?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'));
+ }
+
+ $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;
+
+ 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' => $this->url('vcard_add_contact.png'),
+ '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..021087edc
--- /dev/null
+++ b/plugins/vcard_attachments/vcardattach.js
@@ -0,0 +1,13 @@
+/*
+ * vcard_attachments plugin script
+ * @version @package_version@
+ */
+function plugin_vcard_save_contact(mime_id)
+{
+ rcmail.set_busy(true, 'loading');
+ rcmail.http_post('plugin.savevcard', '_uid='+rcmail.env.uid+'&_mbox='+urlencode(rcmail.env.mailbox)+'&_part='+urlencode(mime_id), true);
+
+ return false;
+}
+
+