Skip to content
Snippets Groups Projects
Commit d40e071e authored by deuce's avatar deuce
Browse files

Mow uses b64_encode for file attaches.

parent 150eb25f
No related branches found
No related tags found
No related merge requests found
...@@ -180,7 +180,7 @@ CON_OBJS = $(EXEODIR)/sbbscon.o $(EXEODIR)/conwrap.o \ ...@@ -180,7 +180,7 @@ CON_OBJS = $(EXEODIR)/sbbscon.o $(EXEODIR)/conwrap.o \
$(EXEODIR)/ini_file.o $(EXEODIR)/sbbs_ini.o $(EXEODIR)/ini_file.o $(EXEODIR)/sbbs_ini.o
FTP_OBJS = $(LIBODIR)/ftpsrvr.o FTP_OBJS = $(LIBODIR)/ftpsrvr.o
MAIL_OBJS = $(LIBODIR)/mailsrvr.o $(LIBODIR)/mxlookup.o \ MAIL_OBJS = $(LIBODIR)/mailsrvr.o $(LIBODIR)/mxlookup.o \
$(LIBODIR)/mime.o $(LIBODIR)/mime.o $(LIBODIR)/base64.o
WEB_OBJS = $(LIBODIR)/websrvr.o $(LIBODIR)/sockwrap.o $(LIBODIR)/base64.o WEB_OBJS = $(LIBODIR)/websrvr.o $(LIBODIR)/sockwrap.o $(LIBODIR)/base64.o
SERVICE_OBJS= $(LIBODIR)/services.o SERVICE_OBJS= $(LIBODIR)/services.o
......
...@@ -43,14 +43,9 @@ ...@@ -43,14 +43,9 @@
#include "sbbs.h" #include "sbbs.h"
#include "mailsrvr.h" #include "mailsrvr.h"
#include "base64.h"
#define SIZEOF_MIMEBOUNDARY 36 #define SIZEOF_MIMEBOUNDARY 36
#define BASE64_BITMASK 0x0000003F
static const char * base64alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
static void tobase64(char * in, char * out, int bytesread);
char * mimegetboundary() char * mimegetboundary()
{ {
...@@ -106,36 +101,23 @@ void mimetextpartheader(SOCKET socket, char * boundary) ...@@ -106,36 +101,23 @@ void mimetextpartheader(SOCKET socket, char * boundary)
BOOL base64out(SOCKET socket, char * pathfile) BOOL base64out(SOCKET socket, char * pathfile)
{ {
FILE * fp; FILE * fp;
char in[3]={0}; char in[57];
char out[5]; /* one for the '\0' */ char out[77];
char line[77]; /* one for the '\0' */
int bytesread; int bytesread;
int i = 0;
if((fp=fopen(pathfile,"rb"))==NULL) if((fp=fopen(pathfile,"rb"))==NULL)
return(FALSE); return(FALSE);
while(1) { while(1) {
bytesread=fread(in,1,3,fp); bytesread=fread(in,1,57,fp);
tobase64(in,out,bytesread); if((b64_encode(out,in,sizeof(out),bytesread)==NULL)
if(i==0) || !sockprintf(socket,out)) {
strcpy(line,out);
else
strcat(line,out);
if(i==18) {
if(!sockprintf(socket,line)) {
fclose(fp); fclose(fp);
return(FALSE); return(FALSE);
} }
i=-1; if(bytesread!=57 || feof(fp))
}
if(bytesread!=3 || feof(fp))
break; break;
i++;
memset(in,0,3);
} }
fclose(fp); fclose(fp);
if(i!=-1) /* already printed the last line */
sockprintf(socket,line);
sockprintf(socket,""); sockprintf(socket,"");
return(TRUE); return(TRUE);
} }
...@@ -181,38 +163,3 @@ void endmime(SOCKET socket, char * boundary) ...@@ -181,38 +163,3 @@ void endmime(SOCKET socket, char * boundary)
sockprintf(socket,bndline); sockprintf(socket,bndline);
sockprintf(socket,""); sockprintf(socket,"");
} }
static void tobase64(char * in, char * out, int bytesread)
{
#define BITCAST_MASK 0x000000FF
unsigned int tmpnum0 = ((unsigned int)in[0])&BITCAST_MASK;
unsigned int tmpnum1 = ((unsigned int)in[1])&BITCAST_MASK;
unsigned int data = ((unsigned int)in[2])&BITCAST_MASK;
data|=(tmpnum1<<8);
data|=(tmpnum0<<16);
if(bytesread==0) {
out[0]='\0';
return;
}
out[4]='\0';
out[3]=base64alphabet[(data&BASE64_BITMASK)];
out[2]=base64alphabet[((data>>6)&BASE64_BITMASK)];
out[1]=base64alphabet[((data>>12)&BASE64_BITMASK)];
out[0]=base64alphabet[((data>>18)&BASE64_BITMASK)];
if(bytesread==1) {
/* pad last bytes */
out[3]=base64alphabet[64];
out[2]=base64alphabet[64];
}
else if(bytesread==2)
out[3]=base64alphabet[64];
#undef BITCAST_MASK
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment