diff options
author | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-04-27 10:07:08 +0200 |
---|---|---|
committer | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-04-27 10:07:08 +0200 |
commit | b4cc0894d91caa6f17b70be2ea401631797bd35e (patch) | |
tree | df0bbf0c6594d036b6f2516f3b4c71990eacf32b | |
parent | 78d59e7199c5d8a99ee3329434e89c2e0e952942 (diff) | |
parent | 33cf707a904abc13a411dd18a770069e80242e46 (diff) |
Merge pull request #392 from owncloud/ignore-file-mime-on-import
Do not rely on the file type but simply try to parse the given file a…
-rw-r--r-- | js/services/contact_service.js | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/js/services/contact_service.js b/js/services/contact_service.js index 99aaffca..dec16385 100644 --- a/js/services/contact_service.js +++ b/js/services/contact_service.js @@ -113,21 +113,24 @@ angular.module('contactsApp') this.import = function(data, type, addressBook, progressCallback) { addressBook = addressBook || AddressBookService.getDefaultAddressBook(); - if(type === 'text/vcard') { - var regexp = /BEGIN:VCARD[\s\S]*?END:VCARD/mgi; - var singleVCards = data.match(regexp); - - var num = 1; - for(var i in singleVCards) { - var newContact = new Contact(addressBook, {addressData: singleVCards[i]}); - this.create(newContact, addressBook).then(function() { - // Update the progress indicator - if (progressCallback) progressCallback(num/singleVCards.length); - num++; - }); + var regexp = /BEGIN:VCARD[\s\S]*?END:VCARD/mgi; + var singleVCards = data.match(regexp); + + if (!singleVCards) { + OC.Notification.showTemporary(t('contacts', 'No contacts in file. Only VCard files are allowed.')); + if (progressCallback) { + progressCallback(1); } - } else { - OC.Notification.showTemporary(t('contacts', 'Invalid file type.')); + return; + } + var num = 1; + for(var i in singleVCards) { + var newContact = new Contact(addressBook, {addressData: singleVCards[i]}); + this.create(newContact, addressBook).then(function() { + // Update the progress indicator + if (progressCallback) progressCallback(num/singleVCards.length); + num++; + }); } }; |