more changes

This commit is contained in:
rsc 2006-02-11 22:35:38 +00:00
parent 0c7c441e90
commit 00d75e0eae
8 changed files with 147 additions and 141 deletions

View file

@ -153,8 +153,8 @@ extern Window *wbox;
extern Message mbox; extern Message mbox;
extern Message replies; extern Message replies;
extern char *fsname; extern char *fsname;
extern int plumbsendfd; extern CFid *plumbsendfd;
extern int plumbseemailfd; extern CFid *plumbseemailfd;
extern char *home; extern char *home;
extern char *outgoing; extern char *outgoing;
extern char *mailboxdir; extern char *mailboxdir;

View file

@ -2,13 +2,13 @@
#include <libc.h> #include <libc.h>
#include <bio.h> #include <bio.h>
#include <thread.h> #include <thread.h>
#include <9pclient.h>
#include <plumb.h> #include <plumb.h>
#include <ctype.h> #include <ctype.h>
#include <9pclient.h>
#include "dat.h" #include "dat.h"
char *maildir = "/mail/"; /* mountpoint of mail file system */ char *maildir = "Mail/"; /* mountpoint of mail file system */
char *mboxname = "INBOX"; /* mailboxdir/mboxname is mail spool file */ char *mboxname = "mbox"; /* mailboxdir/mboxname is mail spool file */
char *mailboxdir = nil; /* nil == /mail/box/$user */ char *mailboxdir = nil; /* nil == /mail/box/$user */
char *fsname; /* filesystem for mailboxdir/mboxname is at maildir/fsname */ char *fsname; /* filesystem for mailboxdir/mboxname is at maildir/fsname */
char *user; char *user;
@ -18,10 +18,10 @@ Window *wbox;
Message mbox; Message mbox;
Message replies; Message replies;
char *home; char *home;
int plumbsendfd; CFid *plumbsendfd;
int plumbseemailfd; CFid *plumbseemailfd;
int plumbshowmailfd; CFid *plumbshowmailfd;
int plumbsendmailfd; CFid *plumbsendmailfd;
Channel *cplumb; Channel *cplumb;
Channel *cplumbshow; Channel *cplumbshow;
Channel *cplumbsend; Channel *cplumbsend;
@ -85,9 +85,9 @@ threadmain(int argc, char *argv[])
quotefmtinstall(); quotefmtinstall();
/* open these early so we won't miss notification of new mail messages while we read mbox */ /* open these early so we won't miss notification of new mail messages while we read mbox */
plumbsendfd = plumbopen("send", OWRITE|OCEXEC); plumbsendfd = plumbopenfid("send", OWRITE|OCEXEC);
plumbseemailfd = plumbopen("seemail", OREAD|OCEXEC); plumbseemailfd = plumbopenfid("seemail", OREAD|OCEXEC);
plumbshowmailfd = plumbopen("showmail", OREAD|OCEXEC); plumbshowmailfd = plumbopenfid("showmail", OREAD|OCEXEC);
shortmenu = 0; shortmenu = 0;
ARGBEGIN{ ARGBEGIN{
@ -114,7 +114,7 @@ threadmain(int argc, char *argv[])
if(mailfs == nil) if(mailfs == nil)
error("cannot mount mail: %r"); error("cannot mount mail: %r");
name = "INBOX"; name = "mbox";
newdir = 1; newdir = 1;
if(argc > 0){ if(argc > 0){
@ -159,9 +159,9 @@ threadmain(int argc, char *argv[])
if(outgoing == nil) if(outgoing == nil)
outgoing = estrstrdup(mailboxdir, "/outgoing"); outgoing = estrstrdup(mailboxdir, "/outgoing");
mbox.ctlfd = fsopen(mailfs, "INBOX/ctl", OWRITE); mbox.ctlfd = fsopen(mailfs, "mbox/ctl", OWRITE);
if(mbox.ctlfd == nil) if(mbox.ctlfd == nil)
error("can't open %s: %r", "INBOX/ctl"); error("can't open %s: %r", "mbox/ctl");
fsname = estrdup(name); fsname = estrdup(name);
if(newdir && argc > 0){ if(newdir && argc > 0){
@ -216,12 +216,12 @@ threadmain(int argc, char *argv[])
wctlfd = -1; wctlfd = -1;
cplumb = chancreate(sizeof(Plumbmsg*), 0); cplumb = chancreate(sizeof(Plumbmsg*), 0);
cplumbshow = chancreate(sizeof(Plumbmsg*), 0); cplumbshow = chancreate(sizeof(Plumbmsg*), 0);
if(strcmp(name, "INBOX") == 0){ if(strcmp(name, "mbox") == 0){
/* /*
* Avoid creating multiple windows to send mail by only accepting * Avoid creating multiple windows to send mail by only accepting
* sendmail plumb messages if we're reading the main mailbox. * sendmail plumb messages if we're reading the main mailbox.
*/ */
plumbsendmailfd = plumbopen("sendmail", OREAD|OCEXEC); plumbsendmailfd = plumbopenfid("sendmail", OREAD|OCEXEC);
cplumbsend = chancreate(sizeof(Plumbmsg*), 0); cplumbsend = chancreate(sizeof(Plumbmsg*), 0);
proccreate(plumbsendproc, nil, STACK); proccreate(plumbsendproc, nil, STACK);
threadcreate(plumbsendthread, nil, STACK); threadcreate(plumbsendthread, nil, STACK);
@ -241,7 +241,7 @@ plumbproc(void* v)
threadsetname("plumbproc"); threadsetname("plumbproc");
for(;;){ for(;;){
m = plumbrecv(plumbseemailfd); m = plumbrecvfid(plumbseemailfd);
sendp(cplumb, m); sendp(cplumb, m);
if(m == nil) if(m == nil)
threadexits(nil); threadexits(nil);
@ -255,7 +255,7 @@ plumbshowproc(void* v)
threadsetname("plumbshowproc"); threadsetname("plumbshowproc");
for(;;){ for(;;){
m = plumbrecv(plumbshowmailfd); m = plumbrecvfid(plumbshowmailfd);
sendp(cplumbshow, m); sendp(cplumbshow, m);
if(m == nil) if(m == nil)
threadexits(nil); threadexits(nil);
@ -269,7 +269,7 @@ plumbsendproc(void* v)
threadsetname("plumbsendproc"); threadsetname("plumbsendproc");
for(;;){ for(;;){
m = plumbrecv(plumbsendmailfd); m = plumbrecvfid(plumbsendmailfd);
sendp(cplumbsend, m); sendp(cplumbsend, m);
if(m == nil) if(m == nil)
threadexits(nil); threadexits(nil);
@ -285,8 +285,8 @@ newmesg(char *name, char *digest)
return; /* message is about another mailbox */ return; /* message is about another mailbox */
if(mesglookupfile(&mbox, name, digest) != nil) if(mesglookupfile(&mbox, name, digest) != nil)
return; return;
if(strncmp(name, "/mail/", 6) == 0) if(strncmp(name, "Mail/", 5) == 0)
name += 6; name += 5;
d = fsdirstat(mailfs, name); d = fsdirstat(mailfs, name);
if(d == nil) if(d == nil)
return; return;
@ -300,10 +300,8 @@ showmesg(char *name, char *digest)
{ {
char *n; char *n;
char *mb; char *mb;
mb = mbox.name; mb = mbox.name;
if(strncmp(mb, "/mail/", 6) == 0)
mb += 6;
if(strncmp(name, mb, strlen(mb)) != 0) if(strncmp(name, mb, strlen(mb)) != 0)
return; /* message is about another mailbox */ return; /* message is about another mailbox */
n = estrdup(name+strlen(mb)); n = estrdup(name+strlen(mb));

View file

@ -3,8 +3,8 @@
#include <bio.h> #include <bio.h>
#include <thread.h> #include <thread.h>
#include <ctype.h> #include <ctype.h>
#include <plumb.h>
#include <9pclient.h> #include <9pclient.h>
#include <plumb.h>
#include "dat.h" #include "dat.h"
enum enum
@ -200,9 +200,9 @@ isnumeric(char *s)
CFid* CFid*
mailopen(char *name, int mode) mailopen(char *name, int mode)
{ {
if(strncmp(name, "/mail/", 6) != 0) if(strncmp(name, "Mail/", 5) != 0)
return nil; return nil;
return fsopen(mailfs, name+6, mode); return fsopen(mailfs, name+5, mode);
} }
Dir* Dir*
@ -624,7 +624,7 @@ mesgsave(Message *m, char *s, int save)
char *t, *raw, *unixheader, *all; char *t, *raw, *unixheader, *all;
if(save){ if(save){
if(fsprint(mbox.ctlfd, "save %q %q", m->name, s) < 0){ if(fsprint(mbox.ctlfd, "save %q %q", s, m->name) < 0){
fprint(2, "Mail: can't save %s to %s: %r\n", m->name, s); fprint(2, "Mail: can't save %s to %s: %r\n", m->name, s);
return 0; return 0;
} }
@ -865,7 +865,7 @@ replytoaddr(Window *w, Message *m, Event *e, char *s)
pm->attr->value = estrdup(m->subject); pm->attr->value = estrdup(m->subject);
pm->attr->next = nil; pm->attr->next = nil;
} }
if(plumbsend(plumbsendfd, pm) < 0) if(plumbsendtofid(plumbsendfd, pm) < 0)
fprint(2, "error writing plumb message: %r\n"); fprint(2, "error writing plumb message: %r\n");
plumbfree(pm); plumbfree(pm);
} }
@ -1253,7 +1253,7 @@ plumb(Message *m, char *dir)
pm->ndata = -1; pm->ndata = -1;
pm->data = estrstrdup(dir, "body"); pm->data = estrstrdup(dir, "body");
pm->data = eappend(pm->data, "", ports[i].suffix); pm->data = eappend(pm->data, "", ports[i].suffix);
if(plumbsend(plumbsendfd, pm) < 0) if(plumbsendtofid(plumbsendfd, pm) < 0)
fprint(2, "error writing plumb message: %r\n"); fprint(2, "error writing plumb message: %r\n");
plumbfree(pm); plumbfree(pm);
} }

View file

@ -1,7 +1,5 @@
<$PLAN9/src/mkhdr <$PLAN9/src/mkhdr
CC=9c
TARG=Mail TARG=Mail
OFILES=\ OFILES=\
html.$O\ html.$O\
@ -12,21 +10,6 @@ OFILES=\
win.$O win.$O
HFILES=dat.h HFILES=dat.h
LIB=
BIN=/acme/bin/$objtype
UPDATE=\
mkfile\
$HFILES\
${OFILES:%.$O=%.c}\
<$PLAN9/src/mkone <$PLAN9/src/mkone
$O.out: $OFILES
$LD -o $target $LDFLAGS $OFILES
syms:V:
8c -a mail.c >syms
8c -aa mesg.c reply.c util.c win.c >>syms

View file

@ -15,6 +15,9 @@ enum /* number of deleted faces to cache */
static Facefile *facefiles; static Facefile *facefiles;
static int nsaved; static int nsaved;
static char *facedom; static char *facedom;
static char *libface;
static char *homeface;
static char *machinelist;
/* /*
* Loading the files is slow enough on a dial-up line to be worth this trouble * Loading the files is slow enough on a dial-up line to be worth this trouble
@ -148,9 +151,8 @@ readfile(char *s)
return strdup(r->data); return strdup(r->data);
} }
static char* static char*
translatedomain(char *dom) translatedomain(char *dom, char *list)
{ {
static char buf[200]; static char buf[200];
char *p, *ep, *q, *nextp, *file; char *p, *ep, *q, *nextp, *file;
@ -160,7 +162,7 @@ translatedomain(char *dom)
if(dom == nil || *dom == 0) if(dom == nil || *dom == 0)
return nil; return nil;
if((file = readfile(unsharp("#9/face/.machinelist"))) == nil) if(list == nil || (file = readfile(list)) == nil)
return dom; return dom;
for(p=file; p; p=nextp) { for(p=file; p; p=nextp) {
@ -210,26 +212,17 @@ translatedomain(char *dom)
} }
static char* static char*
tryfindpicture_user(char *dom, char *user, int depth) tryfindpicture(char *dom, char *user, char *dir, char *dict)
{ {
static char buf[200]; static char buf[1024];
char *p, *q, *nextp, *file; char *file, *p, *nextp, *q;
static char *home;
if((file = readfile(dict)) == nil)
if(home == nil)
home = getenv("home");
if(home == nil)
home = getenv("HOME");
if(home == nil)
return nil;
sprint(buf, "%s/lib/face/48x48x%d/.dict", home, depth);
if((file = readfile(buf)) == nil)
return nil; return nil;
snprint(buf, sizeof buf, "%s/%s", dom, user); snprint(buf, sizeof buf, "%s/%s", dom, user);
for(p=file; p; p=nextp) { for(p=file; p; p=nextp){
if(nextp = strchr(p, '\n')) if(nextp = strchr(p, '\n'))
*nextp++ = '\0'; *nextp++ = '\0';
@ -237,75 +230,114 @@ tryfindpicture_user(char *dom, char *user, int depth)
continue; continue;
*q++ = 0; *q++ = 0;
if(strcmp(buf, p) == 0) { if(strcmp(buf, p) == 0){
q += strspn(q, " \t"); q += strspn(q, " \t");
q = buf+snprint(buf, sizeof buf, "%s/lib/face/48x48x%d/%s", home, depth, q); snprint(buf, sizeof buf, "%s/%s", dir, q);
q = buf+strlen(buf);
while(q > buf && (q[-1] == ' ' || q[-1] == '\t')) while(q > buf && (q[-1] == ' ' || q[-1] == '\t'))
*--q = 0; *--q = 0;
free(file); free(file);
return buf; return estrdup(buf);
} }
} }
free(file); free(file);
return nil; return nil;
} }
static char* static char*
tryfindpicture_global(char *dom, char *user, int depth) estrstrdup(char *a, char *b)
{ {
static char buf[200]; char *t;
char *p, *q, *nextp, *file;
t = emalloc(strlen(a)+strlen(b)+1);
strcpy(t, a);
strcat(t, b);
return t;
}
sprint(buf, "#9/face/48x48x%d/.dict", depth); static char*
if((file = readfile(unsharp(buf))) == nil) tryfindfiledir(char *dom, char *user, char *dir)
{
char *dict, *ndir, *x;
int fd;
int i, n;
Dir *d;
/*
* If this directory has a .machinelist, use it.
*/
x = estrstrdup(dir, "/.machinelist");
dom = estrdup(translatedomain(dom, x));
free(x);
/*
* If this directory has a .dict, use it.
*/
dict = estrstrdup(dir, "/.dict");
if(access(dict, AEXIST) >= 0){
x = tryfindpicture(dom, user, dir, dict);
free(dict);
free(dom);
return x;
}
free(dict);
/*
* If not, recurse into subdirectories.
* Ignore 48x48xN directories for now.
*/
if((fd = open(dir, OREAD)) < 0)
return nil; return nil;
while((n = dirread(fd, &d)) > 0){
snprint(buf, sizeof buf, "%s/%s", dom, user); for(i=0; i<n; i++){
if((d[i].mode&DMDIR)&& strncmp(d[i].name, "48x48x", 6) != 0){
for(p=file; p; p=nextp) { ndir = emalloc(strlen(dir)+1+strlen(d[i].name)+1);
if(nextp = strchr(p, '\n')) strcpy(ndir, dir);
*nextp++ = '\0'; strcat(ndir, "/");
strcat(ndir, d[i].name);
if(*p == '#' || (q = strpbrk(p, " \t")) == nil) if((x = tryfindfiledir(dom, user, ndir)) != nil){
continue; free(ndir);
*q++ = 0; free(d);
close(fd);
if(strcmp(buf, p) == 0) { free(dom);
q += strspn(q, " \t"); return x;
q = buf+snprint(buf, sizeof buf, "#9/face/48x48x%d/%s", depth, q); }
while(q > buf && (q[-1] == ' ' || q[-1] == '\t')) }
*--q = 0; }
free(file); free(d);
return unsharp(buf); }
close(fd);
/*
* Handle 48x48xN directories in the right order.
*/
ndir = estrstrdup(dir, "/48x48x8");
for(i=8; i>0; i>>=1){
ndir[strlen(ndir)-1] = i+'0';
if(access(ndir, AEXIST) >= 0 && (x = tryfindfiledir(dom, user, ndir)) != nil){
free(ndir);
free(dom);
return x;
} }
} }
free(file); free(ndir);
return nil; free(dom);
return nil;
} }
static char* static char*
tryfindpicture(char *dom, char *user, int depth) tryfindfile(char *dom, char *user)
{ {
char* result; char *p;
if((result = tryfindpicture_user(dom, user, depth)) != nil) while(dom && *dom){
return result; if(homeface && (p = tryfindfiledir(dom, user, homeface)) != nil)
return p;
return tryfindpicture_global(dom, user, depth); if((p = tryfindfiledir(dom, user, libface)) != nil)
} return p;
if((dom = strchr(dom, '.')) == nil)
static char*
tryfindfile(char *dom, char *user, int depth)
{
char *p, *q;
for(;;){
for(p=dom; p; (p=strchr(p, '.')) && p++)
if(q = tryfindpicture(p, user, depth))
return q;
depth >>= 1;
if(depth == 0)
break; break;
dom++;
} }
return nil; return nil;
} }
@ -314,34 +346,31 @@ char*
findfile(Face *f, char *dom, char *user) findfile(Face *f, char *dom, char *user)
{ {
char *p; char *p;
int depth;
if(facedom == nil){ if(facedom == nil){
facedom = getenv("facedom"); facedom = getenv("facedom");
if(facedom == nil) if(facedom == nil)
facedom = DEFAULT; facedom = DEFAULT;
} }
if(libface == nil)
libface = unsharp("#9/face");
if(machinelist == nil)
machinelist = estrstrdup(libface, "/.machinelist");
if(homeface == nil)
homeface = smprint("%s/lib/face", getenv("HOME"));
dom = translatedomain(dom); dom = translatedomain(dom, machinelist);
if(dom == nil) if(dom == nil)
dom = facedom; dom = facedom;
if(screen == nil)
depth = 8;
else
depth = screen->depth;
if(depth > 8)
depth = 8;
f->unknown = 0; f->unknown = 0;
if(p = tryfindfile(dom, user, depth)) if((p = tryfindfile(dom, user)) != nil)
return p; return p;
f->unknown = 1; f->unknown = 1;
p = tryfindfile(dom, "unknown", depth); p = tryfindfile(dom, "unknown");
if(p != nil || strcmp(dom, facedom)==0) if(p != nil || strcmp(dom, facedom) == 0)
return p; return p;
return tryfindfile("unknown", "unknown", depth); return tryfindfile("unknown", "unknown");
} }
static static

View file

@ -77,7 +77,7 @@ int ndown;
char date[64]; char date[64];
Face **faces; Face **faces;
char *maildir = "INBOX"; char *maildir = "mbox";
ulong now; ulong now;
Point datep = { 8, 6 }; Point datep = { 8, 6 };
@ -108,7 +108,7 @@ init(void)
initplumb(); initplumb();
/* make background color */ /* make background color */
bgrnd = allocimagemix(display, DPalebluegreen, DWhite); bgrnd = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DWhite);
blue = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x008888FF); /* blue-green */ blue = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x008888FF); /* blue-green */
left = allocimage(display, leftright, GREY1, 0, DWhite); left = allocimage(display, leftright, GREY1, 0, DWhite);
right = allocimage(display, leftright, GREY1, 0, DWhite); right = allocimage(display, leftright, GREY1, 0, DWhite);

View file

@ -22,5 +22,5 @@ UPDATE=\
<$PLAN9/src/mkone <$PLAN9/src/mkone
CFLAGS=$CFLAGS '-DDEFAULT='$DEFAULT CFLAGS=$CFLAGS '-DDEFAULT='$DEFAULT
$O.dblook: dblook.$O facedb.$O util.$O dblook: dblook.$O facedb.$O util.$O
$LD -o $target $prereq $LD -o $target $prereq

View file

@ -45,24 +45,23 @@ attr(Face *f)
void void
showmail(Face *f) showmail(Face *f)
{ {
char buf[256];
Plumbmsg pm; Plumbmsg pm;
Plumbattr a; Plumbattr a;
char *s;
if(showfd<0 || f->str[Sshow]==nil || f->str[Sshow][0]=='\0') if(showfd<0 || f->str[Sshow]==nil || f->str[Sshow][0]=='\0')
return; return;
s = emalloc(strlen("/mail/fs")+1+strlen(f->str[Sshow])); snprint(buf, sizeof buf, "Mail/%s", f->str[Sshow]);
sprint(s,"/mail/fs/%s",f->str[Sshow]);
pm.src = "faces"; pm.src = "faces";
pm.dst = "showmail"; pm.dst = "showmail";
pm.wdir = "/mail/fs"; pm.wdir = "/";
pm.type = "text"; pm.type = "text";
a.name = "digest"; a.name = "digest";
a.value = f->str[Sdigest]; a.value = f->str[Sdigest];
a.next = nil; a.next = nil;
pm.attr = &a; pm.attr = &a;
pm.ndata = strlen(s); pm.ndata = strlen(buf);
pm.data = s; pm.data = buf;
plumbsendtofid(showfd, &pm); plumbsendtofid(showfd, &pm);
} }
@ -203,12 +202,9 @@ nextface(void)
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)
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); plumbfree(m);
continue; continue;