diff --git a/src/sbbs3/mime.c b/src/sbbs3/mime.c index 7ce01846836ce56c61f184ff6578e3e5b9d561fb..514f558a6e12e9c8d11ebfc43692da11c61e5de6 100644 --- a/src/sbbs3/mime.c +++ b/src/sbbs3/mime.c @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -47,10 +47,10 @@ #define SIZEOF_MIMEBOUNDARY 36 -char * mimegetboundary() +char* mimegetboundary() { - int i, num; - char * boundaryString = (char *)malloc(SIZEOF_MIMEBOUNDARY + 1); + int i, num; + char* boundaryString = (char*)malloc(SIZEOF_MIMEBOUNDARY + 1); srand(time(NULL)); if (boundaryString == NULL) @@ -69,36 +69,28 @@ char * mimegetboundary() return boundaryString; } -void mimeheaders(SOCKET socket, char * boundary) +void mimeheaders(SOCKET socket, char* boundary) { - char bndline[50]; sockprintf(socket,"MIME-Version: 1.0"); sockprintf(socket,"Content-Type: multipart/mixed;"); - strcpy(bndline," boundary=\""); - strcat(bndline,boundary); - strcat(bndline,"\""); - sockprintf(socket,bndline); + sockprintf(socket," boundary=\"%s\"",boundary); } -void mimeblurb(SOCKET socket, char * boundary) +void mimeblurb(SOCKET socket, char* boundary) { - sockprintf(socket,"This is a MIME blurb. You shouldn't be seeing this!"); + sockprintf(socket,"This is a multi-part message in MIME format."); sockprintf(socket,""); } -void mimetextpartheader(SOCKET socket, char * boundary) +void mimetextpartheader(SOCKET socket, char* boundary) { - char bndline[50]; - - strcpy(bndline,"--"); - strcat(bndline,boundary); - sockprintf(socket,bndline); + sockprintf(socket,"--%s",boundary); sockprintf(socket,"Content-Type: text/plain;"); sockprintf(socket," charset=\"iso-8859-1\""); sockprintf(socket,"Content-Transfer-Encoding: 7bit"); } -BOOL base64out(SOCKET socket, char * pathfile) +BOOL base64out(SOCKET socket, char* pathfile) { FILE * fp; char in[57]; @@ -108,13 +100,13 @@ BOOL base64out(SOCKET socket, char * pathfile) if((fp=fopen(pathfile,"rb"))==NULL) return(FALSE); while(1) { - bytesread=fread(in,1,57,fp); + bytesread=fread(in,1,sizeof(in),fp); if((b64_encode(out,sizeof(out),in,bytesread)==-1) || !sockprintf(socket,out)) { fclose(fp); return(FALSE); } - if(bytesread!=57 || feof(fp)) + if(bytesread!=sizeof(in) || feof(fp)) break; } fclose(fp); @@ -122,44 +114,26 @@ BOOL base64out(SOCKET socket, char * pathfile) return(TRUE); } -BOOL mimeattach(SOCKET socket, char * boundary, char * pathfile) +BOOL mimeattach(SOCKET socket, char* boundary, char* pathfile) { - char bndline[41]; - char * fname = getfname(pathfile); - char * line = (char*)MALLOC(strlen(fname) + 20); - - if(line==NULL) - return(FALSE); + char* fname = getfname(pathfile); - strcpy(bndline,"--"); - strcat(bndline,boundary); - sockprintf(socket,bndline); + sockprintf(socket,"--%s",boundary); sockprintf(socket,"Content-Type: application/octet-stream;"); - strcpy(line," name=\""); - strcat(line,fname); - strcat(line,"\""); - sockprintf(socket,line); + sockprintf(socket," name=\"%s\"",fname); sockprintf(socket,"Content-Transfer-Encoding: base64"); sockprintf(socket,"Content-Disposition: attachment;"); - strcpy(line," filename=\""); - strcat(line,fname); - strcat(line,"\""); - sockprintf(socket,line); + sockprintf(socket," filename=\"%s\"",fname); sockprintf(socket,""); if(!base64out(socket,pathfile)) return(FALSE); sockprintf(socket,""); - FREE(line); return(TRUE); } -void endmime(SOCKET socket, char * boundary) +void endmime(SOCKET socket, char* boundary) { - char bndline[128]; - - strcpy(bndline,"--"); - strcat(bndline,boundary); - strcat(bndline,"--"); /* last boundary */ - sockprintf(socket,bndline); + /* last boundary */ + sockprintf(socket,"--%s--",boundary); sockprintf(socket,""); }