-
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
Open
yorkie
wants to merge
5
commits into
MailCore:master
Choose a base branch
from
yorkie:document
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
204f2b5
imap, doc: documented stuffs on imapsession
yorkie fe68157
doc: split document -> README/API
yorkie 4cc6bc4
doc: fix some comments
yorkie 93021c1
imap: remove options parameter of copyMessages: use only UID.
yorkie 4e5965e
document the fetch* functions
yorkie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,53 @@ | ||
|
||
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 | ||
``` | ||
|
||
### Usage | ||
|
||
```js | ||
var imap = new IMAPSession(993, 'imap.gmail.com', { | ||
secure: 'ssl', | ||
auth: { | ||
username: '[email protected]', | ||
password: 'xxxxxxxxx' | ||
} | ||
}); | ||
|
||
imap.connect(); | ||
imap.once('error', function(err) { | ||
throw err; | ||
}); | ||
imap.once('connect', function() { | ||
console.log('connected'); | ||
imap.select('INBOX', function(inbox) { | ||
console.log(inbox); | ||
}); | ||
imap.fetchMessagesByNumber(0, 2, null, function(messages) { | ||
console.log(messages); | ||
}); | ||
}); | ||
|
||
``` | ||
|
||
If you want to get more details, you could go to [API.md](docs/API.md). | ||
|
||
### TODO | ||
|
||
* API `imap.seach` | ||
* API `imap.fetchMessagesByNumber` and `imap.fetchMessagesByUID` | ||
* API `imap.search` | ||
* API `imap.appendMessage` | ||
* API `imap.copyMessages` | ||
|
||
### License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
### 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, an instance of `Error` class | ||
|
||
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 | ||
* `option.secure` String, the value of `ssl`, `starttls` and `none`. Default value is none. | ||
* `option.auth.username`, String | ||
* `option.auth.password`, String, if you provide this field, then use `LOGIN` to authenticate, otherwise do `AUTHENTICATE` | ||
* `option.auth.accessToken`, String, used by `AUTHENTICATE` command | ||
* `option.auth.refreshToken`, String reversed | ||
* `option.auth.clientId`, String reversed | ||
* `option.auth.clientSecret`, String reversed | ||
|
||
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]) | ||
|
||
Start to create the connection to IMAP server, once your account has been authenticated/loged in, `callback` will be called and the `connect` event will be emitted. | ||
|
||
These `callback` and `connect` functions are zero-arguments function: `function() { /* ... */ }` | ||
|
||
#### imap.disconnect([callback]) | ||
|
||
* callback Function, `function() { /* ... */ }` | ||
|
||
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 Array|String, default value: `["uid", "flags", "headers", "internal-date"]` | ||
* callback Function | ||
|
||
Fetches the messages from your selected folder. The element of `option` array could be the below listed string: | ||
|
||
* uid | ||
* flags | ||
* headers | ||
* structure | ||
* internal-date | ||
* full-headers | ||
* header-subject | ||
* gmail-labels | ||
* gmail-message-id | ||
* gmail-thread-id | ||
* size | ||
|
||
And the element of `option` could also be custom header string like `X-Mailer`, `X-Envelope-Sender`, `X-Mailing-List` and etc. | ||
|
||
#### imap.search(query, callback) | ||
|
||
* query String | ||
* callback Function | ||
|
||
The `SEARCH` command implementation. | ||
|
||
#### imap.appendMessage(folder, data, [flags,] callback) | ||
|
||
* folder String | ||
* data String, rfc822 message data | ||
* flags Array, the element of this array should be a string of `answered`, `flagged`, `deleted`, `seen` and `draft`. | ||
* callback Function | ||
|
||
Append message to you specified folder. | ||
|
||
#### imap.copyMessages(uids, dest, callback) | ||
|
||
* uids Array, a uid set like: `[1000, 1001, 1003]` | ||
* dest String, the folder that you want this message to | ||
* callback Function | ||
|
||
Copy the messages that you specified by `uids` to `dest` folder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
exports.IMAP | ||
= exports.IMAPSession | ||
= require('./imapsession').IMAPSession; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Couldn't it be
['uid', 'flags', {'custom-headers': ['X-Mailer', 'X-Enveloper-Sender']}]
?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.
Ah, i think it is too nested :(
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 about:
'uid', 'flags', 'custom-header:X-Mailer', 'custom-header:X-Mailing-List'
?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.
the
custom-header
andX-
prefix seems act a same actor? i'm not sure if there is a custom header that doesn't contain aX-
prefix?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.
There are custom header that contain a X-Prefix. And some headers are not listed as part of the "headers" or "full-headers".
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.
Hi, there is a problem on implementation:
This is a line that you write at libetpan.node, and could you provide a way of add custom header fetch item?
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.
for example, how do i add the
x-mailer
to thefetchAtt
?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.
Have a look at _fetchTypeToString() in imapbase.js. You can use
{type: Constants.FetchBodySection, section:'HEADER.FIELDS (x-mailer mailing-list)'}
.I think the documentation in comments is wrong. It should be
section
and notparam
.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.
Thanks, i see