summaryrefslogtreecommitdiff
path: root/plugins/vcard_attachments/vcard_attachments.php
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2012-04-13 10:08:51 +0000
committeralecpl <alec@alec.pl>2012-04-13 10:08:51 +0000
commit3c32f32025fa9556a3f902c004f831bdc9f6f9b8 (patch)
treec543c0328d58f7a960ed36c0091ad0423475f264 /plugins/vcard_attachments/vcard_attachments.php
parent71950df6df07614300b6a79b726e7cfd61534b29 (diff)
- Fixed doble urlencoding of vcard identifier
- Fixed encoding when default charset is different than vcard charset - Improved vcards import to work as addressbook::import procedure (with validation and autofix)
Diffstat (limited to 'plugins/vcard_attachments/vcard_attachments.php')
-rw-r--r--plugins/vcard_attachments/vcard_attachments.php55
1 files changed, 34 insertions, 21 deletions
diff --git a/plugins/vcard_attachments/vcard_attachments.php b/plugins/vcard_attachments/vcard_attachments.php
index c321e84aa..c9f843f2b 100644
--- a/plugins/vcard_attachments/vcard_attachments.php
+++ b/plugins/vcard_attachments/vcard_attachments.php
@@ -66,7 +66,7 @@ class vcard_attachments extends rcube_plugin
$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));
+ $vcards = rcube_vcard::import($this->message->get_part_content($part, null, true));
// successfully parsed vcards?
if (empty($vcards))
@@ -114,46 +114,59 @@ class vcard_attachments extends rcube_plugin
$mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
$mime_id = get_input_value('_part', RCUBE_INPUT_POST);
- $rcmail = rcmail::get_instance();
+ $rcmail = rcmail::get_instance();
+ $storage = $rcmail->get_storage();
+ $storage->set_folder($mbox);
if ($uid && $mime_id) {
list($mime_id, $index) = explode(':', $mime_id);
- $part = $rcmail->storage->get_message_part($uid, $mime_id);
+ $part = $storage->get_message_part($uid, $mime_id, null, null, null, true);
}
$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');
+ && ($vcard = $vcards[$index]) && $vcard->displayname && $vcard->email
+ ) {
+ $CONTACTS = $rcmail->get_address_book(null, true);
+ $email = $vcard->email[0];
+ $contact = $vcard->get_assoc();
+ $valid = true;
+
+ // skip entries without an e-mail address or invalid
+ if (empty($email) || !$CONTACTS->validate($contact, true)) {
+ $valid = false;
}
else {
- // add contact
- $contact = array(
- 'name' => $vcard->displayname,
- 'firstname' => $vcard->firstname,
- 'surname' => $vcard->surname,
- 'email' => $vcard->email[0],
- 'vcard' => $vcard->export(),
- );
+ // We're using UTF8 internally
+ $email = rcube_idn_to_utf8($email);
+
+ // compare e-mail address
+ $existing = $CONTACTS->search('email', $email, 1, false);
+ // compare display name
+ if (!$existing->count && $vcard->displayname) {
+ $existing = $CONTACTS->search('name', $vcard->displayname, 1, false);
+ }
+
+ if ($existing->count) {
+ $rcmail->output->command('display_message', $this->gettext('contactexists'), 'warning');
+ $valid = false;
+ }
+ }
+ if ($valid) {
$plugin = $rcmail->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null));
$contact = $plugin['record'];
- if (!$plugin['abort'] && ($done = $contacts->insert($contact)))
+ if (!$plugin['abort'] && $CONTACTS->insert($contact))
$rcmail->output->command('display_message', $this->gettext('addedsuccessfully'), 'confirmation');
else
$rcmail->output->command('display_message', $error_msg, 'error');
}
}
- else
+ else {
$rcmail->output->command('display_message', $error_msg, 'error');
+ }
$rcmail->output->send();
}