-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imap, doc: documented stuffs on imapsession #2
base: master
Are you sure you want to change the base?
Changes from 1 commit
204f2b5
fe68157
4cc6bc4
93021c1
4e5965e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,139 @@ mailcore.node | |
============= | ||
|
||
MailCore provide a simple API to work with e-mail protocols IMAP, POP and SMTP on NodeJS | ||
|
||
|
||
### Installation | ||
|
||
```sh | ||
$ npm install mailcore --save | ||
``` | ||
|
||
### API | ||
|
||
#### Class: IMAPSession | ||
|
||
The IMAPSession class the class that can be implemented to handle the IMAP operators, like `LOGIN`, `FETCH`, `COPY` and etc, and this class inherits from `EventEmitter` indirectly, then you could use methods of `EventEmitter` to simplify your source code. | ||
|
||
#### Event: 'error' | ||
|
||
* err `Error` the error object | ||
|
||
When an arbitrary error is raised, it will emit a 'error' event. | ||
|
||
Because the trigger should be called once in one session, then use the best practice: | ||
|
||
```js | ||
imap.once('error', yourErrorHandler); | ||
``` | ||
|
||
to avoid memroy leaks. | ||
|
||
#### Event: 'connect' | ||
|
||
When the account has been authenticated/loged in, it will emit a `connect` event. | ||
|
||
Because the trigger should be called once in one session, then use the best practice: | ||
|
||
```js | ||
imap.once('connect', yourErrorHandler); | ||
``` | ||
|
||
to avoid memroy leaks. | ||
|
||
#### new IMAPSession(port, hostname, option) | ||
|
||
* port Number, the port number of IMAP server | ||
* hostname String, the hostname of IMAP server | ||
* option Object, you config the authenticate option here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to document what option can contain. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before showing the example. |
||
|
||
Constructs an instance of IMAPSession with these 3 specified arguments, and an simple example for calling this constructor just is following: | ||
|
||
```js | ||
var session = new IMAPSession(993, 'imap.gmail.com', { | ||
secure: 'ssl', | ||
auth: { | ||
username: '[email protected]', | ||
password: 'xxxxxxx' | ||
} | ||
}); | ||
``` | ||
|
||
As you have seen before, the secure has multiple values that you're able to pass, the below is the complete valided value for the `option.secure` field: | ||
|
||
* ssl | ||
* starttls | ||
* none/null | ||
|
||
The `option.auth` field before just use the plain to request the authentication, and if you want to use `XOAuth2`, then: | ||
|
||
```js | ||
{ | ||
username: '[email protected]', | ||
accessToken: 'your access_token' | ||
} | ||
``` | ||
|
||
(In later version, we can support the auto fetch the token when you specified `clientId`, `clientSecret` and `refreshToken`). | ||
|
||
#### imap.connect([callback]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does the callback function look like (parameters)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment for every callbacks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No parameters, just a simple function, should i still document more on this function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. You should document it. Hoa V. Dinh On Sunday, June 29, 2014 at 11:23 AM, Yazhong Liu wrote:
|
||
|
||
Start to create the connection to IMAP server, once you account has been authenticated/loged in, program would call `callback` and trigger the `connect` event. | ||
|
||
#### imap.disconnect([callback]) | ||
|
||
End this session. | ||
|
||
#### imap.select(folder, callback) | ||
|
||
* folder String, the path of folder | ||
|
||
Select a folder(mailbox). | ||
|
||
#### imap.fetchMessagesByNumber(start, end, option, callback) | ||
#### imap.fetchMessagesByUID(start, end, option, callback) | ||
|
||
* start Number|String | ||
* end Number|String | ||
* option Number|Object|null TODO | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. document how what options are supported. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we ignore this in this PR, because i have no idea about how simplify this option, the |
||
* callback Function | ||
|
||
Fetches the messages from you selected folder. | ||
|
||
#### imap.search(query, callback) | ||
|
||
* query String | ||
* callback Function | ||
|
||
The `SEARCH` command implementation. | ||
|
||
#### imap.appendMessage(folder, data, flags, date, callback) | ||
|
||
* folder String | ||
* data String, rfc822 message data | ||
* flags Array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. values allowed for the flags? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unsure this, just copy from the mailcore2, could you please provide something about me on the flags, shouldn't it be an array? :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Options = {date: optional date, flags: ['seen', 'flagged']} Flags should be an array. Hoa V. Dinh On Sunday, June 29, 2014 at 11:26 AM, Yazhong Liu wrote:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is. |
||
* date Date | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove date parameters. appendMessage(folder, data, {}, callback) should just work. |
||
* callback Function | ||
|
||
Append message to you specified folder. | ||
|
||
#### imap.copyMessages(uids, dest, options, callback) | ||
|
||
* uids Array, a uid set like: `[1000, 1001, 1003]` | ||
* dest String, the folder that you want this message to | ||
* options Object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove options? |
||
* callback Function | ||
|
||
Copy the messages that you specified by `uids` to `dest` folder. | ||
|
||
### TODO | ||
|
||
* API `imap.seach` | ||
* API `imap.fetchMessagesByNumber` and `imap.fetchMessagesByUID` | ||
* API `imap.search` | ||
* API `imap.appendMessage` | ||
* API `imap.copyMessages` | ||
|
||
### License | ||
|
||
MIT |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
exports.IMAP | ||
= exports.IMAPSession | ||
= require('./imapsession').IMAPSession; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the error object look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just is an instance of Error class of v8.