Skip to content

Commit

Permalink
1.4-c beta - add options for replacing NBSPs and deleting stuffed spa…
Browse files Browse the repository at this point in the history
…ces in quotes

- New setting def_nonbsp (user parameter nonbsp) for replacing UTF-8 non-breaking spaces by regular spaces.
TODO: check if msg is UTF-8, add support for NBSPs in other charsets (like iso-8859-1)

- New setting def_delssq (user parameter delssq) for deleting space stuffing from quoted text (only in format=flowed).

Both settings are off by default.
  • Loading branch information
cnb committed Apr 7, 2024
1 parent 7c55fcc commit e4a5ec3
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 3 deletions.
36 changes: 36 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,38 @@ bool parseargs(int argc, char **argv,uchar *filename,ulong line)

c++;
}
else if(stricmp(arg,"-def_nonbsp")==0)
{
if(c+1 == argc)
{
printf("Missing argument for %s%s\n",argv[c],src);
return(FALSE);
}

if(!(setboolonoff(argv[c+1],&cfg_def_nonbsp)))
{
printf("Invalid setting %s for %s, must be on or off%s\n",argv[c+1],argv[c],src);
return(FALSE);
}

c++;
}
else if(stricmp(arg,"-def_delssq")==0)
{
if(c+1 == argc)
{
printf("Missing argument for %s%s\n",argv[c],src);
return(FALSE);
}

if(!(setboolonoff(argv[c+1],&cfg_def_delssq)))
{
printf("Invalid setting %s for %s, must be on or off%s\n",argv[c+1],argv[c],src);
return(FALSE);
}

c++;
}
else if(stricmp(arg,"-origin")==0)
{
if(c+1 == argc)
Expand Down Expand Up @@ -332,6 +364,8 @@ void createconfig(uchar *file)
fprintf(fp,"%sstrictnetmail\n",cfg_strictnetmail ? "" : "#");
fprintf(fp,"def_flowed %s\n",cfg_def_flowed ? "on" : "off");
fprintf(fp,"def_showto %s\n",cfg_def_showto ? "on" : "off");
fprintf(fp,"def_nonbsp %s\n",cfg_def_nonbsp ? "on" : "off");
fprintf(fp,"def_delssq %s\n",cfg_def_delssq ? "on" : "off");
fprintf(fp,"%snostripre\n",cfg_nostripre ? "" : "#");
fprintf(fp,"%snotearline\n",cfg_notearline ? "" : "#");
fprintf(fp,"%snoreplyaddr\n",cfg_noreplyaddr ? "" : "#");
Expand Down Expand Up @@ -395,6 +429,8 @@ int main(int argc, char **argv)
" -strictnetmail Use strict article counters in netmail areas\n"
" -def_flowed on/off Default setting for format=flowed (RFC 2646)\n"
" -def_showto on/off Default setting for the display of recipient on from line\n"
" -def_nonbsp on/off Default setting for replacing non-breaking spaces by normal spaces\n"
" -def_delssq on/off Default setting for deleting stuffed space from quoted text (format=flowed)\n"
"\n"
" Options for posting messages:\n"
"\n"
Expand Down
51 changes: 49 additions & 2 deletions src/nntpserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ uchar *cfg_xlatfile = CFG_XLATFILE;

bool cfg_def_flowed = CFG_DEF_FLOWED;
bool cfg_def_showto = CFG_DEF_SHOWTO;
bool cfg_def_nonbsp = CFG_DEF_NONBSP;
bool cfg_def_delssq = CFG_DEF_DELSSQ;

bool cfg_debug;
bool cfg_noecholog;
Expand Down Expand Up @@ -2392,6 +2394,29 @@ void command_post(struct var *var)
}

line[c]=0;

/* Replace UTF-8 non-breaking spaces by normal spaces */
if(var->opt_nonbsp && strstr(line,"\0xC2\0xA0")!=NULL)
{
int i = strlen(line)-2;
while(i>0)
{
if (line[i]==0xC2 && line[i+1]==0xA0)
{
memmove(line+i, line+i+1, strlen(line)-i);
line[i] = ' ';
}
i--;
}
}

/* Delete stuffed space from quotes (format=flowed) */
if(flowed && var->opt_delssq && line[0]=='>')
{
if(strlen(line)>3 && strncmp(line,"> ",3)==0)
memmove(line+1,line+2,strlen(line)-1);
}


if(flowed && line[0]!=0 && line[0]!='>' && strncmp(line,"-- ",3)!=0)
{
Expand Down Expand Up @@ -2824,7 +2849,7 @@ void command_post(struct var *var)
void command_authinfo(struct var *var)
{
uchar *tmp,*opt,*next,*equal;
bool flowed,showto;
bool flowed,showto,nonbsp,delssq;

if(!(tmp=parseinput(var)))
{
Expand Down Expand Up @@ -2874,6 +2899,8 @@ void command_authinfo(struct var *var)

flowed=var->opt_flowed;
showto=var->opt_showto;
nonbsp=var->opt_nonbsp;
delssq=var->opt_delssq;

if(strchr(var->loginname,'/'))
{
Expand Down Expand Up @@ -2919,9 +2946,25 @@ void command_authinfo(struct var *var)
return;
}
}
else if(stricmp(opt,"nonbsp")==0)
{
if(!(setboolonoff(equal,&nonbsp)))
{
sockprintf(var,"482 Unknown setting %s for option %s, use on or off" CRLF,equal,opt);
return;
}
}
else if(stricmp(opt,"delssq")==0)
{
if(!(setboolonoff(equal,&delssq)))
{
sockprintf(var,"482 Unknown setting %s for option %s, use on or off" CRLF,equal,opt);
return;
}
}
else
{
sockprintf(var,"482 Unknown option %s, known options: flowed, showto" CRLF,opt);
sockprintf(var,"482 Unknown option %s, known options: flowed, showto, nonbsp, delssq" CRLF,opt);
return;
}

Expand All @@ -2945,6 +2988,8 @@ void command_authinfo(struct var *var)

var->opt_flowed=flowed;
var->opt_showto=showto;
var->opt_nonbsp=nonbsp;
var->opt_delssq=delssq;

return;
}
Expand Down Expand Up @@ -2986,6 +3031,8 @@ void server(SOCKET s)

var.opt_flowed=cfg_def_flowed;
var.opt_showto=cfg_def_showto;
var.opt_nonbsp=cfg_def_nonbsp;
var.opt_delssq=cfg_def_delssq;

if(getpeername(s,(struct sockaddr *)&fromsa,&fromsa_len) == SOCKET_ERROR)
{
Expand Down
8 changes: 7 additions & 1 deletion src/nntpserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct var

bool opt_flowed;
bool opt_showto;
bool opt_nonbsp;
bool opt_delssq;

bool login;
};
Expand All @@ -70,7 +72,7 @@ struct var
#define CRLF CR LF

#define SERVER_NAME "JamNNTPd/" PLATFORM_NAME
#define SERVER_VERSION "1.3.5-c"
#define SERVER_VERSION "1.4-c beta 1"
#define SERVER_PIDVERSION SERVER_VERSION

#define SOCKIO_TIMEOUT 5*60
Expand All @@ -97,6 +99,8 @@ void server(SOCKET s);

#define CFG_DEF_FLOWED TRUE
#define CFG_DEF_SHOWTO TRUE
#define CFG_DEF_NONBSP FALSE
#define CFG_DEF_DELSSQ FALSE

extern ulong cfg_port;
extern ulong cfg_maxconn;
Expand Down Expand Up @@ -125,3 +129,5 @@ extern bool cfg_readorigin;

extern bool cfg_def_flowed;
extern bool cfg_def_showto;
extern bool cfg_def_nonbsp;
extern bool cfg_def_delssq;

3 comments on commit e4a5ec3

@cnb
Copy link
Owner Author

@cnb cnb commented on e4a5ec3 Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why replace NBSPs? Thunderbird and Seamonkey insert them in quoted text when there are 2 or more consecutive spaces, but NBSPs are not displayed (converted) properly in most FTN/BBS software, that currently don't fully support UTF-8.

Why remove space stuffing from quotes? The aforementioned clients insert them. I'm not sure if it's correct. If yes, then it was JamNNTPd's fault. Just in case, for now I'm leaving this off by default.

@cnb
Copy link
Owner Author

@cnb cnb commented on e4a5ec3 Apr 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setting delssq to on by default in next commit.

@cnb
Copy link
Owner Author

@cnb cnb commented on e4a5ec3 May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nonbsp completed in 0896df5

Please sign in to comment.