Initial
This commit is contained in:
19
test/imaps/node_modules/utf7/LICENSE
generated
vendored
Normal file
19
test/imaps/node_modules/utf7/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2010-2011 Konstantin Käfer
|
||||
|
||||
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.
|
||||
33
test/imaps/node_modules/utf7/README.md
generated
vendored
Normal file
33
test/imaps/node_modules/utf7/README.md
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# UTF-7
|
||||
|
||||
[](https://circleci.com/gh/kkaefer/utf7)
|
||||
|
||||
Encodes and decodes JavaScript (Unicode/UCS-2) strings to UTF-7 ASCII strings. It supports two modes: UTF-7 as defined in [RFC 2152](http://tools.ietf.org/html/rfc2152) and Modified UTF-7 as defined by the IMAP standard in [RFC 3501, section 5.1.3](http://tools.ietf.org/html/rfc3501#section-5.1.3)
|
||||
|
||||
## Usage
|
||||
|
||||
**RFC 2152**
|
||||
|
||||
```javascript
|
||||
var utf7 = require('utf7');
|
||||
|
||||
var encoded = utf7.encode('Jyväskylä');
|
||||
assert.equal('Jyv+AOQ-skyl+AOQ-', encoded);
|
||||
|
||||
var decoded = utf7.decode(encoded);
|
||||
assert.equal('Jyväskylä', decoded);
|
||||
```
|
||||
|
||||
By default, `.encode()` only encodes the default characeters defined in RFC 2152. To also encode optional characters, use `.encodeAll()` or specify the characters you want to encode as the second argument to `.encode()`.
|
||||
|
||||
**IMAP (RFC 3501)**
|
||||
|
||||
```javascript
|
||||
var utf7 = require('utf7').imap;
|
||||
|
||||
var encoded = utf7.encode('"你好" heißt "Hallo"');
|
||||
assert.equal('"&T2BZfQ-" hei&AN8-t "Hallo"', encoded);
|
||||
|
||||
var decoded = utf7.decode(encoded);
|
||||
assert.equal('"你好" heißt "Hallo"', decoded);
|
||||
```
|
||||
21
test/imaps/node_modules/utf7/package.json
generated
vendored
Normal file
21
test/imaps/node_modules/utf7/package.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "utf7",
|
||||
"version": "1.0.2",
|
||||
"description": "Converts text to and from UTF-7 (RFC 2152 and IMAP)",
|
||||
"author": "Konstantin Käfer <kkaefer@gmail.com>",
|
||||
"licenses": [ { "type": "BSD" } ],
|
||||
|
||||
"main": "./utf7",
|
||||
|
||||
"dependencies": {
|
||||
"semver": "~5.3.0"
|
||||
},
|
||||
|
||||
"devDependencies": {
|
||||
"tape": "~4.6.0"
|
||||
},
|
||||
|
||||
"scripts": {
|
||||
"test": "tape test/*.js"
|
||||
}
|
||||
}
|
||||
48
test/imaps/node_modules/utf7/test/utf7-imap.js
generated
vendored
Normal file
48
test/imaps/node_modules/utf7/test/utf7-imap.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
var test = require('tape');
|
||||
var utf7 = require('..').imap;
|
||||
|
||||
test('test conversion from utf8 to utf7', function(assert) {
|
||||
assert.plan(9);
|
||||
|
||||
// Examples from RFC 2152.
|
||||
assert.equal('A&ImIDkQ-.', utf7.encode('A\u2262\u0391.'));
|
||||
assert.equal('&ZeVnLIqe-', utf7.encode('\u65E5\u672C\u8A9E'));
|
||||
assert.equal('Hi Mom -&Jjo--!', utf7.encode('Hi Mom -\u263A-!'));
|
||||
assert.equal('Item 3 is &AKM-1.', utf7.encode('Item 3 is \u00A31.'));
|
||||
|
||||
// Custom examples that contain more than one mode shift.
|
||||
assert.equal('Jyv&AOQ-skyl&AOQ-', utf7.encode('Jyv\u00E4skyl\u00E4'));
|
||||
assert.equal('\'&T2BZfQ-\' hei&AN8-t "Hallo"', utf7.encode('\'\u4F60\u597D\' heißt "Hallo"'));
|
||||
|
||||
// The ampersand sign is represented as &-.
|
||||
assert.equal('Hot &- Spicy &- Fruity', utf7.encode('Hot & Spicy & Fruity'));
|
||||
|
||||
// Slashes are converted to commas.
|
||||
assert.equal('&,,,typh2VDIf7Q-', utf7.encode('\uffff\uedca\u9876\u5432\u1fed'));
|
||||
|
||||
// & sign around non-ASCII chars
|
||||
assert.equal('&AOQ-&-&AOQ-&-&AOQ-', utf7.encode('\u00E4&\u00E4&\u00E4'));
|
||||
});
|
||||
|
||||
test('test conversion from utf7 to utf8', function(assert) {
|
||||
assert.plan(9);
|
||||
|
||||
// Examples from RFC 2152.
|
||||
assert.equal('A\u2262\u0391.', utf7.decode('A&ImIDkQ-.'));
|
||||
assert.equal('\u65E5\u672C\u8A9E', utf7.decode('&ZeVnLIqe-'));
|
||||
assert.equal('Hi Mom -\u263A-!', utf7.decode('Hi Mom -&Jjo--!'));
|
||||
assert.equal('Item 3 is \u00A31.', utf7.decode('Item 3 is &AKM-1.'));
|
||||
|
||||
// Custom examples that contain more than one mode shift.
|
||||
assert.equal('Jyv\u00E4skyl\u00E4', utf7.decode('Jyv&AOQ-skyl&AOQ-'));
|
||||
assert.equal('\'\u4F60\u597D\' heißt "Hallo"', utf7.decode('\'&T2BZfQ-\' hei&AN8-t "Hallo"'));
|
||||
|
||||
// The ampersand sign is represented by &-.
|
||||
assert.equal('Hot & Spicy & Fruity', utf7.decode('Hot &- Spicy &- Fruity'));
|
||||
|
||||
// Slashes are converted to commas.
|
||||
assert.equal('\uffff\uedca\u9876\u5432\u1fed', utf7.decode('&,,,typh2VDIf7Q-'));
|
||||
|
||||
// & sign around non-ASCII chars
|
||||
assert.equal('\u00E4&\u00E4&\u00E4', utf7.decode('&AOQ-&-&AOQ-&-&AOQ-'));
|
||||
});
|
||||
78
test/imaps/node_modules/utf7/test/utf7-rfc2152.js
generated
vendored
Normal file
78
test/imaps/node_modules/utf7/test/utf7-rfc2152.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
var test = require('tape');
|
||||
var utf7 = require('..');
|
||||
|
||||
test('test conversion from utf8 to utf7', function(assert) {
|
||||
assert.plan(20);
|
||||
|
||||
// Examples from RFC 2152.
|
||||
assert.equal('A+ImIDkQ-.', utf7.encodeAll('A\u2262\u0391.'));
|
||||
assert.equal('A+ImIDkQ-.', utf7.encode('A\u2262\u0391.'));
|
||||
|
||||
assert.equal('+ZeVnLIqe-', utf7.encodeAll('\u65E5\u672C\u8A9E'));
|
||||
assert.equal('+ZeVnLIqe-', utf7.encode('\u65E5\u672C\u8A9E'));
|
||||
|
||||
assert.equal('Hi Mom -+Jjo--!', utf7.encodeAll('Hi Mom -\u263A-!'));
|
||||
assert.equal('Hi Mom -+Jjo--!', utf7.encode('Hi Mom -\u263A-!', ' !'));
|
||||
assert.equal('Hi+ACA-Mom+ACA--+Jjo--+ACE-', utf7.encode('Hi Mom -\u263A-!'));
|
||||
|
||||
assert.equal('Item 3 is +AKM-1.', utf7.encodeAll('Item 3 is \u00A31.'));
|
||||
assert.equal('Item 3 is +AKM-1.', utf7.encode('Item 3 is \u00A31.', ' '));
|
||||
assert.equal('Item+ACA-3+ACA-is+ACAAow-1.', utf7.encode('Item 3 is \u00A31.'));
|
||||
|
||||
// Custom examples that contain more than one mode shift.
|
||||
assert.equal('Jyv+AOQ-skyl+AOQ-', utf7.encode('Jyv\u00E4skyl\u00E4'));
|
||||
assert.equal('Jyv+AOQ-skyl+AOQ-', utf7.encodeAll('Jyv\u00E4skyl\u00E4'));
|
||||
|
||||
assert.equal('\'+T2BZfQ-\' hei+AN8-t "Hallo"', utf7.encodeAll('\'\u4F60\u597D\' heißt "Hallo"'));
|
||||
assert.equal('\'+T2BZfQ-\' hei+AN8-t "Hallo"', utf7.encode('\'\u4F60\u597D\' heißt "Hallo"', ' "'));
|
||||
assert.equal('\'+T2BZfQ-\'+ACA-hei+AN8-t+ACAAIg-Hallo+ACI-', utf7.encode('\'\u4F60\u597D\' heißt "Hallo"'));
|
||||
|
||||
// The plus sign is represented as +-.
|
||||
assert.equal('Hot +- Spicy +- Fruity', utf7.encodeAll('Hot + Spicy + Fruity'));
|
||||
assert.equal('Hot +- Spicy +- Fruity', utf7.encode('Hot + Spicy + Fruity', ' '));
|
||||
assert.equal('Hot+ACAAKwAg-Spicy+ACAAKwAg-Fruity', utf7.encode('Hot + Spicy + Fruity'));
|
||||
|
||||
// Slashes in the beginning.
|
||||
assert.equal('+///typh2VDIf7Q-', utf7.encodeAll('\uffff\uedca\u9876\u5432\u1fed'));
|
||||
|
||||
// + sign around non-ASCII chars
|
||||
assert.equal('+AOQAKwDkACsA5A-', utf7.encodeAll('\u00E4+\u00E4+\u00E4'));
|
||||
});
|
||||
|
||||
test('test conversion from utf7 to utf8', function(assert) {
|
||||
assert.plan(22);
|
||||
|
||||
// Examples from RFC 2152.
|
||||
assert.equal('A\u2262\u0391.', utf7.decode('A+ImIDkQ-.'));
|
||||
assert.equal('A\u2262\u0391.', utf7.decode('A+ImIDkQ.'));
|
||||
|
||||
assert.equal('\u65E5\u672C\u8A9E', utf7.decode('+ZeVnLIqe-'));
|
||||
assert.equal('\u65E5\u672C\u8A9E', utf7.decode('+ZeVnLIqe'));
|
||||
|
||||
assert.equal('Hi Mom -\u263A-!', utf7.decode('Hi Mom -+Jjo--!'));
|
||||
assert.equal('Hi Mom -\u263A-!', utf7.decode('Hi+ACA-Mom+ACA--+Jjo--+ACE-'));
|
||||
assert.equal('Item 3 is \u00A31.', utf7.decode('Item 3 is +AKM-1.'));
|
||||
assert.equal('Item 3 is \u00A31.', utf7.decode('Item+ACA-3+ACA-is+ACAAow-1.'));
|
||||
|
||||
// Custom examples that contain more than one mode shift.
|
||||
assert.equal('Jyv\u00E4skyl\u00E4', utf7.decode('Jyv+AOQ-skyl+AOQ-'));
|
||||
assert.equal('Jyv\u00E4skyl\u00E4', utf7.decode('Jyv+AOQ-skyl+AOQ'));
|
||||
assert.equal('\'\u4F60\u597D\' heißt "Hallo"', utf7.decode('\'+T2BZfQ-\' hei+AN8-t "Hallo"'));
|
||||
assert.equal('\'\u4F60\u597D\' heißt "Hallo"', utf7.decode('\'+T2BZfQ\' hei+AN8-t "Hallo"'));
|
||||
assert.equal('\'\u4F60\u597D\' heißt "Hallo"', utf7.decode('\'+T2BZfQ-\'+ACA-hei+AN8-t+ACAAIg-Hallo+ACI-'));
|
||||
assert.equal('\'\u4F60\u597D\' heißt "Hallo"', utf7.decode('\'+T2BZfQ-\'+ACA-hei+AN8-t+ACAAIg-Hallo+ACI'));
|
||||
|
||||
// The plus sign is represented by +-.
|
||||
assert.equal('Hot + Spicy + Fruity', utf7.decode('Hot +- Spicy +- Fruity'));
|
||||
assert.equal('Hot + Spicy + Fruity', utf7.decode('Hot+ACAAKwAg-Spicy+ACAAKwAg-Fruity'));
|
||||
|
||||
// Slashes in the beginning.
|
||||
assert.equal('\uffff\uedca\u9876\u5432\u1fed', utf7.decode('+///typh2VDIf7Q-'));
|
||||
assert.equal('\uffff\uedca\u9876\u5432\u1fed', utf7.decode('+///typh2VDIf7Q'));
|
||||
|
||||
// + sign around non-ASCII chars
|
||||
assert.equal('\u00E4+\u00E4+\u00E4', utf7.decode('+AOQ-+-+AOQ-+-+AOQ-'));
|
||||
assert.equal('\u00E4+\u00E4+\u00E4', utf7.decode('+AOQ++AOQ+-+AOQ'));
|
||||
assert.equal('\u00E4+\u00E4+\u00E4', utf7.decode('+AOQAKwDkACsA5A-'));
|
||||
assert.equal('\u00E4+\u00E4+\u00E4', utf7.decode('+AOQAKwDkACsA5A'));
|
||||
});
|
||||
119
test/imaps/node_modules/utf7/utf7.js
generated
vendored
Normal file
119
test/imaps/node_modules/utf7/utf7.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
var Buffer = require('buffer').Buffer;
|
||||
var semver = require('semver');
|
||||
|
||||
if (semver.gte(process.version, '6.0.0')) {
|
||||
function allocateAsciiBuffer(length) {
|
||||
return Buffer.alloc(length, 'ascii');
|
||||
}
|
||||
} else {
|
||||
function allocateAsciiBuffer(length) {
|
||||
return new Buffer(length, 'ascii');
|
||||
}
|
||||
}
|
||||
|
||||
function encode(str) {
|
||||
var b = allocateAsciiBuffer(str.length * 2);
|
||||
for (var i = 0, bi = 0; i < str.length; i++) {
|
||||
// Note that we can't simply convert a UTF-8 string to Base64 because
|
||||
// UTF-8 uses a different encoding. In modified UTF-7, all characters
|
||||
// are represented by their two byte Unicode ID.
|
||||
var c = str.charCodeAt(i);
|
||||
// Upper 8 bits shifted into lower 8 bits so that they fit into 1 byte.
|
||||
b[bi++] = c >> 8;
|
||||
// Lower 8 bits. Cut off the upper 8 bits so that they fit into 1 byte.
|
||||
b[bi++] = c & 0xFF;
|
||||
}
|
||||
// Modified Base64 uses , instead of / and omits trailing =.
|
||||
return b.toString('base64').replace(/=+$/, '');
|
||||
}
|
||||
|
||||
if (semver.gte(process.version, '6.0.0')) {
|
||||
function allocateBase64Buffer(str) {
|
||||
return Buffer.from(str, 'base64');
|
||||
}
|
||||
} else {
|
||||
function allocateBase64Buffer(str) {
|
||||
return new Buffer(str, 'base64');
|
||||
}
|
||||
}
|
||||
|
||||
function decode(str) {
|
||||
var b = allocateBase64Buffer(str);
|
||||
var r = [];
|
||||
for (var i = 0; i < b.length;) {
|
||||
// Calculate charcode from two adjacent bytes.
|
||||
r.push(String.fromCharCode(b[i++] << 8 | b[i++]));
|
||||
}
|
||||
return r.join('');
|
||||
}
|
||||
|
||||
// Escape RegEx from http://simonwillison.net/2006/Jan/20/escape/
|
||||
function escape(chars) {
|
||||
return chars.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
}
|
||||
|
||||
// Character classes defined by RFC 2152.
|
||||
var setD = "A-Za-z0-9" + escape("'(),-./:?");
|
||||
var setO = escape("!\"#$%&*;<=>@[]^_'{|}");
|
||||
var setW = escape(" \r\n\t");
|
||||
|
||||
// Stores compiled regexes for various replacement pattern.
|
||||
var regexes = {};
|
||||
var regexAll = new RegExp("[^" + setW + setD + setO + "]+", 'g');
|
||||
|
||||
exports.imap = {};
|
||||
|
||||
// RFC 2152 UTF-7 encoding.
|
||||
exports.encode = function(str, mask) {
|
||||
// Generate a RegExp object from the string of mask characters.
|
||||
if (!mask) {
|
||||
mask = '';
|
||||
}
|
||||
if (!regexes[mask]) {
|
||||
regexes[mask] = new RegExp("[^" + setD + escape(mask) + "]+", 'g');
|
||||
}
|
||||
|
||||
// We replace subsequent disallowed chars with their escape sequence.
|
||||
return str.replace(regexes[mask], function(chunk) {
|
||||
// + is represented by an empty sequence +-, otherwise call encode().
|
||||
return '+' + (chunk === '+' ? '' : encode(chunk)) + '-';
|
||||
});
|
||||
};
|
||||
|
||||
// RFC 2152 UTF-7 encoding with all optionals.
|
||||
exports.encodeAll = function(str) {
|
||||
// We replace subsequent disallowed chars with their escape sequence.
|
||||
return str.replace(regexAll, function(chunk) {
|
||||
// + is represented by an empty sequence +-, otherwise call encode().
|
||||
return '+' + (chunk === '+' ? '' : encode(chunk)) + '-';
|
||||
});
|
||||
};
|
||||
|
||||
// RFC 3501, section 5.1.3 UTF-7 encoding.
|
||||
exports.imap.encode = function(str) {
|
||||
// All printable ASCII chars except for & must be represented by themselves.
|
||||
// We replace subsequent non-representable chars with their escape sequence.
|
||||
return str.replace(/&/g, '&-').replace(/[^\x20-\x7e]+/g, function(chunk) {
|
||||
// & is represented by an empty sequence &-, otherwise call encode().
|
||||
chunk = (chunk === '&' ? '' : encode(chunk)).replace(/\//g, ',');
|
||||
return '&' + chunk + '-';
|
||||
});
|
||||
};
|
||||
|
||||
// RFC 2152 UTF-7 decoding.
|
||||
exports.decode = function(str) {
|
||||
return str.replace(/\+([A-Za-z0-9\/]*)-?/gi, function(_, chunk) {
|
||||
// &- represents &.
|
||||
if (chunk === '') return '+';
|
||||
return decode(chunk);
|
||||
});
|
||||
};
|
||||
|
||||
// RFC 3501, section 5.1.3 UTF-7 decoding.
|
||||
exports.imap.decode = function(str) {
|
||||
return str.replace(/&([^-]*)-/g, function(_, chunk) {
|
||||
// &- represents &.
|
||||
if (chunk === '') return '&';
|
||||
return decode(chunk.replace(/,/g, '/'));
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user