From 3139af61d2f5a88c7b06fb21d7f3066cb6780b39 Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Wed, 14 Nov 2018 11:42:04 +0100 Subject: [PATCH] Make dc.configure() take camel case options --- README.md | 32 ++++++++++++------------- index.js | 39 ++++++++++++++++--------------- test/integration.js | 57 ++++++++++++++++++++++++--------------------- test/open.js | 6 ++--- 4 files changed, 70 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index b21e541c..6d236f79 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ dc.open(() => { dc.once('ready', onReady) dc.configure({ addr: 'user@site.org', - mail_pw: 'password' + mailPw: 'password' }) } else { onReady() @@ -166,21 +166,21 @@ Configure and connect a context. Corresponds to [`dc_configure()`](https://c.del The `options` object takes the following properties: * `options.addr` *(string, required)*: Email address of the chat user. -* `options.mail_server` *(string, optional)*: IMAP-server, guessed if left out. -* `options.mail_user` *(string, optional)*: IMAP-username, guessed if left out. -* `options.mail_pw` *(string, required)*: IMAP-password of the chat user. -* `options.mail_port` *(string | integer, optional)*: IMAP-port, guessed if left out. -* `options.send_server` *(string, optional)*: SMTP-server, guessed if left out. -* `options.send_user` *(string, optional)*: SMTP-user, guessed if left out. -* `options.send_pw` *(string, optional)*: SMTP-password, guessed if left out. -* `options.send_port` *(string | integer, optional)*: SMTP-port, guessed if left out. -* `options.server_flags` *(integer, optional)*: IMAP-/SMTP-flags as a combination of DC_LP flags, guessed if left out. -* `options.displayname` *(string, optional)*: Own name to use when sending messages. MUAs are allowed to spread this way e.g. using CC, defaults to empty. -* `options.selfstatus` *(string, optional)*: Own status to display e.g. in email footers, defaults to a standard text. -* `options.selfavatar` *(string, optional)*: File containing avatar. -* `options.e2ee_enabled` *(boolean, optional)*: Enable E2EE. Defaults to `true`. -* `options.mdns_enabled` *(boolean, optional)*: Send and request read receipts. Defaults to `true`. -* `options.save_mime_headers` *(boolean, optional)*: Set to `true` if you want to use [`dc.getMimeHeaders()`](#getmimeheaders) later. +* `options.mailServer` *(string, optional)*: IMAP-server, guessed if left out. +* `options.mailUser` *(string, optional)*: IMAP-username, guessed if left out. +* `options.mailPw` *(string, required)*: IMAP-password of the chat user. +* `options.mailPort` *(string | integer, optional)*: IMAP-port, guessed if left out. +* `options.sendServer` *(string, optional)*: SMTP-server, guessed if left out. +* `options.sendUser` *(string, optional)*: SMTP-user, guessed if left out. +* `options.sendPw` *(string, optional)*: SMTP-password, guessed if left out. +* `options.sendPort` *(string | integer, optional)*: SMTP-port, guessed if left out. +* `options.serverFlags` *(integer, optional)*: IMAP-/SMTP-flags as a combination of DC_LP flags, guessed if left out. +* `options.displayName` *(string, optional)*: Own name to use when sending messages. MUAs are allowed to spread this way e.g. using CC, defaults to empty. +* `options.selfStatus` *(string, optional)*: Own status to display e.g. in email footers, defaults to a standard text. +* `options.selfAvatar` *(string, optional)*: File containing avatar. +* `options.e2eeEnabled` *(boolean, optional)*: Enable E2EE. Defaults to `true`. +* `options.mdnsEnabled` *(boolean, optional)*: Send and request read receipts. Defaults to `true`. +* `options.saveMimeHeaders` *(boolean, optional)*: Set to `true` if you want to use [`dc.getMimeHeaders()`](#getmimeheaders) later. #### `dc.continueKeyTransfer(messageId, setupCode, callback)` diff --git a/index.js b/index.js index 928fddda..bf6c1e9b 100644 --- a/index.js +++ b/index.js @@ -102,32 +102,33 @@ class DeltaChat extends EventEmitter { throw new Error('Missing .addr') } - if (typeof opts.mail_pw !== 'string') { - throw new Error('Missing .mail_pw') + if (typeof opts.mailPw !== 'string') { + throw new Error('Missing .mailPw') } this.once('_configured', ready) - if (typeof opts.e2ee_enabled === 'undefined') opts.e2ee_enabled = 1 + if (typeof opts.e2eeEnabled === 'undefined') opts.e2eeEnabled = 1 this.setConfig('addr', opts.addr) - this.setConfig('mail_server', opts.mail_server) - this.setConfig('mail_user', opts.mail_user) - this.setConfig('mail_port', String(opts.mail_port)) - - this.setConfig('mail_pw', opts.mail_pw) - this.setConfig('send_server', opts.send_server) - this.setConfig('send_user', opts.send_user) - this.setConfig('send_pw', opts.send_pw) - this.setConfig('send_port', String(opts.send_port)) - this.setConfig('server_flags', String(opts.server_flags)) - this.setConfig('displayname', opts.displayname) - this.setConfig('selfstatus', opts.selfstatus) - this.setConfig('selfavatar', opts.selfavatar) - this.setConfig('e2ee_enabled', String(opts.e2ee_enabled ? 1 : 0)) - this.setConfig('mdns_enabled', String(opts.mdns_enabled ? 1 : 0)) - this.setConfig('save_mime_headers', String(opts.save_mime_headers ? 1 : 0)) + this.setConfig('mail_server', opts.mailServer) + this.setConfig('mail_user', opts.mailUser) + this.setConfig('mail_pw', opts.mailPw) + this.setConfig('mail_port', String(opts.mailPort)) + + this.setConfig('send_server', opts.sendServer) + this.setConfig('send_user', opts.sendUser) + this.setConfig('send_pw', opts.sendPw) + this.setConfig('send_port', String(opts.sendPort)) + + this.setConfig('server_flags', String(opts.serverFlags)) + this.setConfig('displayname', opts.displayName) + this.setConfig('selfstatus', opts.selfStatus) + this.setConfig('selfavatar', opts.selfAvatar) + this.setConfig('e2ee_enabled', String(opts.e2eeEnabled ? 1 : 0)) + this.setConfig('mdns_enabled', String(opts.mdnsEnabled ? 1 : 0)) + this.setConfig('save_mime_headers', String(opts.saveMimeHeaders ? 1 : 0)) binding.dcn_configure(this.dcn_context) } diff --git a/test/integration.js b/test/integration.js index 81d52a7b..7266d7b7 100644 --- a/test/integration.js +++ b/test/integration.js @@ -10,19 +10,24 @@ let dc = null function configureDefaultDC (dc) { dc.configure({ addr: 'delta1@delta.localhost', - mail_server: '127.0.0.1', - mail_user: 'delta1', - mail_pw: 'delta1', - mail_port: 3143, - send_server: '127.0.0.1', - send_user: 'delta1', - send_pw: 'delta1', - send_port: 3025, - server_flags: 0x400 | 0x40000, - displayname: 'Delta One', - selfstatus: 'From Delta One with <3', - e2ee_enabled: true, - save_mime_headers: true + + mailServer: '127.0.0.1', + mailUser: 'delta1', + mailPw: 'delta1', + mailPort: 3143, + + sendServer: '127.0.0.1', + sendUser: 'delta1', + sendPw: 'delta1', + sendPort: 3025, + + serverFlags: 0x400 | 0x40000, + + displayName: 'Delta One', + selfStatus: 'From Delta One with <3', + + e2eeEnabled: true, + saveMimeHeaders: true }) } @@ -38,19 +43,19 @@ test('setUp dc context', t => { dc = new DeltaChat() dc.once('ready', () => { t.is(dc.getConfig('addr'), 'delta1@delta.localhost', 'addr correct') - t.is(dc.getConfig('mail_server'), '127.0.0.1', 'mail_server correct') - t.is(dc.getConfig('mail_port'), '3143', 'mail_port correct') - t.is(dc.getConfig('mail_user'), 'delta1', 'mail_user correct') - t.is(dc.getConfig('mail_pw'), 'delta1', 'mail_pw correct') - t.is(dc.getConfig('send_server'), '127.0.0.1', 'send_server correct') - t.is(dc.getConfig('send_port'), '3025', 'send_port correct') - t.is(dc.getConfig('send_user'), 'delta1', 'send_user correct') - t.is(dc.getConfig('send_pw'), 'delta1', 'send_pw correct') - t.is(dc.getConfig('server_flags'), String(0x400 | 0x40000), 'server_flags correct') - t.is(dc.getConfig('displayname'), 'Delta One', 'displayname correct') - t.is(dc.getConfig('selfstatus'), 'From Delta One with <3', 'selfstatus correct') - t.is(dc.getConfig('e2ee_enabled'), '1', 'e2ee enabled') - t.is(dc.getConfig('save_mime_headers'), '1', 'saving mime headers enabled') + t.is(dc.getConfig('mail_server'), '127.0.0.1', 'mailServer correct') + t.is(dc.getConfig('mail_port'), '3143', 'mailPort correct') + t.is(dc.getConfig('mail_user'), 'delta1', 'mailUser correct') + t.is(dc.getConfig('mail_pw'), 'delta1', 'mailPw correct') + t.is(dc.getConfig('send_server'), '127.0.0.1', 'sendServer correct') + t.is(dc.getConfig('send_port'), '3025', 'sendPort correct') + t.is(dc.getConfig('send_user'), 'delta1', 'sendUser correct') + t.is(dc.getConfig('send_pw'), 'delta1', 'sendPw correct') + t.is(dc.getConfig('server_flags'), String(0x400 | 0x40000), 'serverFlags correct') + t.is(dc.getConfig('displayname'), 'Delta One', 'displayName correct') + t.is(dc.getConfig('selfstatus'), 'From Delta One with <3', 'selfStatus correct') + t.is(dc.getConfig('e2ee_enabled'), '1', 'e2eeEnabled correct') + t.is(dc.getConfig('save_mime_headers'), '1', 'saveMimeHeaders correct') t.is(dc.getBlobdir(), `${cwd}/db.sqlite-blobs`, 'correct blobdir') }) dc.once('DC_EVENT_CONFIGURE_PROGRESS', data => { diff --git a/test/open.js b/test/open.js index d796fc65..b59bd265 100644 --- a/test/open.js +++ b/test/open.js @@ -13,9 +13,9 @@ test('open', t => { t.test('> missing addr or mail_pw throws', t => { t.throws(function () { dc.configure({ addr: 'delta1@delta.localhost' }) - }, /Missing \.mail_pw/, 'missing mail_pw throws') + }, /Missing \.mailPw/, 'missing mailPw throws') t.throws(function () { - dc.configure({ mail_pw: 'delta1' }) + dc.configure({ mailPw: 'delta1' }) }, /Missing \.addr/, 'missing addr throws') t.end() }) @@ -32,7 +32,7 @@ test('open', t => { }) dc.configure({ addr: 'hpk2@hq5.merlinux.eu', - mail_pw: 'whatever' + mailPw: 'whatever' }) })