3 #include <libfmail/socketipc.h>
6 enum {MSG_LIST
= 1, MSG_STORE
= 2, MSG_RETR
= 3};
9 if ((v
>= 'A') && (v
<= 'Z'))
12 if ((v
>= 'a') && (v
<= 'z'))
18 class FSMailbox
: public ProtocolHandler
{
20 SearchTree
<int, 26, &knhash
> cmdtree
;
23 cmdtree
.Insert("list", MSG_LIST
);
24 cmdtree
.Insert("store", MSG_STORE
);
25 cmdtree
.Insert("retr", MSG_RETR
);
27 int Handle(Socket
*s
){
30 int onRun
, msgid
, n
, i
, len
;
31 char *user
, *rcpt
, *msglen
, buffer
[255];
36 printf("Got Client\n");
37 printf("Creating new IPC\n");
39 ipc
= new SocketIPC(s
);
43 printf("Waiting for Message\n");
44 if (ipc
->PeekMessage()){
45 printf("Got Message\n");
46 msg
= ipc
->PopMessage();
48 msgid
= cmdtree
.Lookup((char*)msg
->GetMessageName());
49 }catch (SearchNotFound
){
54 user
= msg
->PopParam();
55 sprintf(buffer
, "/tmp/fmail/%s/", user
);
56 n
= scandir(buffer
, &dent
, NULL
, alphasort
);
57 sprintf(buffer
, "%i", n
);
58 msg
= new IPCMessage("ok");
59 msg
->PushParam(buffer
);
60 ipc
->PushMessage(msg
);
61 for (i
= 0; i
< n
; i
++){
62 msg
= new IPCMessage("mailinfo");
63 msg
->PushParam(dent
[i
]->d_name
);
69 user
= msg
->PopParam();
70 rcpt
= msg
->PopParam();
71 msglen
= msg
->PopParam();
74 fd
= fopen("/tmp/fmail/in/1", "w");
77 i
= ipc
->RawRead(buffer
, 255);
78 fwrite(buffer
, 1, i
, fd
);
100 class SimpleLoad
: public LoadHandler
{
102 int Dispatch(Socket
*sock
, ProtocolHandler
*ph
){
103 printf("SimpleLoad: Dispatching\n");
105 return ph
->Handle(sock
);
117 s
= Socket::CreateSocket(SOCKET_INET
, 0);
118 s
->setAddress("127.0.0.1");
124 printf("Creating new FSMailbox\n");
125 handler
= new FSMailbox();
127 printf("Creating new SimpleLoad\n");
128 lh
= new SimpleLoad();
131 r
= s
->Poll(10000, SOCKET_POLL_READ
);
132 if (r
== SOCKET_POLL_READ
){
133 printf("Got new client!\n");
134 client
= s
->Accept();
135 lh
->Dispatch(client
, handler
);