Skip to content
Open
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
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["transform-es2015-destructuring"],
"ignore": ["./node_modules/**/*", "./jsmime.*"]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
dist
node_modules
/npm-debug.log
/coverage
/jsmime.*
4 changes: 4 additions & 0 deletions .tern-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ecmaVersion": 6,
"libs": []
}
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ This code depends on the following ES6 features and Web APIs:
* btoa, atob (found on global Windows or WorkerScopes)
* TextDecoder

Developments
============
```
npm install -g mocha # For running mocha tests
npm install -g http-server # Installing the http-server for firefox test
http-server # At the jsmime root directory

npm install -g gulp # Installing gulp for mocha test with node

gulp test #Running all the tests
npm run mocha -- test\test_header.js #Used for running specific test case

gulp bundle # Creating the dist\jsmime.js that could be able used in browser
gulp coverage # Viewing the running result
gulp watch # Watch the file changes & generating the dist\jsmime.js automatically
```

Versions and API stability
==========================

Expand Down
12 changes: 12 additions & 0 deletions encodings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'


if (typeof TextDecoder === 'undefined' || typeof TextEncoder === 'undefined') {
// TODO: GB18030 decode is invalid in text-encoding
module.exports = require('text-encoding')
} else {
module.exports = {
TextDecoder: TextDecoder,
TextEncoder: TextEncoder
}
}
111 changes: 111 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
'use strict'

const watchify = require('watchify')
const browserify = require('browserify')
const gulp = require('gulp')
const plumber = require('gulp-plumber')
// const uglify = require('gulp-uglify')
const source = require('vinyl-source-stream')
const buffer = require('vinyl-buffer')
const gutil = require('gulp-util')
const sourcemaps = require('gulp-sourcemaps')
const mocha = require('gulp-mocha') // Unit testing
const rename = require('gulp-rename')
const babelify = require('babelify')
const istanbul = require('gulp-babel-istanbul')
const clean = require('gulp-clean')

require('./test')

// Browsersync + Gulp.js
// http://www.browsersync.cn/docs/gulp/

function compile (watch) {
let bundler = browserify('./jsmimeMain.js', {
debug: true,
standalone: 'jsmime'
})
bundler = bundler.transform(babelify)
bundler.on('log', gutil.log)

function rebundle () {
return bundler.bundle()
.on('error', function (err) { console.error(err); this.emit('end') })
.pipe(plumber())
.pipe(source('./jsmimeMain.js'))
.pipe(rename('jsmime.js'))
.pipe(buffer())
// .pipe(uglify())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'))
.pipe(gulp.dest('./'))
}

if (watch) {
bundler = watchify(bundler)
bundler.on('update', function () {
console.log('-> bundling...')
rebundle()
})
}

return rebundle()
}

gulp.task('bundle', function () {
return compile(false)
})

gulp.task('watch-bundle', function () {
return compile(true)
})

function handleError (e) {
console.error(e.toString())
this.emit('end')
}

gulp.task('cleanup', () => {
return gulp.src(['./jsmime.*', './dist/*'], {read:false})
.pipe(clean({force: true}))
})

gulp.task('test', () => {
// gulp-mocha needs filepaths so you can't have any plugins before it
return gulp.src(['test/**/test_*.js'], {read: false})
.pipe(
mocha({
ui: 'tdd',
reporters : ['xunit-file', 'spec'],
globals: ['define']
}).on('error', handleError)
)
})

gulp.task('coverage-hook', () => {
return gulp.src(['./*.js', '!jsmime.*'])
// Covering files
.pipe(istanbul())
.pipe(istanbul.hookRequire())
})

gulp.task('coverage', ['coverage-hook'], () => {
// gulp-mocha needs filepaths so you can't have any plugins before it
return gulp.src(['test/**/test_*.js'], {read: false})
.pipe(
mocha({
ui: 'tdd',
reporters : ['xunit-file', 'spec'],
globals: ['define']
}).on('error', handleError)
)
// Creating the reports after tests ran
.pipe(
istanbul.writeReports()
)
// Enforce a coverage of at least 90%
.pipe(
istanbul.enforceThresholds({ thresholds: { global: 10 } })
)
})
7 changes: 2 additions & 5 deletions headeremitter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
define(function(require) {
/**
* This module implements the code for emitting structured representations of
* MIME headers into their encoded forms. The code here is a companion to,
Expand All @@ -10,6 +9,7 @@ define(function(require) {
"use strict";

var mimeutils = require('./mimeutils');
const { TextEncoder } = require('./encodings');

// Get the default structured encoders and add them to the map
var structuredHeaders = require('./structuredHeaders');
Expand Down Expand Up @@ -768,12 +768,9 @@ function addStructuredEncoder(header, encoder) {
preferredSpellings.set(lowerName, header);
}

return Object.freeze({
module.exports = Object.freeze({
addStructuredEncoder: addStructuredEncoder,
emitStructuredHeader: emitStructuredHeader,
emitStructuredHeaders: emitStructuredHeaders,
makeStreamingEmitter: makeStreamingEmitter
});

});

12 changes: 6 additions & 6 deletions headerparser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
define(function(require) {
/**
* This file implements the structured decoding of message header fields. It is
* part of the same system as found in mimemimeutils.js, and occasionally makes
Expand All @@ -8,6 +7,7 @@ define(function(require) {

"use strict";
var mimeutils = require('./mimeutils');
const { TextDecoder } = require('./encodings');

/**
* This is the API that we ultimately return.
Expand Down Expand Up @@ -934,7 +934,10 @@ const kKnownTZs = {
* above.
*/
function parseDateHeader(header) {
let tokens = [for (x of getHeaderTokens(header, ",:", {})) x.toString()];
let tokens = []
for (let x of getHeaderTokens(header, ",:", {})) {
tokens.push(x.toString());
}
// What does a Date header look like? In practice, most date headers devolve
// into Date: [dow ,] dom mon year hh:mm:ss tzoff [(abbrev)], with the day of
// week mostly present and the timezone abbreviation mostly absent.
Expand Down Expand Up @@ -1148,7 +1151,4 @@ headerparser.parseAddressingHeader = parseAddressingHeader;
headerparser.parseDateHeader = parseDateHeader;
headerparser.parseParameterHeader = parseParameterHeader;
headerparser.parseStructuredHeader = parseStructuredHeader;
return Object.freeze(headerparser);

});

module.exports = Object.freeze(headerparser);
7 changes: 0 additions & 7 deletions jsmime.js

This file was deleted.

6 changes: 6 additions & 0 deletions jsmimeDefine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'
const path = require('path')
define(function (require, exports, module) {
const mainURI = path.join(module.uri, '../jsmimeMain')
return require(mainURI)
})
5 changes: 5 additions & 0 deletions jsmimeMain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
MimeParser: require('./mimeparser'),
headerparser: require('./headerparser'),
headeremitter: require('./headeremitter')
}
5 changes: 2 additions & 3 deletions mimeparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
* to the outermost message/rfc822 envelope.
*/

define(function(require) {
"use strict";

var mimeutils = require('./mimeutils');
var headerparser = require('./headerparser');
var spellings = require('./structuredHeaders').spellings;
const { TextDecoder } = require('./encodings');

/**
* An object that represents the structured MIME headers for a message.
Expand Down Expand Up @@ -1056,5 +1056,4 @@ var ContentDecoders = {};
ContentDecoders['quoted-printable'] = mimeutils.decode_qp;
ContentDecoders['base64'] = mimeutils.decode_base64;

return MimeParser;
});
module.exports = MimeParser;
4 changes: 1 addition & 3 deletions mimeutils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
define(function() {
"use strict";

/**
Expand Down Expand Up @@ -83,11 +82,10 @@ function typedArrayToString(buffer) {
const kMonthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"];

return {
module.exports = {
decode_base64: decode_base64,
decode_qp: decode_qp,
kMonthNames: kMonthNames,
stringToTypedArray: stringToTypedArray,
typedArrayToString: typedArrayToString,
};
});
54 changes: 53 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "gulp test",
"mocha-all": "mocha -u tdd -r test test/test_*.js",
"mocha": "mocha -u tdd -r test",
"mocha-debug": "node-debug --hidden node_modules/ node_modules/mocha/bin/_mocha -u tdd -r test"
},
"repository": {
"type": "git",
Expand All @@ -17,5 +20,54 @@
"license": "MIT",
"bugs": {
"url": "https://github.com/mozilla-comm/jsmime/issues"
},
"devDependencies": {
"babel-core": "^6.4.0",
"babel-plugin-transform-es2015-destructuring": "^6.4.0",
"babel-register": "^6.4.3",
"babelify": "^7.2.0",
"browser-sync": "^2.11.0",
"browserify": "^13.0.0",
"gulp": "^3.9.0",
"gulp-babel-istanbul": "^0.11.0",
"gulp-clean": "^0.3.1",
"gulp-mocha": "^2.2.0",
"gulp-plumber": "^1.0.1",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^1.6.0",
"gulp-uglify": "^1.5.1",
"gulp-util": "^3.0.7",
"mocha": "^2.3.4",
"requirejs": "^2.1.22",
"requirejs-babel": "0.0.8",
"spec-xunit-file": "0.0.1-3",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.7.0"
},
"standard": {
"parser": "babel-eslint",
"globals": [
"__URI__",
"Components",
"Globals",
"Blob",
"URL",
"FormData",
"describe",
"dump",
"expect",
"it",
"setup",
"suite",
"test",
"define"
]
},
"dependencies": {
"atob": "^2.0.0",
"btoa": "^1.1.2",
"legacy-encoding": "^3.0.0",
"text-encoding": "^0.5.2"
}
}
5 changes: 1 addition & 4 deletions structuredHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* for several key headers. It is not meant to be used externally to jsmime.
*/

define(function (require) {
"use strict";

var structuredDecoders = new Map();
Expand Down Expand Up @@ -161,10 +160,8 @@ function preprocessMessageIDs(values) {
structuredDecoders.set("References", preprocessMessageIDs);
structuredDecoders.set("In-Reply-To", preprocessMessageIDs);

return Object.freeze({
module.exports = Object.freeze({
decoders: structuredDecoders,
encoders: structuredEncoders,
spellings: preferredSpellings,
});

});
Loading