diff --git a/src/importers/buttercupCsvImporter.ts b/src/importers/buttercupCsvImporter.ts new file mode 100644 index 0000000000..9173dc6569 --- /dev/null +++ b/src/importers/buttercupCsvImporter.ts @@ -0,0 +1,51 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { ImportResult } from '../models/domain/importResult'; + +const OfficialProps = [ + '!group_id', '!group_name', 'title', 'username', 'password', 'URL', 'id', +]; + +export class ButtercupCsvImporter extends BaseImporter implements Importer { + parse(data: string): ImportResult { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return result; + } + + results.forEach((value) => { + this.processFolder(result, this.getValueOrDefault(value['!group_name'])); + + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.title, '--'); + cipher.login.username = this.getValueOrDefault(value.username); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.uris = this.makeUriArray(value.URL); + + let processingCustomFields = false; + for (const prop in value) { + if (value.hasOwnProperty(prop)) { + if (!processingCustomFields && OfficialProps.indexOf(prop) === -1) { + processingCustomFields = true; + } + if (processingCustomFields) { + this.processKvp(cipher, prop, value[prop]); + } + } + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return result; + } +} diff --git a/src/services/import.service.ts b/src/services/import.service.ts index 8e2ce4e429..2526485bc9 100644 --- a/src/services/import.service.ts +++ b/src/services/import.service.ts @@ -30,6 +30,7 @@ import { BitwardenCsvImporter } from '../importers/bitwardenCsvImporter'; import { BitwardenJsonImporter } from '../importers/bitwardenJsonImporter'; import { BlackBerryCsvImporter } from '../importers/blackBerryCsvImporter'; import { BlurCsvImporter } from '../importers/blurCsvImporter'; +import { ButtercupCsvImporter } from '../importers/buttercupCsvImporter'; import { ChromeCsvImporter } from '../importers/chromeCsvImporter'; import { ClipperzHtmlImporter } from '../importers/clipperzHtmlImporter'; import { DashlaneJsonImporter } from '../importers/dashlaneJsonImporter'; @@ -123,6 +124,7 @@ export class ImportService implements ImportServiceAbstraction { { id: 'securesafecsv', name: 'SecureSafe (csv)' }, { id: 'logmeoncecsv', name: 'LogMeOnce (csv)' }, { id: 'blackberrycsv', name: 'BlackBerry Password Keeper (csv)' }, + { id: 'buttercupcsv', name: 'Buttercup (csv)' }, ]; constructor(private cipherService: CipherService, private folderService: FolderService, @@ -263,6 +265,8 @@ export class ImportService implements ImportServiceAbstraction { return new LogMeOnceCsvImporter(); case 'blackberrycsv': return new BlackBerryCsvImporter(); + case 'buttercupcsv': + return new ButtercupCsvImporter(); default: return null; }