#include <u.h>
#include <libc.h>
#include <plumb.h>
void
main(int argc, char *argv[])
{
int seefd, notefd;
Plumbmsg *m;
char *from, *date, *note, *subj;
USED(argc);
USED(argv);
if((seefd = plumbopen("seemail", OREAD)) < 0)
exits(smprint("can't read seemail port: %r"));
for(;;){
m = plumbrecv(seefd);
if(m == nil)
exits("error on seemail plumb port");
if(strcmp(plumblookup(m->attr, "mailtype"), "new") != 0){
plumbfree(m);
continue;
}
from = plumblookup(m->attr, "sender");
date = plumblookup(m->attr, "date");
if(date == nil)
date = "<no date>";
USED(*subj); /* not yet */
note = smprint("Mail: %s\t%s\n\t%s\n", from, m->data, date);
if((notefd = open(smprint("/srv/notify.%s", getuser()), OWRITE)) < 0)
exits(smprint("notefd: %r"));
if(fprint(notefd, note) < 0)
print("fprint: %r\n");
plumbfree(m);
close(notefd);
}
}
|