Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
136 changes: 136 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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?

Copy link
Contributor Author

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.


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to document what option can contain.

Copy link
Member

Choose a reason for hiding this comment

The 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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the callback function look like (parameters)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment for every callbacks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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:

In README.md:

+* 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])
No parameters, just a simple function, should i still document more on this function?


Reply to this email directly or view it on GitHub (https://github.com/MailCore/mailcore.node/pull/2/files#r14330652).


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document how what options are supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 libetpan.node in this API has a little bit complex.

* 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

values allowed for the flags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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? :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options = {date: optional date, flags: ['seen', 'flagged']}

Flags should be an array.
I'd like to make flags optional too.

Hoa V. Dinh

On Sunday, June 29, 2014 at 11:26 AM, Yazhong Liu wrote:

In README.md:

+* 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
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? :(


Reply to this email directly or view it on GitHub (https://github.com/MailCore/mailcore.node/pull/2/files#r14330663).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is.

* date Date
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

exports.IMAP
= exports.IMAPSession
= require('./imapsession').IMAPSession;