Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not rely on the file type but simply try to parse the given file a… #392

Merged
merged 1 commit into from
Apr 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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