Skip to content
Snippets Groups Projects
Commit 5291dc24 authored by rswindell's avatar rswindell
Browse files

Eliminated silly strcpy/strcat code.

Changed mime blurb.
parent 2fcd5122
Branches
Tags
No related merge requests found
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * @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 * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License * * modify it under the terms of the GNU General Public License *
...@@ -47,10 +47,10 @@ ...@@ -47,10 +47,10 @@
#define SIZEOF_MIMEBOUNDARY 36 #define SIZEOF_MIMEBOUNDARY 36
char * mimegetboundary() char* mimegetboundary()
{ {
int i, num; int i, num;
char * boundaryString = (char *)malloc(SIZEOF_MIMEBOUNDARY + 1); char* boundaryString = (char*)malloc(SIZEOF_MIMEBOUNDARY + 1);
srand(time(NULL)); srand(time(NULL));
if (boundaryString == NULL) if (boundaryString == NULL)
...@@ -69,36 +69,28 @@ char * mimegetboundary() ...@@ -69,36 +69,28 @@ char * mimegetboundary()
return boundaryString; 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,"MIME-Version: 1.0");
sockprintf(socket,"Content-Type: multipart/mixed;"); sockprintf(socket,"Content-Type: multipart/mixed;");
strcpy(bndline," boundary=\""); sockprintf(socket," boundary=\"%s\"",boundary);
strcat(bndline,boundary);
strcat(bndline,"\"");
sockprintf(socket,bndline);
} }
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,""); sockprintf(socket,"");
} }
void mimetextpartheader(SOCKET socket, char * boundary) void mimetextpartheader(SOCKET socket, char* boundary)
{ {
char bndline[50]; sockprintf(socket,"--%s",boundary);
strcpy(bndline,"--");
strcat(bndline,boundary);
sockprintf(socket,bndline);
sockprintf(socket,"Content-Type: text/plain;"); sockprintf(socket,"Content-Type: text/plain;");
sockprintf(socket," charset=\"iso-8859-1\""); sockprintf(socket," charset=\"iso-8859-1\"");
sockprintf(socket,"Content-Transfer-Encoding: 7bit"); sockprintf(socket,"Content-Transfer-Encoding: 7bit");
} }
BOOL base64out(SOCKET socket, char * pathfile) BOOL base64out(SOCKET socket, char* pathfile)
{ {
FILE * fp; FILE * fp;
char in[57]; char in[57];
...@@ -108,13 +100,13 @@ BOOL base64out(SOCKET socket, char * pathfile) ...@@ -108,13 +100,13 @@ BOOL base64out(SOCKET socket, char * pathfile)
if((fp=fopen(pathfile,"rb"))==NULL) if((fp=fopen(pathfile,"rb"))==NULL)
return(FALSE); return(FALSE);
while(1) { while(1) {
bytesread=fread(in,1,57,fp); bytesread=fread(in,1,sizeof(in),fp);
if((b64_encode(out,sizeof(out),in,bytesread)==-1) if((b64_encode(out,sizeof(out),in,bytesread)==-1)
|| !sockprintf(socket,out)) { || !sockprintf(socket,out)) {
fclose(fp); fclose(fp);
return(FALSE); return(FALSE);
} }
if(bytesread!=57 || feof(fp)) if(bytesread!=sizeof(in) || feof(fp))
break; break;
} }
fclose(fp); fclose(fp);
...@@ -122,44 +114,26 @@ BOOL base64out(SOCKET socket, char * pathfile) ...@@ -122,44 +114,26 @@ BOOL base64out(SOCKET socket, char * pathfile)
return(TRUE); 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 * fname = getfname(pathfile);
char * line = (char*)MALLOC(strlen(fname) + 20);
if(line==NULL)
return(FALSE);
strcpy(bndline,"--"); sockprintf(socket,"--%s",boundary);
strcat(bndline,boundary);
sockprintf(socket,bndline);
sockprintf(socket,"Content-Type: application/octet-stream;"); sockprintf(socket,"Content-Type: application/octet-stream;");
strcpy(line," name=\""); sockprintf(socket," name=\"%s\"",fname);
strcat(line,fname);
strcat(line,"\"");
sockprintf(socket,line);
sockprintf(socket,"Content-Transfer-Encoding: base64"); sockprintf(socket,"Content-Transfer-Encoding: base64");
sockprintf(socket,"Content-Disposition: attachment;"); sockprintf(socket,"Content-Disposition: attachment;");
strcpy(line," filename=\""); sockprintf(socket," filename=\"%s\"",fname);
strcat(line,fname);
strcat(line,"\"");
sockprintf(socket,line);
sockprintf(socket,""); sockprintf(socket,"");
if(!base64out(socket,pathfile)) if(!base64out(socket,pathfile))
return(FALSE); return(FALSE);
sockprintf(socket,""); sockprintf(socket,"");
FREE(line);
return(TRUE); return(TRUE);
} }
void endmime(SOCKET socket, char * boundary) void endmime(SOCKET socket, char* boundary)
{ {
char bndline[128]; /* last boundary */
sockprintf(socket,"--%s--",boundary);
strcpy(bndline,"--");
strcat(bndline,boundary);
strcat(bndline,"--"); /* last boundary */
sockprintf(socket,bndline);
sockprintf(socket,""); sockprintf(socket,"");
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment