Skip to content

Commit

Permalink
Merge pull request #392 from owncloud/ignore-file-mime-on-import
Browse files Browse the repository at this point in the history
Do not rely on the file type but simply try to parse the given file a…
  • Loading branch information
DeepDiver1975 committed Apr 27, 2016
2 parents 78d59e7 + 33cf707 commit b4cc089
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 b4cc089

Please sign in to comment.