3 #include <libfmail/socketipc.h>
11 if ((v
>= 'A') && (v
<= 'Z'))
14 if ((v
>= 'a') && (v
<= 'z'))
20 class FSMailbox
: public ProtocolHandler
{
22 SearchTree
<int, 26, &knhash
> cmdtree
;
25 cmdtree
.Insert("list", MSG_LIST
);
26 cmdtree
.Insert("store", MSG_STORE
);
27 cmdtree
.Insert("retr", MSG_RETR
);
29 int Handle(Socket
*s
){
32 int onRun
, msgid
, n
, i
, len
;
33 char *user
, *rcpt
, *msglen
, buffer
[255];
38 printf("Got Client\n");
39 printf("Creating new IPC\n");
41 ipc
= new SocketIPC(s
);
45 printf("Waiting for Message\n");
46 if (ipc
->PeekMessage()){
47 printf("Got Message\n");
48 msg
= ipc
->PopMessage();
50 msgid
= cmdtree
.Lookup((char*)msg
->GetMessageName());
51 }catch (SearchNotFound
){
56 user
= msg
->PopParam();
57 sprintf(buffer
, "/tmp/fmail/%s/", user
);
58 n
= scandir(buffer
, &dent
, NULL
, alphasort
);
59 sprintf(buffer
, "%i", n
);
60 msg
= new IPCMessage("ok");
61 msg
->PushParam(buffer
);
62 ipc
->PushMessage(msg
);
63 for (i
= 0; i
< n
; i
++){
64 msg
= new IPCMessage("mailinfo");
65 msg
->PushParam(dent
[i
]->d_name
);
71 user
= msg
->PopParam();
72 rcpt
= msg
->PopParam();
73 msglen
= msg
->PopParam();
76 fd
= fopen("/tmp/fmail/in/1", "w");
79 i
= ipc
->RawRead(buffer
, 255);
80 fwrite(buffer
, 1, i
, fd
);
102 class SimpleLoad
: public LoadHandler
{
104 int Dispatch(Socket
*sock
, ProtocolHandler
*ph
){
105 printf("SimpleLoad: Dispatching\n");
107 return ph
->Handle(sock
);
119 s
= Socket::CreateSocket(SOCKET_INET
, 0);
120 s
->setAddress("127.0.0.1");
126 printf("Creating new FSMailbox\n");
127 handler
= new FSMailbox();
129 printf("Creating new SimpleLoad\n");
130 lh
= new SimpleLoad();
133 r
= s
->Poll(10000, SOCKET_POLL_READ
);
134 if (r
== SOCKET_POLL_READ
){
135 printf("Got new client!\n");
136 client
= s
->Accept();
137 lh
->Dispatch(client
, handler
);