Skip to content

Commit 3175d72

Browse files
Initial code
1 parent e58ee81 commit 3175d72

File tree

8 files changed

+158
-2
lines changed

8 files changed

+158
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ logs
1212
results
1313

1414
npm-debug.log
15+
16+
node_modules

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- "0.8"
4+
- "0.10"

LICENSE

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Copyright (c) 2013 Forbes Lindesay
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16+
SOFTWARE.

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
imap-stringify
2-
==============
1+
# imap-stringify
32

43
The reverse of imap-parser, takes an array representation of an IMAP command and converts it to a string.
4+
5+
This module is currently very much pre-release. It only works for the most ludicrously basic of commands.
6+
7+
## License
8+
9+
MIT

index.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict'
2+
3+
var Transform = require('stream').Transform || require('readable-stream').Transform
4+
5+
module.exports = IMAPLineStringifier
6+
7+
/**
8+
* Creates a reusable parser for parsing. It is a writable stream for piping
9+
* data directly in.
10+
*
11+
* @constructor
12+
*/
13+
function IMAPLineStringifier(){
14+
if (!(this instanceof IMAPLineStringifier)) return new IMAPLineStringifier()
15+
Transform.call(this, {objectMode: true})
16+
}
17+
IMAPLineStringifier.prototype = Object.create(Transform.prototype)
18+
IMAPLineStringifier.prototype.constructor = IMAPLineStringifier
19+
20+
IMAPLineStringifier.prototype._transform = function (chunk, encoding, callback) {
21+
this.push(chunk.join(' ') + '\r\n')
22+
callback()
23+
}

package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "imap-stringify",
3+
"version": "0.0.0",
4+
"description": "A stringifier for IMAP line based commands",
5+
"scripts": {
6+
"test": "mocha -R spec"
7+
},
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/hashmail/imap-stringify.git"
11+
},
12+
"keywords": [
13+
"IMAP",
14+
"email",
15+
"e-mail",
16+
"server",
17+
"client"
18+
],
19+
"license": "MIT",
20+
"devDependencies": {
21+
"mocha": "~1.9.0"
22+
},
23+
"dependencies": {
24+
"readable-stream": "~1.0.2"
25+
}
26+
}

spec.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Specifications
2+
3+
This page contains extracts from the important specifications defining IMAP data formats to be parsed. Sections in block quotes are my comments.
4+
5+
## [RFC 3501](http://tools.ietf.org/html/rfc3501#section-4)
6+
7+
### 4. Data Formats
8+
9+
IMAP4rev1 uses textual commands and responses. Data in IMAP4rev1 can be in one of several forms: atom, number, string, parenthesized list, or NIL. Note that a particular data item may take more than one form; for example, a data item defined as using "astring" syntax may be either an atom or a string.
10+
11+
#### 4.1. Atom
12+
13+
> Treated as a string by imap-parser
14+
15+
An atom consists of one or more non-special characters.
16+
17+
#### 4.2. Number
18+
19+
> Treated as a string by imap-parser
20+
21+
A number consists of one or more digit characters, and represents a numeric value.
22+
23+
#### 4.3. String
24+
25+
> Treated as a string by imap-parser
26+
27+
A string is in one of two forms: either literal or quoted string. The literal form is the general form of string. The quoted string form is an alternative that avoids the overhead of processing a literal at the cost of limitations of characters which may be used.
28+
29+
A literal is a sequence of zero or more octets (including CR and LF), prefix-quoted with an octet count in the form of an open brace ("{"), the number of octets, close brace ("}"), and CRLF. In the case of literals transmitted from server to client, the CRLF is immediately followed by the octet data. In the case of literals transmitted from client to server, the client MUST wait to receive a command continuation request (described later in this document) before sending the octet data (and the remainder of the command).
30+
31+
A quoted string is a sequence of zero or more 7-bit characters, excluding CR and LF, with double quote (<">) characters at each end.
32+
33+
The empty string is represented as either "" (a quoted string with zero characters between double quotes) or as {0} followed by CRLF (a literal with an octet count of 0).
34+
35+
Note: Even if the octet count is 0, a client transmitting a literal MUST wait to receive a command continuation request.
36+
37+
##### 4.3.1. 8-bit and Binary Strings
38+
39+
> TODO: I'm not yet sure how this is handled by imap-parser
40+
41+
8-bit textual and binary mail is supported through the use of a [MIME-IMB] content transfer encoding. IMAP4rev1 implementations MAY transmit 8-bit or multi-octet characters in literals, but SHOULD do so only when the [CHARSET] is identified.
42+
43+
Although a BINARY body encoding is defined, unencoded binary strings are not permitted. A "binary string" is any string with NUL characters. Implementations MUST encode binary data into a textual form, such as BASE64, before transmitting the data. A string with an excessive amount of CTL characters MAY also be considered to be binary.
44+
45+
#### 4.4. Parenthesized List
46+
47+
> becomes a nested array when parsed with imap-parser
48+
49+
Data structures are represented as a "parenthesized list"; a sequence of data items, delimited by space, and bounded at each end by parentheses. A parenthesized list can contain other parenthesized lists, using multiple levels of parentheses to indicate nesting.
50+
51+
The empty list is represented as () -- a parenthesized list with no members.
52+
53+
#### 4.5. NIL
54+
55+
> becomes `null` when parsed with imap-parser
56+
57+
The special form "NIL" represents the non-existence of a particular data item that is represented as a string or parenthesized list, as distinct from the empty string "" or the empty parenthesized list ().
58+
59+
Note: NIL is never used for any data item which takes the form of an atom. For example, a mailbox name of "NIL" is a mailbox named NIL as opposed to a non-existent mailbox name. This is because mailbox uses "astring" syntax which is an atom or a string. Conversely, an addr-name of NIL is a non-existent personal name, because addr-name uses "nstring" syntax which is NIL or a string, but never an atom.
60+
61+
## [RFC 2088](http://tools.ietf.org/html/rfc2088)
62+
63+
> An extension to the string literal format that improves performance. Still treated as a string.
64+
65+
### 3. Specification
66+
67+
The non-synchronizing literal is added an alternate form of literal, and may appear in communication from client to server instead of the IMAP4 form of literal. The IMAP4 form of literal, used in communication from client to server, is referred to as a synchronizing literal.
68+
69+
Non-synchronizing literals may be used with any IMAP4 server implementation which returns "LITERAL+" as one of the supported capabilities to the CAPABILITY command. If the server does not advertise the LITERAL+ capability, the client must use synchronizing literals instead.
70+
71+
The non-synchronizing literal is distinguished from the original synchronizing literal by having a plus ('+') between the octet count and the closing brace ('}'). The server does not generate a command continuation request in response to a non-synchronizing literal, and clients are not required to wait before sending the octets of a non-synchronizing literal.

test/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var assert = require('assert')
2+
3+
var Parser = require('../')
4+
5+
describe('tests', function () {
6+
it('exist', function (done) {
7+
throw new Error('No tests yet.')
8+
})
9+
})

0 commit comments

Comments
 (0)