Skip to content

Commit

Permalink
Do not rely on the file type but simply try to parse the given file a…
Browse files Browse the repository at this point in the history
…s vcard - fixes #385
  • Loading branch information
DeepDiver1975 committed Apr 25, 2016
1 parent b28ef41 commit 33cf707
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions js/services/contact_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
});
}
};

Expand Down

0 comments on commit 33cf707

Please sign in to comment.