w3mail

program to send a web page by email
git clone https://logand.com/git/w3mail.git/
Log | Files | Refs | README | LICENSE

commit 729199ea313b92b560483c4cf45f12de56abf15a
parent 9fea1d51b528953d0699c9c55a0d08d02ebe7131
Author: Tomas Hlavaty <tom@logand.com>
Date:   Tue, 11 Jan 2011 00:26:09 +0100

url server sketched

Diffstat:
Mw3maild.vala | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 54 insertions(+), 12 deletions(-)

diff --git a/w3maild.vala b/w3maild.vala @@ -16,7 +16,7 @@ abstract class Pop3Server { LIST } - public Pop3Server(SocketConnection _c) { + public Pop3Server (SocketConnection _c) { c = _c; i = new DataInputStream (c.input_stream); o = new DataOutputStream (c.output_stream); @@ -41,14 +41,13 @@ abstract class Pop3Server { prinl (msg2); } - public async void process_request () { + public async void process_request_async () { try { ready (); - string line = yield i.read_line_async (Priority.HIGH_IDLE); - while (true) { + string line = null; + while ((line = yield i.read_line_async (Priority.HIGH_IDLE)) != null) { var cmd = parse_line (line); if(!process_command (cmd)) break; - line = yield i.read_line_async (Priority.HIGH_IDLE); } } catch (Error e) { stderr.printf ("Error: %s\n", e.message); @@ -107,13 +106,19 @@ abstract class Pop3Server { // ~/.w3maild // ~/.w3maild/[tomas] // ~/.w3maild/[tomas]/[data] +// ~/.w3maild/in +// ~/.w3maild/log -class W3maildServer : Pop3Server { +static string root_dirname () { + return Environment.get_home_dir () + "/.w3maild"; +} + +class W3maildPop3Server : Pop3Server { string usr = ""; string pwd = ""; HashMap<int, FileInfo> map = new HashMap<int, FileInfo> (); - public W3maildServer(SocketConnection c) { + public W3maildPop3Server (SocketConnection c) { base (c); } @@ -127,11 +132,11 @@ class W3maildServer : Pop3Server { } string data_dirname () { - return Environment.get_home_dir () + "/.w3maild/" + usr; + return root_dirname () + "/" + usr; } File data_dir () { - return File.new_for_path (data_dirname ());; + return File.new_for_path (data_dirname ()); } bool user_exists () { @@ -240,18 +245,55 @@ class W3maildServer : Pop3Server { } static bool on_incoming_connection (SocketConnection c) { - var s = new W3maildServer (c); - s.process_request.begin (); + var s = new W3maildPop3Server (c); + s.process_request_async.begin (); return true; } +// async void url_server_read_async () { +// var file = File.new_for_path (root_dirname () + "/in"); +// try { +// var i = new DataInputStream (file.read ()); +// string line = null; +// while ((line = yield i.read_line_async (Priority.HIGH_IDLE)) != null) { +// stderr.printf ("%s\n", line); +// } +// stdout.printf ("finito\n"); +// } catch (Error e) { +// stderr.printf ("%s\n", e.message); +// } +// //main_loop.quit (); +// } + +// bool url_server_read () { +// var file = File.new_for_path (root_dirname () + "/in"); +// try { +// var i = new DataInputStream (file.read ()); +// string line = null; +// while ((line = yield i.read_line_async (Priority.HIGH_IDLE)) != null) { +// stderr.printf ("%s\n", line); +// } +// stdout.printf ("finito\n"); +// } catch (Error e) { +// stderr.printf ("%s\n", e.message); +// } +// return true; +// } + void main () { try { + // start pop3 server var srv = new SocketService (); srv.add_inet_port (3333, null); srv.incoming.connect (on_incoming_connection); srv.start (); - new MainLoop ().run (); + // start url server + //url_server_read_async.begin (); + //Idle.add(url_server_read_async.callback); + //Idle.add(url_server_read); + // go + new MainLoop ().run (); + //main_loop.run (); } catch (Error e) { stderr.printf ("%s\n", e.message); }