'use strict';

module.exports = function(onepifdata) {

    var items = onepifdata.split(/\n\*\*\*.*?\*\*\*\n/);

    var creds = [];
    var count_password = 0;
    var count_credential = 0;

    items.forEach(function(item) {
        if (item) {
            var i = JSON.parse(item);
            var f = {
                location: i.locationKey,
                username: '',
                password: ''
            };

            if (i.typeName === 'passwords.Password') {
                f.password = i.secureContents.password;
                creds.push(f);
                count_password++;
                console.log('INFO: Password for ' + i.locationKey + ' collected.');
            } else if (i.typeName === 'webforms.WebForm') {
                i.secureContents.fields.forEach(function(field) {

                    if (field.designation === 'username') {
                        f.username = field.value;
                    }
                    if (field.designation === 'password') {
                        f.password = field.value;
                    }

                });
                creds.push(f);
                count_credential++;
                console.log('INFO: Credential for ' + i.locationKey + ' collected.');
            } else {
                console.log('WARN: Unknown type "' + i.typeName + '" item skipped.');
            }
        }
    });

    console.log('INFO: ' + items.length + ' items parsed\n' +
        'INFO: ' + count_credential + ' credentials collected\n' +
        'INFO: ' + count_password + ' passwords collected\n' +
        'INFO: Total ' + (count_credential + count_password) + ' collected. Now continuing...');

    return creds;

};

@@ -88,27 +88,43 @@
 t(/%5C
-n%5C
 *%5C*%5C*
-.*
+%5Ba-zA-Z0-9%5C-%5D%7B30,40%7D
 ?%5C*%5C*%5C*
-%5Cn/
+/gm
 );%0A%0A
@@ -292,16 +292,23 @@
 rse(item
+.trim()
 );%0A     

Fix .1pif JSON parsing