int fd; int bytesRead; struct stat statbuf;
SmtpParseEnd (pmail_command_t cmd,		string_list_t *section,		param_list_t *defparm){    string_list_t	*sp;    int fd;    int bytesRead;    struct stat statbuf;    pish_command_t	*pish = (pish_command_t *)cmd->data;    /* Now parse section lines */    D_PRINTF(stderr, "Smtp Assign section lines\n");					/* skip first and last */    for (sp = section->next; sp->next; sp = sp->next) {	char *name = sp->value;	char *tok = name + strcspn(name, " \t=");	*tok++ = 0;			/* split name off */	tok += strspn(tok, " \t=");	string_tolower(name);	tok = string_unquote(tok);	if (pishParseNameValue (cmd, name, tok) < 0) {	    /* not a known attr */	    D_PRINTF(stderr,"unknown attribute '%s' '%s'\n", name, tok);	    returnerr(stderr,"unknown attribute '%s' '%s'\n", name, tok);	}	    }    /* check for some of the required command attrs */    if (!pish->hostInfo.hostName) {	D_PRINTF(stderr,"missing server for command");	return returnerr(stderr,"missing server for command\n");    }    if (!pish->loginFormat) {	D_PRINTF(stderr,"missing loginFormat for command");	return returnerr(stderr,"missing loginFormat for command\n");    }    if (!pish->passwdFormat) {	D_PRINTF(stderr,"missing passwdFormat for command");	return returnerr(stderr,"missing passwdFormat for command\n");    }    if (!pish->addressFormat) {	D_PRINTF(stderr,"missing addressFormat for command");	return returnerr(stderr,"missing addressFormat for command\n");    }    /* check for required attrs */    if (!pish->filename) {	D_PRINTF(stderr,"missing file for SMTP command");	return returnerr(stderr,"missing file for SMTP command\n");    }	/* read the contents of file into struct */    memset(&statbuf, 0, sizeof(statbuf));    if (stat(pish->filename, &statbuf) != 0) {	return returnerr(stderr,"Couldn't stat file %s: errno=%d: %s\n", 			 pish->filename, errno, strerror(errno));    }    /* open file */    if ((fd = open(pish->filename, O_RDONLY)) <= 0) {	return returnerr(stderr, "Cannot open file %s: errno=%d: %s\n",			 pish->filename, errno, strerror(errno));    }    /* read into loaded_comm_list */#define MSG_TRAILER CRLF "." CRLF    pish->msgsize = statbuf.st_size;    pish->msgMailFrom = NULL;    pish->msgdata = (char *) mycalloc(pish->msgsize+strlen(MSG_TRAILER)+1);    if ((bytesRead = read(fd, pish->msgdata, pish->msgsize)) <= 0) {	close(fd);	return returnerr(stderr, "Cannot read file %s: errno=%d: %s\n", 			 pish->filename, errno, strerror(errno));    }    if (bytesRead != pish->msgsize) {	returnerr(stderr, "Error reading file %s, got %d expected %d\n",		  pish->filename, bytesRead, pish->msgsize);	close(fd);	return -1;    }    pish->msgdata[pish->msgsize] = 0;    /* clean up message to rfc822 style */#define PROTO_HEADER "SMTP"#define PROTO_MAIL_FROM "\nMAIL FROM:"#define PROTO_DATA "\nDATA\n"    D_PRINTF (stderr, "checking for PROTO_HEADER [%s]\n", PROTO_HEADER);    if (strncmp(pish->msgdata, PROTO_HEADER, strlen(PROTO_HEADER)) == 0) {	    char *cp, *cp2;	    int off;	    D_PRINTF(stderr, "got PROTO_HEADER\n");	    D_PRINTF(stderr, "find PROTO_MAIL_FROM...\n");	    cp = strstr(pish->msgdata, PROTO_MAIL_FROM); 	    if (cp != NULL) {		    cp += strlen(PROTO_MAIL_FROM);		    cp2 = strchr(cp, '\n');		    off = cp2 - cp;		    pish->msgMailFrom = (char *) mycalloc(off+1);		    memcpy(pish->msgMailFrom, cp, off);		    pish->msgMailFrom[off] = 0;		    D_PRINTF(stderr, "got PROTO_MAIL_FROM:%s\n",pish->msgMailFrom);	    }	    D_PRINTF(stderr, "find PROTO_DATA...\n");	    cp = strstr(pish->msgdata, PROTO_DATA);	    if (cp != NULL) {		    off = cp - pish->msgdata;		    off += strlen(PROTO_DATA);		    D_PRINTF(stderr, "got past PROTO_DATA at off=%d\n", off);		    char *newmsg = (char *) mycalloc(pish->msgsize+strlen(MSG_TRAILER)+1-off);		    memcpy(newmsg, pish->msgdata+off, pish->msgsize-off+1);		    myfree(pish->msgdata);		    pish->msgdata = newmsg;		    D_PRINTF(stderr, "done msg shrink\n");	    }    }    strcat(pish->msgdata, MSG_TRAILER);    close(fd);    /* see if we can resolve the mailserver addr */    if (resolve_addrs(pish->hostInfo.hostName, "tcp",		      &(pish->hostInfo.host_phe),		      &(pish->hostInfo.host_ppe),		      &(pish->hostInfo.host_addr),		      &(pish->hostInfo.host_type))) {	return returnerr (stderr, "Error resolving hostname '%s'\n",			  pish->hostInfo.hostName);    } else {	pish->hostInfo.resolved = 1;	/* mark the hostInfo resolved */    }    rangeSetFirstCount (&pish->loginRange, pish->loginRange.first,			   pish->loginRange.span, pish->loginRange.sequential);    rangeSetFirstCount (&pish->domainRange, pish->domainRange.first,			   pish->domainRange.span, pish->domainRange.sequential);    rangeSetFirstCount (&pish->addressRange, pish->addressRange.first,			   pish->addressRange.span, pish->addressRange.sequential);    return 1;}