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

Truncate all white-space chars off end of imported messages - allows for better

"empty netmail" detection and dupe-message detection.
parent df42f5c0
No related branches found
No related tags found
No related merge requests found
...@@ -2209,8 +2209,6 @@ static short fmsgzone(char* p) ...@@ -2209,8 +2209,6 @@ static short fmsgzone(char* p)
return(val); return(val);
} }
#if 1 /* Old way */
char* getfmsg(FILE *stream, ulong *outlen) char* getfmsg(FILE *stream, ulong *outlen)
{ {
uchar* fbuf; uchar* fbuf;
...@@ -2221,69 +2219,32 @@ char* getfmsg(FILE *stream, ulong *outlen) ...@@ -2221,69 +2219,32 @@ char* getfmsg(FILE *stream, ulong *outlen)
start=ftell(stream); /* Beginning of Message */ start=ftell(stream); /* Beginning of Message */
while(1) { while(1) {
ch=fgetc(stream); /* Look for Terminating NULL */ ch=fgetc(stream); /* Look for Terminating NULL */
if(!ch || ch==EOF) /* Found end of message */ if(ch==0 || ch==EOF) /* Found end of message */
break; break;
length++; } /* Increment the Length */ length++; /* Increment the Length */
}
if((fbuf=(char *)malloc(length+1))==NULL) { if((fbuf=(char *)malloc(length+1))==NULL) {
printf("Unable to allocate %lu bytes for message.\n",length+1); printf("Unable to allocate %lu bytes for message.\n",length+1);
logprintf("ERROR line %d allocating %lu bytes of memory",__LINE__,length+1); logprintf("ERROR line %d allocating %lu bytes of memory",__LINE__,length+1);
bail(1); } bail(1);
}
fseek(stream,start,SEEK_SET); fseek(stream,start,SEEK_SET);
for(l=0;l<length;l++) for(l=0;l<length;l++)
fbuf[l]=fgetc(stream); fbuf[l]=fgetc(stream);
fbuf[length]=0; if(ch==0)
if(!ch)
fgetc(stream); /* Read NULL */ fgetc(stream); /* Read NULL */
if(outlen)
*outlen=length;
return(fbuf);
}
#else while(length && fbuf[length-1]<=' ') /* truncate white-space */
length--;
#define FBUF_BLOCK 4096 fbuf[length]=0;
char *getfmsg(FILE *stream)
{
uchar *fbuf,*p;
ulong l,n,length,start;
length=0L;
start=ftell(stream); /* Beginning of Message */
if((fbuf=malloc(FBUF_BLOCK))==NULL)
return(fbuf);
while(!feof(stream)) {
l=fread(fbuf+length,1,FBUF_BLOCK,stream);
if(l<1)
break;
*(fbuf+length+l)=0;
n=strlen(fbuf+length);
if(n<l) {
length+=(n+1);
break; }
printf(",");
length+=l;
if(l<FBUF_BLOCK)
break;
printf("<");
if((p=REALLOC(fbuf,length+FBUF_BLOCK+1))==NULL) {
free(fbuf);
printf("!");
fseek(stream,-l,SEEK_CUR);
return(NULL); }
fbuf=p;
printf(">");
}
printf(".");
fseek(stream,start+length,SEEK_SET); if(outlen)
*outlen=length;
return(fbuf); return(fbuf);
} }
#endif
#define MAX_TAILLEN 1024 #define MAX_TAILLEN 1024
/****************************************************************************/ /****************************************************************************/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment