Skip to content

Commit

Permalink
use grunt, whiteout code style, enable CI
Browse files Browse the repository at this point in the history
TODO: port tests
  • Loading branch information
Felix Hammerl committed Mar 20, 2014
1 parent 43fdf5b commit 80e13d4
Show file tree
Hide file tree
Showing 37 changed files with 1,420 additions and 3,839 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
bower_components
node_modules/
npm-debug.log
.DS_Store
test/lib
49 changes: 49 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"indent": 4,
"strict": true,
"globalstrict": true,
"node": true,
"browser": true,
"nonew": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"newcap": true,
"regexp": true,
"evil": true,
"eqnull": true,
"expr": true,
"trailing": true,
"undef": true,
"unused": true,
"-W100": true,

"globals": {
"define": true,
"chrome": true,
"TextEncoder": true,
"TextDecoder": true,
"mimefuncs" : true,
"BrowserboxImap": true,
"BrowserboxSpecialUse": true,
"utf7": true,
"imapHandler": true,
"mimetypes" : true,
"escape" : true,
"unescape" : true,
"punycode" : true,
"addressparser" : true,
"console": true,
"describe": true,
"it": true,
"beforeEach": true,
"afterEach": true,
"window": true,
"mocha": true,
"mochaPhantomJS": true,
"importScripts": true,
"postMessage": true,
"before": true,
"self": true
}
}
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: node_js
node_js:
- "0.11"
before_install:
- npm install -g grunt-cli
notifications:
email:
- [email protected]
160 changes: 160 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
module.exports = function(grunt) {
'use strict';

// Project configuration.
grunt.initConfig({
jshint: {
all: ['*.js', 'src/*.js', 'test/*.js'],
options: {
jshintrc: '.jshintrc'
}
},

connect: {
dev: {
options: {
port: 12345,
base: '.',
keepalive: true
}
}
},

mocha_phantomjs: {
all: {
options: {
reporter: 'spec'
},
src: ['test/unit.html']
}
},

watch: {
js: {
files: ['src/*.js'],
tasks: ['deps']
}
},

copy: {
npm: {
expand: true,
flatten: false,
cwd: 'node_modules/',
src: [
'mocha/mocha.js',
'mocha/mocha.css',
'chai/chai.js',
'sinon/pkg/sinon.js',
'requirejs/require.js',
'tcp-socket/src/tcp-socket.js',
'node-forge/js/forge.min.js',
'arraybuffer-slice/index.js',
'stringencoding/encoding-indexes.js',
'stringencoding/encoding.js',
'utf7/src/utf7.js',
'imap-handler/src/*.js',
'mimefuncs/src/mimefuncs.js'
],
dest: 'test/lib/',
rename: function(dest, src) {
if (src === 'arraybuffer-slice/index.js') {
// 'index.js' is obviously a good name for a polyfill. duh.
return dest + 'arraybuffer-slice.js';
}
return dest + '/' + src.split('/').pop();
}
},
app: {
expand: true,
flatten: true,
cwd: 'src/',
src: [
'*.js',
],
dest: 'test/lib/'
}
},
clean: ['test/lib/**/*']
});

// Load the plugin(s)
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-mocha-phantomjs');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');

// Tasks
grunt.registerTask('hoodiecrow', function() {
var hoodiecrow, server, port, options;

hoodiecrow = require("hoodiecrow"),
options = {
debug: true,
secureConnection: true,
credentials: {
key: '-----BEGIN RSA PRIVATE KEY-----\r\nMIICWwIBAAKBgQDA9jfkw2yzUyfc15vECzGMZT2wfM4O5lyobFH/Z3rGNerxPIwm\r\nDyxlOCq5cE8/K8FNuaNm9NkbECSX9WR7yyUTG8kX7cG6Hhw1ICsE5RKWa/7uIJIa\r\nu517Q5N6A2zBM4YLCAewQZhdv4fYNCz3vsTuyGznD5pAR7bIfCHR6lblBQIDAQAB\r\nAoGAY0hMSfAjJcFLaV2mT6BSxiHxM7WDcDcmxaG2LutXSFTFpYm5sntsJEhZ8z/O\r\nBnrE4vD5Gigw7LPJoEYqhWdok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RsQJJf1\r\nZHvLJRMbyRftwboeHDUgKwTlEpZr/u4gkhq7nXtDk3oDbMEzhgsIB7BBmF2/h9g0\r\nLPe+xO7IbOcPmkBHtsh8IdHqVuUFAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAbs6+\r\nswTx03uGJfihujLC7sUiTmv9rFOTiqgElhK0R3Pft4nbWL1Jhn4twUwCa+csCDEA\r\nroItaeKZAC5zUGA4uXn1R0dZdOdLOff7998zSY3V5/cMAUYFztqSJjvqllDXxAmF\r\n30HHOMhiXQI1Wm0pqKlgzGCBt0fObgSaob9Zqbs=\r\n-----END CERTIFICATE-----\r\n'
},
storage: {
"INBOX":{
messages: [
{raw: "Subject: hello 1\r\n\r\nWorld 1!"},
{raw: "Subject: hello 2\r\n\r\nWorld 2!", flags: ["\\Seen"]},
{raw: "Subject: hello 3\r\n\r\nWorld 3!"},
{raw: "From: sender name <[email protected]>\r\nTo: Receiver name <[email protected]>\r\nSubject: hello 4\r\nMessage-Id: <abcde>\r\nDate: Fri, 13 Sep 2013 15:01:00 +0300\r\n\r\nWorld 4!"},
{raw: "Subject: hello 5\r\n\r\nWorld 5!"},
{raw: "Subject: hello 6\r\n\r\nWorld 6!"}
]
},
"":{
"separator": "/",
"folders":{
"[Gmail]":{
"flags": ["\\Noselect"],
"folders": {
"All Mail":{
"special-use": "\\All"
},
"Drafts":{
"special-use": "\\Drafts"
},
"Important":{
"special-use": "\\Important"
},
"Sent Mail":{
"special-use": "\\Sent"
},
"Spam":{
"special-use": "\\Junk"
},
"Starred":{
"special-use": "\\Flagged"
},
"Trash":{
"special-use": "\\Trash"
}
}
}
}
}
}
};
port = 10000;

server = hoodiecrow(options),
grunt.log.writeln('> Starting IMAP server on port ' + port);
server.listen(port, function() {
grunt.log.write('> Listening...\n');
});

this.async();
});

grunt.registerTask('imap', ['deps', 'hoodiecrow']);
grunt.registerTask('dev', ['jshint', 'deps', 'connect']);
grunt.registerTask('deps', ['clean', 'copy']);
grunt.registerTask('default', ['jshint', 'deps', 'mocha_phantomjs']);
};
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2014 Andris Reinman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
82 changes: 59 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,54 @@

IMAP client for browsers

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

If you run the application as a FirefoxOS packaged webapp (using the manifest.webapp file) or as a Chrome packaged app (using manifes.json), you can connect to an non SSL IMAP server. Thats about it for now.
## StringEncoding API

## Usage
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)!

Depending on your browser, you might need [this polyfill for ArrayBuffer #slice](https://github.com/ttaubert/node-arraybuffer-slice), e.g. phantomjs.

## 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

### [Bower](http://bower.io/):

1. Download the source of this repo
2. Install dependencies with `bower install imapHandler mimefuncs utf7`
3. Add this directory as a packaged app either to FirefoxOS simulato/device or Chrome extensions
4. Start the simulator and open browserbox app
bower install [email protected]:whiteout-io/browserbox.git#0.1.0

**NB!** You might need to reinstall bower dependencies when upgrading
### [npm](https://www.npmjs.org/):

**NB!** The build system is going to change from bower to npm + grunt at one point
npm install https://github.com/whiteout-io/browserbox/tarball/0.1.0

## SSL support
## Usage

Currently only non secure connections are used. If you want to use a secure server, use the man-in-the-middle imap proxy. Run
### AMD

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

And use host "localhost" and port "1143" to connect to GMail IMAP.
### Global context

If you want to connect to another host, for example to *imap-mail.outlook.com*, run
Include following fileson the page.

SMTP_HOST="imap-mail.outlook.com" node example/proxy.js
```html
<script src="browserbox.js"></script>
<script src="browserbox-special-use.js"></script>
<script src="browserbox-imap.js"></script>
```

SSL support for the IMAP client is coming soon but the proxy might be interesting to use in terms of debugging data flow between the client and the server as all communication is logged to console.
This exposes the constructor `BrowserBox` as a global variable

## API

Require [browserbox.js](browserbox.js) as an AMD module to use it. This exposes `browserbox` function.
var BrowserBox = require('browserbox')

## Create connection to an IMAP server

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

Where
Expand All @@ -51,6 +62,8 @@ Where
* **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"}`)
* **useSSL** (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

Example

Expand Down Expand Up @@ -314,12 +327,35 @@ clisne.close();

Once the connection is actually closed `onclose` event is fired.

## Screenshots
## Get your hands dirty

git clone [email protected]:whiteout-io/browserbox.git
cd browserbox
npm install && npm test

To run the integration tests against a local smtp server

grunt imap
add the test folder as a chrome app (chrome settings -> extensions -> check 'developer mode' -> load unpacked extension)

## License

**FirefoxOS**
Copyright (c) 2014 Andris Reinman

![](https://raw2.github.com/Kreata/browserbox/master/example/img/firefoxos.png)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

**Chrome**
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

![](https://raw2.github.com/Kreata/browserbox/master/example/img/chrome.png)
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 80e13d4

Please sign in to comment.