From: Art Cancro Date: Tue, 23 Mar 1999 04:33:51 +0000 (+0000) Subject: ARRGH X-Git-Tag: v7.86~7816 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=40f5f208d4fe137829d006eca0d80008882e7e1f;p=citadel.git ARRGH --- diff --git a/citadel/citmail.c b/citadel/citmail.c index aefd43b16..9f179352f 100644 --- a/citadel/citmail.c +++ b/citadel/citmail.c @@ -39,8 +39,9 @@ #undef tolower #define tolower(x) isupper(x) ? (x+'a'-'A') : x -char *monthdesc[] = { "Jan","Feb","Mar","Apr","May","Jun", - "Jul","Aug","Sep","Oct","Nov","Dec" }; +char *monthdesc[] = +{"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; char ALIASES[128]; char CIT86NET[128]; @@ -54,73 +55,72 @@ int RUN_NETPROC = 1; long conv_date(char *sdbuf) { - int a,b,cpos,tend,tval; + int a, b, cpos, tend, tval; time_t now; struct tm *tmbuf; char dbuf[128]; - strcpy(dbuf,sdbuf); + strcpy(dbuf, sdbuf); time(&now); - tmbuf = (struct tm *)localtime(&now); + tmbuf = (struct tm *) localtime(&now); /* get rid of + or - timezone mods */ - for (a=0; a=0; --a) - if ((dbuf[a]==':')&&(atoi(&dbuf[a-1])!=0)) cpos=a; - if (cpos>=0) { + for (a = strlen(dbuf); a >= 0; --a) + if ((dbuf[a] == ':') && (atoi(&dbuf[a - 1]) != 0)) + cpos = a; + if (cpos >= 0) { cpos = cpos - 2; tend = strlen(dbuf); - for (a=tend; a>=cpos; --a) if (dbuf[a]==' ') tend=a; + for (a = tend; a >= cpos; --a) + if (dbuf[a] == ' ') + tend = a; tmbuf->tm_hour = atoi(&dbuf[cpos]); - tmbuf->tm_min = atoi(&dbuf[cpos+3]); - tmbuf->tm_sec = atoi(&dbuf[cpos+6]); + tmbuf->tm_min = atoi(&dbuf[cpos + 3]); + tmbuf->tm_sec = atoi(&dbuf[cpos + 6]); do { - strcpy(&dbuf[cpos],&dbuf[cpos+1]); - } while ((dbuf[cpos]!=32)&&(dbuf[cpos]!=0)); - } - + strcpy(&dbuf[cpos], &dbuf[cpos + 1]); + } while ((dbuf[cpos] != 32) && (dbuf[cpos] != 0)); + } /* next try to extract a month */ - + tval = (-1); - for (a=0; a= 0) { tmbuf->tm_mon = tval; - strcpy(&dbuf[cpos],&dbuf[cpos+3]); - } - + strcpy(&dbuf[cpos], &dbuf[cpos + 3]); + } /* now the year */ - for (a=0; a=1900) && (dbuf[a]!=32)) { + for (a = 0; a < strlen(dbuf); ++a) + if ((atoi(&dbuf[a]) >= 1900) && (dbuf[a] != 32)) { tmbuf->tm_year = atoi(&dbuf[a]) - 1900; - strcpy(&dbuf[a],&dbuf[a+4]); - } - + strcpy(&dbuf[a], &dbuf[a + 4]); + } /* whatever's left is the mday (hopefully) */ - for (a=0; a=1)&&(atoi(&dbuf[a])<=31) - && ( (a==0)||(dbuf[a-1]==' ') ) ) { + for (a = 0; a < strlen(dbuf); ++a) + if ((dbuf[a] != 32) && (atoi(&dbuf[a]) >= 1) && (atoi(&dbuf[a]) <= 31) + && ((a == 0) || (dbuf[a - 1] == ' '))) { tmbuf->tm_mday = atoi(&dbuf[a]); - strcpy(&dbuf[a],&dbuf[a+2]); - } - - return((long)mktime(tmbuf)); - } + strcpy(&dbuf[a], &dbuf[a + 2]); + } + return ((long) mktime(tmbuf)); +} #ifndef HAVE_STRERROR @@ -131,37 +131,42 @@ char *strerror(int e) { static char buf[32]; - snprintf(buf,sizeof buf,"errno = %d",e); - return(buf); - } + snprintf(buf, sizeof buf, "errno = %d", e); + return (buf); +} #endif int haschar(char *st, int ch) { - int a,b; - b=0; - for (a=0; a0) && (buf[0]==32) ) strcpy(buf,&buf[1]); - while (buf[strlen(buf)-1] == 32) buf[strlen(buf)-1] = 0; - } + while ((strlen(buf) > 0) && (buf[0] == 32)) + strcpy(buf, &buf[1]); + while (buf[strlen(buf) - 1] == 32) + buf[strlen(buf) - 1] = 0; +} /* * Check to see if a given FQDN really maps to a Citadel network node */ -void host_alias(char host[]) { +void host_alias(char host[]) +{ int a; @@ -170,21 +175,21 @@ void host_alias(char host[]) { if (IsHostLocal(host)) { strcpy(host, config.c_nodename); return; - } - + } /* Other hosts in the gateway domain? */ - for (a=0; a */ - strcpy(name,rfc822); - for (a=0; a 0) && (name[a]!='>') ); - strcpy(&name[a],&name[a+1]); + strcpy(name, rfc822); + for (a = 0; a < strlen(name); ++a) + if (name[a] == '<') { + do { + strcpy(&name[a], &name[a + 1]); + } while ((strlen(name) > 0) && (name[a] != '>')); + strcpy(&name[a], &name[a + 1]); } - /* strip anything to the left of a bang */ - while ( (strlen(name)>0) && (haschar(name,'!')>0) ) - strcpy(name,&name[1]); + while ((strlen(name) > 0) && (haschar(name, '!') > 0)) + strcpy(name, &name[1]); /* and anything to the right of a @ or % */ - for (a=0; a 0) && (name[0]!='(') ) { - strcpy(&name[0],&name[1]); - } - strcpy(&name[0],&name[1]); - for (a=0; a 0) && (name[0] != '(')) { + strcpy(&name[0], &name[1]); + } + strcpy(&name[0], &name[1]); + for (a = 0; a < strlen(name); ++a) + if (name[a] == ')') + name[a] = 0; + } /* but if there are a set of quotes, that supersedes everything */ - if (haschar(rfc822,34)==2) { - strcpy(name,rfc822); - while ( (strlen(name) > 0) && (name[0]!=34) ) { - strcpy(&name[0],&name[1]); - } - strcpy(&name[0],&name[1]); - for (a=0; a 0) && (name[0] != 34)) { + strcpy(&name[0], &name[1]); + } + strcpy(&name[0], &name[1]); + for (a = 0; a < strlen(name); ++a) + if (name[a] == 34) + name[a] = 0; + } /* extract user id */ - strcpy(user,rfc822); + strcpy(user, rfc822); /* first get rid of anything in parens */ - for (a=0; a 0) && (user[a]!=')') ); - strcpy(&user[a],&user[a+1]); + for (a = 0; a < strlen(user); ++a) + if (user[a] == '(') { + do { + strcpy(&user[a], &user[a + 1]); + } while ((strlen(user) > 0) && (user[a] != ')')); + strcpy(&user[a], &user[a + 1]); } - /* if there's a set of angle brackets, strip it down to that */ - if ( (haschar(user,'<') == 1) && (haschar(user,'>') == 1) ) { - while ( (strlen(user) > 0) && (user[0]!='<') ) { - strcpy(&user[0],&user[1]); - } - strcpy(&user[0],&user[1]); - for (a=0; a') user[a]=0; - } - + if ((haschar(user, '<') == 1) && (haschar(user, '>') == 1)) { + while ((strlen(user) > 0) && (user[0] != '<')) { + strcpy(&user[0], &user[1]); + } + strcpy(&user[0], &user[1]); + for (a = 0; a < strlen(user); ++a) + if (user[a] == '>') + user[a] = 0; + } /* strip anything to the left of a bang */ - while ( (strlen(user)>0) && (haschar(user,'!')>0) ) - strcpy(user,&user[1]); + while ((strlen(user) > 0) && (haschar(user, '!') > 0)) + strcpy(user, &user[1]); /* and anything to the right of a @ or % */ - for (a=0; a 0) && (node[a]!=')') ); - strcpy(&node[a],&node[a+1]); + for (a = 0; a < strlen(node); ++a) + if (node[a] == '(') { + do { + strcpy(&node[a], &node[a + 1]); + } while ((strlen(node) > 0) && (node[a] != ')')); + strcpy(&node[a], &node[a + 1]); } - /* if there's a set of angle brackets, strip it down to that */ - if ( (haschar(node,'<') == 1) && (haschar(node,'>') == 1) ) { - while ( (strlen(node) > 0) && (node[0]!='<') ) { - strcpy(&node[0],&node[1]); - } - strcpy(&node[0],&node[1]); - for (a=0; a') node[a]=0; - } - + if ((haschar(node, '<') == 1) && (haschar(node, '>') == 1)) { + while ((strlen(node) > 0) && (node[0] != '<')) { + strcpy(&node[0], &node[1]); + } + strcpy(&node[0], &node[1]); + for (a = 0; a < strlen(node); ++a) + if (node[a] == '>') + node[a] = 0; + } /* strip anything to the left of a @ */ - while ( (strlen(node)>0) && (haschar(node,'@')>0) ) - strcpy(node,&node[1]); + while ((strlen(node) > 0) && (haschar(node, '@') > 0)) + strcpy(node, &node[1]); /* strip anything to the left of a % */ - while ( (strlen(node)>0) && (haschar(node,'%')>0) ) - strcpy(node,&node[1]); + while ((strlen(node) > 0) && (haschar(node, '%') > 0)) + strcpy(node, &node[1]); /* reduce multiple system bang paths to node!user */ - while ( (strlen(node)>0) && (haschar(node,'!')>1) ) - strcpy(node,&node[1]); + while ((strlen(node) > 0) && (haschar(node, '!') > 1)) + strcpy(node, &node[1]); /* now get rid of the user portion of a node!user string */ - for (a=0; a 0) { fprintf(temp, "O%s%c", targetroom, 0); - } - else { + } else { fprintf(temp, "O%s%c", MAILROOM, 0); - } - - fprintf(temp,"N%s%c", nodebuf, 0); - fprintf(temp,"H%s%c", frombuf, 0); - if (dtype==REMOTE) { - fprintf(temp,"D%s%c", destsys, 0); - } + } + fprintf(temp, "N%s%c", nodebuf, 0); + fprintf(temp, "H%s%c", frombuf, 0); + if (dtype == REMOTE) { + fprintf(temp, "D%s%c", destsys, 0); + } if (strlen(recp) > 0) { - fprintf(temp,"R%s%c", recp, 0); - } - + fprintf(temp, "R%s%c", recp, 0); + } /* Subject and text */ - if (strlen(subject)>0) { - fprintf(temp,"U%s%c", subject, 0); - } - putc('M',temp); + if (strlen(subject) > 0) { + fprintf(temp, "U%s%c", subject, 0); + } + putc('M', temp); if (format_type == 4) { fprintf(temp, "Content-type: %s\n", content_type); if (extra_headers != NULL) fprintf(temp, "%s", extra_headers); fprintf(temp, "\n"); - } - if (extra_headers != NULL) free(extra_headers); - if (strcmp(buf, ".")) loopcopy(temp, stdin); - putc(0,temp); - fclose(temp); } + if (extra_headers != NULL) + free(extra_headers); + if (strcmp(buf, ".")) + loopcopy(temp, stdin); + putc(0, temp); + fclose(temp); +} void do_uudecode(char *target) { static char buf[1024]; FILE *fp; - - snprintf(buf,sizeof buf,"cd %s; uudecode",target); - fp=popen(buf,"w"); - if (fp==NULL) return; - while (fgets(buf,1024,stdin)!=NULL) { - fprintf(fp,"%s",buf); - } - pclose(fp); + snprintf(buf, sizeof buf, "cd %s; uudecode", target); + fp = popen(buf, "w"); + if (fp == NULL) + return; + while (fgets(buf, 1024, stdin) != NULL) { + fprintf(fp, "%s", buf); } + pclose(fp); + +} int alias(char *name) { FILE *fp; int a; char abuf[256]; - - fp=fopen(ALIASES,"r"); - if (fp==NULL) { - syslog(LOG_ERR,"cannot open %s: %s",ALIASES,strerror(errno)); - return(2); - } - while (fgets(abuf,256,fp)!=NULL) { + fp = fopen(ALIASES, "r"); + if (fp == NULL) { + syslog(LOG_ERR, "cannot open %s: %s", ALIASES, strerror(errno)); + return (2); + } + while (fgets(abuf, 256, fp) != NULL) { strip_trailing_whitespace(abuf); - for (a=0; a 0) buf[strlen(buf) - 1] = 0; + if (strlen(buf) > 0) + buf[strlen(buf) - 1] = 0; strcpy(ParamName, ""); strcpy(ParamValue, ""); if (buf[0] != '#') { eqpos = (-1); - for (a=strlen(buf); a>=0; --a) { - if (buf[a] == '=') eqpos = a; - } + for (a = strlen(buf); a >= 0; --a) { + if (buf[a] == '=') + eqpos = a; + } if (eqpos >= 0) { strcpy(ParamName, buf); ParamName[eqpos] = 0; - strcpy(ParamValue, &buf[eqpos+1]); - } - + strcpy(ParamValue, &buf[eqpos + 1]); + } StripLeadingAndTrailingWhitespace(ParamName); StripLeadingAndTrailingWhitespace(ParamValue); @@ -78,27 +83,29 @@ void LoadInternetConfig(void) { strcpy(TABLEFILE, ParamValue); if (!strcasecmp(ParamName, "deliver local")) strcpy(metoo[mecount++], ParamValue); - if (!strcasecmp(ParamName, "run netproc")) + if (!strcasecmp(ParamName, "run netproc")) RUN_NETPROC = atoi(ParamValue); - } } - fclose(conf); } + fclose(conf); +} /* * returns nonzero if the specified host is listed as local */ -int IsHostLocal(char *WhichHost) { +int IsHostLocal(char *WhichHost) +{ int a; - if (!strcasecmp(WhichHost, FQDN)) return(1); + if (!strcasecmp(WhichHost, FQDN)) + return (1); if (mecount > 0) { - for (a=0; a