mailfs: add -r flag to specify mail root (Richard Bilson)
This commit is contained in:
parent
f1ea0d2916
commit
e84044be84
3 changed files with 38 additions and 13 deletions
|
|
@ -17,6 +17,7 @@ struct Imap
|
||||||
int autoreconnect;
|
int autoreconnect;
|
||||||
int ticks; /* until boom! */
|
int ticks; /* until boom! */
|
||||||
char* server;
|
char* server;
|
||||||
|
char* root;
|
||||||
int mode;
|
int mode;
|
||||||
int fd;
|
int fd;
|
||||||
Biobuf b;
|
Biobuf b;
|
||||||
|
|
@ -90,7 +91,7 @@ static Sx* zBrdsx(Imap*);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Imap*
|
Imap*
|
||||||
imapconnect(char *server, int mode)
|
imapconnect(char *server, int mode, char *root)
|
||||||
{
|
{
|
||||||
Imap *z;
|
Imap *z;
|
||||||
|
|
||||||
|
|
@ -100,6 +101,13 @@ imapconnect(char *server, int mode)
|
||||||
z = emalloc(sizeof *z);
|
z = emalloc(sizeof *z);
|
||||||
z->server = estrdup(server);
|
z->server = estrdup(server);
|
||||||
z->mode = mode;
|
z->mode = mode;
|
||||||
|
if(root)
|
||||||
|
if(root[0] != 0 && root[strlen(root)-1] != '/')
|
||||||
|
z->root = smprint("%s/", root);
|
||||||
|
else
|
||||||
|
z->root = root;
|
||||||
|
else
|
||||||
|
z->root = "";
|
||||||
z->fd = -1;
|
z->fd = -1;
|
||||||
z->autoreconnect = 0;
|
z->autoreconnect = 0;
|
||||||
z->io = ioproc();
|
z->io = ioproc();
|
||||||
|
|
@ -220,7 +228,9 @@ getboxes(Imap *z)
|
||||||
boxes[i]->exists = 0;
|
boxes[i]->exists = 0;
|
||||||
boxes[i]->maxseen = 0;
|
boxes[i]->maxseen = 0;
|
||||||
}
|
}
|
||||||
if(imapcmd(z, nil, "LIST %Z *", "") < 0)
|
if(imapcmd(z, nil, "LIST %Z *", z->root) < 0)
|
||||||
|
return -1;
|
||||||
|
if(z->root != nil && imapcmd(z, nil, "LIST %Z INBOX", "") < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if(z->nextbox && z->nextbox->mark)
|
if(z->nextbox && z->nextbox->mark)
|
||||||
z->nextbox = nil;
|
z->nextbox = nil;
|
||||||
|
|
@ -739,7 +749,8 @@ imapdial(char *server, int mode)
|
||||||
fd[1] = dup(p[0], -1);
|
fd[1] = dup(p[0], -1);
|
||||||
fd[2] = dup(2, -1);
|
fd[2] = dup(2, -1);
|
||||||
tmp = esmprint("%s:993", server);
|
tmp = esmprint("%s:993", server);
|
||||||
if(threadspawnl(fd, "/usr/sbin/stunnel", "stunnel", "-c", "-r", tmp, nil) < 0){
|
if(threadspawnl(fd, "/usr/sbin/stunnel", "stunnel", "-c", "-r", tmp, nil) < 0
|
||||||
|
&& threadspawnl(fd, "/usr/bin/stunnel", "stunnel", "-c", "-r", tmp, nil) < 0){
|
||||||
free(tmp);
|
free(tmp);
|
||||||
close(p[0]);
|
close(p[0]);
|
||||||
close(p[1]);
|
close(p[1]);
|
||||||
|
|
@ -1223,21 +1234,31 @@ xlist(Imap *z, Sx *sx)
|
||||||
s = gsub(s, sx->sx[3]->data, "/");
|
s = gsub(s, sx->sx[3]->data, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* INBOX is the special imap name for the main mailbox.
|
||||||
|
* All other mailbox names have the root prefix removed, if applicable.
|
||||||
|
*/
|
||||||
|
inbox = 0;
|
||||||
|
if(cistrcmp(s, "INBOX") == 0){
|
||||||
|
inbox = 1;
|
||||||
|
free(s);
|
||||||
|
s = estrdup("mbox");
|
||||||
|
} else if(z->root && strstr(s, z->root) == s) {
|
||||||
|
t = estrdup(s+strlen(z->root));
|
||||||
|
free(s);
|
||||||
|
s = t;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Plan 9 calls the main mailbox mbox.
|
* Plan 9 calls the main mailbox mbox.
|
||||||
* Rename any existing mbox by appending a $.
|
* Rename any existing mbox by appending a $.
|
||||||
*/
|
*/
|
||||||
inbox = 0;
|
if(!inbox && strncmp(s, "mbox", 4) == 0 && alldollars(s+4)){
|
||||||
if(strncmp(s, "mbox", 4) == 0 && alldollars(s+4)){
|
|
||||||
t = emalloc(strlen(s)+2);
|
t = emalloc(strlen(s)+2);
|
||||||
strcpy(t, s);
|
strcpy(t, s);
|
||||||
strcat(t, "$");
|
strcat(t, "$");
|
||||||
free(s);
|
free(s);
|
||||||
s = t;
|
s = t;
|
||||||
}else if(cistrcmp(s, "INBOX") == 0){
|
|
||||||
inbox = 1;
|
|
||||||
free(s);
|
|
||||||
s = estrdup("mbox");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
box = boxcreate(s);
|
box = boxcreate(s);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
typedef struct Imap Imap;
|
typedef struct Imap Imap;
|
||||||
|
|
||||||
void imapcheckbox(Imap *z, Box *b);
|
void imapcheckbox(Imap *z, Box *b);
|
||||||
Imap* imapconnect(char *server, int mode);
|
Imap* imapconnect(char *server, int mode, char *root);
|
||||||
int imapcopylist(Imap *z, char *nbox, Msg **m, uint nm);
|
int imapcopylist(Imap *z, char *nbox, Msg **m, uint nm);
|
||||||
void imapfetchraw(Imap *z, Part *p);
|
void imapfetchraw(Imap *z, Part *p);
|
||||||
void imapfetchrawbody(Imap *z, Part *p);
|
void imapfetchrawbody(Imap *z, Part *p);
|
||||||
|
|
|
||||||
|
|
@ -22,17 +22,18 @@ Imap *imap;
|
||||||
void
|
void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprint(2, "usage: mailfs [-DVtx] [-s srvname] server\n");
|
fprint(2, "usage: mailfs [-DVtx] [-s srvname] [-r root] server\n");
|
||||||
threadexitsall("usage");
|
threadexitsall("usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
threadmain(int argc, char **argv)
|
threadmain(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *server, *srvname;
|
char *server, *srvname, *root;
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
srvname = "mail";
|
srvname = "mail";
|
||||||
|
root = "";
|
||||||
mode = Unencrypted;
|
mode = Unencrypted;
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
default:
|
default:
|
||||||
|
|
@ -52,6 +53,9 @@ threadmain(int argc, char **argv)
|
||||||
case 'x':
|
case 'x':
|
||||||
mode = Cmd;
|
mode = Cmd;
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
root = EARGF(usage());
|
||||||
|
break;
|
||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
||||||
quotefmtinstall();
|
quotefmtinstall();
|
||||||
|
|
@ -65,7 +69,7 @@ threadmain(int argc, char **argv)
|
||||||
boxinit();
|
boxinit();
|
||||||
fsinit0();
|
fsinit0();
|
||||||
|
|
||||||
if((imap = imapconnect(server, mode)) == nil)
|
if((imap = imapconnect(server, mode, root)) == nil)
|
||||||
sysfatal("imapconnect: %r");
|
sysfatal("imapconnect: %r");
|
||||||
threadpostmountsrv(&fs, srvname, nil, 0);
|
threadpostmountsrv(&fs, srvname, nil, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue