]> git.cworth.org Git - nodemuch/blob - nodemuch.js
Add an explicit license (GPLv3+) to nodemuch.js
[nodemuch] / nodemuch.js
1 /* nodemuch - A nodejs interface to the notmuch mail system
2  *
3  * Copyright © 2010 Carl Worth
4  * Copyright © 2010 Richard D. Worth
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see http://www.gnu.org/licenses/ .
18  *
19  * Authors: Carl Worth <cworth@cworth.org>
20  *          Richard D. Worth <rdworth@rdworth.org>
21  */
22
23 var http = require( "http" ),
24     parse = require( "url" ).parse,
25     exec = require( "child_process" ).exec;
26
27 http.createServer( function(req, res) {
28     var url = parse( req.url ),
29         action = url.pathname.split( "/" ).splice(-1)[0];
30     if ( action  === "search" ) {
31         exec( "notmuch search " + url.query, function( error, stdout, stderr ) {
32             res.writeHead( 200, { "Content-Type": "text/plain" } );
33             res.end( stdout );    
34         });
35     } else if ( action === "show" ) {
36         exec( "notmuch show " + url.query, function( error, stdout, stderr ) {
37             res.writeHead( 200, { "Content-Type": "text/plain" } );
38             res.end( stdout );    
39         });
40     } else {
41         res.writeHead( 404 );
42         res.end("404");
43     }
44 }).listen( 8124, "127.0.0.1" );
45
46 console.log( "Server running at http://127.0.0.1:8124/" );