1 /* nodemuch - A nodejs interface to the notmuch mail system
3 * Copyright © 2010 Carl Worth
4 * Copyright © 2010 Richard D. Worth
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.
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.
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/ .
19 * Authors: Carl Worth <cworth@cworth.org>
20 * Richard D. Worth <rdworth@rdworth.org>
23 var http = require( "http" ),
24 parse = require( "url" ).parse,
25 exec = require( "child_process" ).exec;
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" } );
35 } else if ( action === "show" ) {
36 exec( "notmuch show " + url.query, function( error, stdout, stderr ) {
37 res.writeHead( 200, { "Content-Type": "text/plain" } );
44 }).listen( 8124, "127.0.0.1" );
46 console.log( "Server running at http://127.0.0.1:8124/" );