Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms.

This commit is contained in:
rsc 2006-04-01 19:24:03 +00:00
parent 226d80b821
commit cbeb0b26e4
492 changed files with 3218 additions and 3167 deletions

View file

@ -79,7 +79,7 @@ enum
Dfile,
Dignore,
PAD64= '=',
PAD64= '='
};
typedef struct Mailbox Mailbox;
@ -194,7 +194,7 @@ enum
Qmbox,
Qdir,
Qctl,
Qmboxctl,
Qmboxctl
};
#define PATH(id, f) ((((id)&0xfffff)<<10) | (f))

View file

@ -8,7 +8,7 @@
enum
{
OPERM = 0x3, // mask of all permission types in open mode
OPERM = 0x3, /* mask of all permission types in open mode */
};
typedef struct Fid Fid;
@ -22,15 +22,15 @@ struct Fid
Fid *next;
Mailbox *mb;
Message *m;
Message *mtop; // top level message
Message *mtop; /* top level message */
//finger pointers to speed up reads of large directories
long foff; // offset/DIRLEN of finger
Message *fptr; // pointer to message at off
int fvers; // mailbox version when finger was saved
/*finger pointers to speed up reads of large directories */
long foff; /* offset/DIRLEN of finger */
Message *fptr; /* pointer to message at off */
int fvers; /* mailbox version when finger was saved */
};
ulong path; // incremented for each new file
ulong path; /* incremented for each new file */
Fid *fids;
int mfd[2];
char user[Elemlen];
@ -81,7 +81,7 @@ char *(*fcalls[])(Fid*) = {
[Tclunk] rclunk,
[Tremove] rremove,
[Tstat] rstat,
[Twstat] rwstat,
[Twstat] rwstat
};
char Eperm[] = "permission denied";
@ -125,12 +125,12 @@ char *dirtab[] =
[Qunixdate] "unixdate",
[Qunixheader] "unixheader",
[Qctl] "ctl",
[Qmboxctl] "ctl",
[Qmboxctl] "ctl"
};
enum
{
Hsize= 1277,
Hsize= 1277
};
Hash *htab[Hsize];
@ -455,7 +455,7 @@ int infofields[] = {
Qsender,
Qmessageid,
Qlines,
-1,
-1
};
static int
@ -654,7 +654,7 @@ dowalk(Fid *f, char *name)
else
qlock(&mbllock);
// this must catch everything except . and ..
/* this must catch everything except . and .. */
retry:
h = hlook(f->qid.path, name);
if(h != nil){
@ -788,7 +788,7 @@ ropen(Fid *f)
if(file != Qctl && file != Qmboxctl)
return Eperm;
// make sure we've decoded
/* make sure we've decoded */
if(file == Qbody){
if(f->m->decoded == 0)
decode(f->m);
@ -865,7 +865,7 @@ readmboxdir(Fid *f, uchar *buf, long off, int cnt, int blen)
off -= m;
}
// to avoid n**2 reads of the directory, use a saved finger pointer
/* to avoid n**2 reads of the directory, use a saved finger pointer */
if(f->mb->vers == f->fvers && off >= f->foff && f->fptr != nil){
msg = f->fptr;
pos = f->foff;
@ -875,7 +875,7 @@ readmboxdir(Fid *f, uchar *buf, long off, int cnt, int blen)
}
for(; cnt > 0 && msg != nil; msg = msg->next){
// act like deleted files aren't there
/* act like deleted files aren't there */
if(msg->deleted)
continue;
@ -890,7 +890,7 @@ readmboxdir(Fid *f, uchar *buf, long off, int cnt, int blen)
pos += m;
}
// save a finger pointer for next read of the mbox directory
/* save a finger pointer for next read of the mbox directory */
f->foff = pos;
f->fptr = msg;
f->fvers = f->mb->vers;
@ -1370,7 +1370,7 @@ hdrlen(char *p, char *e)
return ep - p;
}
// rfc2047 non-ascii
/* rfc2047 non-ascii */
typedef struct Charset Charset;
struct Charset {
char *name;
@ -1386,7 +1386,7 @@ struct Charset {
{ "big5", 4, 2, "big5", },
{ "iso-2022-jp", 11, 2, "jis", },
{ "windows-1251", 12, 2, "cp1251"},
{ "koi8-r", 6, 2, "koi8"},
{ "koi8-r", 6, 2, "koi8"}
};
int
@ -1403,7 +1403,7 @@ rfc2047convert(String *s, char *token, int len)
e = token+len-2;
token += 2;
// bail if we don't understand the character set
/* bail if we don't understand the character set */
for(i = 0; i < nelem(charsets); i++)
if(cistrncmp(charsets[i].name, token, charsets[i].len) == 0)
if(token[charsets[i].len] == '?'){
@ -1413,11 +1413,11 @@ rfc2047convert(String *s, char *token, int len)
if(i >= nelem(charsets))
return -1;
// bail if it doesn't fit
/* bail if it doesn't fit */
if(e-token > sizeof(decoded)-1)
return -1;
// bail if we don't understand the encoding
/* bail if we don't understand the encoding */
if(cistrncmp(token, "b?", 2) == 0){
token += 2;
len = dec64((uchar*)decoded, sizeof(decoded), token, e-token);
@ -1483,7 +1483,7 @@ rfc2047start(char *start, char *end)
return nil;
}
// convert a header line
/* convert a header line */
String*
stringconvert(String *s, char *uneaten, int len)
{
@ -1521,7 +1521,7 @@ readheader(Message *m, char *buf, int off, int cnt)
e = m->hend;
s = nil;
// copy in good headers
/* copy in good headers */
while(cnt > 0 && p < e){
n = hdrlen(p, e);
if(ignore(p)){
@ -1529,7 +1529,7 @@ readheader(Message *m, char *buf, int off, int cnt)
continue;
}
// rfc2047 processing
/* rfc2047 processing */
s = stringconvert(s, p, n);
ns = s_len(s);
if(off > 0){

View file

@ -15,7 +15,7 @@ int pipeline = 1;
typedef struct Imap Imap;
struct Imap {
char *freep; // free this to free the strings below
char *freep; /* free this to free the strings below */
char *host;
char *user;
@ -38,7 +38,7 @@ struct Imap {
Thumbprint *thumb;
// open network connection
/* open network connection */
Biobuf bin;
Biobuf bout;
int fd;
@ -56,9 +56,9 @@ removecr(char *s)
return s;
}
//
// send imap4 command
//
/* */
/* send imap4 command */
/* */
static void
imap4cmd(Imap *imap, char *fmt, ...)
{
@ -89,7 +89,7 @@ enum {
EXISTS,
STATUS,
FETCH,
UNKNOWN,
UNKNOWN
};
static char *verblist[] = {
@ -99,7 +99,7 @@ static char *verblist[] = {
[BYE] "BYE",
[EXISTS] "EXISTS",
[STATUS] "STATUS",
[FETCH] "FETCH",
[FETCH] "FETCH"
};
static int
@ -141,7 +141,7 @@ imapgrow(Imap *imap, int n)
imap->size = n+1;
}
if(n >= imap->size){
// friggin microsoft - reallocate
/* friggin microsoft - reallocate */
i = imap->data - imap->base;
imap->base = erealloc(imap->base, i+n+1);
imap->data = imap->base + i;
@ -150,10 +150,10 @@ imapgrow(Imap *imap, int n)
}
//
// get imap4 response line. there might be various
// data or other informational lines mixed in.
//
/* */
/* get imap4 response line. there might be various */
/* data or other informational lines mixed in. */
/* */
static char*
imap4resp(Imap *imap)
{
@ -176,7 +176,7 @@ imap4resp(Imap *imap)
fprint(2, "unexpected: %s\n", p);
break;
// ``unsolicited'' information; everything happens here.
/* ``unsolicited'' information; everything happens here. */
case '*':
if(p[1]!=' ')
continue;
@ -196,19 +196,19 @@ imap4resp(Imap *imap)
case OK:
case NO:
case BAD:
// human readable text at p;
/* human readable text at p; */
break;
case BYE:
// early disconnect
// human readable text at p;
/* early disconnect */
/* human readable text at p; */
break;
// * 32 EXISTS
/* * 32 EXISTS */
case EXISTS:
imap->nmsg = n;
break;
// * STATUS Inbox (MESSAGES 2 UIDVALIDITY 960164964)
/* * STATUS Inbox (MESSAGES 2 UIDVALIDITY 960164964) */
case STATUS:
if(q = strstr(p, "MESSAGES"))
imap->nmsg = atoi(q+8);
@ -217,9 +217,9 @@ imap4resp(Imap *imap)
break;
case FETCH:
// * 1 FETCH (uid 8889 RFC822.SIZE 3031 body[] {3031}
// <3031 bytes of data>
// )
/* * 1 FETCH (uid 8889 RFC822.SIZE 3031 body[] {3031} */
/* <3031 bytes of data> */
/* ) */
if(strstr(p, "RFC822.SIZE") && strstr(p, "BODY[]")){
if((q = strchr(p, '{'))
&& (n=strtol(q+1, &en, 0), *en=='}')){
@ -257,16 +257,16 @@ imap4resp(Imap *imap)
break;
}
// * 1 FETCH (UID 1 RFC822.SIZE 511)
/* * 1 FETCH (UID 1 RFC822.SIZE 511) */
if(q=strstr(p, "RFC822.SIZE")){
imap->size = atoi(q+11);
break;
}
// * 1 FETCH (UID 1 RFC822.HEADER {496}
// <496 bytes of data>
// )
// * 1 FETCH (UID 1 RFC822.HEADER "data")
/* * 1 FETCH (UID 1 RFC822.HEADER {496} */
/* <496 bytes of data> */
/* ) */
/* * 1 FETCH (UID 1 RFC822.HEADER "data") */
if(strstr(p, "RFC822.HEADER") || strstr(p, "RFC822.TEXT")){
if((q = strchr(p, '{'))
&& (n=strtol(q+1, &en, 0), *en=='}')){
@ -304,8 +304,8 @@ imap4resp(Imap *imap)
break;
}
// * 1 FETCH (UID 1)
// * 2 FETCH (UID 6)
/* * 1 FETCH (UID 1) */
/* * 2 FETCH (UID 6) */
if(q = strstr(p, "UID")){
if(imap->nuid < imap->muid)
imap->uid[imap->nuid++] = ((vlong)imap->validity<<32)|strtoul(q+3, nil, 10);
@ -317,7 +317,7 @@ imap4resp(Imap *imap)
return line;
break;
case '9': // response to our message
case '9': /* response to our message */
op = p;
if(p[1]=='X' && strtoul(p+2, &p, 10)==imap->tag){
while(*p==' ')
@ -343,9 +343,9 @@ isokay(char *resp)
return strncmp(resp, "OK", 2)==0;
}
//
// log in to IMAP4 server, select mailbox, no SSL at the moment
//
/* */
/* log in to IMAP4 server, select mailbox, no SSL at the moment */
/* */
static char*
imap4login(Imap *imap)
{
@ -377,9 +377,9 @@ imap4login(Imap *imap)
return nil;
}
//
// push tls onto a connection
//
/* */
/* push tls onto a connection */
/* */
int
mypushtls(int fd)
{
@ -409,9 +409,9 @@ mypushtls(int fd)
return p[1];
}
//
// dial and handshake with the imap server
//
/* */
/* dial and handshake with the imap server */
/* */
static char*
imap4dial(Imap *imap)
{
@ -476,9 +476,9 @@ imap4dial(Imap *imap)
return nil;
}
//
// close connection
//
/* */
/* close connection */
/* */
#if 0 /* jpc */
static void
imap4hangup(Imap *imap)
@ -489,9 +489,9 @@ imap4hangup(Imap *imap)
}
#endif
//
// download a single message
//
/* */
/* download a single message */
/* */
static char*
imap4fetch(Mailbox *mb, Message *m)
{
@ -522,7 +522,7 @@ imap4fetch(Mailbox *mb, Message *m)
parse(m, 0, mb, 1);
// digest headers
/* digest headers */
sha1((uchar*)m->start, m->end - m->start, m->digest, nil);
for(i = 0; i < SHA1dlen; i++)
sprint(sdigest+2*i, "%2.2ux", m->digest[i]);
@ -531,10 +531,10 @@ imap4fetch(Mailbox *mb, Message *m)
return nil;
}
//
// check for new messages on imap4 server
// download new messages, mark deleted messages
//
/* */
/* check for new messages on imap4 server */
/* download new messages, mark deleted messages */
/* */
static char*
imap4read(Imap *imap, Mailbox *mb, int doplumb)
{
@ -565,7 +565,7 @@ imap4read(Imap *imap, Mailbox *mb, int doplumb)
l = &(*l)->next;
break;
}else{
// old mail, we don't have it anymore
/* old mail, we don't have it anymore */
if(doplumb)
mailplumb(mb, *l, 1);
(*l)->inmbox = 0;
@ -576,18 +576,18 @@ imap4read(Imap *imap, Mailbox *mb, int doplumb)
if(ignore)
continue;
// new message
/* new message */
m = newmessage(mb->root);
m->mallocd = 1;
m->inmbox = 1;
m->imapuid = imap->uid[i];
// add to chain, will download soon
/* add to chain, will download soon */
*l = m;
l = &m->next;
}
// whatever is left at the end of the chain is gone
/* whatever is left at the end of the chain is gone */
while(*l != nil){
if(doplumb)
mailplumb(mb, *l, 1);
@ -596,7 +596,7 @@ imap4read(Imap *imap, Mailbox *mb, int doplumb)
l = &(*l)->next;
}
// download new messages
/* download new messages */
t = imap->tag;
if(pipeline)
switch(rfork(RFPROC|RFMEM)){
@ -631,7 +631,7 @@ imap4read(Imap *imap, Mailbox *mb, int doplumb)
}
if(s = imap4fetch(mb, m)){
// message disappeared? unchain
/* message disappeared? unchain */
fprint(2, "download %lud: %s\n", (ulong)m->imapuid, s);
delmessage(mb, m);
mb->root->subname--;
@ -652,9 +652,9 @@ imap4read(Imap *imap, Mailbox *mb, int doplumb)
return nil;
}
//
// sync mailbox
//
/* */
/* sync mailbox */
/* */
static void
imap4purge(Imap *imap, Mailbox *mb)
{
@ -682,9 +682,9 @@ imap4purge(Imap *imap, Mailbox *mb)
}
}
//
// connect to imap4 server, sync mailbox
//
/* */
/* connect to imap4 server, sync mailbox */
/* */
static char*
imap4sync(Mailbox *mb, int doplumb)
{
@ -705,7 +705,7 @@ imap4sync(Mailbox *mb, int doplumb)
/*
* don't hang up; leave connection open for next time.
*/
// imap4hangup(imap);
/* imap4hangup(imap); */
mb->waketime = time(0) + imap->refreshtime;
return err;
}
@ -754,9 +754,9 @@ imap4ctl(Mailbox *mb, int argc, char **argv)
return Eimap4ctl;
}
//
// free extra memory associated with mb
//
/* */
/* free extra memory associated with mb */
/* */
static void
imap4close(Mailbox *mb)
{
@ -771,9 +771,9 @@ imap4close(Mailbox *mb)
free(imap);
}
//
// open mailboxes of the form /imap/host/user
//
/* */
/* open mailboxes of the form /imap/host/user */
/* */
char*
imap4mbox(Mailbox *mb, char *path)
{
@ -818,20 +818,20 @@ imap4mbox(Mailbox *mb, char *path)
mb->close = imap4close;
mb->ctl = imap4ctl;
mb->d = emalloc(sizeof(*mb->d));
//mb->fetch = imap4fetch;
/*mb->fetch = imap4fetch; */
return nil;
}
//
// Formatter for %"
// Use double quotes to protect white space, frogs, \ and "
//
/* */
/* Formatter for %" */
/* Use double quotes to protect white space, frogs, \ and " */
/* */
enum
{
Qok = 0,
Qquote,
Qbackslash,
Qbackslash
};
static int

View file

@ -53,7 +53,7 @@ Header head[] =
[Mhead] { "content-type:", ctype, },
{ "content-transfer-encoding:", cencoding, },
{ "content-disposition:", cdisposition, },
{ 0, },
{ 0, }
};
/* static void fatal(char *fmt, ...); jpc */
@ -76,13 +76,13 @@ char *Enotme = "path not served by this file server";
enum
{
Chunksize = 1024,
Chunksize = 1024
};
Mailboxinit *boxinit[] = {
imap4mbox,
pop3mbox,
plan9mbox,
plan9mbox
};
char*
@ -119,7 +119,7 @@ newmbox(char *path, char *name, int std)
}
rv = nil;
// check for a mailbox type
/* check for a mailbox type */
for(i=0; i<nelem(boxinit); i++)
if((rv = (*boxinit[i])(mb, path)) != Enotme)
break;
@ -128,13 +128,13 @@ newmbox(char *path, char *name, int std)
return "bad path";
}
// on error, give up
/* on error, give up */
if(rv){
free(mb);
return rv;
}
// make sure name isn't taken
/* make sure name isn't taken */
qlock(&mbllock);
for(l = &mbl; *l != nil; l = &(*l)->next){
if(strcmp((*l)->name, mb->name) == 0){
@ -150,7 +150,7 @@ newmbox(char *path, char *name, int std)
}
}
// always try locking
/* always try locking */
mb->dolock = 1;
mb->refs = 1;
@ -172,7 +172,7 @@ newmbox(char *path, char *name, int std)
return rv;
}
// close the named mailbox
/* close the named mailbox */
void
freembox(char *name)
{
@ -248,7 +248,7 @@ parseheaders(Message *m, int justmime, Mailbox *mb, int addfrom)
henter(PATH(m->id, Qdir), dirtab[i],
(Qid){PATH(m->id, i), 0, QTFILE}, m, mb);
// parse mime headers
/* parse mime headers */
p = m->header;
hl = s_new();
while(headerline(&p, hl)){
@ -266,7 +266,7 @@ parseheaders(Message *m, int justmime, Mailbox *mb, int addfrom)
}
s_free(hl);
// the blank line isn't really part of the body or header
/* the blank line isn't really part of the body or header */
if(justmime){
m->mhend = p;
m->hend = m->header;
@ -277,27 +277,27 @@ parseheaders(Message *m, int justmime, Mailbox *mb, int addfrom)
p++;
m->rbody = m->body = p;
// if type is text, get any nulls out of the body. This is
// for the two seans and imap clients that get confused.
/* if type is text, get any nulls out of the body. This is */
/* for the two seans and imap clients that get confused. */
if(strncmp(s_to_c(m->type), "text/", 5) == 0)
nullsqueeze(m);
//
// cobble together Unix-style from line
// for local mailbox messages, we end up recreating the
// original header.
// for pop3 messages, the best we can do is
// use the From: information and the RFC822 date.
//
/* */
/* cobble together Unix-style from line */
/* for local mailbox messages, we end up recreating the */
/* original header. */
/* for pop3 messages, the best we can do is */
/* use the From: information and the RFC822 date. */
/* */
if(m->unixdate == nil || strcmp(s_to_c(m->unixdate), "???") == 0
|| strcmp(s_to_c(m->unixdate), "Thu Jan 1 00:00:00 GMT 1970") == 0){
if(m->unixdate){
s_free(m->unixdate);
m->unixdate = nil;
}
// look for the date in the first Received: line.
// it's likely to be the right time zone (it's
// the local system) and in a convenient format.
/* look for the date in the first Received: line. */
/* it's likely to be the right time zone (it's */
/* the local system) and in a convenient format. */
if(cistrncmp(m->header, "received:", 9)==0){
if((q = strchr(m->header, ';')) != nil){
p = q;
@ -314,7 +314,7 @@ parseheaders(Message *m, int justmime, Mailbox *mb, int addfrom)
}
}
// fall back on the rfc822 date
/* fall back on the rfc822 date */
if(m->unixdate==nil && m->date822)
m->unixdate = date822tounix(s_to_c(m->date822));
}
@ -322,10 +322,10 @@ parseheaders(Message *m, int justmime, Mailbox *mb, int addfrom)
if(m->unixheader != nil)
s_free(m->unixheader);
// only fake header for top-level messages for pop3 and imap4
// clients (those protocols don't include the unix header).
// adding the unix header all the time screws up mime-attached
// rfc822 messages.
/* only fake header for top-level messages for pop3 and imap4 */
/* clients (those protocols don't include the unix header). */
/* adding the unix header all the time screws up mime-attached */
/* rfc822 messages. */
if(!addfrom && !m->unixfrom){
m->unixheader = nil;
return;
@ -365,7 +365,7 @@ parsebody(Message *m, Mailbox *mb)
{
Message *nm;
// recurse
/* recurse */
if(strncmp(s_to_c(m->type), "multipart/", 10) == 0){
parseattachments(m, mb);
} else if(strcmp(s_to_c(m->type), "message/rfc822") == 0){
@ -373,7 +373,7 @@ parsebody(Message *m, Mailbox *mb)
parseattachments(m, mb);
nm = m->part;
// promote headers
/* promote headers */
if(m->replyto822 == nil && m->from822 == nil && m->sender822 == nil){
m->from822 = promote(&nm->from822);
m->to822 = promote(&nm->to822);
@ -399,7 +399,7 @@ parseattachments(Message *m, Mailbox *mb)
Message *nm, **l;
char *p, *x;
// if there's a boundary, recurse...
/* if there's a boundary, recurse... */
if(m->boundary != nil){
p = m->body;
nm = nil;
@ -442,7 +442,7 @@ parseattachments(Message *m, Mailbox *mb)
return;
}
// if we've got an rfc822 message, recurse...
/* if we've got an rfc822 message, recurse... */
if(strcmp(s_to_c(m->type), "message/rfc822") == 0){
nm = newmessage(m);
m->part = nm;
@ -496,11 +496,11 @@ addr822(char *p)
for(; *p; p++){
c = *p;
// whitespace is ignored
/* whitespace is ignored */
if(!quoted && isspace(c) || c == '\r')
continue;
// strings are always treated as atoms
/* strings are always treated as atoms */
if(!quoted && c == '"'){
if(!addrdone && !incomment)
s_putc(s, c);
@ -520,7 +520,7 @@ addr822(char *p)
continue;
}
// ignore everything in an expicit comment
/* ignore everything in an expicit comment */
if(!quoted && c == '('){
incomment = 1;
continue;
@ -532,7 +532,7 @@ addr822(char *p)
continue;
}
// anticomments makes everything outside of them comments
/* anticomments makes everything outside of them comments */
if(!quoted && c == '<' && !inanticomment){
inanticomment = 1;
s = s_reset(s);
@ -544,7 +544,7 @@ addr822(char *p)
continue;
}
// commas separate addresses
/* commas separate addresses */
if(!quoted && c == ',' && !inanticomment){
s_terminate(s);
addrdone = 0;
@ -555,10 +555,10 @@ addr822(char *p)
continue;
}
// what's left is part of the address
/* what's left is part of the address */
s_putc(s, c);
// quoted characters are recognized only as characters
/* quoted characters are recognized only as characters */
if(c == '\\')
quoted = 1;
else
@ -801,7 +801,7 @@ newmessage(Message *parent)
return m;
}
// delete a message from a mailbox
/* delete a message from a mailbox */
void
delmessage(Mailbox *mb, Message *m)
{
@ -812,13 +812,13 @@ delmessage(Mailbox *mb, Message *m)
msgfreed++;
if(m->whole != m){
// unchain from parent
/* unchain from parent */
for(l = &m->whole->part; *l && *l != m; l = &(*l)->next)
;
if(*l != nil)
*l = m->next;
// clear out of name lookup hash table
/* clear out of name lookup hash table */
if(m->whole->whole == m->whole)
hfree(PATH(mb->id, Qmbox), m->name);
else
@ -862,7 +862,7 @@ delmessage(Mailbox *mb, Message *m)
free(m);
}
// mark messages (identified by path) for deletion
/* mark messages (identified by path) for deletion */
void
delmessages(int ac, char **av)
{
@ -1019,9 +1019,9 @@ setfilename(Message *m, char *p)
*p = '_';
}
//
// undecode message body
//
/* */
/* undecode message body */
/* */
void
decode(Message *m)
{
@ -1033,7 +1033,7 @@ decode(Message *m)
switch(m->encoding){
case Ebase64:
len = m->bend - m->body;
i = (len*3)/4+1; // room for max chars + null
i = (len*3)/4+1; /* room for max chars + null */
x = emalloc(i);
len = dec64((uchar*)x, i, m->body, len);
if(m->ballocd)
@ -1044,7 +1044,7 @@ decode(Message *m)
break;
case Equoted:
len = m->bend - m->body;
x = emalloc(len+2); // room for null and possible extra nl
x = emalloc(len+2); /* room for null and possible extra nl */
len = decquoted(x, m->body, m->bend);
if(m->ballocd)
free(m->body);
@ -1058,14 +1058,14 @@ decode(Message *m)
m->decoded = 1;
}
// convert latin1 to utf
/* convert latin1 to utf */
void
convert(Message *m)
{
int len;
char *x;
// don't convert if we're not a leaf, not text, or already converted
/* don't convert if we're not a leaf, not text, or already converted */
if(m->converted)
return;
if(m->part != nil)
@ -1161,7 +1161,7 @@ convert(Message *m)
enum
{
Self= 1,
Hex= 2,
Hex= 2
};
uchar tableqp[256];
@ -1243,7 +1243,7 @@ decquoted(char *out, char *in, char *e)
if(in < e)
p = decquotedline(p, in, e-1);
// make sure we end with a new line
/* make sure we end with a new line */
if(*(p-1) != '\n'){
*p++ = '\n';
*p = 0;
@ -1281,7 +1281,7 @@ is8bit(Message *m)
return count;
}
// translate latin1 directly since it fits neatly in utf
/* translate latin1 directly since it fits neatly in utf */
int
latin1toutf(char *out, char *in, char *e)
{
@ -1297,7 +1297,7 @@ latin1toutf(char *out, char *in, char *e)
return p - out;
}
// translate any thing else using the tcs program
/* translate any thing else using the tcs program */
int
xtoutf(char *charset, char **out, char *in, char *e)
{
@ -1334,7 +1334,7 @@ xtoutf(char *charset, char **out, char *in, char *e)
dup(totcs[0], 0);
close(fromtcs[1]); close(totcs[0]);
dup(open("/dev/null", OWRITE), 2);
//jpc exec("/bin/tcs", av);
/*jpc exec("/bin/tcs", av); */
exec(unsharp("#9/bin/tcs"), av);
/* _exits(0); */
threadexits(nil);
@ -1380,7 +1380,7 @@ xtoutf(char *charset, char **out, char *in, char *e)
enum {
Winstart= 0x7f,
Winend= 0x9f,
Winend= 0x9f
};
Rune winchars[] = {
@ -1388,7 +1388,7 @@ Rune winchars[] = {
L'', L'', L'', L'ƒ', L'', L'', L'', L'',
L'ˆ', L'', L'Š', L'', L'Œ', L'', L'', L'',
L'', L'', L'', L'', L'', L'', L'', L'',
L'˜', L'', L'š', L'', L'œ', L'', L'', L'Ÿ',
L'˜', L'', L'š', L'', L'œ', L'', L'', L'Ÿ'
};
int
@ -1518,9 +1518,9 @@ mailplumb(Mailbox *mb, Message *m, int delete)
plumbsend(fd, &p);
}
//
// count the number of lines in the body (for imap4)
//
/* */
/* count the number of lines in the body (for imap4) */
/* */
void
countlines(Message *m)
{
@ -1573,15 +1573,15 @@ nullsqueeze(Message *m)
}
//
// convert an RFC822 date into a Unix style date
// for when the Unix From line isn't there (e.g. POP3).
// enough client programs depend on having a Unix date
// that it's easiest to write this conversion code once, right here.
//
// people don't follow RFC822 particularly closely,
// so we use strtotm, which is a bunch of heuristics.
//
/* */
/* convert an RFC822 date into a Unix style date */
/* for when the Unix From line isn't there (e.g. POP3). */
/* enough client programs depend on having a Unix date */
/* that it's easiest to write this conversion code once, right here. */
/* */
/* people don't follow RFC822 particularly closely, */
/* so we use strtotm, which is a bunch of heuristics. */
/* */
extern int strtotm(char*, Tm*);
String*

View file

@ -5,7 +5,7 @@
#include "dat.h"
enum {
Buffersize = 64*1024,
Buffersize = 64*1024
};
typedef struct Inbuf Inbuf;
@ -23,7 +23,7 @@ addtomessage(Message *m, uchar *p, int n, int done)
{
int i, len;
// add to message (+ 1 in malloc is for a trailing null)
/* add to message (+ 1 in malloc is for a trailing null) */
if(m->lim - m->end < n){
if(m->start != nil){
i = m->end-m->start;
@ -48,9 +48,9 @@ addtomessage(Message *m, uchar *p, int n, int done)
m->end += n;
}
//
// read in a single message
//
/* */
/* read in a single message */
/* */
static int
readmessage(Message *m, Inbuf *inb)
{
@ -83,9 +83,9 @@ readmessage(Message *m, Inbuf *inb)
inb->wptr += i;
}
// look for end of message
/* look for end of message */
for(p = inb->rptr; p < inb->wptr; p = np+1){
// first part of search for '\nFrom '
/* first part of search for '\nFrom ' */
np = memchr(p, '\n', inb->wptr - p);
if(np == nil){
p = inb->wptr;
@ -109,24 +109,24 @@ readmessage(Message *m, Inbuf *inb)
}
}
// add to message (+ 1 in malloc is for a trailing null)
/* add to message (+ 1 in malloc is for a trailing null) */
n = p - inb->rptr;
addtomessage(m, inb->rptr, n, done);
inb->rptr += n;
}
// if it doesn't start with a 'From ', this ain't a mailbox
/* if it doesn't start with a 'From ', this ain't a mailbox */
if(strncmp(m->start, "From ", 5) != 0)
return -1;
// dump trailing newline, make sure there's a trailing null
// (helps in body searches)
/* dump trailing newline, make sure there's a trailing null */
/* (helps in body searches) */
if(*(m->end-1) == '\n')
m->end--;
*m->end = 0;
m->bend = m->rbend = m->end;
// digest message
/* digest message */
sha1((uchar*)m->start, m->end - m->start, m->digest, nil);
for(i = 0; i < SHA1dlen; i++)
sprint(sdigest+2*i, "%2.2ux", m->digest[i]);
@ -136,14 +136,14 @@ readmessage(Message *m, Inbuf *inb)
}
// throw out deleted messages. return number of freshly deleted messages
/* throw out deleted messages. return number of freshly deleted messages */
int
purgedeleted(Mailbox *mb)
{
Message *m, *next;
int newdels;
// forget about what's no longer in the mailbox
/* forget about what's no longer in the mailbox */
newdels = 0;
for(m = mb->root->part; m != nil; m = next){
next = m->next;
@ -156,9 +156,9 @@ purgedeleted(Mailbox *mb)
return newdels;
}
//
// read in the mailbox and parse into messages.
//
/* */
/* read in the mailbox and parse into messages. */
/* */
static char*
_readmbox(Mailbox *mb, int doplumb, Mlock *lk)
{
@ -223,7 +223,7 @@ retry:
inb->rptr = inb->wptr = inb->data;
inb->fd = fd;
// read new messages
/* read new messages */
snprint(err, sizeof err, "reading '%s'", mb->path);
logmsg(err, nil);
for(;;){
@ -238,10 +238,10 @@ retry:
break;
}
// merge mailbox versions
/* merge mailbox versions */
while(*l != nil){
if(memcmp((*l)->digest, m->digest, SHA1dlen) == 0){
// matches mail we already read, discard
/* matches mail we already read, discard */
logmsg("duplicate", *l);
delmessage(mb, m);
mb->root->subname--;
@ -249,7 +249,7 @@ retry:
l = &(*l)->next;
break;
} else {
// old mail no longer in box, mark deleted
/* old mail no longer in box, mark deleted */
logmsg("disappeared", *l);
if(doplumb)
mailplumb(mb, *l, 1);
@ -280,7 +280,7 @@ retry:
}
logmsg("mbox read", nil);
// whatever is left has been removed from the mbox, mark deleted
/* whatever is left has been removed from the mbox, mark deleted */
while(*l != nil){
if(doplumb)
mailplumb(mb, *l, 1);
@ -380,9 +380,9 @@ plan9syncmbox(Mailbox *mb, int doplumb)
return rv;
}
//
// look to see if we can open this mail box
//
/* */
/* look to see if we can open this mail box */
/* */
char*
plan9mbox(Mailbox *mb, char *path)
{

View file

@ -11,7 +11,7 @@
typedef struct Pop Pop;
struct Pop {
char *freep; // free this to free the strings below
char *freep; /* free this to free the strings below */
char *host;
char *user;
@ -26,11 +26,11 @@ struct Pop {
int notls;
int needssl;
// open network connection
/* open network connection */
Biobuf bin;
Biobuf bout;
int fd;
char *lastline; // from Brdstr
char *lastline; /* from Brdstr */
Thumbprint *thumb;
};
@ -45,11 +45,11 @@ geterrstr(void)
return err;
}
//
// get pop3 response line , without worrying
// about multiline responses; the clients
// will deal with that.
//
/* */
/* get pop3 response line , without worrying */
/* about multiline responses; the clients */
/* will deal with that. */
/* */
static int
isokay(char *s)
{
@ -124,7 +124,7 @@ pop3pushtls(Pop *pop)
TLSconn conn;
memset(&conn, 0, sizeof conn);
// conn.trace = pop3log;
/* conn.trace = pop3log; */
fd = tlsClient(pop->fd, &conn);
if(fd < 0)
return "tls error";
@ -149,9 +149,9 @@ pop3pushtls(Pop *pop)
return nil;
}
//
// get capability list, possibly start tls
//
/* */
/* get capability list, possibly start tls */
/* */
static char*
pop3capa(Pop *pop)
{
@ -183,9 +183,9 @@ pop3capa(Pop *pop)
return nil;
}
//
// log in using APOP if possible, password if allowed by user
//
/* */
/* log in using APOP if possible, password if allowed by user */
/* */
static char*
pop3login(Pop *pop)
{
@ -204,7 +204,7 @@ pop3login(Pop *pop)
else
ubuf[0] = '\0';
// look for apop banner
/* look for apop banner */
if(pop->ppop==0 && (p = strchr(s, '<')) && (q = strchr(p+1, '>'))) {
*++q = '\0';
if((n=auth_respond(p, q-p, user, sizeof user, buf, sizeof buf, auth_getkey, "proto=apop role=client server=%q%s",
@ -250,9 +250,9 @@ pop3login(Pop *pop)
}
}
//
// dial and handshake with pop server
//
/* */
/* dial and handshake with pop server */
/* */
static char*
pop3dial(Pop *pop)
{
@ -277,9 +277,9 @@ pop3dial(Pop *pop)
return nil;
}
//
// close connection
//
/* */
/* close connection */
/* */
static void
pop3hangup(Pop *pop)
{
@ -288,9 +288,9 @@ pop3hangup(Pop *pop)
close(pop->fd);
}
//
// download a single message
//
/* */
/* download a single message */
/* */
static char*
pop3download(Pop *pop, Message *m)
{
@ -361,13 +361,13 @@ pop3download(Pop *pop, Message *m)
m->end = wp;
// make sure there's a trailing null
// (helps in body searches)
/* make sure there's a trailing null */
/* (helps in body searches) */
*m->end = 0;
m->bend = m->rbend = m->end;
m->header = m->start;
// digest message
/* digest message */
sha1((uchar*)m->start, m->end - m->start, m->digest, nil);
for(i = 0; i < SHA1dlen; i++)
sprint(sdigest+2*i, "%2.2ux", m->digest[i]);
@ -376,12 +376,12 @@ pop3download(Pop *pop, Message *m)
return nil;
}
//
// check for new messages on pop server
// UIDL is not required by RFC 1939, but
// netscape requires it, so almost every server supports it.
// we'll use it to make our lives easier.
//
/* */
/* check for new messages on pop server */
/* UIDL is not required by RFC 1939, but */
/* netscape requires it, so almost every server supports it. */
/* we'll use it to make our lives easier. */
/* */
static char*
pop3read(Pop *pop, Mailbox *mb, int doplumb)
{
@ -389,12 +389,12 @@ pop3read(Pop *pop, Mailbox *mb, int doplumb)
int mesgno, ignore, nnew;
Message *m, *next, **l;
// Some POP servers disallow UIDL if the maildrop is empty.
/* Some POP servers disallow UIDL if the maildrop is empty. */
pop3cmd(pop, "STAT");
if(!isokay(s = pop3resp(pop)))
return s;
// fetch message listing; note messages to grab
/* fetch message listing; note messages to grab */
l = &mb->root->part;
if(strncmp(s, "+OK 0 ", 6) != 0) {
pop3cmd(pop, "UIDL");
@ -411,19 +411,19 @@ pop3read(Pop *pop, Mailbox *mb, int doplumb)
mesgno = atoi(f[0]);
uidl = f[1];
if(strlen(uidl) > 75) // RFC 1939 says 70 characters max
if(strlen(uidl) > 75) /* RFC 1939 says 70 characters max */
continue;
ignore = 0;
while(*l != nil) {
if(strcmp((*l)->uidl, uidl) == 0) {
// matches mail we already have, note mesgno for deletion
/* matches mail we already have, note mesgno for deletion */
(*l)->mesgno = mesgno;
ignore = 1;
l = &(*l)->next;
break;
} else {
// old mail no longer in box mark deleted
/* old mail no longer in box mark deleted */
if(doplumb)
mailplumb(mb, *l, 1);
(*l)->inmbox = 0;
@ -440,13 +440,13 @@ pop3read(Pop *pop, Mailbox *mb, int doplumb)
m->mesgno = mesgno;
strcpy(m->uidl, uidl);
// chain in; will fill in message later
/* chain in; will fill in message later */
*l = m;
l = &m->next;
}
}
// whatever is left has been removed from the mbox, mark as deleted
/* whatever is left has been removed from the mbox, mark as deleted */
while(*l != nil) {
if(doplumb)
mailplumb(mb, *l, 1);
@ -455,7 +455,7 @@ pop3read(Pop *pop, Mailbox *mb, int doplumb)
l = &(*l)->next;
}
// download new messages
/* download new messages */
nnew = 0;
if(pop->pipeline){
switch(rfork(RFPROC|RFMEM)){
@ -485,7 +485,7 @@ pop3read(Pop *pop, Mailbox *mb, int doplumb)
continue;
if(s = pop3download(pop, m)) {
// message disappeared? unchain
/* message disappeared? unchain */
fprint(2, "download %d: %s\n", m->mesgno, s);
delmessage(mb, m);
mb->root->subname--;
@ -509,9 +509,9 @@ pop3read(Pop *pop, Mailbox *mb, int doplumb)
return nil;
}
//
// delete marked messages
//
/* */
/* delete marked messages */
/* */
static void
pop3purge(Pop *pop, Mailbox *mb)
{
@ -554,7 +554,7 @@ pop3purge(Pop *pop, Mailbox *mb)
}
// connect to pop3 server, sync mailbox
/* connect to pop3 server, sync mailbox */
static char*
pop3sync(Mailbox *mb, int doplumb)
{
@ -625,7 +625,7 @@ pop3ctl(Mailbox *mb, int argc, char **argv)
return Epop3ctl;
}
// free extra memory associated with mb
/* free extra memory associated with mb */
static void
pop3close(Mailbox *mb)
{
@ -636,9 +636,9 @@ pop3close(Mailbox *mb)
free(pop);
}
//
// open mailboxes of the form /pop/host/user or /apop/host/user
//
/* */
/* open mailboxes of the form /pop/host/user or /apop/host/user */
/* */
char*
pop3mbox(Mailbox *mb, char *path)
{