<commit_before># browserbox

IMAP client for browsers

[![Build Status](https://travis-ci.org/whiteout-io/browserbox.png?branch=master)](https://travis-ci.org/whiteout-io/browserbox)

## StringEncoding API

This module requires `TextEncoder` and `TextDecoder` to exist as part of the StringEncoding API (see: [MDN](https://developer.mozilla.org/en-US/docs/WebAPI/Encoding_API) [whatwg.org](http://encoding.spec.whatwg.org/#api)). Firefox 19+ is basically the only browser that supports this at the time of writing, while [Chromium in canary, not stable](https://code.google.com/p/chromium/issues/detail?id=243354). Luckily, [there is a polyfill](https://github.com/whiteout-io/stringencoding)!

## TCPSocket API

There is a [shim](https://github.com/whiteout-io/tcp-socket) that brings [Mozilla-flavored](https://developer.mozilla.org/en-US/docs/WebAPI/TCP_Socket) version of the [Raw Socket API](http://www.w3.org/TR/raw-sockets/) to Chromium.

## Installation

### [npm](https://www.npmjs.org/):

    npm install https://github.com/whiteout-io/browserbox/tarball/<TAG_NAME>

## Usage

### AMD

Require [browserbox.js](src/browserbox.js) as `browserbox`

### Global context

Include following files on the page.

```html
<script src="browserbox.js"></script>
<script src="browserbox-imap.js"></script>
```

This exposes the constructor `BrowserBox` as a global variable

## API

    var BrowserBox = require('browserbox')

## Create connection to an IMAP server

```
new BrowserBox(host[, port][, options]) → IMAP client object
```

Where

  * **host** is to hostname to connect to
  * **port** (optional) is the port to connect to (defaults to 143)
  * **options** (optional) is the options object
    * **auth** is the authentication information object
      * **user** is the username of the user (also applies to Oauth2)
      * **pass** is the password of the user
      * **xoauth2** is the OAuth2 access token to be used instead of password
    * **id** (optional) is the identification object for [RFC2971](http://tools.ietf.org/html/rfc2971#section-3.3) (ex. `{name: 'myclient', version: '1'}`)
    * **useSecureTransport** (optional) enables TLS
    * **ca** (optional) (only in conjunction with this [TCPSocket shim](https://github.com/whiteout-io/tcp-socket)) if you use TLS, pin a PEM-encoded certificate as a string
    * **ignoreTLS** – if set to true, do not call STARTTLS before authentication

Example

```javascript
var client = new BrowserBox('localhost', 143, {
    auth: {
        user: 'testuser',
        pass: '<PASSWORD>'
    },
    id: {
        name: 'My Client',
        version: '0.1'
    }
});
```

## Initiate connection

BrowserBox object by default does not initiate the connection, you need to call `client.connect()` to establish it

    client.connect();

This function does not take any arguments and does not return anything. See the events section to handle connection issues.

## Events

The IMAP client has several events you can attach to by setting a listener

### onerror

Is fired when something unexpected happened.

```
client.onerror = function(err){}
```

Where

  * **err** is an error object

### onclose

Is fired when the connection to the IMAP server is closed.

```
client.onerror = function(err){}
```

### onauth<commit_msg>Fix usage of onerror in the onclose section<commit_after># browserbox

IMAP client for browsers

[![Build Status](https://travis-ci.org/whiteout-io/browserbox.png?branch=master)](https://travis-ci.org/whiteout-io/browserbox)

## StringEncoding API

This module requires `TextEncoder` and `TextDecoder` to exist as part of the StringEncoding API (see: [MDN](https://developer.mozilla.org/en-US/docs/WebAPI/Encoding_API) [whatwg.org](http://encoding.spec.whatwg.org/#api)). Firefox 19+ is basically the only browser that supports this at the time of writing, while [Chromium in canary, not stable](https://code.google.com/p/chromium/issues/detail?id=243354). Luckily, [there is a polyfill](https://github.com/whiteout-io/stringencoding)!

## TCPSocket API

There is a [shim](https://github.com/whiteout-io/tcp-socket) that brings [Mozilla-flavored](https://developer.mozilla.org/en-US/docs/WebAPI/TCP_Socket) version of the [Raw Socket API](http://www.w3.org/TR/raw-sockets/) to Chromium.

## Installation

### [npm](https://www.npmjs.org/):

    npm install https://github.com/whiteout-io/browserbox/tarball/<TAG_NAME>

## Usage

### AMD

Require [browserbox.js](src/browserbox.js) as `browserbox`

### Global context

Include following files on the page.

```html
<script src="browserbox.js"></script>
<script src="browserbox-imap.js"></script>
```

This exposes the constructor `BrowserBox` as a global variable

## API

    var BrowserBox = require('browserbox')

## Create connection to an IMAP server

```
new BrowserBox(host[, port][, options]) → IMAP client object
```

Where

  * **host** is to hostname to connect to
  * **port** (optional) is the port to connect to (defaults to 143)
  * **options** (optional) is the options object
    * **auth** is the authentication information object
      * **user** is the username of the user (also applies to Oauth2)
      * **pass** is the password of the user
      * **xoauth2** is the OAuth2 access token to be used instead of password
    * **id** (optional) is the identification object for [RFC2971](http://tools.ietf.org/html/rfc2971#section-3.3) (ex. `{name: 'myclient', version: '1'}`)
    * **useSecureTransport** (optional) enables TLS
    * **ca** (optional) (only in conjunction with this [TCPSocket shim](https://github.com/whiteout-io/tcp-socket)) if you use TLS, pin a PEM-encoded certificate as a string
    * **ignoreTLS** – if set to true, do not call STARTTLS before authentication

Example

```javascript
var client = new BrowserBox('localhost', 143, {
    auth: {
        user: 'testuser',
        pass: '<PASSWORD>'
    },
    id: {
        name: 'My Client',
        version: '0.1'
    }
});
```

## Initiate connection

BrowserBox object by default does not initiate the connection, you need to call `client.connect()` to establish it

    client.connect();

This function does not take any arguments and does not return anything. See the events section to handle connection issues.

## Events

The IMAP client has several events you can attach to by setting a listener

### onerror

Is fired when something unexpected happened.

```
client.onerror = function(err){}
```

Where

  * **err** is an error object

### onclose

Is fired when the connection to the IMAP server is closed.

```
client.onclose = function(){}
```

### onauth
{'fraction_non_alphanumeric': 0.13681177005915365, 'fraction_numerical': 0.009403913241316548, 'mean_word_length': 4.095826893353942, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 20, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '579791', 'n_tokens_mistral': 2102, 'n_tokens_neox': 1993, 'n_words': 674}