Index: plugins/vcard_attachments/package.xml
===================================================================
--- plugins/vcard_attachments/package.xml	(revision 48e9c14ebded89d858c8be0333f77f77a81b0877)
+++ plugins/vcard_attachments/package.xml	(revision 3c32f32025fa9556a3f902c004f831bdc9f6f9b8)
@@ -20,9 +20,9 @@
 		<active>yes</active>
 	</lead>
-	<date>2012-03-11</date>
-	<time>19:00</time>
+	<date>2012-04-13</date>
+	<time>12:00</time>
 	<version>
-		<release>3.1-beta</release>
-		<api>3.1-beta</api>
+		<release>3.1</release>
+		<api>3.1</api>
 	</version>
 	<stability>
@@ -32,8 +32,7 @@
 	<license uri="http://www.gnu.org/licenses/gpl.html">GNU GPLv3+</license>
 	<notes>
-- Add styles for new skin "Larry"
-- Exec contact_create hook when adding contact (#1486964)
-- Make icons skinable
-- Display vcard icon on messages list when message is of type vcard
+- 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)
 	</notes>
 	<contents>
@@ -118,4 +117,23 @@
 			</notes>
 		</release>
+        <release>
+        	<date>2012-03-11</date>
+        	<time>19:00</time>
+	        <version>
+        		<release>3.1-beta</release>
+		        <api>3.1-beta</api>
+        	</version>
+	        <stability>
+        		<release>stable</release>
+        		<api>stable</api>
+        	</stability>
+        	<license uri="http://www.gnu.org/licenses/gpl.html">GNU GPLv3+</license>
+        	<notes>
+- Add styles for new skin "Larry"
+- Exec contact_create hook when adding contact (#1486964)
+- Make icons skinable
+- Display vcard icon on messages list when message is of type vcard
+        	</notes>
+	    </release>
 	</changelog>
 </package>
Index: plugins/vcard_attachments/vcard_attachments.php
===================================================================
--- plugins/vcard_attachments/vcard_attachments.php	(revision 48e9c14ebded89d858c8be0333f77f77a81b0877)
+++ plugins/vcard_attachments/vcard_attachments.php	(revision 3c32f32025fa9556a3f902c004f831bdc9f6f9b8)
@@ -67,5 +67,5 @@
 
         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?
@@ -115,9 +115,11 @@
         $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);
         }
 
@@ -125,27 +127,37 @@
 
         if ($part && ($vcards = rcube_vcard::import($part))
-            && ($vcard = $vcards[$index]) && $vcard->displayname && $vcard->email) {
+            && ($vcard = $vcards[$index]) && $vcard->displayname && $vcard->email
+        ) {
+            $CONTACTS = $rcmail->get_address_book(null, true);
+            $email    = $vcard->email[0];
+            $contact  = $vcard->get_assoc();
+            $valid    = true;
 
-            $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');
+            // 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
@@ -153,6 +165,7 @@
             }
         }
-        else
+        else {
             $rcmail->output->command('display_message', $error_msg, 'error');
+        }
 
         $rcmail->output->send();
Index: plugins/vcard_attachments/vcardattach.js
===================================================================
--- plugins/vcard_attachments/vcardattach.js	(revision 48e9c14ebded89d858c8be0333f77f77a81b0877)
+++ plugins/vcard_attachments/vcardattach.js	(revision 3c32f32025fa9556a3f902c004f831bdc9f6f9b8)
@@ -6,6 +6,6 @@
 {
   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);
-  
+  rcmail.http_post('plugin.savevcard', { _uid: rcmail.env.uid, _mbox: rcmail.env.mailbox, _part: mime_id }, lock);
+
   return false;
 }
