Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Make options in bindings 1-1 with options in core #339

Merged
merged 3 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
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
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,26 @@ Configure and connect a context. Corresponds to `dc_configure()`.
The `options` object takes the following properties:

- `options.addr` _(string, required)_: Email address of the chat user.
- `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.imapFolder` _(string, optional)_: IMAP folder to use, defaults to `'INBOX'`.
- `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 <a href="#getmimeheaders">`dc.getMimeHeaders()`</a> later.
- `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.inbox_watch` _(boolean, optional)_: Watch `INBOX`-folder for changes. Defaults to `true`.
- `options.sentbox_watch` _(boolean, optional)_: Watch `Sent`-folder for changes. Defaults to `true`.
- `options.mvbox_watch` _(boolean, optional)_: Watch `DeltaChat`-folder for changes. Defaults to `true`.
- `options.mvbox_move` _(boolean, optional)_: Heuristically detect chat-messages and move them to the `DeltaChat`-folder. Defaults to `true`.
- `options.show_emails` _(integer, optional)_: `DC_SHOW_EMAILS_OFF` (0) show direct replies to chats only (default), `DC_SHOW_EMAILS_ACCEPTED_CONTACTS` (1) also show all mails of confirmed contacts, `DC_SHOW_EMAILS_ALL` (2) also show mails of unconfirmed contacts in the deaddrop.
- `options.save_mime_headers` _(boolean, optional)_: Set to `true` if you want to use <a href="#getmimeheaders">`dc.getMimeHeaders()`</a> later.

#### `dc.continueKeyTransfer(messageId, setupCode, callback)`

Expand Down
58 changes: 37 additions & 21 deletions lib/deltachat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const pick = require('lodash.pick')
const debug = require('debug')('deltachat:node:index')

const noop = function () {}
const DC_SHOW_EMAILS = [
C.DC_SHOW_EMAILS_ACCEPTED_CONTACTS,
C.DC_SHOW_EMAILS_ALL,
C.DC_SHOW_EMAILS_OFF
]

/**
* Wrapper around dcn_context_t*
Expand Down Expand Up @@ -98,34 +103,45 @@ class DeltaChat extends EventEmitter {
throw new Error('Missing .addr')
}

if (typeof opts.mailPw !== 'string') {
throw new Error('Missing .mailPw')
if (typeof opts.mail_pw !== 'string') {
throw new Error('Missing .mail_pw')
}

this.once('_configured', ready)

if (typeof opts.e2eeEnabled === 'undefined') opts.e2eeEnabled = 1
if (typeof opts.e2ee_enabled === 'undefined') opts.e2ee_enabled = 1

this.setConfig('addr', opts.addr)

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('imap_folder', opts.imapFolder)
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))
this.setConfig('mail_server', opts.mail_server)
this.setConfig('mail_user', opts.mail_user)
this.setConfig('mail_pw', opts.mail_pw)
this.setConfig('mail_port', String(opts.mail_port))

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('inbox_watch', String(opts.inbox_watch ? 1 : 0))
this.setConfig('sentbox_watch', String(opts.sentbox_watch ? 1 : 0))
this.setConfig('mvbox_watch', String(opts.mvbox_watch ? 1 : 0))
this.setConfig('mvbox_move', String(opts.mvbox_move ? 1 : 0))

if (DC_SHOW_EMAILS.includes(opts.show_emails)) {
this.setConfig('show_emails', String(opts.show_emails))
}

this.setConfig('save_mime_headers', String(opts.save_mime_headers ? 1 : 0))

binding.dcn_configure(this.dcn_context)
}
Expand Down
5 changes: 2 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ tape('invalid input to configure throws', t => {
const dc = new DeltaChat()
t.throws(function () {
dc.configure({ addr: 'delta1@delta.localhost' })
}, /Missing \.mailPw/, 'missing mailPw throws')
}, /Missing \.mail_pw/, 'missing mail_pw throws')
t.throws(function () {
dc.configure({ mailPw: 'delta1' })
dc.configure({ mail_pw: 'delta1' })
}, /Missing \.addr/, 'missing addr throws')
dc.close()
t.end()
Expand Down Expand Up @@ -109,7 +109,6 @@ tape('static getSystemInfo()', t => {
})

test('basic configuration', (t, dc, cwd) => {
t.is(dc.getConfig('imap_folder'), 'INBOX', 'default imap folder')
t.is(dc.getConfig('e2ee_enabled'), '1', 'e2eeEnabled correct')
t.is(
dc.getBlobdir(),
Expand Down
32 changes: 15 additions & 17 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ function configureDefaultDC (dc) {
dc.configure({
addr: ADDR,

mailServer: SERVER,
mailUser: ADDR,
mailPw: process.env.DC_MAIL_PW,
mail_server: SERVER,
mail_user: ADDR,
mail_pw: process.env.DC_MAIL_PW,

sendServer: SERVER,
sendUser: ADDR,
sendPw: process.env.DC_MAIL_PW,
send_server: SERVER,
send_user: ADDR,
send_pw: process.env.DC_MAIL_PW,

displayName: 'Delta One',
selfStatus: 'From Delta One with <3',
selfAvatar: path.join(__dirname, 'fixtures', 'avatar.png'),
displayname: 'Delta One',
selfstatus: 'From Delta One with <3',
selfavatar: path.join(__dirname, 'fixtures', 'avatar.png'),

e2eeEnabled: true,
saveMimeHeaders: true
e2ee_enabled: true,
save_mime_headers: true
})
}

Expand All @@ -46,17 +46,15 @@ function configureDefaultDC (dc) {
// 4. test opening an already configured account (re-open above)

test('setUp dc context', t => {
t.plan(15)
t.plan(13)
const cwd = tempy.directory()
dc = new DeltaChat()
t.is(dc.getConfig('imap_folder'), 'INBOX', 'default imap folder')
dc.once('ready', () => {
t.is(dc.getConfig('addr'), ADDR, 'addr correct')
t.is(dc.getConfig('mail_server'), SERVER, 'mailServer correct')
t.is(dc.getConfig('mail_user'), ADDR, 'mailUser correct')
t.is(dc.getConfig('send_server'), SERVER, 'sendServer correct')
t.is(dc.getConfig('send_user'), ADDR, 'sendUser correct')
t.is(dc.getConfig('imap_folder'), 'INBOX', 'default imap folder')
t.is(dc.getConfig('displayname'), 'Delta One', 'displayName correct')
t.is(dc.getConfig('selfstatus'), 'From Delta One with <3', 'selfStatus correct')
// TODO comment back in once fixed in core
Expand All @@ -65,10 +63,10 @@ test('setUp dc context', t => {
// path.join(cwd,
// 'db.sqlite-blobs',
// 'avatar.png'),
// 'selfAvatar correct'
// 'selfavatar correct'
// )
t.is(dc.getConfig('e2ee_enabled'), '1', 'e2eeEnabled correct')
t.is(dc.getConfig('save_mime_headers'), '1', 'saveMimeHeaders correct')
t.is(dc.getConfig('e2ee_enabled'), '1', 'e2ee_enabled correct')
t.is(dc.getConfig('save_mime_headers'), '1', 'save_mime_headers correct')
t.is(
dc.getBlobdir(),
path.join(cwd, 'db.sqlite-blobs'),
Expand Down