Skip to content

Commit

Permalink
Added incoming SMTP to hoodiecrow command
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Sep 23, 2013
1 parent a62c6f7 commit 89a36a1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Hoodiecrow

![It's a dove - I know - but I didn't have a proper hoodiecrow picture in my computer](https://raw.github.com/andris9/hoodiecrow/master/hoodiecrow.jpg)

*It's a dove - I know - but I didn't have a proper hoodiecrow picture. Fake crow like a fake IMAP server*
![Hoodiecrow](https://raw.github.com/andris9/hoodiecrow/master/hoodiecrow_actual.jpg)

Hoodiecrow is a scriptable IMAP server for client integration testing. It offers partial IMAP4ver1 support and some optional plugins that can be turned on and off. Nothing is ever written to disk, so when you restart the server, the original state is restored.

Expand All @@ -22,9 +20,12 @@ npm install -g hoodiecrow
sudo hoodiecrow
```

Sudo is needed to bind to port 143. If you choose to use a higher port, say 1143, you do not need to use sudo.
Sudo is needed to bind to port 143. If you choose to use a higher port, say 1143 (`hoodiecrow -p 1143`), you do not need to use sudo.

`hoodiecrow` command also provides an incoming SMTP server which appends all incoming messages
automatically to INBOX. To use it, use *smtpPort* option (`hoodiecrow --smtpPort=1025`).

> Protip: Running `hoodiecrow --help` displays useful information about command line options for Hoodiecrow and some sample configuration data.
> **Protip** Running `hoodiecrow --help` displays useful information about command line options for Hoodiecrow and some sample configuration data.
After you have started Hoodiecrow server, you can point your IMAP client to `localhost:143`. Use `"testuser"` as user name and `"testpass"` as password to log in to the server.

Expand All @@ -44,7 +45,7 @@ var hoodiecrow = require("hoodiecrow"),
server.listen(143);
```

See [example.js](https://github.com/andris9/hoodiecrow/blob/master/example.js) for an example configuration.
See [example.js](https://github.com/andris9/hoodiecrow/blob/master/example.js) for an example.

## Scope

Expand Down Expand Up @@ -193,6 +194,7 @@ config.json:

```json
{
"INBOX":{},
"INBOX.":{},
"user.":{
"type":"user"
Expand Down
13 changes: 12 additions & 1 deletion bin/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ integration tests. Nothing is written to disk, all operations are
performed on memory and the changes are lost after restart, so the
initial state is always guaranteed when running your tests.

Additionally Hoodiecrow offers an incoming SMTP server - every mail
sent to it, is appended to INBOX. To use the incoming SMTP server,
use smtpPort option.

Usage: hoodiecrow [OPTS]

-p <port>, --port=<port> Port number to listen to, defaults to 143
Expand All @@ -14,6 +18,12 @@ Usage: hoodiecrow [OPTS]
--config=<config> Path to config JSON file
--plugin=<plugin> Enables a plugin for the server. See below for
available plugins.
--smtpPort=<port> Port numbr for incoming SMTP server. If not set
SMTP server is not started.

NB! If port or smtpPort values are below 1024 you most probably need to
use sudo or run the command in Administrator rights.

Available plugins
-----------------

Expand All @@ -39,7 +49,8 @@ Configuration file takes the following structure
}
}

Storage file is a tree like structure starting with namespace values
Storage file is a tree like structure starting with namespace values.
INBOX has its own namespace.

{
"INBOX":{
Expand Down
23 changes: 23 additions & 0 deletions bin/hoodiecrow
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ var hoodiecrow = require("../lib/server"),
packageData = require("../package"),
fs = require("fs"),
argv = require('optimist').argv,
simplesmtp = require("simplesmtp"),

configLocation = argv.config || process.env.HOODIECROW_CONFIG,
storageLocation = argv.storage || process.env.HOODIECROW_STORAGE,
port = argv.port || argv.p || process.env.HOODIECROW_PORT,

smtpPort = argv.smtpPort || process.env.HOODIECROW_SMTPPORT,

pluginsList = [].concat.apply([], [].concat(argv.plugin || process.env.HOODIECROW_PLUGINS || []).map(function(plugin){
return (plugin || "").toUpperCase().trim().split(/\s*,\s*/)
})),
Expand Down Expand Up @@ -98,5 +101,25 @@ if(argv.h || argv.help){
server.listen(port, function(){
console.log("Hoodiecrow successfully%s listening on port %s", secure ? " and securely" : "", port);
});

if(smtpPort){
simplesmtp.createSimpleServer({SMTPBanner:"Hoodiecrow"}, function(req){
var data = [], dataLen = 0;
req.on("data", function(chunk){
if(!chunk || !chunk.length){
return;
}
data.push(chunk);
dataLen += chunk.length;
});
req.on("end", function(){
var message = Buffer.concat(data, dataLen);
server.appendMessage("INBOX", [], false, message.toString("binary"));
});
req.accept();
}).listen(smtpPort, function(){
console.log("Incoming SMTP server up and running on port %s", smtpPort);
});
}
}

Binary file added hoodiecrow_actual.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"name": "hoodiecrow",
"version": "0.1.7",
"version": "0.1.8",
"description": "Scriptable IMAP mock server for testing purposes",
"main": "lib/server.js",
"scripts": {
"test": "grunt"
},
"bin":{
"bin": {
"hoodiecrow": "./bin/hoodiecrow"
},
"repository": "[email protected]:andris9/hoodiecrow.git",
"keywords": [
"IMAP"
],
"dependencies":{
"imap-handler": "~0.1.11",
"optimist": "~0.6.0"
"dependencies": {
"imap-handler": "~0.1.11"
},
"devDependencies":{
"optionalDependencies": {
"optimist": "~0.6.0",
"simplesmtp": "~0.3.10"
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.4",
"grunt-contrib-nodeunit": "~0.2.0",
Expand Down

0 comments on commit 89a36a1

Please sign in to comment.