Intial Commit
This commit is contained in:
32
nodered/rootfs/data/node_modules/poplib/CHANGELOG
generated
vendored
Normal file
32
nodered/rootfs/data/node_modules/poplib/CHANGELOG
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
0.1.7 (Wed Apr 2 17:41:53 MYT 2014)
|
||||
* Fixed typos
|
||||
|
||||
0.1.6 (Wed Mar 19 13:16:51 MYT 2014)
|
||||
* Fixed examples in README.md
|
||||
* Added MIT license to package.json
|
||||
* Addition of TLS options to pass through to underlying TLS module (thanks to Brendan Hill [https://github.com/brendanhill])
|
||||
* Fixed ignoring TLS errors, bug in LIST (thanks to Brendan Hill [https://github.com/brendanhill])
|
||||
|
||||
0.1.5 (Wed Feb 13 19:05:40 MYT 2013)
|
||||
|
||||
* Fixed issue #4 (thanks to [https://github.com/AVBelyy] )
|
||||
* Fixed issue #3 (replaced references to hashlib with inbuilt crypto)
|
||||
* Better documentation, including
|
||||
|
||||
0.1.4 (Tue Nov 8 11:30:36 MYT 2011):
|
||||
|
||||
* Fixed issue #1 (thanks to Nazar [https://github.com/nazar] )
|
||||
* Removed unused files
|
||||
* Fixed demo/demo.js
|
||||
* Fixed bug for non-match on multiline response when -ERR is received
|
||||
|
||||
0.1.3:
|
||||
|
||||
* Fixed default value for options in constructor
|
||||
* Fixed documentation text
|
||||
* Miscellaneous minor fixes
|
||||
|
||||
0.1.2:
|
||||
|
||||
* Removed unixlib as a dependency
|
||||
* Added CHANGELOG
|
||||
21
nodered/rootfs/data/node_modules/poplib/LICENSE
generated
vendored
Normal file
21
nodered/rootfs/data/node_modules/poplib/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (C) 2011-2014 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
|
||||
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.
|
||||
395
nodered/rootfs/data/node_modules/poplib/README.md
generated
vendored
Normal file
395
nodered/rootfs/data/node_modules/poplib/README.md
generated
vendored
Normal file
@@ -0,0 +1,395 @@
|
||||
# node-poplib
|
||||
|
||||
node-poplib offers an MIT-licensed client library for the POP3 protocol. It is currently provides the following capabilities:
|
||||
|
||||
* USER, PASS, APOP
|
||||
* LIST, TOP, RETR, DELE
|
||||
* UIDL, NOOP, CAPA
|
||||
* RSET, QUIT
|
||||
* Plaintext and encrypted TLS support
|
||||
* STLS
|
||||
* SASL PLAIN CRAM-MD5
|
||||
|
||||
It complies to:
|
||||
|
||||
* RFC 1939 (POP3)
|
||||
* RFC 2595 (STLS);
|
||||
* RFC 5034 (SASL AUTH)
|
||||
* RFC 2195 (CRAM-MD5)
|
||||
|
||||
## Installation
|
||||
|
||||
You have two installation options:
|
||||
|
||||
0. Via npm: `npm install poplib`
|
||||
|
||||
1. Download the source and install it yourself
|
||||
|
||||
## Quick demo
|
||||
|
||||
Connect to GMail's POP3 servers using the provided demo script as follows:
|
||||
|
||||
````bash
|
||||
$ node demos/demo.js --host pop.gmail.com --port 995 --username user@gmail.com --password potato --tls on --debug on --networkdebug on
|
||||
Server: '+OK Gpop ready for requests from 1.2.3.4 bh7pf61475604pab.24\r\n'
|
||||
CONNECT success
|
||||
Client: 'USER user@gmail.com\r\n'
|
||||
Server: '+OK send PASS\r\n'
|
||||
Client: 'PASS potato\r\n'
|
||||
Server: '-ERR [AUTH] Username and password not accepted.\r\n'
|
||||
LOGIN/PASS failed
|
||||
Client: 'QUIT\r\n'
|
||||
Server: '+OK Farewell.\r\n'
|
||||
QUIT success
|
||||
````
|
||||
|
||||
## Detailed Usage
|
||||
|
||||
node-poplib is event based. It is best to illustrate via examples:
|
||||
|
||||
Here we initialize the client (for plain text transmission):
|
||||
|
||||
````javascript
|
||||
var POP3Client = require("poplib");
|
||||
var client = new POP3Client(port, host, {
|
||||
|
||||
tlserrs: false,
|
||||
enabletls: true,
|
||||
debug: false
|
||||
|
||||
});
|
||||
````
|
||||
|
||||
The third parameter, `options`, takes three options. If `enabletls` is true, the library will use a TLS connection. Note that you will have to set the correct port (generally 995). If `tlserrs` is true, then TLS errors will be ignored. Finally, the `debug` parameter prints out requests and responses.
|
||||
|
||||
Next, we trap several common states:
|
||||
|
||||
````javascript
|
||||
client.on("error", function(err) {
|
||||
|
||||
if (err.errno === 111) console.log("Unable to connect to server");
|
||||
else console.log("Server error occurred");
|
||||
|
||||
console.log(err);
|
||||
|
||||
});
|
||||
|
||||
client.on("connect", function() {
|
||||
|
||||
console.log("CONNECT success");
|
||||
client.login(username, password);
|
||||
|
||||
});
|
||||
|
||||
client.on("invalid-state", function(cmd) {
|
||||
console.log("Invalid state. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("locked", function(cmd) {
|
||||
console.log("Current command has not finished yet. You tried calling " + cmd);
|
||||
});
|
||||
````
|
||||
|
||||
The `error` event is emitted when there is a network error. The underlying error object is passed back to user-code.
|
||||
|
||||
The `connect` event is emitted when the connection to the remote server is successful.
|
||||
|
||||
The `invalid-state` event is emitted when you try to carry out an action not allowed within your current state (eg, attempting to `RETR`-ieve a message when authentication has not been completed).
|
||||
|
||||
The `locked` event is emitted when you try to execute another command while the current command has not finished executing successfully (eg, attempting to `RETR`-ieve a message while the remote server has not finished sending `LIST` data).
|
||||
|
||||
On a successful connect, we try authenticating:
|
||||
|
||||
````javascript
|
||||
client.on("connect", function() {
|
||||
|
||||
console.log("CONNECT success");
|
||||
client.login(username, password);
|
||||
|
||||
});
|
||||
````
|
||||
|
||||
Note that on successful login, we try listing. For all events, the first received argument is always a boolean indicating whether the command succeeded. The last received argument is always the raw unparsed data received from the remote server. The intermediate arguments contain parsed data.
|
||||
|
||||
````javascript
|
||||
client.on("login", function(status, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("LOGIN/PASS success");
|
||||
client.list();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LOGIN/PASS failed");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// Data is a 1-based index of messages, if there are any messages
|
||||
client.on("list", function(status, msgcount, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === false) {
|
||||
|
||||
console.log("LIST failed");
|
||||
client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LIST success with " + msgcount + " element(s)");
|
||||
|
||||
if (msgcount > 0)
|
||||
client.retr(1);
|
||||
else
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("retr", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("RETR success for msgnumber " + msgnumber);
|
||||
client.dele(msgnumber);
|
||||
client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("RETR failed for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("dele", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("DELE success for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("DELE failed for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("quit", function(status, rawdata) {
|
||||
|
||||
if (status === true) console.log("QUIT success");
|
||||
else console.log("QUIT failed");
|
||||
|
||||
});
|
||||
````
|
||||
|
||||
## API
|
||||
|
||||
`login(username, password)`
|
||||
|
||||
Self explanatory. This executes `USER` and `PASS`. Do not use over cleartext channels. Preferably don't use it at all as `auth()` implements `AUTH` which deprecates the need for USER and PASS. Emits `login` event.
|
||||
|
||||
`apop(username, password)`
|
||||
|
||||
This executes `APOP`. Requires server side support. Preferably don't use it as `auth()` implements `AUTH` which deprecates the need for USER and PASS. Emits `apop` event.
|
||||
|
||||
`auth(type, username, password)`
|
||||
|
||||
This executes `AUTH`. Requires server side support. Currently only "PLAIN" and "CRAM-MD5" types are supported. Emits `auth` event.
|
||||
|
||||
`stls()`
|
||||
|
||||
This executes `STLS`. Requires server side support (check using `capa()` first). According to the RFC's, using `STLS` is preferable to a purely TLS connection (although some servers only support purely TLS connections). Emits `stls` event.
|
||||
|
||||
`capa()`
|
||||
|
||||
This executes `CAPA`. Requires server side support. Emits `capa` event.
|
||||
|
||||
`list([msgnumber])`
|
||||
|
||||
This executes `LIST`. If the optional `msgnumber` is provided, then `LIST msgnumber` is executed. Emits `list` event.
|
||||
|
||||
`top(msgnumber, lines)`
|
||||
|
||||
This executes `TOP`. Requires server side support. `msgnumber` and `lines` must be provided. TEmits `top` event.
|
||||
|
||||
`stat()`
|
||||
|
||||
This executes `STAT`. Emits `stat` event.
|
||||
|
||||
`uidl([msgnumber])`
|
||||
|
||||
This executes `UIDL`. If the optional `msgnumber` is provided, then `UIDL msgnumber` is executed. Emits `uidl` event.
|
||||
|
||||
`retr(msgnumber)`
|
||||
|
||||
This executes `RETR`. `msgnumber` must be provided. Emits `retr` event.
|
||||
|
||||
`dele(msgnumber)`
|
||||
|
||||
This executes `DELE`. `msgnumber` must be provided. Emits `dele` event.
|
||||
|
||||
`rset()`
|
||||
|
||||
This executes `RSET`. Emits `rset` event.
|
||||
|
||||
`noop()`
|
||||
|
||||
This executes `NOOP`. Emits `noop` event.
|
||||
|
||||
`quit()`
|
||||
|
||||
This executes `QUIT`. Emits `quit` event.
|
||||
|
||||
|
||||
## Events
|
||||
|
||||
`connect`
|
||||
|
||||
The `connect` event is emitted upon competion of connection attempt (initiated in the constructor). The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`login`
|
||||
|
||||
The `login` event is emitted upon competion of `login()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`apop`
|
||||
|
||||
The `apop` event is emitted upon competion of `apop()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`auth`
|
||||
|
||||
The `auth` event is emitted upon competion of `auth()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`stls`
|
||||
|
||||
The `stls` event is emitted upon competion of `stls()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`capa`
|
||||
|
||||
The `capa` event is emitted upon competion of `capa()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* data: if status is true, this is an array containing list of server capabilities
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`list`
|
||||
|
||||
The `list` event is emitted upon competion of `list()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
msgcount: this contains the number of messages return by the `list()` method. If a valid msgnumber was provided, this value will naturally be `1` (else `null`)
|
||||
* msgnumber: if msgnumber was provided to the method, the provided value will be reflected here (else `undefined`)
|
||||
* data: if status is true, this is an array containing list of server capabilities (else `null`)
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`top`
|
||||
|
||||
The `top` event is emitted upon competion of `top()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* msgnumber: if msgnumber was provided to the method, the provided value will be reflected here (else `undefined`)
|
||||
* data: if status is true, this is an ASCII string containing the returnValue (else `null`)
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`stat`
|
||||
|
||||
The `stat` event is emitted upon competion of `stat()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* data: if status is true, an object with keys `count` and `octet` (else `null`)
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`uidl`
|
||||
|
||||
The `uidl` event is emitted upon competion of `uidl()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* msgnumber: if msgnumber was provided to the method, the provided value will be reflected here (else `undefined`)
|
||||
* data: if status is true, this is an array containing the UIDL list (else `null`)
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`retr`
|
||||
|
||||
The `retr` event is emitted upon competion of `retr()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* msgnumber: the `msgnumber` provided to the method
|
||||
* data: if status is `true`, the results are returned as an ASCII string (else `null`)
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`dele`
|
||||
|
||||
The `dele` event is emitted upon competion of the `dele()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* msgnumber: the `msgnumber` provided to the method
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`rset`
|
||||
|
||||
The `rset` event is emitted upon competion of the `rset()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`noop`
|
||||
|
||||
The `noop` event is emitted upon competion of the `noop()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* rawdata: string containing success or error message from the server
|
||||
|
||||
`quit`
|
||||
|
||||
The `quit` event is emitted upon competion of the `quit()` method. The arguments, in order, are:
|
||||
|
||||
* status: boolean true or false, indicating whether the execution was successful
|
||||
* * rawdata: string containing success or error message from the server
|
||||
|
||||
`error`
|
||||
|
||||
The `error` event is emitted if there is an `error` event from the underlying socket. The original error object is passed as an argument.
|
||||
|
||||
`invalid-state`
|
||||
|
||||
The `invalid-state` event is emitted when an action not allowed within the current state s attmempted (eg, attempting to `RETR`-ieve a message when `AUTH`-entication has not been completed).
|
||||
|
||||
`locked`
|
||||
|
||||
The `locked` event is emitted when a method is called while existing execution has not finished executing (eg, attempting to `RETR`-ieve a message while the remote server has not finished sending `LIST` data).
|
||||
|
||||
## Tests & Demos
|
||||
|
||||
Tests are in `tests`. Demos are in `demos`.
|
||||
|
||||
There is a full-featured POP3 client example in `demos/demo.js`. There is also a simple example of downloading all emails in a POP3 server and saving it locally in an mbox formatted file in `demos/retrieve-all.js`.
|
||||
|
||||
For testing purposes, you can use the following sendmail.sh script to pump email into your SMTP server for retrieval via POP3:
|
||||
|
||||
````bash
|
||||
./sendmail.sh 10 "user@example.com" "this is my subject" "this is my body"
|
||||
````
|
||||
|
||||
You can execute the test-runner as follows:
|
||||
|
||||
````bash
|
||||
./runner.sh username password pop3server pop3port pop3tlsport testemail@address.com
|
||||
````
|
||||
240
nodered/rootfs/data/node_modules/poplib/demos/demo.js
generated
vendored
Normal file
240
nodered/rootfs/data/node_modules/poplib/demos/demo.js
generated
vendored
Normal file
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
|
||||
Node.js POP3 client demo
|
||||
|
||||
Copyright (C) 2011-2013 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
var util = require("util");
|
||||
var POP3Client = require("../main.js");
|
||||
var argv = require('optimist')
|
||||
.usage("Usage: $0 --host [host] --port [port] --username [username] --password [password] --tls [on/off] --debug [on/off] --networkdebug [on/off] --msgnumber [number]")
|
||||
.demand(['username', 'password'])
|
||||
.argv;
|
||||
|
||||
var host = argv.host || "localhost";
|
||||
var port = argv.port || 110;
|
||||
var debug = argv.debug === "on" ? true : false;
|
||||
var enabletls = argv.tls === "on" ? true : false;
|
||||
var msgnumber = argv.msgnumber;
|
||||
var username = argv.username;
|
||||
var password = argv.password;
|
||||
|
||||
var client = new POP3Client(port, host, {
|
||||
debug: debug,
|
||||
enabletls: enabletls
|
||||
});
|
||||
|
||||
client.on("error", function(err) {
|
||||
|
||||
if (err.errno === 111) console.log("Unable to connect to server");
|
||||
else console.log("Server error occurred");
|
||||
|
||||
console.log(err);
|
||||
|
||||
});
|
||||
|
||||
client.on("connect", function(rawdata) {
|
||||
|
||||
console.log("CONNECT success");
|
||||
client.login(username, password);
|
||||
|
||||
});
|
||||
|
||||
client.on("invalid-state", function(cmd) {
|
||||
console.log("Invalid state. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("locked", function(cmd) {
|
||||
console.log("Current command has not finished yet. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("login", function(status, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("LOGIN/PASS success");
|
||||
client.capa();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LOGIN/PASS failed");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
client.on("capa", function(status, data, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("CAPA success");
|
||||
if (debug) console.log("Parsed data: " + util.inspect(data));
|
||||
client.noop();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("CAPA failed");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
client.on("noop", function(status, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("NOOP success");
|
||||
client.stat();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("NOOP failed");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
client.on("stat", function(status, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("STAT success");
|
||||
if (debug) console.log("Parsed data: " + util.inspect(data));
|
||||
client.list();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("STAT failed");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("list", function(status, msgcount, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === false) {
|
||||
|
||||
if (msgnumber !== undefined) console.log("LIST failed for msgnumber " + msgnumber);
|
||||
else console.log("LIST failed");
|
||||
|
||||
client.quit();
|
||||
|
||||
} else if (msgcount === 0) {
|
||||
|
||||
console.log("LIST success with 0 elements");
|
||||
client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LIST success with " + msgcount + " element(s)");
|
||||
client.uidl();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("uidl", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("UIDL success");
|
||||
if (debug) console.log("Parsed data: " + data);
|
||||
client.top(123123, 10);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("UIDL failed for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
client.on("top", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("TOP success for msgnumber " + msgnumber);
|
||||
if (debug) console.log("Parsed data: " + data);
|
||||
client.retr(msgnumber);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("TOP failed for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("retr", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("RETR success for msgnumber " + msgnumber);
|
||||
if (debug) console.log("Parsed data: " + data);
|
||||
|
||||
if (msgnumber !== undefined) client.dele(msgnumber);
|
||||
else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("RETR failed for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("dele", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("DELE success for msgnumber " + msgnumber);
|
||||
client.rset();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("DELE failed for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("rset", function(status, rawdata) {
|
||||
|
||||
if (status === true) console.log("RSET success");
|
||||
else console.log("RSET failed");
|
||||
|
||||
client.quit();
|
||||
|
||||
});
|
||||
|
||||
client.on("quit", function(status, rawdata) {
|
||||
|
||||
if (status === true) console.log("QUIT success");
|
||||
else console.log("QUIT failed");
|
||||
|
||||
});
|
||||
166
nodered/rootfs/data/node_modules/poplib/demos/retrieve-all.js
generated
vendored
Normal file
166
nodered/rootfs/data/node_modules/poplib/demos/retrieve-all.js
generated
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
|
||||
Node.js POP3 client demo in retrieving all POP3 messages into mbox file
|
||||
|
||||
Copyright (C) 2011-2013 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
var fs = require("fs");
|
||||
var POP3Client = require("../main.js");
|
||||
var argv = require('optimist')
|
||||
.usage("Usage: $0 --host [host] --port [port] --username [username] --password [password] --filename [filename] --debug [on/off] --networkdebug [on/off] --tls [on/off]")
|
||||
.demand(['username', 'password', 'filename'])
|
||||
.argv;
|
||||
|
||||
var host = argv.host || "localhost";
|
||||
var port = argv.port || 110;
|
||||
var debug = argv.debug === "on" ? true : false;
|
||||
var tls = argv.tls === "on" ? true : false;
|
||||
var filename = argv.filename;
|
||||
var username = argv.username;
|
||||
var password = argv.password;
|
||||
var totalmsgcount = 0;
|
||||
var currentmsg = 0;
|
||||
|
||||
var fd = fs.openSync(filename, "a+");
|
||||
|
||||
var client = new POP3Client(port, host, {
|
||||
|
||||
tlserrs: false,
|
||||
enabletls: (argv.tls === "on" ? true: false),
|
||||
debug: (argv.networkdebug === "on" ? true: false)
|
||||
|
||||
});
|
||||
|
||||
client.on("error", function(err) {
|
||||
|
||||
if (err.errno === 111) console.log("Unable to connect to server, failed");
|
||||
else console.log("Server error occurred, failed");
|
||||
|
||||
console.log(err);
|
||||
|
||||
});
|
||||
|
||||
client.on("connect", function() {
|
||||
|
||||
console.log("CONNECT success");
|
||||
client.auth(username, password);
|
||||
|
||||
});
|
||||
|
||||
client.on("invalid-state", function(cmd) {
|
||||
console.log("Invalid state. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("locked", function(cmd) {
|
||||
console.log("Current command has not finished yet. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("auth", function(status, data) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("LOGIN/PASS success");
|
||||
client.list();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LOGIN/PASS failed");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
client.on("list", function(status, msgcount, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === false) {
|
||||
|
||||
console.log("LIST failed");
|
||||
client.quit();
|
||||
|
||||
} else if (msgcount > 0) {
|
||||
|
||||
totalmsgcount = msgcount;
|
||||
currentmsg = 1;
|
||||
console.log("LIST success with " + msgcount + " message(s)");
|
||||
client.retr(1);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LIST success with 0 message(s)");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("retr", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("RETR success " + msgnumber);
|
||||
currentmsg += 1;
|
||||
|
||||
fs.write(fd, new Buffer(data + "\r\n\r\n"), 0, data.length+4, null, function(err, written, buffer) {
|
||||
|
||||
if (err) client.rset();
|
||||
else client.dele(msgnumber);
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
console.log("RETR failed for msgnumber " + msgnumber);
|
||||
client.rset();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("dele", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("DELE success for msgnumber " + msgnumber);
|
||||
|
||||
if (currentmsg > totalmsgcount)
|
||||
client.quit();
|
||||
else
|
||||
client.retr(currentmsg);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("DELE failed for msgnumber " + msgnumber);
|
||||
client.rset();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("rset", function(status,rawdata) {
|
||||
client.quit();
|
||||
});
|
||||
|
||||
client.on("quit", function(status, rawdata) {
|
||||
|
||||
if (status === true) console.log("QUIT success");
|
||||
else console.log("QUIT failed");
|
||||
|
||||
});
|
||||
867
nodered/rootfs/data/node_modules/poplib/main.js
generated
vendored
Normal file
867
nodered/rootfs/data/node_modules/poplib/main.js
generated
vendored
Normal file
@@ -0,0 +1,867 @@
|
||||
/*
|
||||
|
||||
Node.js POP3 client library
|
||||
|
||||
Copyright (C) 2011-2013 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
var net = require("net"),
|
||||
tls = require("tls"),
|
||||
util = require("util"),
|
||||
crypto = require("crypto"),
|
||||
events = require("events");
|
||||
|
||||
// Constructor
|
||||
function POP3Client(port, host, options) {
|
||||
|
||||
if (options === undefined) options = {};
|
||||
|
||||
// Optional constructor arguments
|
||||
var enabletls = options.enabletls !== undefined ? options.enabletls: false;
|
||||
var ignoretlserrs = options.ignoretlserrs !== undefined ? options.ignoretlserrs: false;
|
||||
var debug = options.debug || false;
|
||||
|
||||
var tlsDirectOpts = options.tlsopts !== undefined ? options.tlsopts: {};
|
||||
|
||||
// Private variables follow
|
||||
var self = this;
|
||||
var response = null;
|
||||
var checkResp = true;
|
||||
var bufferedData = "";
|
||||
var state = 0;
|
||||
var locked = false;
|
||||
var multiline = false;
|
||||
var socket = null;
|
||||
var tlssock = null;
|
||||
var callback = function(resp, data) {
|
||||
|
||||
if (resp === false) {
|
||||
|
||||
locked = false;
|
||||
callback = function() {};
|
||||
self.emit("connect", false, data);
|
||||
|
||||
} else {
|
||||
|
||||
// Checking for APOP support
|
||||
var banner = data.trim();
|
||||
var bannerComponents = banner.split(" ");
|
||||
|
||||
for(var i=0; i < bannerComponents.length; i++) {
|
||||
|
||||
if (bannerComponents[i].indexOf("@") > 0) {
|
||||
|
||||
self.data["apop"] = true;
|
||||
self.data["apop-timestamp"] = bannerComponents[i];
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
state = 1;
|
||||
self.data["banner"] = banner;
|
||||
self.emit("connect", true, data);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Public variables follow
|
||||
this.data = {
|
||||
|
||||
host: host,
|
||||
port: port,
|
||||
banner: "",
|
||||
stls: false,
|
||||
apop: false,
|
||||
username: "",
|
||||
tls: enabletls,
|
||||
ignoretlserrs: ignoretlserrs
|
||||
|
||||
};
|
||||
|
||||
// Privileged methods follow
|
||||
this.setCallback = function(cb) { callback = cb; };
|
||||
this.getCallback = function() { return callback };
|
||||
this.setState = function(val) { state = val; };
|
||||
this.getState = function() { return state; };
|
||||
this.setLocked = function(val) { locked = val; };
|
||||
this.getLocked = function() { return locked; };
|
||||
this.setMultiline = function(val) { multiline = val; };
|
||||
this.getMultiline = function() { return multiline; };
|
||||
|
||||
// Writes to remote server socket
|
||||
this.write = function(command, argument) {
|
||||
|
||||
var text = command;
|
||||
|
||||
if (argument !== undefined) text = text + " " + argument + "\r\n";
|
||||
else text = text + "\r\n";
|
||||
|
||||
if (debug) console.log("Client: " + util.inspect(text));
|
||||
|
||||
socket.write(text);
|
||||
|
||||
};
|
||||
|
||||
// Kills the socket connection
|
||||
this.end = function() {
|
||||
socket.end();
|
||||
};
|
||||
|
||||
// Upgrades a standard unencrypted TCP connection to use TLS
|
||||
// Liberally copied and modified from https://gist.github.com/848444
|
||||
// starttls() should be a private function, but I can't figure out
|
||||
// how to get a public prototypal method (stls) to talk to private method (starttls)
|
||||
// which references private variables without going through a privileged method
|
||||
this.starttls = function(options) {
|
||||
|
||||
var s = socket;
|
||||
s.removeAllListeners("end");
|
||||
s.removeAllListeners("data");
|
||||
s.removeAllListeners("error");
|
||||
socket=null;
|
||||
|
||||
var sslcontext = require('crypto').createCredentials(options);
|
||||
var pair = tls.createSecurePair(sslcontext, false);
|
||||
var cleartext = pipe(pair);
|
||||
|
||||
pair.on('secure', function() {
|
||||
|
||||
var verifyError = pair.ssl.verifyError();
|
||||
cleartext.authorized = true;
|
||||
|
||||
if (verifyError) {
|
||||
|
||||
cleartext.authorized = false;
|
||||
cleartext.authorizationError = verifyError;
|
||||
|
||||
}
|
||||
|
||||
cleartext.on("data", onData);
|
||||
cleartext.on("error", onError);
|
||||
cleartext.on("end", onEnd);
|
||||
socket=cleartext;
|
||||
(self.getCallback())(cleartext.authorized, cleartext.authorizationError);
|
||||
|
||||
});
|
||||
|
||||
cleartext._controlReleased = true;
|
||||
|
||||
function pipe(pair) {
|
||||
|
||||
pair.encrypted.pipe(s);
|
||||
s.pipe(pair.encrypted);
|
||||
|
||||
pair.fd = s.fd;
|
||||
var cleartext = pair.cleartext;
|
||||
cleartext.socket = s;
|
||||
cleartext.encrypted = pair.encrypted;
|
||||
cleartext.authorized = false;
|
||||
|
||||
function onerror(e) {
|
||||
if (cleartext._controlReleased) cleartext.emit('error', e);
|
||||
}
|
||||
|
||||
function onclose() {
|
||||
s.removeListener('error', onerror);
|
||||
s.removeListener('close', onclose);
|
||||
}
|
||||
|
||||
s.on('error', onerror);
|
||||
s.on('close', onclose);
|
||||
return cleartext;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Private methods follow
|
||||
// Event handlers follow
|
||||
function onData(data) {
|
||||
|
||||
data = data.toString("ascii");
|
||||
bufferedData += data;
|
||||
|
||||
if (debug) console.log("Server: " + util.inspect(data));
|
||||
|
||||
if (checkResp === true) {
|
||||
|
||||
if (bufferedData.substr(0, 3) === "+OK") {
|
||||
|
||||
checkResp = false;
|
||||
response = true;
|
||||
|
||||
} else if (bufferedData.substr(0, 4) === "-ERR") {
|
||||
|
||||
checkResp = false;
|
||||
response = false;
|
||||
|
||||
// The following is only used for SASL
|
||||
} else if (multiline === false) {
|
||||
|
||||
checkResp = false;
|
||||
response = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (checkResp === false) {
|
||||
|
||||
if (multiline === true && (response === false || bufferedData.substr(bufferedData.length-5) === "\r\n.\r\n")) {
|
||||
|
||||
// Make a copy to avoid race conditions
|
||||
var responseCopy = response;
|
||||
var bufferedDataCopy = bufferedData;
|
||||
|
||||
response = null;
|
||||
checkResp = true;
|
||||
multiline = false;
|
||||
bufferedData = "";
|
||||
|
||||
callback(responseCopy, bufferedDataCopy);
|
||||
|
||||
} else if (multiline === false) {
|
||||
|
||||
// Make a copy to avoid race conditions
|
||||
var responseCopy = response;
|
||||
var bufferedDataCopy = bufferedData;
|
||||
|
||||
response = null;
|
||||
checkResp = true;
|
||||
multiline = false;
|
||||
bufferedData = "";
|
||||
|
||||
callback(responseCopy, bufferedDataCopy);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onError(err) {
|
||||
|
||||
if (err.errno === 111) self.emit("connect", false, err);
|
||||
else self.emit("error", err);
|
||||
|
||||
}
|
||||
|
||||
function onEnd(data) {
|
||||
self.setState(0);
|
||||
socket = null;
|
||||
}
|
||||
|
||||
function onClose() {
|
||||
self.emit("close");
|
||||
}
|
||||
|
||||
// Constructor code follows
|
||||
// Set up EventEmitter constructor function
|
||||
events.EventEmitter.call(this);
|
||||
|
||||
// Remote end socket
|
||||
if (enabletls === true) {
|
||||
|
||||
tlssock = tls.connect({
|
||||
host: host,
|
||||
port: port,
|
||||
rejectUnauthorized: !self.data.ignoretlserrs
|
||||
}, function() {
|
||||
|
||||
if (tlssock.authorized === false &&
|
||||
self.data["ignoretlserrs"] === false)
|
||||
self.emit("tls-error", tlssock.authorizationError);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
socket = tlssock;
|
||||
|
||||
} else socket = new net.createConnection(port, host);
|
||||
|
||||
// Set up event handlers
|
||||
socket.on("data", onData);
|
||||
socket.on("error", onError);
|
||||
socket.on("end", onEnd);
|
||||
socket.on("close", onClose);
|
||||
|
||||
}
|
||||
|
||||
util.inherits(POP3Client, events.EventEmitter);
|
||||
|
||||
POP3Client.prototype.login = function (username, password) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() !== 1) self.emit("invalid-state", "login");
|
||||
else if (self.getLocked() === true) self.emit("locked", "login");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
if (resp === false) {
|
||||
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
self.emit("login", false, data);
|
||||
|
||||
} else {
|
||||
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
|
||||
if (resp !== false) self.setState(2);
|
||||
self.emit("login", resp, data);
|
||||
|
||||
});
|
||||
|
||||
self.setMultiline(false);
|
||||
self.write("PASS", password);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
self.setMultiline(false);
|
||||
self.write("USER", username);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// SASL AUTH implementation
|
||||
// Currently supports SASL PLAIN and CRAM-MD5
|
||||
POP3Client.prototype.auth = function (type, username, password) {
|
||||
|
||||
type = type.toUpperCase();
|
||||
var self = this;
|
||||
var types = {"PLAIN": 1, "CRAM-MD5": 1};
|
||||
var initialresp = "";
|
||||
|
||||
if (self.getState() !== 1) self.emit("invalid-state", "auth");
|
||||
else if (self.getLocked() === true) self.emit("locked", "auth");
|
||||
|
||||
if ((type in types) === false) {
|
||||
|
||||
self.emit("auth", false, "Invalid auth type", null);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
function tlsok() {
|
||||
|
||||
if (type === "PLAIN") {
|
||||
|
||||
initialresp = " " + new Buffer(username + "\u0000" + username + "\u0000" + password).toString("base64") + "=";
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
if (resp !== false) self.setState(2);
|
||||
self.emit("auth", resp, data, data);
|
||||
|
||||
});
|
||||
|
||||
} else if (type === "CRAM-MD5") {
|
||||
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
if (resp === false) self.emit("auth", resp, "Server responded -ERR to AUTH CRAM-MD5", data);
|
||||
else {
|
||||
|
||||
var challenge = new Buffer(data.trim().substr(2), "base64").toString();
|
||||
var hmac = crypto.createHmac("md5", password);
|
||||
var response = new Buffer(username + " " + hmac.update(challenge).digest("hex")).toString("base64");
|
||||
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
var errmsg = null;
|
||||
|
||||
if (resp !== false) self.setState(2);
|
||||
else errmsg = "Server responded -ERR to response";
|
||||
|
||||
self.emit("auth", resp, null, data);
|
||||
|
||||
});
|
||||
|
||||
self.write(response);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
self.write("AUTH " + type + initialresp);
|
||||
|
||||
}
|
||||
|
||||
if (self.data["tls"] === false && self.data["stls"] === false) {
|
||||
|
||||
// Remove all existing STLS listeners
|
||||
self.removeAllListeners("stls");
|
||||
|
||||
self.on("stls", function(resp, rawdata) {
|
||||
|
||||
if (resp === false) {
|
||||
|
||||
// We (optionally) ignore self signed cert errors,
|
||||
// in blatant violation of RFC 2595, Section 2.4
|
||||
if (self.data["ignoretlserrs"] === true && rawdata === "DEPTH_ZERO_SELF_SIGNED_CERT") tlsok();
|
||||
else self.emit("auth", false, "Unable to upgrade connection to STLS", rawdata);
|
||||
|
||||
} else tlsok();
|
||||
|
||||
});
|
||||
|
||||
self.stls();
|
||||
|
||||
} else tlsok();
|
||||
};
|
||||
|
||||
POP3Client.prototype.apop = function (username, password) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() !== 1) self.emit("invalid-state", "apop");
|
||||
else if (self.getLocked() === true) self.emit("locked", "apop");
|
||||
else if (self.data["apop"] === false) self.emit("apop", false, "APOP support not detected on remote server");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
|
||||
if (resp === true) self.setState(2);
|
||||
self.emit("apop", resp, data);
|
||||
|
||||
});
|
||||
|
||||
self.setMultiline(false);
|
||||
self.write("APOP", username + " " + crypto.createHash("md5").update(self.data["apop-timestamp"] + password).digest("hex"));
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
POP3Client.prototype.stls = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() !== 1) self.emit("invalid-state", "stls");
|
||||
else if (self.getLocked() === true) self.emit("locked", "stls");
|
||||
else if (self.data["tls"] === true) self.emit("stls", false, "Unable to execute STLS as TLS connection already established");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
|
||||
if (resp === true) {
|
||||
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
if (resp === false && self.data["ignoretlserrs"] === true && data === "DEPTH_ZERO_SELF_SIGNED_CERT")
|
||||
resp = true;
|
||||
|
||||
self.data["stls"] = true;
|
||||
self.emit("stls", resp, data);
|
||||
|
||||
});
|
||||
|
||||
self.starttls();
|
||||
|
||||
} else self.emit("stls", false, data);
|
||||
});
|
||||
|
||||
self.setMultiline(false);
|
||||
self.write("STLS");
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
POP3Client.prototype.top = function(msgnumber, lines) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() !== 2) self.emit("invalid-state", "top");
|
||||
else if (self.getLocked() === true) self.emit("locked", "top");
|
||||
else {
|
||||
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
var returnValue = null;
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
|
||||
if (resp !== false) {
|
||||
|
||||
returnValue = "";
|
||||
var startOffset = data.indexOf("\r\n", 0) + 2;
|
||||
var endOffset = data.indexOf("\r\n.\r\n", 0) + 2;
|
||||
|
||||
if (endOffset > startOffset)
|
||||
returnValue = data.substr(startOffset, endOffset-startOffset);
|
||||
|
||||
}
|
||||
|
||||
self.emit("top", resp, msgnumber, returnValue, data);
|
||||
|
||||
});
|
||||
|
||||
self.setMultiline(true);
|
||||
self.write("TOP", msgnumber + " " + lines);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
POP3Client.prototype.list = function(msgnumber) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() !== 2) self.emit("invalid-state", "list");
|
||||
else if (self.getLocked() === true) self.emit("locked", "list");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
var returnValue = null;
|
||||
var msgcount = 0;
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
|
||||
if (resp !== false) {
|
||||
|
||||
returnValue = [];
|
||||
|
||||
if (msgnumber !== undefined) {
|
||||
|
||||
msgcount = 1
|
||||
listitem = data.split(" ");
|
||||
returnValue[listitem[1]] = listitem[2];
|
||||
|
||||
} else {
|
||||
|
||||
var offset = 0;
|
||||
var listitem = "";
|
||||
var newoffset = 0;
|
||||
var returnValue = [];
|
||||
var startOffset = data.indexOf("\r\n", 0) + 2;
|
||||
var endOffset = data.indexOf("\r\n.\r\n", 0) + 2;
|
||||
|
||||
if (endOffset > startOffset) {
|
||||
|
||||
data = data.substr(startOffset, endOffset-startOffset);
|
||||
|
||||
while(true) {
|
||||
|
||||
if (offset > endOffset)
|
||||
break;
|
||||
|
||||
newoffset = data.indexOf("\r\n", offset);
|
||||
|
||||
if (newoffset < 0)
|
||||
break;
|
||||
|
||||
msgcount++;
|
||||
listitem = data.substr(offset, newoffset-offset);
|
||||
listitem = listitem.split(" ");
|
||||
returnValue[listitem[0]] = listitem[1];
|
||||
offset = newoffset + 2;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.emit("list", resp, msgcount, msgnumber, returnValue, data);
|
||||
|
||||
});
|
||||
|
||||
if (msgnumber !== undefined) self.setMultiline(false);
|
||||
else self.setMultiline(true);
|
||||
|
||||
self.write("LIST", msgnumber);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
POP3Client.prototype.stat = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() !== 2) self.emit("invalid-state", "stat");
|
||||
else if (self.getLocked() === true) self.emit("locked", "stat");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
var returnValue = null;
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
|
||||
if (resp !== false) {
|
||||
|
||||
listitem = data.split(" ");
|
||||
returnValue = {
|
||||
|
||||
"count": listitem[1].trim(),
|
||||
"octets": listitem[2].trim(),
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
self.emit("stat", resp, returnValue, data);
|
||||
|
||||
});
|
||||
|
||||
self.setMultiline(false);
|
||||
self.write("STAT", undefined);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
POP3Client.prototype.uidl = function(msgnumber) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() !== 2) self.emit("invalid-state", "uidl");
|
||||
else if (self.getLocked() === true) self.emit("locked", "uidl");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
var returnValue = null;
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
|
||||
if (resp !== false) {
|
||||
|
||||
returnValue = [];
|
||||
|
||||
if (msgnumber !== undefined) {
|
||||
|
||||
listitem = data.split(" ");
|
||||
returnValue[listitem[1]] = listitem[2].trim();
|
||||
|
||||
} else {
|
||||
|
||||
var offset = 0;
|
||||
var listitem = "";
|
||||
var newoffset = 0;
|
||||
var returnValue = [];
|
||||
var startOffset = data.indexOf("\r\n", 0) + 2;
|
||||
var endOffset = data.indexOf("\r\n.\r\n", 0) + 2;
|
||||
|
||||
if (endOffset > startOffset) {
|
||||
|
||||
data = data.substr(startOffset, endOffset-startOffset);
|
||||
endOffset -= startOffset;
|
||||
|
||||
while (offset < endOffset) {
|
||||
|
||||
newoffset = data.indexOf("\r\n", offset);
|
||||
listitem = data.substr(offset, newoffset-offset);
|
||||
listitem = listitem.split(" ");
|
||||
returnValue[listitem[0]] = listitem[1];
|
||||
offset = newoffset + 2;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.emit("uidl", resp, msgnumber, returnValue, data);
|
||||
|
||||
});
|
||||
|
||||
if (msgnumber !== undefined) self.setMultiline(false);
|
||||
else self.setMultiline(true);
|
||||
|
||||
self.write("UIDL", msgnumber);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
POP3Client.prototype.retr = function(msgnumber) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() !== 2) self.emit("invalid-state", "retr");
|
||||
else if (self.getLocked() === true) self.emit("locked", "retr");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
var returnValue = null;
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
|
||||
if (resp !== false) {
|
||||
|
||||
var startOffset = data.indexOf("\r\n", 0) + 2;
|
||||
var endOffset = data.indexOf("\r\n.\r\n", 0);
|
||||
returnValue = data.substr(startOffset, endOffset-startOffset);
|
||||
|
||||
}
|
||||
|
||||
self.emit("retr", resp, msgnumber, returnValue, data);
|
||||
|
||||
});
|
||||
|
||||
self.setMultiline(true);
|
||||
self.write("RETR", msgnumber);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
POP3Client.prototype.dele = function(msgnumber) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() !== 2) self.emit("invalid-state", "dele");
|
||||
else if (self.getLocked() === true) self.emit("locked", "dele");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
self.emit("dele", resp, msgnumber, data);
|
||||
|
||||
});
|
||||
|
||||
self.setMultiline(false);
|
||||
self.write("DELE", msgnumber);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
POP3Client.prototype.noop = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() !== 2) self.emit("invalid-state", "noop");
|
||||
else if (self.getLocked() === true) self.emit("locked", "noop");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
self.emit("noop", resp, data);
|
||||
|
||||
});
|
||||
|
||||
self.setMultiline(false);
|
||||
self.write("NOOP", undefined);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
POP3Client.prototype.rset = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() !== 2) self.emit("invalid-state", "rset");
|
||||
else if (self.getLocked() === true) self.emit("locked", "rset");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
self.emit("rset", resp, data);
|
||||
|
||||
});
|
||||
|
||||
self.setMultiline(false);
|
||||
self.write("RSET", undefined);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
POP3Client.prototype.capa = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() === 0) self.emit("invalid-state", "quit");
|
||||
else if (self.getLocked() === true) self.emit("locked", "capa");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
var returnValue = null;
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
|
||||
if (resp === true) {
|
||||
|
||||
var startOffset = data.indexOf("\r\n", 0) + 2;
|
||||
var endOffset = data.indexOf("\r\n.\r\n", 0);
|
||||
returnValue = data.substr(startOffset, endOffset-startOffset);
|
||||
returnValue = returnValue.split("\r\n");
|
||||
|
||||
}
|
||||
|
||||
self.emit("capa", resp, returnValue, data);
|
||||
|
||||
});
|
||||
|
||||
self.setMultiline(true);
|
||||
self.write("CAPA", undefined);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
POP3Client.prototype.quit = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (self.getState() === 0) self.emit("invalid-state", "quit");
|
||||
else if (self.getLocked() === true) self.emit("locked", "quit");
|
||||
else {
|
||||
|
||||
self.setLocked(true);
|
||||
self.setCallback(function(resp, data) {
|
||||
|
||||
self.setLocked(false);
|
||||
self.setCallback(function() {});
|
||||
|
||||
self.end();
|
||||
self.emit("quit", resp, data);
|
||||
|
||||
});
|
||||
|
||||
self.setMultiline(false);
|
||||
self.write("QUIT", undefined);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = POP3Client;
|
||||
56
nodered/rootfs/data/node_modules/poplib/package.json
generated
vendored
Normal file
56
nodered/rootfs/data/node_modules/poplib/package.json
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"_from": "poplib@^0.1.7",
|
||||
"_id": "poplib@0.1.7",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-L0tYtVkpcjUM2X9IKrpo+OBVdLw=",
|
||||
"_location": "/poplib",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "poplib@^0.1.7",
|
||||
"name": "poplib",
|
||||
"escapedName": "poplib",
|
||||
"rawSpec": "^0.1.7",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.1.7"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/node-red-node-email"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/poplib/-/poplib-0.1.7.tgz",
|
||||
"_shasum": "2f4b58b5592972350cd97f482aba68f8e05574bc",
|
||||
"_spec": "poplib@^0.1.7",
|
||||
"_where": "/data/node_modules/node-red-node-email",
|
||||
"author": {
|
||||
"name": "Ditesh Shashikant Gathani",
|
||||
"email": "ditesh@gathani.org",
|
||||
"url": "http://ditesh.gathani.org/blog/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/ditesh/node-poplib/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"optimist": "*"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "POP3 client library for Node.js",
|
||||
"homepage": "https://github.com/ditesh/node-poplib",
|
||||
"keywords": [
|
||||
"POP3",
|
||||
"pop3",
|
||||
"pop",
|
||||
"client",
|
||||
"mail",
|
||||
"email"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "main.js",
|
||||
"name": "poplib",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ditesh/node-poplib.git"
|
||||
},
|
||||
"version": "0.1.7"
|
||||
}
|
||||
153
nodered/rootfs/data/node_modules/poplib/tests/apop.js
generated
vendored
Normal file
153
nodered/rootfs/data/node_modules/poplib/tests/apop.js
generated
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
|
||||
Node.js POP3 client test file
|
||||
|
||||
Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
var POP3Client = require("../main.js");
|
||||
var argv = require('optimist')
|
||||
.usage("Usage: $0 --host [host] --port [port] --username [username] --password [password] --debug [on/off] --networkdebug [on/off] --login [on/off] --download [on/off]")
|
||||
.demand(['username', 'password'])
|
||||
.argv;
|
||||
|
||||
var host = argv.host || "localhost";
|
||||
var port = argv.port || 110;
|
||||
var debug = argv.debug === "on" ? true : false;
|
||||
var login = argv.login === "on" ? true : false;
|
||||
var download = argv.download === "on" ? true : false;
|
||||
|
||||
var username = argv.username;
|
||||
var password = argv.password;
|
||||
var totalmsgcount = 0;
|
||||
var currentmsg = 0;
|
||||
|
||||
var client = new POP3Client(port, host, { debug: (argv.debug === "on" ? true: false) });
|
||||
|
||||
client.on("error", function(err) {
|
||||
console.log("Server error occurred, failed, " + err);
|
||||
});
|
||||
|
||||
client.on("connect", function(status, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("CONNECT success");
|
||||
if (login) client.apop(username, password);
|
||||
else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("CONNECT failed because " + rawdata);
|
||||
return;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("invalid-state", function(cmd) {
|
||||
console.log("Invalid state, failed. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("locked", function(cmd) {
|
||||
console.log("Current command has not finished yet, failed. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("apop", function(status, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("APOP success");
|
||||
if (download) client.list();
|
||||
else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("APOP failed because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("list", function(status, msgcount, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === false) {
|
||||
|
||||
console.log("LIST failed because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
} else if (msgcount > 0) {
|
||||
|
||||
totalmsgcount = msgcount;
|
||||
currentmsg = 1;
|
||||
console.log("LIST success with " + msgcount + " message(s)");
|
||||
client.retr(1);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LIST success with 0 message(s)");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("retr", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("RETR success " + msgnumber + " with data " + data);
|
||||
client.dele(msgnumber);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("RETR failed for msgnumber " + msgnumber + " because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("dele", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("DELE success for msgnumber " + msgnumber);
|
||||
|
||||
if (currentmsg < totalmsgcount) {
|
||||
|
||||
currentmsg += 1;
|
||||
client.retr(currentmsg);
|
||||
|
||||
} else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("DELE failed for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("quit", function(status, rawdata) {
|
||||
|
||||
if (status === true) console.log("QUIT success");
|
||||
else console.log("QUIT failed because " + rawdata);
|
||||
|
||||
});
|
||||
45
nodered/rootfs/data/node_modules/poplib/tests/apop.sh
generated
vendored
Normal file
45
nodered/rootfs/data/node_modules/poplib/tests/apop.sh
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
# Test script
|
||||
#
|
||||
# Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
#
|
||||
# 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.
|
||||
|
||||
print_title "apop.js"
|
||||
RANDOMID=$RANDOM
|
||||
|
||||
print_test "Sending test message (str: $RANDOMID)"
|
||||
OUTPUT=`./sendmail.sh 1 $EMAIL "subject with $RANDOMID" "body with $RANDOMID"`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Correct auth"
|
||||
OUTPUT=`node apop.js --username $USER --password $PASS --host $HOST --port $PORT --login on`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Invalid auth"
|
||||
OUTPUT=`node apop.js --username $USER --password ${PASS}a --host $HOST --port $PORT --login on`;
|
||||
print_result 1 $OUTPUT
|
||||
|
||||
print_test "Login and message download"
|
||||
OUTPUT=`node apop.js --username $USER --password $PASS --host $HOST --port $PORT --login on --download on`
|
||||
OUTPUT=`echo $OUTPUT | grep $RANDOMID`
|
||||
|
||||
if [ $? -eq 1 ]; then OUTPUT="fail"; fi
|
||||
|
||||
print_result 0 $OUTPUT
|
||||
197
nodered/rootfs/data/node_modules/poplib/tests/basic.js
generated
vendored
Normal file
197
nodered/rootfs/data/node_modules/poplib/tests/basic.js
generated
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
|
||||
Node.js POP3 client test file
|
||||
|
||||
Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
var POP3Client = require("../main.js");
|
||||
var argv = require('optimist')
|
||||
.usage("Usage: $0 --host [host] --port [port] --username [username] --password [password] --debug [on/off] --networkdebug [on/off] --download [on/off] --dele [on/off] --rset [on/off]")
|
||||
.demand(['username', 'password'])
|
||||
.argv;
|
||||
|
||||
var host = argv.host || "localhost";
|
||||
var port = argv.port || 110;
|
||||
var debug = argv.debug === "on" ? true : false;
|
||||
var dele = argv.dele === "on" ? true : false;
|
||||
var rset = argv.rset === "on" ? true : false;
|
||||
var download = argv.download === "on" ? true : false;
|
||||
|
||||
var username = argv.username;
|
||||
var password = argv.password;
|
||||
var totalmsgcount = 0;
|
||||
var currentmsg = 0;
|
||||
|
||||
var client = new POP3Client(port, host, {
|
||||
|
||||
debug: (argv.networkdebug === "on" ? true: false)
|
||||
|
||||
});
|
||||
|
||||
|
||||
client.on("error", function(err) {
|
||||
console.log("Server error occurred, failed, " + err);
|
||||
});
|
||||
|
||||
client.on("connect", function(status, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("CONNECT success");
|
||||
client.login(username, password);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("CONNECT failed because " + rawdata);
|
||||
return;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("invalid-state", function(cmd) {
|
||||
console.log("Invalid state, failed. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("locked", function(cmd) {
|
||||
console.log("Current command has not finished yet, failed. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("login", function(status, data, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("LOGIN/PASS success");
|
||||
if (download || dele) client.list();
|
||||
else client.capa();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LOGIN/PASS failed because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
client.on("capa", function(status, data, rawdata) {
|
||||
|
||||
if (download) client.list();
|
||||
else client.quit();
|
||||
|
||||
});
|
||||
|
||||
client.on("rset", function(status,rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("RSET success");
|
||||
rset=false;
|
||||
currentmsg=1;
|
||||
client.retr(1);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("RSET failed because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("list", function(status, msgcount, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === false) {
|
||||
|
||||
console.log("LIST failed");
|
||||
client.quit();
|
||||
|
||||
} else if (msgcount > 0) {
|
||||
|
||||
totalmsgcount = msgcount;
|
||||
currentmsg = 1;
|
||||
console.log("LIST success with " + msgcount + " message(s)");
|
||||
|
||||
if (download) client.retr(1);
|
||||
else if (dele) client.dele(1);
|
||||
else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LIST success with 0 message(s)");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("retr", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("RETR success " + msgnumber + " with data " + data);
|
||||
if (dele) client.dele(msgnumber);
|
||||
else {
|
||||
|
||||
if (currentmsg < totalmsgcount) {
|
||||
|
||||
currentmsg += 1;
|
||||
client.retr(currentmsg);
|
||||
|
||||
} else client.quit();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
console.log("RETR failed for msgnumber " + msgnumber + " because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("dele", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("DELE success for msgnumber " + msgnumber);
|
||||
|
||||
if (currentmsg < totalmsgcount) {
|
||||
|
||||
currentmsg += 1;
|
||||
if (!rset && download) client.retr(currentmsg);
|
||||
else client.dele(currentmsg);
|
||||
|
||||
} else if (rset) client.rset()
|
||||
else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("DELE failed for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("quit", function(status, rawdata) {
|
||||
|
||||
if (status === true) console.log("QUIT success");
|
||||
else console.log("QUIT failed");
|
||||
|
||||
});
|
||||
81
nodered/rootfs/data/node_modules/poplib/tests/basic.sh
generated
vendored
Normal file
81
nodered/rootfs/data/node_modules/poplib/tests/basic.sh
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
#!/bin/sh
|
||||
# Test script
|
||||
#
|
||||
# Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
#
|
||||
# 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.
|
||||
|
||||
print_title "basic.js"
|
||||
RANDOMID=$RANDOM
|
||||
|
||||
print_test "Sending test message to $EMAIL (str: $RANDOMID)"
|
||||
OUTPUT=`./sendmail.sh -q 1 $EMAIL "subject with $RANDOMID" "body with $RANDOMID"`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Sleeping 5 seconds"
|
||||
OUTPUT=`sleep 5`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "CAPA test"
|
||||
OUTPUT=`node basic.js --username $USER --password $PASS --host $HOST --port $PORT`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "RETR test"
|
||||
OUTPUT=`node basic.js --username $USER --password $PASS --host $HOST --port $PORT --download on`;
|
||||
OUTPUT=`echo $OUTPUT | grep $RANDOMID`
|
||||
if [ $? -eq 1 ]; then OUTPUT="fail"; fi
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "RETR, DELE test"
|
||||
OUTPUT=`node basic.js --username $USER --password $PASS --host $HOST --port $PORT --download on --dele on`;
|
||||
OUTPUT=`node basic.js --username $USER --password $PASS --host $HOST --port $PORT --download on`;
|
||||
OUTPUT=`echo $OUTPUT | grep $RANDOMID`
|
||||
if [ $? -eq 0 ]; then OUTPUT="fail"; fi
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
RANDOMID=$RANDOM
|
||||
print_test "Sending test message to $EMAIL (str: $RANDOMID)"
|
||||
OUTPUT=`./sendmail.sh -q 1 $EMAIL "subject with $RANDOMID" "body with $RANDOMID"`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Sleeping 5 seconds"
|
||||
OUTPUT=`sleep 5`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "DELE test"
|
||||
OUTPUT=`node basic.js --username $USER --password $PASS --host $HOST --port $PORT --dele on`;
|
||||
OUTPUT=`node basic.js --username $USER --password $PASS --host $HOST --port $PORT --download on`;
|
||||
OUTPUT=`echo $OUTPUT | grep $RANDOMID`
|
||||
if [ $? -eq 0 ]; then OUTPUT="fail"; fi
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
RANDOMID=$RANDOM
|
||||
print_test "Sending test message to $EMAIL (str: $RANDOMID)"
|
||||
OUTPUT=`./sendmail.sh -q 1 $EMAIL "subject with $RANDOMID" "body with $RANDOMID"`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Sleeping 5 seconds"
|
||||
OUTPUT=`sleep 5`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "DELE, RSET, RETR test"
|
||||
OUTPUT=`node basic.js --username $USER --password $PASS --host $HOST --port $PORT --dele on --rset on --download on`;
|
||||
OUTPUT=`echo $OUTPUT | grep $RANDOMID`
|
||||
if [ $? -eq 1 ]; then OUTPUT="fail"; fi
|
||||
print_result 0 $OUTPUT
|
||||
84
nodered/rootfs/data/node_modules/poplib/tests/login.js
generated
vendored
Normal file
84
nodered/rootfs/data/node_modules/poplib/tests/login.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
|
||||
Node.js POP3 client test file
|
||||
|
||||
Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
var POP3Client = require("../main.js");
|
||||
var argv = require('optimist')
|
||||
.usage("Usage: $0 --host [host] --port [port] --username [username] --password [password] --debug [on/off] --networkdebug [on/off]")
|
||||
.demand(['username', 'password'])
|
||||
.argv;
|
||||
|
||||
var host = argv.host || "localhost";
|
||||
var port = argv.port || 110;
|
||||
var debug = argv.debug === "on" ? true : false;
|
||||
var filename = argv.filename;
|
||||
var username = argv.username;
|
||||
var password = argv.password;
|
||||
var totalmsgcount = 0;
|
||||
var currentmsg = 0;
|
||||
|
||||
var client = new POP3Client(port, host, { debug: (argv.debug === "on" ? true: false) });
|
||||
|
||||
client.on("error", function(err) {
|
||||
console.log("Server error occurred, failed, " + err);
|
||||
});
|
||||
|
||||
client.on("connect", function(status, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("CONNECT success");
|
||||
client.login(username, password);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("CONNECT failed because " + rawdata);
|
||||
return;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("invalid-state", function(cmd) {
|
||||
console.log("Invalid state, failed. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("locked", function(cmd) {
|
||||
console.log("Current command has not finished yet, failed. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("login", function(status, rawdata) {
|
||||
|
||||
if (status) console.log("LOGIN success");
|
||||
else console.log("LOGIN failed because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
});
|
||||
|
||||
client.on("quit", function(status, rawdata) {
|
||||
|
||||
if (status === true) console.log("QUIT success");
|
||||
else console.log("QUIT failed because " + rawdata);
|
||||
|
||||
});
|
||||
47
nodered/rootfs/data/node_modules/poplib/tests/login.sh
generated
vendored
Normal file
47
nodered/rootfs/data/node_modules/poplib/tests/login.sh
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/bin/sh
|
||||
# Test script
|
||||
#
|
||||
# Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
#
|
||||
# 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.
|
||||
|
||||
print_title "login.js"
|
||||
print_test "Correct auth"
|
||||
OUTPUT=`node login.js --username $USER --password $PASS --host $HOST --port $PORT`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Invalid auth"
|
||||
OUTPUT=`node login.js --username $USER --password ${PASS}a --host $HOST --port $PORT`
|
||||
print_result 1 $OUTPUT
|
||||
|
||||
print_test "Correct host"
|
||||
OUTPUT=`node login.js --username $USER --password $PASS --host $HOST --port $PORT`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Invalid host"
|
||||
OUTPUT=`node login.js --username $USER --password $PASS --host ${HOST}a --port $PORT`
|
||||
print_result 1 $OUTPUT
|
||||
|
||||
print_test "Correct port"
|
||||
OUTPUT=`node login.js --username $USER --password $PASS --host $HOST --port $PORT`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Invalid port"
|
||||
OUTPUT=`node login.js --username $USER --password $PASS --host $HOST --port ${PORT}1`
|
||||
print_result 1 $OUTPUT
|
||||
100
nodered/rootfs/data/node_modules/poplib/tests/runner.sh
generated
vendored
Executable file
100
nodered/rootfs/data/node_modules/poplib/tests/runner.sh
generated
vendored
Executable file
@@ -0,0 +1,100 @@
|
||||
#!/bin/sh
|
||||
# Test runner
|
||||
#
|
||||
# Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
#
|
||||
# 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.
|
||||
|
||||
print_title() {
|
||||
echo -e "\033[1;30mTesting ${1}\033[0;30m";
|
||||
}
|
||||
|
||||
print_test() {
|
||||
printf "%-60s" "$1";
|
||||
}
|
||||
|
||||
print_result() {
|
||||
|
||||
echo $* | grep -q "fail"
|
||||
|
||||
# $1: 0 is expecting no failure, 1 is expecting failure
|
||||
if [ $? -eq $1 ]; then
|
||||
FAILCOUNT=`expr $FAILCOUNT + 1`
|
||||
echo -e " [\033[1;31mFAIL\033[0;30m]";
|
||||
else
|
||||
PASSCOUNT=`expr $PASSCOUNT + 1`
|
||||
echo -e " [\033[1;32mPASS\033[0;30m]";
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
echo "runner.sh v0.1 - a test runner utility"
|
||||
echo "Copyright (c) 2011 Ditesh Shashikant Gathani <ditesh@gathani.org>"
|
||||
|
||||
if [ $# -lt 6 ]; then
|
||||
|
||||
echo "Usage:"
|
||||
echo " runner.sh username password host standard-port tls-port testemail@example.com [test]"
|
||||
echo
|
||||
echo " username: POP3 username"
|
||||
echo " password: POP3 password"
|
||||
echo " host: POP3 host"
|
||||
echo " standard-port: POP3 port (eg 110)"
|
||||
echo " tls-port: POP3 TLS port (eg 995)"
|
||||
echo " email: valid email address on POP3 server which can receive emails"
|
||||
echo " test: which test to run (default all)"
|
||||
echo
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
USER=$1
|
||||
PASS=$2
|
||||
HOST=$3
|
||||
PORT=$4
|
||||
TLSPORT=$5
|
||||
EMAIL=$6
|
||||
FAILCOUNT=0
|
||||
PASSCOUNT=0
|
||||
|
||||
if [ $# -eq 7 ]; then
|
||||
|
||||
echo
|
||||
source ./$7
|
||||
|
||||
else
|
||||
|
||||
echo
|
||||
source ./login.sh
|
||||
echo
|
||||
source ./basic.sh
|
||||
echo
|
||||
source ./apop.sh
|
||||
echo
|
||||
source ./stls.sh
|
||||
echo
|
||||
source ./tls.sh
|
||||
|
||||
fi
|
||||
|
||||
echo
|
||||
echo -e "\033[1;30mSummary:"
|
||||
echo -e " \033[1;32mPassed tests: ${PASSCOUNT}\033[0;30m"
|
||||
echo -e " \033[1;31mFailed tests: ${FAILCOUNT}\033[0;30m"
|
||||
echo
|
||||
177
nodered/rootfs/data/node_modules/poplib/tests/sasl.js
generated
vendored
Normal file
177
nodered/rootfs/data/node_modules/poplib/tests/sasl.js
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
|
||||
Node.js POP3 client test file
|
||||
|
||||
Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
var POP3Client = require("../main.js");
|
||||
var argv = require('optimist')
|
||||
.usage("Usage: $0 --host [host] --port [port] --username [username] --password [password] --debug [on/off] --networkdebug [on/off] --auth [plain/cram-md5] --tls [on/off] --download [on/off]")
|
||||
.demand(['username', 'password', 'auth'])
|
||||
.describe('auth', 'Valid AUTH types: plain, cram-md5')
|
||||
.argv;
|
||||
|
||||
var host = argv.host || "localhost";
|
||||
var port = argv.port || 110;
|
||||
var debug = argv.debug === "on" ? true : false;
|
||||
var tls = argv.tls === "on" ? true : false;
|
||||
var auth = argv.auth;
|
||||
var download = argv.download === "on" ? true : false;
|
||||
|
||||
var username = argv.username;
|
||||
var password = argv.password;
|
||||
var totalmsgcount = 0;
|
||||
var currentmsg = 0;
|
||||
|
||||
// We carefully ignore self signed cert errors (bad practice!)
|
||||
var client = new POP3Client(port, host, {
|
||||
|
||||
enabletls: tls,
|
||||
ignoretlserrs: true,
|
||||
debug: (argv.networkdebug === "on" ? true: false)
|
||||
|
||||
});
|
||||
|
||||
client.on("tls-error", function(err) {
|
||||
|
||||
console.log("TLS error occurred, failed");
|
||||
console.log(err);
|
||||
|
||||
});
|
||||
|
||||
client.on("close", function() {
|
||||
console.log("close event unexpectedly received, failed");
|
||||
});
|
||||
|
||||
client.on("error", function(err) {
|
||||
console.log("Server error occurred, failed, " + err);
|
||||
});
|
||||
|
||||
client.on("connect", function(status, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("CONNECT success");
|
||||
client.auth(auth, username, password);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("CONNECT failed because " + rawdata);
|
||||
return;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("invalid-state", function(cmd) {
|
||||
console.log("Invalid state. You tried calling " + cmd);
|
||||
client.quit();
|
||||
});
|
||||
|
||||
client.on("locked", function(cmd) {
|
||||
console.log("Current command has not finished yet. You tried calling " + cmd);
|
||||
client.quit();
|
||||
});
|
||||
|
||||
client.on("auth", function(status, errmsg, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("AUTH success");
|
||||
if (download) client.list();
|
||||
else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("AUTH failed (" + errmsg + ")");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
client.on("list", function(status, msgcount, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === false) {
|
||||
|
||||
console.log("LIST failed");
|
||||
client.quit();
|
||||
|
||||
} else if (msgcount > 0) {
|
||||
|
||||
totalmsgcount = msgcount;
|
||||
currentmsg = 1;
|
||||
console.log("LIST success with " + msgcount + " message(s)");
|
||||
client.retr(1);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LIST success with 0 message(s)");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("retr", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("RETR success " + msgnumber + " with data " + data);
|
||||
client.dele(msgnumber);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("RETR failed for msgnumber " + msgnumber + " because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("dele", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("DELE success for msgnumber " + msgnumber);
|
||||
|
||||
if (currentmsg < totalmsgcount) {
|
||||
|
||||
currentmsg += 1;
|
||||
client.retr(currentmsg);
|
||||
|
||||
} else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("DELE failed for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
client.on("quit", function(status, rawdata) {
|
||||
|
||||
client.removeAllListeners("close");
|
||||
if (status === true) console.log("QUIT success");
|
||||
else console.log("QUIT failed");
|
||||
|
||||
});
|
||||
85
nodered/rootfs/data/node_modules/poplib/tests/sasl.sh
generated
vendored
Normal file
85
nodered/rootfs/data/node_modules/poplib/tests/sasl.sh
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/bin/sh
|
||||
# Test script
|
||||
#
|
||||
# Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
#
|
||||
# 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.
|
||||
|
||||
print_title "sasl.js"
|
||||
RANDOMID=$RANDOM
|
||||
|
||||
print_test "Sending test message to $EMAIL (str: $RANDOMID)"
|
||||
OUTPUT=`./sendmail.sh -q 1 $EMAIL "subject with $RANDOMID" "body with $RANDOMID"`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Valid PLAIN login without TLS"
|
||||
OUTPUT=`node sasl.js --username $USER --password $PASS --host $HOST --port $PORT --auth plain`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Valid CRAM-MD5 login without TLS"
|
||||
OUTPUT=`node sasl.js --username $USER --password $PASS --host $HOST --port $PORT --auth "cram-md5"`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Invalid PLAIN login without TLS"
|
||||
OUTPUT=`node sasl.js --username $USER --password ${PASS}a --host $HOST --port $PORT --auth plain`;
|
||||
print_result 1 $OUTPUT
|
||||
|
||||
print_test "Invalid CRAM-MD5 login without TLS"
|
||||
OUTPUT=`node sasl.js --username $USER --password ${PASS}a --host $HOST --port $PORT --auth "cram-md5"`;
|
||||
print_result 1 $OUTPUT
|
||||
|
||||
print_test "Valid PLAIN login with TLS"
|
||||
OUTPUT=`node sasl.js --username $USER --password $PASS --host $HOST --port $TLSPORT --auth plain --tls on`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Valid CRAM-MD5 login with TLS"
|
||||
OUTPUT=`node sasl.js --username $USER --password $PASS --host $HOST --port $TLSPORT --auth "cram-md5" --tls on`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Invalid PLAIN login with TLS"
|
||||
OUTPUT=`node sasl.js --username $USER --password ${PASS}a --host $HOST --port $TLSPORT --auth plain --tls on`;
|
||||
print_result 1 $OUTPUT
|
||||
|
||||
print_test "Invalid CRAM-MD5 login with TLS"
|
||||
OUTPUT=`node sasl.js --username $USER --password ${PASS}a --host $HOST --port $TLSPORT --auth "cram-md5" --tls on`;
|
||||
print_result 1 $OUTPUT
|
||||
|
||||
print_test "PLAIN login and message download"
|
||||
OUTPUT=`node sasl.js --username $USER --password $PASS --host $HOST --port $PORT --auth plain --download on`
|
||||
OUTPUT=`echo $OUTPUT | grep $RANDOMID`
|
||||
|
||||
if [ $? -eq 1 ]; then OUTPUT="fail"; fi
|
||||
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Sending another test message to $EMAIL (str: $RANDOMID)"
|
||||
OUTPUT=`./sendmail.sh -q 1 $EMAIL "subject with $RANDOMID" "body with $RANDOMID"`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Sleeping 5 seconds"
|
||||
OUTPUT=`sleep 5`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "CRAM-MD5 login and message download"
|
||||
OUTPUT=`node sasl.js --username $USER --password $PASS --host $HOST --port $PORT --auth "cram-md5" --download on`
|
||||
OUTPUT=`echo $OUTPUT | grep $RANDOMID`
|
||||
|
||||
if [ $? -eq 1 ]; then OUTPUT="fail"; fi
|
||||
|
||||
print_result 0 $OUTPUT
|
||||
60
nodered/rootfs/data/node_modules/poplib/tests/sendmail.sh
generated
vendored
Executable file
60
nodered/rootfs/data/node_modules/poplib/tests/sendmail.sh
generated
vendored
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Email pumper helper script
|
||||
#
|
||||
# Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
#
|
||||
# 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.
|
||||
|
||||
QUIET=0
|
||||
if [ "$1" = "-q" ]; then
|
||||
QUIET=1
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ $QUIET -eq 0 ]; then
|
||||
|
||||
echo "sendmail.sh v0.1 - a utility to pump email into an SMTP server"
|
||||
echo "Copyright (c) 2011 Ditesh Shashikant Gathani <ditesh@gathani.org>"
|
||||
echo
|
||||
|
||||
fi
|
||||
|
||||
|
||||
if [ $# -ne 4 ]; then
|
||||
|
||||
echo "Usage:"
|
||||
echo " sendmail.sh [-q] [number of emails] [to] [subject] [body]"
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
if [ $QUIET -eq 0 ]; then
|
||||
|
||||
echo "Sending $1 email(s)"
|
||||
echo " to: $2"
|
||||
echo " subject: \"$3\""
|
||||
echo " body: \"$4\""
|
||||
echo
|
||||
|
||||
fi
|
||||
|
||||
for i in `seq 1 $1`; do
|
||||
echo "$4" | mail -s "$3" "$2";
|
||||
done
|
||||
177
nodered/rootfs/data/node_modules/poplib/tests/stls.js
generated
vendored
Normal file
177
nodered/rootfs/data/node_modules/poplib/tests/stls.js
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
|
||||
Node.js POP3 client test file
|
||||
|
||||
Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
var POP3Client = require("../main.js");
|
||||
var argv = require('optimist')
|
||||
.usage("Usage: $0 --host [host] --port [port] --username [username] --password [password] --debug [on/off] --networkdebug [on/off] --login [on/off] --download [on/off]")
|
||||
.demand(['username', 'password'])
|
||||
.argv;
|
||||
|
||||
var host = argv.host || "localhost";
|
||||
var port = argv.port || 110;
|
||||
var debug = argv.debug === "on" ? true : false;
|
||||
var login = argv.login === "on" ? true : false;
|
||||
var download = argv.download === "on" ? true : false;
|
||||
|
||||
var username = argv.username;
|
||||
var password = argv.password;
|
||||
var totalmsgcount = 0;
|
||||
var currentmsg = 0;
|
||||
|
||||
var client = new POP3Client(port, host, {
|
||||
|
||||
ignoretlserrs: true,
|
||||
debug: (argv.networkdebug === "on" ? true: false)
|
||||
|
||||
});
|
||||
|
||||
|
||||
client.on("error", function(err, rawdata) {
|
||||
console.log("Server error occurred, failed, " + err);
|
||||
});
|
||||
|
||||
client.on("connect", function(status, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("CONNECT success");
|
||||
client.stls();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("CONNECT failed because " + rawdata);
|
||||
return;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("invalid-state", function(cmd) {
|
||||
console.log("Invalid state, failed. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("locked", function(cmd) {
|
||||
console.log("Current command has not finished yet, failed. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("stls", function(status, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("STLS success");
|
||||
|
||||
if (login) client.login(username, password);
|
||||
else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("STLS failed because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("login", function(status, data, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("LOGIN/PASS success");
|
||||
|
||||
if (download) client.list();
|
||||
else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LOGIN/PASS failed because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
client.on("list", function(status, msgcount, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === false) {
|
||||
|
||||
console.log("LIST failed because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
} else if (msgcount > 0) {
|
||||
|
||||
totalmsgcount = msgcount;
|
||||
currentmsg = 1;
|
||||
console.log("LIST success with " + msgcount + " message(s)");
|
||||
client.retr(1);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LIST success with 0 message(s)");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("retr", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("RETR success " + msgnumber + " with data " + data);
|
||||
client.dele(msgnumber);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("RETR failed for msgnumber " + msgnumber + " because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("dele", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("DELE success for msgnumber " + msgnumber);
|
||||
|
||||
if (currentmsg < totalmsgcount) {
|
||||
|
||||
currentmsg += 1;
|
||||
client.retr(currentmsg);
|
||||
|
||||
} else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("DELE failed for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("quit", function(status, rawdata) {
|
||||
|
||||
if (status === true) console.log("QUIT success");
|
||||
else console.log("QUIT failed");
|
||||
|
||||
});
|
||||
45
nodered/rootfs/data/node_modules/poplib/tests/stls.sh
generated
vendored
Normal file
45
nodered/rootfs/data/node_modules/poplib/tests/stls.sh
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
# Test script
|
||||
#
|
||||
# Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
#
|
||||
# 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.
|
||||
|
||||
print_title "stls.js"
|
||||
RANDOMID=$RANDOM
|
||||
|
||||
print_test "Sending test message to $EMAIL (str: $RANDOMID)"
|
||||
OUTPUT=`./sendmail.sh 1 $EMAIL "subject with $RANDOMID" "body with $RANDOMID"`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "No login"
|
||||
OUTPUT=`node stls.js --username $USER --password $PASS --host $HOST --port $PORT --login off`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Login only"
|
||||
OUTPUT=`node stls.js --username $USER --password $PASS --host $HOST --port $PORT --login on`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Login and message download"
|
||||
OUTPUT=`node stls.js --username $USER --password $PASS --host $HOST --port $PORT --login on --download on`
|
||||
OUTPUT=`echo $OUTPUT | grep $RANDOMID`
|
||||
|
||||
if [ $? -eq 1 ]; then OUTPUT="fail"; fi
|
||||
|
||||
print_result 0 $OUTPUT
|
||||
173
nodered/rootfs/data/node_modules/poplib/tests/tls.js
generated
vendored
Normal file
173
nodered/rootfs/data/node_modules/poplib/tests/tls.js
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
|
||||
Node.js POP3 client test file
|
||||
|
||||
Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
var POP3Client = require("../main.js");
|
||||
var argv = require('optimist')
|
||||
.usage("Usage: $0 --host [host] --port [port] --username [username] --password [password] --debug [on/off] --networkdebug [on/off] --login [on/off] --download [on/off]")
|
||||
.demand(['username', 'password'])
|
||||
.argv;
|
||||
|
||||
var host = argv.host || "localhost";
|
||||
var port = argv.port || 995;
|
||||
var debug = argv.debug === "on" ? true : false;
|
||||
var login = argv.login === "on" ? true : false;
|
||||
var download = argv.download === "on" ? true : false;
|
||||
|
||||
var username = argv.username;
|
||||
var password = argv.password;
|
||||
var totalmsgcount = 0;
|
||||
var currentmsg = 0;
|
||||
|
||||
var client = new POP3Client(port, host, {
|
||||
|
||||
enabletls: true,
|
||||
ignoretlserrs: true,
|
||||
debug: (argv.networkdebug === "on" ? true: false)
|
||||
|
||||
});
|
||||
|
||||
client.on("tls-error", function(err) {
|
||||
|
||||
console.log("TLS error occurred, failed");
|
||||
console.log(err);
|
||||
|
||||
});
|
||||
|
||||
client.on("close", function() {
|
||||
console.log("close event unexpectedly received, failed");
|
||||
});
|
||||
|
||||
client.on("error", function(err) {
|
||||
console.log("Server error occurred, failed, " + err);
|
||||
});
|
||||
|
||||
client.on("connect", function(status, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("CONNECT success");
|
||||
if (login) client.login(username, password);
|
||||
else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("CONNECT failed because " + rawdata);
|
||||
return;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("invalid-state", function(cmd) {
|
||||
console.log("Invalid state, failed. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("locked", function(cmd) {
|
||||
console.log("Current command has not finished yet, failed. You tried calling " + cmd);
|
||||
});
|
||||
|
||||
client.on("login", function(status, data, rawdata) {
|
||||
|
||||
if (status) {
|
||||
|
||||
console.log("LOGIN/PASS success");
|
||||
if (download) client.list();
|
||||
else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LOGIN/PASS failed");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
client.on("list", function(status, msgcount, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === false) {
|
||||
|
||||
console.log("LIST failed");
|
||||
client.quit();
|
||||
|
||||
} else if (msgcount > 0) {
|
||||
|
||||
totalmsgcount = msgcount;
|
||||
currentmsg = 1;
|
||||
console.log("LIST success with " + msgcount + " message(s)");
|
||||
client.retr(1);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("LIST success with 0 message(s)");
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("retr", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("RETR success " + msgnumber + " with data " + data);
|
||||
client.dele(msgnumber);
|
||||
|
||||
} else {
|
||||
|
||||
console.log("RETR failed for msgnumber " + msgnumber + " because " + rawdata);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
client.on("dele", function(status, msgnumber, data, rawdata) {
|
||||
|
||||
if (status === true) {
|
||||
|
||||
console.log("DELE success for msgnumber " + msgnumber);
|
||||
|
||||
if (currentmsg < totalmsgcount) {
|
||||
|
||||
currentmsg += 1;
|
||||
client.retr(currentmsg);
|
||||
|
||||
} else client.quit();
|
||||
|
||||
} else {
|
||||
|
||||
console.log("DELE failed for msgnumber " + msgnumber);
|
||||
client.quit();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
client.on("quit", function(status, rawdata) {
|
||||
|
||||
client.removeAllListeners("close");
|
||||
if (status === true) console.log("QUIT success");
|
||||
else console.log("QUIT failed");
|
||||
|
||||
});
|
||||
49
nodered/rootfs/data/node_modules/poplib/tests/tls.sh
generated
vendored
Normal file
49
nodered/rootfs/data/node_modules/poplib/tests/tls.sh
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
# Test script
|
||||
#
|
||||
# Copyright (C) 2011 by Ditesh Shashikant Gathani <ditesh@gathani.org>
|
||||
#
|
||||
# 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.
|
||||
|
||||
print_title "tls.js"
|
||||
RANDOMID=$RANDOM
|
||||
|
||||
print_test "Sending test message to $EMAIL (str: $RANDOMID)"
|
||||
OUTPUT=`./sendmail.sh -q 1 $EMAIL "subject with $RANDOMID" "body with $RANDOMID"`
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Wrong port"
|
||||
OUTPUT=`node tls.js --username $USER --password $PASS --host $HOST --port $PORT --login off`;
|
||||
print_result 1 $OUTPUT
|
||||
|
||||
print_test "No login"
|
||||
OUTPUT=`node tls.js --username $USER --password $PASS --host $HOST --port $TLSPORT --login off`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Login only"
|
||||
OUTPUT=`node tls.js --username $USER --password $PASS --host $HOST --port $TLSPORT --login on`;
|
||||
print_result 0 $OUTPUT
|
||||
|
||||
print_test "Login and message download"
|
||||
OUTPUT=`node tls.js --username $USER --password $PASS --host $HOST --port $TLSPORT --login on --download on`
|
||||
OUTPUT=`echo $OUTPUT | grep $RANDOMID`
|
||||
|
||||
if [ $? -eq 1 ]; then OUTPUT="fail"; fi
|
||||
|
||||
print_result 0 $OUTPUT
|
||||
Reference in New Issue
Block a user