cleanup
This commit is contained in:
parent
5a1e9de7b1
commit
605c0ea102
11 changed files with 132 additions and 386 deletions
|
|
@ -45,7 +45,7 @@ extern char date[];
|
||||||
extern char *maildir;
|
extern char *maildir;
|
||||||
extern char **maildirs;
|
extern char **maildirs;
|
||||||
extern int nmaildirs;
|
extern int nmaildirs;
|
||||||
extern CFsys *upasfs;
|
extern CFsys *mailfs;
|
||||||
|
|
||||||
Face* nextface(void);
|
Face* nextface(void);
|
||||||
void findbit(Face*);
|
void findbit(Face*);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
#include <draw.h>
|
#include <draw.h>
|
||||||
#include <plumb.h>
|
#include <plumb.h>
|
||||||
#include <regexp.h>
|
#include <regexp.h>
|
||||||
//jpc #include <event.h> /* for support routines only */
|
|
||||||
#include <bio.h>
|
#include <bio.h>
|
||||||
#include <thread.h>
|
#include <thread.h>
|
||||||
#include <mouse.h>
|
#include <mouse.h>
|
||||||
|
|
@ -20,6 +19,8 @@ enum
|
||||||
Infolines = 9,
|
Infolines = 9,
|
||||||
|
|
||||||
HhmmTime = 18*60*60, /* max age of face to display hh:mm time */
|
HhmmTime = 18*60*60, /* max age of face to display hh:mm time */
|
||||||
|
|
||||||
|
STACK = 32768
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
@ -27,6 +28,7 @@ enum
|
||||||
Mainp,
|
Mainp,
|
||||||
Timep,
|
Timep,
|
||||||
Mousep,
|
Mousep,
|
||||||
|
Resizep,
|
||||||
NPROC
|
NPROC
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -34,7 +36,8 @@ int pids[NPROC];
|
||||||
char *procnames[] = {
|
char *procnames[] = {
|
||||||
"main",
|
"main",
|
||||||
"time",
|
"time",
|
||||||
"mouse"
|
"mouse",
|
||||||
|
"resize",
|
||||||
};
|
};
|
||||||
|
|
||||||
Rectangle leftright = {0, 0, 20, 15};
|
Rectangle leftright = {0, 0, 20, 15};
|
||||||
|
|
@ -57,7 +60,7 @@ uchar rightdata[] = {
|
||||||
0x18, 0x00, 0x00, 0x10, 0x00
|
0x18, 0x00, 0x00, 0x10, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
CFsys *upasfs;
|
CFsys *mailfs;
|
||||||
Mousectl *mousectl;
|
Mousectl *mousectl;
|
||||||
Image *blue; /* full arrow */
|
Image *blue; /* full arrow */
|
||||||
Image *bgrnd; /* pale blue background color */
|
Image *bgrnd; /* pale blue background color */
|
||||||
|
|
@ -74,7 +77,7 @@ int ndown;
|
||||||
|
|
||||||
char date[64];
|
char date[64];
|
||||||
Face **faces;
|
Face **faces;
|
||||||
char *maildir = "/mail/fs/mbox";
|
char *maildir = "INBOX";
|
||||||
ulong now;
|
ulong now;
|
||||||
|
|
||||||
Point datep = { 8, 6 };
|
Point datep = { 8, 6 };
|
||||||
|
|
@ -83,6 +86,7 @@ Point enddate; /* where date ends on display; used to place arrows */
|
||||||
Rectangle leftr; /* location of left arrow on display */
|
Rectangle leftr; /* location of left arrow on display */
|
||||||
Rectangle rightr; /* location of right arrow on display */
|
Rectangle rightr; /* location of right arrow on display */
|
||||||
void updatetimes(void);
|
void updatetimes(void);
|
||||||
|
void eresized(int);
|
||||||
|
|
||||||
void
|
void
|
||||||
setdate(void)
|
setdate(void)
|
||||||
|
|
@ -95,15 +99,12 @@ setdate(void)
|
||||||
void
|
void
|
||||||
init(void)
|
init(void)
|
||||||
{
|
{
|
||||||
#if 0
|
mailfs = nsmount("mail", nil);
|
||||||
mousefd = open("/dev/mouse", OREAD);
|
if(mailfs == nil)
|
||||||
if(mousefd < 0){
|
sysfatal("mount mail: %r");
|
||||||
fprint(2, "faces: can't open mouse: %r\n");
|
mousectl = initmouse(nil, screen);
|
||||||
threadexitsall("mouse");
|
if(mousectl == nil)
|
||||||
}
|
sysfatal("initmouse: %r");
|
||||||
#endif
|
|
||||||
upasfs = nsmount("upasfs",nil);
|
|
||||||
mousectl = initmouse(nil,screen);
|
|
||||||
initplumb();
|
initplumb();
|
||||||
|
|
||||||
/* make background color */
|
/* make background color */
|
||||||
|
|
@ -332,7 +333,7 @@ addface(Face *f) /* always adds at 0 */
|
||||||
lockdisplay(display);
|
lockdisplay(display);
|
||||||
if(first != 0){
|
if(first != 0){
|
||||||
first = 0;
|
first = 0;
|
||||||
resized();
|
eresized(0);
|
||||||
}
|
}
|
||||||
findbit(f);
|
findbit(f);
|
||||||
|
|
||||||
|
|
@ -366,27 +367,6 @@ addface(Face *f) /* always adds at 0 */
|
||||||
unlockdisplay(display);
|
unlockdisplay(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
void
|
|
||||||
loadmboxfaces(char *maildir)
|
|
||||||
{
|
|
||||||
int dirfd;
|
|
||||||
Dir *d;
|
|
||||||
int i, n;
|
|
||||||
|
|
||||||
dirfd = open(maildir, OREAD);
|
|
||||||
if(dirfd >= 0){
|
|
||||||
chdir(maildir);
|
|
||||||
while((n = dirread(dirfd, &d)) > 0){
|
|
||||||
for(i=0; i<n; i++)
|
|
||||||
addface(dirface(maildir, d[i].name));
|
|
||||||
free(d);
|
|
||||||
}
|
|
||||||
close(dirfd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
void
|
||||||
loadmboxfaces(char *maildir)
|
loadmboxfaces(char *maildir)
|
||||||
{
|
{
|
||||||
|
|
@ -394,20 +374,16 @@ loadmboxfaces(char *maildir)
|
||||||
Dir *d;
|
Dir *d;
|
||||||
int i, n;
|
int i, n;
|
||||||
|
|
||||||
dirfd = fsopen(upasfs,maildir, OREAD);
|
dirfd = fsopen(mailfs, maildir, OREAD);
|
||||||
if(dirfd != nil){
|
if(dirfd != nil){
|
||||||
//jpc chdir(maildir);
|
|
||||||
while((n = fsdirread(dirfd, &d)) > 0){
|
while((n = fsdirread(dirfd, &d)) > 0){
|
||||||
for(i=0; i<n; i++) {
|
for(i=0; i<n; i++)
|
||||||
addface(dirface(maildir, d[i].name));
|
addface(dirface(maildir, d[i].name));
|
||||||
}
|
|
||||||
free(d);
|
free(d);
|
||||||
}
|
}
|
||||||
fsclose(dirfd);
|
fsclose(dirfd);
|
||||||
}
|
}else
|
||||||
else {
|
sysfatal("open %s: %r", maildir);
|
||||||
error("cannot open %s: %r",maildir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -542,30 +518,15 @@ eresized(int new)
|
||||||
unlockdisplay(display);
|
unlockdisplay(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
void
|
||||||
int
|
resizeproc(void *v)
|
||||||
getmouse(Mouse *m)
|
|
||||||
{
|
{
|
||||||
int n;
|
USED(v);
|
||||||
static int eof;
|
|
||||||
char buf[128];
|
|
||||||
|
|
||||||
if(eof)
|
while(recv(mousectl->resizec, 0) == 1)
|
||||||
return 0;
|
eresized(1);
|
||||||
for(;;){
|
|
||||||
n = read(mousefd, buf, sizeof(buf));
|
|
||||||
if(n <= 0){
|
|
||||||
/* so callers needn't check return value every time */
|
|
||||||
eof = 1;
|
|
||||||
m->buttons = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
//jpc n = eatomouse(m, buf, n);
|
|
||||||
if(n > 0)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
int
|
int
|
||||||
getmouse(Mouse *m)
|
getmouse(Mouse *m)
|
||||||
{
|
{
|
||||||
|
|
@ -573,19 +534,13 @@ getmouse(Mouse *m)
|
||||||
|
|
||||||
if(eof)
|
if(eof)
|
||||||
return 0;
|
return 0;
|
||||||
if( readmouse(mousectl) < 0 ) {
|
if(readmouse(mousectl) < 0){
|
||||||
eof = 1;
|
eof = 1;
|
||||||
m->buttons = 0;
|
m->buttons = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
*m = mousectl->m;
|
||||||
*m = mousectl->m;
|
return 1;
|
||||||
/* m->buttons = mousectl->m.buttons;
|
|
||||||
m->xy.x = mousectl->m.xy.x;
|
|
||||||
m->xy.y = mousectl->m.xy.y;
|
|
||||||
m->msec = mousectl->m.msec; */
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
@ -680,9 +635,10 @@ click(int button, Mouse *m)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mouseproc(void *dummy)
|
mouseproc(void *v)
|
||||||
{
|
{
|
||||||
Mouse mouse;
|
Mouse mouse;
|
||||||
|
USED(v);
|
||||||
|
|
||||||
while(getmouse(&mouse)){
|
while(getmouse(&mouse)){
|
||||||
if(mouse.buttons == 1)
|
if(mouse.buttons == 1)
|
||||||
|
|
@ -700,35 +656,9 @@ mouseproc(void *dummy)
|
||||||
void
|
void
|
||||||
killall(char *s)
|
killall(char *s)
|
||||||
{
|
{
|
||||||
int i, pid;
|
|
||||||
|
|
||||||
pid = getpid();
|
|
||||||
for(i=0; i<NPROC; i++)
|
|
||||||
if(pids[i] && pids[i]!=pid)
|
|
||||||
postnote(PNPROC, pids[i], "kill");
|
|
||||||
threadexitsall(s);
|
threadexitsall(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
startproc(void (*f)(void), int index)
|
|
||||||
{
|
|
||||||
int pid;
|
|
||||||
|
|
||||||
switch(pid = rfork(RFPROC|RFNOWAIT)){ //jpc removed |RFMEM
|
|
||||||
case -1:
|
|
||||||
fprint(2, "faces: fork failed: %r\n");
|
|
||||||
killall("fork failed");
|
|
||||||
case 0:
|
|
||||||
f();
|
|
||||||
fprint(2, "faces: %s process exits\n", procnames[index]);
|
|
||||||
if(index >= 0)
|
|
||||||
killall("process died");
|
|
||||||
threadexitsall(nil);
|
|
||||||
}
|
|
||||||
if(index >= 0)
|
|
||||||
pids[index] = pid;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
|
|
@ -741,6 +671,8 @@ threadmain(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
rfork(RFNOTEG);
|
||||||
|
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
case 'h':
|
case 'h':
|
||||||
history++;
|
history++;
|
||||||
|
|
@ -772,8 +704,9 @@ threadmain(int argc, char *argv[])
|
||||||
eresized(0);
|
eresized(0);
|
||||||
|
|
||||||
pids[Mainp] = getpid();
|
pids[Mainp] = getpid();
|
||||||
pids[Timep] = proccreate(timeproc, nil, 16000);
|
pids[Timep] = proccreate(timeproc, nil, STACK);
|
||||||
pids[Mousep] = proccreate(mouseproc, nil, 16000);
|
pids[Mousep] = proccreate(mouseproc, nil, STACK);
|
||||||
|
pids[Resizep] = proccreate(resizeproc, nil, STACK);
|
||||||
if(initload)
|
if(initload)
|
||||||
for(i = 0; i < nmaildirs; i++)
|
for(i = 0; i < nmaildirs; i++)
|
||||||
loadmboxfaces(maildirs[i]);
|
loadmboxfaces(maildirs[i]);
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
#include <thread.h>
|
||||||
#include <draw.h>
|
#include <draw.h>
|
||||||
#include <plumb.h>
|
|
||||||
#include <regexp.h>
|
#include <regexp.h>
|
||||||
#include <bio.h>
|
#include <bio.h>
|
||||||
#include <9pclient.h>
|
#include <9pclient.h>
|
||||||
|
#include <plumb.h>
|
||||||
#include "faces.h"
|
#include "faces.h"
|
||||||
|
|
||||||
static int showfd = -1;
|
static CFid* showfd;
|
||||||
static int seefd = -1;
|
static CFid* seefd;
|
||||||
static int logfd = -1;
|
|
||||||
static char *user;
|
|
||||||
static char *logtag;
|
|
||||||
|
|
||||||
char **maildirs;
|
char **maildirs;
|
||||||
int nmaildirs;
|
int nmaildirs;
|
||||||
|
|
@ -19,20 +17,10 @@ int nmaildirs;
|
||||||
void
|
void
|
||||||
initplumb(void)
|
initplumb(void)
|
||||||
{
|
{
|
||||||
showfd = plumbopen("send", OWRITE);
|
showfd = plumbopenfid("send", OWRITE);
|
||||||
seefd = plumbopen("seemail", OREAD);
|
seefd = plumbopenfid("seemail", OREAD);
|
||||||
|
if(showfd == nil || seefd == nil)
|
||||||
if(seefd < 0){
|
sysfatal("plumbopen: %r");
|
||||||
logfd = open(unsharp("#9/log/mail"), OREAD);
|
|
||||||
seek(logfd, 0LL, 2);
|
|
||||||
user = getenv("user");
|
|
||||||
if(user == nil){
|
|
||||||
fprint(2, "faces: can't find user name: %r\n");
|
|
||||||
exits("$user");
|
|
||||||
}
|
|
||||||
logtag = emalloc(32+strlen(user)+1);
|
|
||||||
sprint(logtag, " delivered %s From ", user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -75,7 +63,7 @@ showmail(Face *f)
|
||||||
pm.attr = &a;
|
pm.attr = &a;
|
||||||
pm.ndata = strlen(s);
|
pm.ndata = strlen(s);
|
||||||
pm.data = s;
|
pm.data = s;
|
||||||
plumbsend(showfd,&pm);
|
plumbsendtofid(showfd, &pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
|
|
@ -114,43 +102,6 @@ setname(Face *f, char *sender)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
getc(void)
|
|
||||||
{
|
|
||||||
static uchar buf[512];
|
|
||||||
static int nbuf = 0;
|
|
||||||
static int i = 0;
|
|
||||||
|
|
||||||
while(i == nbuf){
|
|
||||||
i = 0;
|
|
||||||
nbuf = read(logfd, buf, sizeof buf);
|
|
||||||
if(nbuf == 0){
|
|
||||||
sleep(15000);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(nbuf < 0)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return buf[i++];
|
|
||||||
}
|
|
||||||
|
|
||||||
char*
|
|
||||||
getline(char *buf, int n)
|
|
||||||
{
|
|
||||||
int i, c;
|
|
||||||
|
|
||||||
for(i=0; i<n-1; i++){
|
|
||||||
c = getc();
|
|
||||||
if(c <= 0)
|
|
||||||
return nil;
|
|
||||||
if(c == '\n')
|
|
||||||
break;
|
|
||||||
buf[i] = c;
|
|
||||||
}
|
|
||||||
buf[i] = '\0';
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char* months[] = {
|
static char* months[] = {
|
||||||
"jan", "feb", "mar", "apr",
|
"jan", "feb", "mar", "apr",
|
||||||
"may", "jun", "jul", "aug",
|
"may", "jun", "jul", "aug",
|
||||||
|
|
@ -216,42 +167,6 @@ parsedate(char *s)
|
||||||
return parsedatev(f);
|
return parsedatev(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* achille Jul 23 14:05:15 delivered jmk From ms.com!bub Fri Jul 23 14:05:14 EDT 1999 (plan9.bell-labs.com!jmk) 1352 */
|
|
||||||
/* achille Oct 26 13:45:42 remote local!rsc From rsc Sat Oct 26 13:45:41 EDT 2002 (rsc) 170 */
|
|
||||||
int
|
|
||||||
parselog(char *s, char **sender, ulong *xtime)
|
|
||||||
{
|
|
||||||
char *f[20];
|
|
||||||
int nf;
|
|
||||||
|
|
||||||
nf = getfields(s, f, nelem(f), 1, " ");
|
|
||||||
if(nf < 14)
|
|
||||||
return 0;
|
|
||||||
if(strcmp(f[4], "delivered") == 0 && strcmp(f[5], user) == 0)
|
|
||||||
goto Found;
|
|
||||||
if(strcmp(f[4], "remote") == 0 && strncmp(f[5], "local!", 6) == 0 && strcmp(f[5]+6, user) == 0)
|
|
||||||
goto Found;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
Found:
|
|
||||||
*sender = estrdup(f[7]);
|
|
||||||
*xtime = parsedatev(&f[8]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
logrecv(char **sender, ulong *xtime)
|
|
||||||
{
|
|
||||||
char buf[4096];
|
|
||||||
|
|
||||||
for(;;){
|
|
||||||
if(getline(buf, sizeof buf) == nil)
|
|
||||||
return 0;
|
|
||||||
if(parselog(buf, sender, xtime))
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char*
|
char*
|
||||||
tweakdate(char *d)
|
tweakdate(char *d)
|
||||||
|
|
@ -280,49 +195,36 @@ nextface(void)
|
||||||
|
|
||||||
f = emalloc(sizeof(Face));
|
f = emalloc(sizeof(Face));
|
||||||
for(;;){
|
for(;;){
|
||||||
if(seefd >= 0){
|
m = plumbrecvfid(seefd);
|
||||||
m = plumbrecv(seefd);
|
if(m == nil)
|
||||||
if(m == nil)
|
killall("error on seemail plumb port");
|
||||||
killall("error on seemail plumb port");
|
t = value(m->attr, "mailtype", "");
|
||||||
t = value(m->attr, "mailtype", "");
|
if(strcmp(t, "delete") == 0)
|
||||||
if(strcmp(t, "delete") == 0)
|
delete(m->data, value(m->attr, "digest", nil));
|
||||||
delete(m->data, value(m->attr, "digest", nil));
|
else if(strcmp(t, "new") != 0)
|
||||||
else if(strcmp(t, "new") != 0)
|
fprint(2, "faces: unknown plumb message type %s\n", t);
|
||||||
fprint(2, "faces: unknown plumb message type %s\n", t);
|
else for(i=0; i<nmaildirs; i++) { /* XXX */
|
||||||
else for(i=0; i<nmaildirs; i++) {
|
if(strncmp(m->data,"/mail/fs/",strlen("/mail/fs/")) == 0)
|
||||||
if(strncmp(m->data,"/mail/fs/",strlen("/mail/fs/")) == 0)
|
m->data += strlen("/mail/fs/");
|
||||||
m->data += strlen("/mail/fs/");
|
if(strncmp(m->data, maildirs[i], strlen(maildirs[i])) == 0)
|
||||||
if(strncmp(m->data, maildirs[i], strlen(maildirs[i])) == 0)
|
goto Found;
|
||||||
goto Found;
|
}
|
||||||
}
|
plumbfree(m);
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Found:
|
||||||
|
xtime = parsedate(value(m->attr, "date", date));
|
||||||
|
digestp = value(m->attr, "digest", nil);
|
||||||
|
if(alreadyseen(digestp)){
|
||||||
|
/* duplicate upas/fs can send duplicate messages */
|
||||||
plumbfree(m);
|
plumbfree(m);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Found:
|
|
||||||
xtime = parsedate(value(m->attr, "date", date));
|
|
||||||
digestp = value(m->attr, "digest", nil);
|
|
||||||
if(alreadyseen(digestp)){
|
|
||||||
/* duplicate upas/fs can send duplicate messages */
|
|
||||||
plumbfree(m);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
senderp = estrdup(value(m->attr, "sender", "???"));
|
|
||||||
showmailp = estrdup(m->data);
|
|
||||||
if(digestp)
|
|
||||||
digestp = estrdup(digestp);
|
|
||||||
plumbfree(m);
|
|
||||||
}else{
|
|
||||||
if(logrecv(&senderp, &xtime) <= 0)
|
|
||||||
killall("error reading log file");
|
|
||||||
showmailp = estrdup("");
|
|
||||||
digestp = nil;
|
|
||||||
}
|
}
|
||||||
setname(f, senderp);
|
senderp = estrdup(value(m->attr, "sender", "???"));
|
||||||
f->time = xtime;
|
showmailp = estrdup(m->data);
|
||||||
f->tm = *localtime(xtime);
|
if(digestp)
|
||||||
f->str[Sshow] = showmailp;
|
digestp = estrdup(digestp);
|
||||||
f->str[Sdigest] = digestp;
|
plumbfree(m);
|
||||||
return f;
|
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
@ -332,6 +234,8 @@ iline(char *data, char **pp)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
|
if(*data == 0)
|
||||||
|
return nil;
|
||||||
for(p=data; *p!='\0' && *p!='\n'; p++)
|
for(p=data; *p!='\0' && *p!='\n'; p++)
|
||||||
;
|
;
|
||||||
if(*p == '\n')
|
if(*p == '\n')
|
||||||
|
|
@ -344,28 +248,16 @@ Face*
|
||||||
dirface(char *dir, char *num)
|
dirface(char *dir, char *num)
|
||||||
{
|
{
|
||||||
Face *f;
|
Face *f;
|
||||||
char *from, *date;
|
char buf[1024], *fld[3], *info, *p, *t, *s;
|
||||||
char buf[1024], *info, *p, *digest;
|
|
||||||
int n;
|
int n;
|
||||||
ulong len;
|
ulong len;
|
||||||
CFid *fid;
|
CFid *fid;
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* loadmbox leaves us in maildir, so we needn't
|
|
||||||
* walk /mail/fs/mbox for each face; this makes startup
|
|
||||||
* a fair bit quicker.
|
|
||||||
*/
|
|
||||||
if(getwd(pwd, sizeof pwd) != nil && strcmp(pwd, dir) == 0)
|
|
||||||
sprint(buf, "%s/info", num);
|
|
||||||
else
|
|
||||||
sprint(buf, "%s/%s/info", dir, num);
|
|
||||||
#endif
|
|
||||||
sprint(buf, "%s/%s/info", dir, num);
|
sprint(buf, "%s/%s/info", dir, num);
|
||||||
len = fsdirlen(upasfs, buf);
|
len = fsdirlen(mailfs, buf);
|
||||||
if(len <= 0)
|
if(len <= 0)
|
||||||
return nil;
|
return nil;
|
||||||
fid = fsopen(upasfs,buf, OREAD);
|
fid = fsopen(mailfs, buf, OREAD);
|
||||||
if(fid == nil)
|
if(fid == nil)
|
||||||
return nil;
|
return nil;
|
||||||
info = emalloc(len+1);
|
info = emalloc(len+1);
|
||||||
|
|
@ -377,22 +269,22 @@ dirface(char *dir, char *num)
|
||||||
}
|
}
|
||||||
info[n] = '\0';
|
info[n] = '\0';
|
||||||
f = emalloc(sizeof(Face));
|
f = emalloc(sizeof(Face));
|
||||||
from = iline(info, &p); /* from */
|
for(p=info; (s=iline(p, &p)) != nil; ){
|
||||||
iline(p, &p); /* to */
|
t = strchr(s, ' ');
|
||||||
iline(p, &p); /* cc */
|
if(t == nil)
|
||||||
iline(p, &p); /* replyto */
|
continue;
|
||||||
date = iline(p, &p); /* date */
|
*t++ = 0;
|
||||||
setname(f, estrdup(from));
|
if(strcmp(s, "unixdate") == 0){
|
||||||
f->time = parsedate(date);
|
f->time = atoi(t);
|
||||||
f->tm = *localtime(f->time);
|
f->tm = *localtime(f->time);
|
||||||
|
}
|
||||||
|
else if(strcmp(s, "from") == 0 && tokenize(t, fld, 3) >= 2)
|
||||||
|
setname(f, estrdup(fld[1]));
|
||||||
|
else if(strcmp(s, "digest") == 0)
|
||||||
|
f->str[Sdigest] = estrdup(t);
|
||||||
|
}
|
||||||
sprint(buf, "%s/%s", dir, num);
|
sprint(buf, "%s/%s", dir, num);
|
||||||
f->str[Sshow] = estrdup(buf);
|
f->str[Sshow] = estrdup(buf);
|
||||||
iline(p, &p); /* subject */
|
|
||||||
iline(p, &p); /* mime content type */
|
|
||||||
iline(p, &p); /* mime disposition */
|
|
||||||
iline(p, &p); /* filename */
|
|
||||||
digest = iline(p, &p); /* digest */
|
|
||||||
f->str[Sdigest] = estrdup(digest);
|
|
||||||
free(info);
|
free(info);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ append_match(Resub *subexp, String *sp, int se)
|
||||||
{
|
{
|
||||||
char *cp, *ep;
|
char *cp, *ep;
|
||||||
|
|
||||||
cp = subexp[se].s.sp; /* jpc .sp -> .s.sp */
|
cp = subexp[se].s.sp;
|
||||||
ep = subexp[se].e.ep; /* jpc .ep -> .e.ep */
|
ep = subexp[se].e.ep;
|
||||||
for (; cp < ep; cp++)
|
for (; cp < ep; cp++)
|
||||||
s_putc(sp, *cp);
|
s_putc(sp, *cp);
|
||||||
s_terminate(sp);
|
s_terminate(sp);
|
||||||
|
|
@ -53,7 +53,7 @@ shellchars(char *cp)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *specialchars = " ()<>{};=\\'\`^&|";
|
static char *specialchars = " ()<>{};=\\'`^&|";
|
||||||
static char *escape = "%%";
|
static char *escape = "%%";
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,19 @@ char *SHELL = "#9/bin/rc";
|
||||||
char *POST = "#9/sys/lib/post/dispatch";
|
char *POST = "#9/sys/lib/post/dispatch";
|
||||||
|
|
||||||
int MBOXMODE = 0662;
|
int MBOXMODE = 0662;
|
||||||
|
|
||||||
|
void
|
||||||
|
upasconfig(void)
|
||||||
|
{
|
||||||
|
static int did;
|
||||||
|
|
||||||
|
if(did)
|
||||||
|
return;
|
||||||
|
did = 1;
|
||||||
|
MAILROOT = unsharp(MAILROOT);
|
||||||
|
UPASLOG = unsharp(UPASLOG);
|
||||||
|
UPASLIB = unsharp(UPASLIB);
|
||||||
|
UPASBIN = unsharp(UPASBIN);
|
||||||
|
SHELL = unsharp(SHELL);
|
||||||
|
POST = unsharp(POST);
|
||||||
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -33,24 +33,7 @@ getlog(void)
|
||||||
{
|
{
|
||||||
return getuser();
|
return getuser();
|
||||||
}
|
}
|
||||||
#if 0 /* jpc */
|
|
||||||
extern char *
|
|
||||||
getlog(void)
|
|
||||||
{
|
|
||||||
static char user[64];
|
|
||||||
int fd;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
fd = open("/dev/user", 0);
|
|
||||||
if(fd < 0)
|
|
||||||
return nil;
|
|
||||||
if((n=read(fd, user, sizeof(user)-1)) <= 0)
|
|
||||||
return nil;
|
|
||||||
close(fd);
|
|
||||||
user[n] = 0;
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
#endif /* jpc */
|
|
||||||
/*
|
/*
|
||||||
* return the lock name (we use one lock per directory)
|
* return the lock name (we use one lock per directory)
|
||||||
*/
|
*/
|
||||||
|
|
@ -704,64 +687,17 @@ pipesigoff(void)
|
||||||
atnotify(catchpipe, 0);
|
atnotify(catchpipe, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
exit9(int i)
|
|
||||||
{
|
|
||||||
char buf[32];
|
|
||||||
|
|
||||||
if(i == 0)
|
|
||||||
exits(0);
|
|
||||||
snprint(buf, sizeof(buf), "%d", i);
|
|
||||||
exits(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
islikeatty(int fd)
|
|
||||||
{
|
|
||||||
Dir *d;
|
|
||||||
int rv;
|
|
||||||
|
|
||||||
d = dirfstat(fd);
|
|
||||||
if(d == nil)
|
|
||||||
return 0;
|
|
||||||
rv = strcmp(d->name, "cons") == 0;
|
|
||||||
free(d);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* jpc */
|
|
||||||
static int
|
|
||||||
islikeatty(int fd)
|
|
||||||
{
|
|
||||||
char buf[64];
|
|
||||||
|
|
||||||
if(fd2path(fd, buf, sizeof buf) != 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* might be /mnt/term/dev/cons */
|
|
||||||
return strlen(buf) >= 9 && strcmp(buf+strlen(buf)-9, "/dev/cons") == 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
holdon(void)
|
holdon(void)
|
||||||
{
|
{
|
||||||
int fd;
|
/* XXX talk to 9term? */
|
||||||
|
return -1;
|
||||||
if(!islikeatty(0))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
fd = open("/dev/consctl", OWRITE);
|
|
||||||
write(fd, "holdon", 6);
|
|
||||||
|
|
||||||
return fd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
sysopentty(void)
|
sysopentty(void)
|
||||||
{
|
{
|
||||||
return open("/dev/cons", ORDWR);
|
return open("/dev/tty", ORDWR);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
|
|
@ -786,11 +722,13 @@ sysfiles(void)
|
||||||
extern String *
|
extern String *
|
||||||
mboxpath(char *path, char *user, String *to, int dot)
|
mboxpath(char *path, char *user, String *to, int dot)
|
||||||
{
|
{
|
||||||
|
upasconfig();
|
||||||
|
|
||||||
if (dot || *path=='/' || strncmp(path, "./", 2) == 0
|
if (dot || *path=='/' || strncmp(path, "./", 2) == 0
|
||||||
|| strncmp(path, "../", 3) == 0) {
|
|| strncmp(path, "../", 3) == 0) {
|
||||||
to = s_append(to, path);
|
to = s_append(to, path);
|
||||||
} else {
|
} else {
|
||||||
to = s_append(to, unsharp(MAILROOT));
|
to = s_append(to, MAILROOT);
|
||||||
to = s_append(to, "/box/");
|
to = s_append(to, "/box/");
|
||||||
to = s_append(to, user);
|
to = s_append(to, user);
|
||||||
to = s_append(to, "/");
|
to = s_append(to, "/");
|
||||||
|
|
@ -885,35 +823,7 @@ username(String *from)
|
||||||
char *
|
char *
|
||||||
remoteaddr(int fd, char *dir)
|
remoteaddr(int fd, char *dir)
|
||||||
{
|
{
|
||||||
char buf[128], *p;
|
/* XXX should call netconninfo */
|
||||||
int n;
|
|
||||||
|
|
||||||
if(dir == 0){
|
|
||||||
fprint(2,"remoteaddr: called fd2path: fixme\n"); /* jpc
|
|
||||||
if(fd2path(fd, buf, sizeof(buf)) != 0)
|
|
||||||
return ""; */
|
|
||||||
|
|
||||||
/* parse something of the form /net/tcp/nnnn/data */
|
|
||||||
p = strrchr(buf, '/');
|
|
||||||
if(p == 0)
|
|
||||||
return "";
|
|
||||||
strncpy(p+1, "remote", sizeof(buf)-(p-buf)-2);
|
|
||||||
} else
|
|
||||||
snprint(buf, sizeof buf, "%s/remote", dir);
|
|
||||||
buf[sizeof(buf)-1] = 0;
|
|
||||||
|
|
||||||
fd = open(buf, OREAD);
|
|
||||||
if(fd < 0)
|
|
||||||
return "";
|
|
||||||
n = read(fd, buf, sizeof(buf)-1);
|
|
||||||
close(fd);
|
|
||||||
if(n > 0){
|
|
||||||
buf[n] = 0;
|
|
||||||
p = strchr(buf, '!');
|
|
||||||
if(p)
|
|
||||||
*p = 0;
|
|
||||||
return strdup(buf);
|
|
||||||
}
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,17 @@
|
||||||
|
|
||||||
LIB=libcommon.a
|
LIB=libcommon.a
|
||||||
|
|
||||||
OFILES=aux.$O\
|
OFILES=\
|
||||||
become.$O\
|
appendfiletombox.$O\
|
||||||
|
aux.$O\
|
||||||
|
config.$O\
|
||||||
|
libsys.$O\
|
||||||
mail.$O\
|
mail.$O\
|
||||||
process.$O\
|
process.$O\
|
||||||
libsys.$O\
|
|
||||||
config.$O\
|
|
||||||
appendfiletombox.$O\
|
|
||||||
|
|
||||||
HFILES=common.h\
|
HFILES=\
|
||||||
|
common.h\
|
||||||
sys.h\
|
sys.h\
|
||||||
|
|
||||||
<$PLAN9/src/mklib
|
<$PLAN9/src/mklib
|
||||||
|
|
||||||
nuke:V:
|
|
||||||
mk clean
|
|
||||||
rm -f libcommon.a
|
|
||||||
|
|
|
||||||
|
|
@ -93,10 +93,8 @@ noshell_proc_start(char **av, stream *inp, stream *outp, stream *errp, int newpg
|
||||||
dup(pp->std[i]->fd, i);
|
dup(pp->std[i]->fd, i);
|
||||||
for (n = sysfiles(); i < n; i++)
|
for (n = sysfiles(); i < n; i++)
|
||||||
close(i);
|
close(i);
|
||||||
if(who) {
|
if(who)
|
||||||
fprint(2,"process.c: trying to become(%s,%s)\n",av,who);
|
fprint(2, "warning: cannot run %s as %s\n", av[0], who);
|
||||||
// jpc become(av, who);
|
|
||||||
}
|
|
||||||
exec(av[0], av);
|
exec(av[0], av);
|
||||||
perror("proc_start");
|
perror("proc_start");
|
||||||
exits("proc_start");
|
exits("proc_start");
|
||||||
|
|
@ -116,7 +114,8 @@ proc_start(char *cmd, stream *inp, stream *outp, stream *errp, int newpg, char *
|
||||||
{
|
{
|
||||||
char *av[4];
|
char *av[4];
|
||||||
|
|
||||||
av[0] = unsharp(SHELL);
|
upasconfig();
|
||||||
|
av[0] = SHELL;
|
||||||
av[1] = "-c";
|
av[1] = "-c";
|
||||||
av[2] = cmd;
|
av[2] = cmd;
|
||||||
av[3] = 0;
|
av[3] = 0;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include <regexp.h>
|
#include <regexp.h>
|
||||||
#include <bio.h>
|
#include <bio.h>
|
||||||
#include "libString.h" /* jpc String.h -> libString.h */
|
#include <libString.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* for the lock routines in libsys.c
|
* for the lock routines in libsys.c
|
||||||
|
|
@ -19,7 +19,7 @@ struct Mlock {
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* from config.c
|
* from config.c - call upasconfig() before using
|
||||||
*/
|
*/
|
||||||
extern char *MAILROOT; /* root of mail system */
|
extern char *MAILROOT; /* root of mail system */
|
||||||
extern char *UPASLOG; /* log directory */
|
extern char *UPASLOG; /* log directory */
|
||||||
|
|
@ -29,6 +29,7 @@ extern char *UPASTMP; /* temporary directory */
|
||||||
extern char *SHELL; /* path name of shell */
|
extern char *SHELL; /* path name of shell */
|
||||||
extern char *POST; /* path name of post server addresses */
|
extern char *POST; /* path name of post server addresses */
|
||||||
extern int MBOXMODE; /* default mailbox protection mode */
|
extern int MBOXMODE; /* default mailbox protection mode */
|
||||||
|
extern void upasconfig(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* files in libsys.c
|
* files in libsys.c
|
||||||
|
|
@ -58,7 +59,6 @@ extern int syskill(int);
|
||||||
extern int syskillpg(int);
|
extern int syskillpg(int);
|
||||||
extern int syscreate(char*, int, ulong);
|
extern int syscreate(char*, int, ulong);
|
||||||
extern Mlock *trylock(char *);
|
extern Mlock *trylock(char *);
|
||||||
extern void exit9(int);
|
|
||||||
extern void pipesig(int*);
|
extern void pipesig(int*);
|
||||||
extern void pipesigoff(void);
|
extern void pipesigoff(void);
|
||||||
extern int holdon(void);
|
extern int holdon(void);
|
||||||
|
|
|
||||||
|
|
@ -231,10 +231,8 @@ pop3login(Pop *pop)
|
||||||
if(pop->needtls && !pop->encrypted)
|
if(pop->needtls && !pop->encrypted)
|
||||||
return "could not negotiate TLS";
|
return "could not negotiate TLS";
|
||||||
|
|
||||||
up = auth_getuserpasswd(auth_getkey, "role=client proto=pass service=pop dom=%q%s",
|
up = auth_getuserpasswd(auth_getkey, "proto=pass role=client service=pop dom=%q%s",
|
||||||
pop->host, ubuf);
|
pop->host, ubuf);
|
||||||
/* up = auth_getuserpasswd(auth_getkey, "proto=pass service=pop dom=%q%s",
|
|
||||||
pop->host, ubuf); jpc */
|
|
||||||
if(up == nil)
|
if(up == nil)
|
||||||
return "no usable keys found";
|
return "no usable keys found";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue