ref: 79eea36a98a8b69cef0c3c78ea2366237b3849f8
parent: 973682f67d3b4f2489eb8cd31cb4fd5c19b0df9c
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Nov 7 01:13:31 EST 2020
plumbing: respond to 'send' messages now plumbing an address should work.
--- a/mbox.c
+++ b/mbox.c
@@ -19,6 +19,7 @@
Cevent,
Cseemail,
Cshowmail,
+ Csendmail,
Nchan,
};
@@ -31,10 +32,10 @@
Reprog *mesgpat;
int threadsort = 1;
-
int plumbsendfd;
int plumbseemailfd;
int plumbshowmailfd;
+int plumbsendmailfd;
Channel *cwait;
Mbox mbox;
@@ -54,7 +55,7 @@
}
static void
-plumbshow(void*)
+plumbshowmail(void*)
{
threadsetname("plumbshow");
plumbloop(mbox.show, plumbshowmailfd);
@@ -61,7 +62,7 @@
}
static void
-plumbsee(void*)
+plumbseemail(void*)
{
threadsetname("plumbsee");
plumbloop(mbox.see, plumbseemailfd);
@@ -68,6 +69,13 @@
}
static void
+plumbsendmail(void*)
+{
+ threadsetname("plumbsend");
+ plumbloop(mbox.send, plumbsendmailfd);
+}
+
+static void
eventread(void*)
{
Event *ev;
@@ -702,6 +710,7 @@
switch(ev->type){
case 'l':
case 'L':
+ print("event: %s\n", ev->text);
if((a = matchaddr(&mbox, ev)) != nil)
compose(a, nil, 0, 0);
else if(matchmesg(&mbox, ev->text))
@@ -731,12 +740,13 @@
mbmain(void*)
{
Event *ev;
- Plumbmsg *psee, *pshow;
+ Plumbmsg *psee, *pshow, *psend;
Alt a[] = {
[Cevent] = {mbox.event, &ev, CHANRCV},
[Cseemail] = {mbox.see, &psee, CHANRCV},
[Cshowmail] = {mbox.show, &pshow, CHANRCV},
+ [Csendmail] = {mbox.send, &psend, CHANRCV},
[Nchan] = {nil, nil, CHANEND},
};
@@ -760,6 +770,11 @@
viewmesg(pshow);
plumbfree(pshow);
break;
+ case Csendmail:
+ print("got plumb: %s\n", psend->data);
+ compose(psend->data, nil, 0, 0);
+ plumbfree(psend);
+ break;
}
}
}
@@ -795,9 +810,11 @@
plumbsendfd = plumbopen("send", OWRITE|OCEXEC);
plumbseemailfd = plumbopen("seemail", OREAD|OCEXEC);
plumbshowmailfd = plumbopen("showmail", OREAD|OCEXEC);
+ plumbsendmailfd = plumbopen("sendmail", OREAD|OCEXEC);
mbox.event = chancreate(sizeof(Event*), 0);
mbox.see = chancreate(sizeof(Plumbmsg*), 0);
mbox.show = chancreate(sizeof(Plumbmsg*), 0);
+ mbox.send = chancreate(sizeof(Plumbmsg*), 0);
addrpat = regcomp("[^ \t]*@[^ \t]*\\.[^ \t]*");
mesgpat = regcomp("[0-9]+(/.*)?");
@@ -808,8 +825,9 @@
if(argc == 1)
mailbox = argv[0];
mbload();
- proccreate(plumbsee, nil, Stack);
- proccreate(plumbshow, nil, Stack);
+ proccreate(plumbseemail, nil, Stack);
+ proccreate(plumbshowmail, nil, Stack);
+ proccreate(plumbsendmail, nil, Stack);
threadcreate(mbmain, nil, Stack);
threadexits(nil);
}