Fixed newspost

This commit is contained in:
Michiel Broek 2005-08-13 21:54:29 +00:00
parent 5acf877610
commit dae0229e9c
3 changed files with 239 additions and 249 deletions

View File

@ -269,7 +269,7 @@ void Send(int newsmode, char *outstr)
unsigned long crc;
fwrite(outstr, 1, strlen(outstr), nfp);
Syslog('m', "+ %s\n", printable(outstr, 0));
// Syslog('m', "+ %s\n", printable(outstr, 0));
if (newsmode) {
Striplf(outstr);
@ -1292,7 +1292,7 @@ int ftn2rfc(faddr *f, faddr *t, char *subj, char *origline, time_t mdate, int fl
* GoldED posts news with plain ftn kludges as rfc headers.
*/
if ((p = hdr((char *)"CHRS", msg))) {
sprintf(temp, "X-FTN-CHARS:%s", p);
sprintf(temp, "X-FTN-CHRS:%s", p);
Send(newsmode, temp);
}
if ((p = hdr((char *)"MSGID", msg))) {
@ -1446,152 +1446,147 @@ int ftn2rfc(faddr *f, faddr *t, char *subj, char *origline, time_t mdate, int fl
}
Syslog('m', "=== ending qmsg loop 2");
if (newsmode) {
fa_list *tmpl,*ptl=NULL;
char sbe[16];
int seenlen=0,oldnet;
if (newsmode) {
fa_list *tmpl,*ptl=NULL;
char sbe[16];
int seenlen=0,oldnet;
for (qmsg = kmsg; qmsg; qmsg = qmsg->next)
if (!strcmp(qmsg->key, "PATH")) {
fill_path(&ptl, qmsg->val);
}
for (qmsg = kmsg; qmsg; qmsg = qmsg->next)
if (!strcmp(qmsg->key, "PATH")) {
fill_path(&ptl, qmsg->val);
}
uniq_list(&ptl);
uniq_list(&ptl);
/*
* ensure it will not match for the first entry
*/
oldnet = ptl->addr->net-1;
q = xstrcpy((char*)"X-FTN-PATH:");
for (tmpl = ptl; tmpl; tmpl = tmpl->next) {
if (tmpl->addr->net == oldnet)
sprintf(sbe," %u",tmpl->addr->node);
else
sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node);
oldnet=tmpl->addr->net;
seenlen+=strlen(sbe);
if (seenlen > MAXPATH) {
seenlen=0;
sprintf(temp, "%s\n", q);
Send(newsmode, temp);
free(q);
q = xstrcpy((char *)"X-FTN-PATH:");
sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node);
seenlen=strlen(sbe);
}
q = xstrcat(q, sbe);
}
sprintf(temp,"%s\n", q);
/*
* ensure it will not match for the first entry
*/
oldnet = ptl->addr->net-1;
q = xstrcpy((char*)"X-FTN-PATH:");
for (tmpl = ptl; tmpl; tmpl = tmpl->next) {
if (tmpl->addr->net == oldnet)
sprintf(sbe," %u",tmpl->addr->node);
else
sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node);
oldnet=tmpl->addr->net;
seenlen+=strlen(sbe);
if (seenlen > MAXPATH) {
seenlen=0;
sprintf(temp, "%s\n", q);
Send(newsmode, temp);
free(q);
tidy_falist(&ptl);
if ((hdr((char *)"X-FTN-SPTH", msg))) {
sprintf(temp,"X-FTN-SPTH: %s\n", ascfnode(bestaka,0x1f));
Send(newsmode, temp);
}
q = xstrcpy((char *)"X-FTN-PATH:");
sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node);
seenlen=strlen(sbe);
}
q = xstrcat(q, sbe);
}
sprintf(temp,"%s\n", q);
Send(newsmode, temp);
free(q);
tidy_falist(&ptl);
/*
* Search past RFC headers.
*/
while (fgets(buf,sizeof(buf)-1,fp)) {
if ((strlen(buf) == 1) && (buf[0] == '\n')) {
break;
}
if ((hdr((char *)"X-FTN-SPTH", msg))) {
sprintf(temp,"X-FTN-SPTH: %s\n", ascfnode(bestaka,0x1f));
Send(newsmode, temp);
}
}
/*
* Send the message body
*/
pass=1;
count = lines = 0;
first = TRUE;
/*
* Search past RFC headers.
*/
while (fgets(buf,sizeof(buf)-1,fp)) {
if ((strlen(buf) == 1) && (buf[0] == '\n')) {
break;
}
}
Syslog('m', "Start sending message body");
while (fgets(buf,sizeof(buf)-1,fp) && pass) {
if (first) {
p = xstrcpy((char *)"\n");
Send(newsmode, p);
free(p);
first = FALSE;
/*
* Send the message body
*/
pass=1;
count = lines = 0;
first = TRUE;
Syslog('m', "Start sending message body");
while (fgets(buf,sizeof(buf)-1,fp) && pass) {
if (first) {
p = xstrcpy((char *)"\n");
Send(newsmode, p);
free(p);
first = FALSE;
/* FIXME: Maybe scan now for repeating headers and drop them as they will appear in the message text */
if ((p=hdr((char *)"X-Body-Start",msg))) {
lines++;
q = xstrcpy(p);
Send(newsmode, q);
free(q);
}
}
if ((p=hdr((char *)"X-Body-Start",msg))) {
lines++;
q = xstrcpy(p);
Send(newsmode, q);
free(q);
}
}
if (ftell(fp) > endmsg_off) {
Syslog('m', "line \"%s\" past message end %ld %ld", buf,(long)endmsg_off, ftell(fp));
pass=0;
if (ftell(fp) > endmsg_off) {
Syslog('m', "line \"%s\" past message end %ld %ld", buf,(long)endmsg_off, ftell(fp));
pass=0;
}
if (pass) {
p=buf;
b=NULL;
while ((c=*p++)) {
switch (c) {
case ' ': b=p-1; break;
case '\n': b=NULL; count=0; lines++; break;
}
if (pass) {
p=buf;
if ((count++ > BOUNDARY) /* && (!pgpsigned) */ ) {
if (b) {
*b++='\n'; // Replace space.
p = b + 1;
b=NULL;
while ((c=*p++)) {
switch (c) {
case ' ': b=p-1; break;
case '\n': b=NULL; count=0; lines++; break;
}
if ((count++ > BOUNDARY) /* && (!pgpsigned) */ ) {
if (b) {
// *b++='\r';
// *b = '\n';
*b++='\n'; // Replace space.
p = b + 1;
// p=b+2;
b=NULL;
lines++;
count=0;
}
}
}
if ((strncmp(buf, ".\r\n", 3)) && (strncmp(buf, ".\n", 2)))
q = xstrcpy(buf);
else
q = xstrcpy((char *)" .\n");
Send(newsmode, q);
free(q);
lines++;
count=0;
}
}
}
if ((strncmp(buf, ".\r\n", 3)) && (strncmp(buf, ".\n", 2)))
q = xstrcpy(buf);
else
q = xstrcpy((char *)" .\n");
Send(newsmode, q);
free(q);
}
Syslog('m', "End sending message body");
}
Syslog('m', "End sending message body");
if ((modtype==1) && (!hdr((char *)"Approved",msg)) &&
if ((modtype==1) && (!hdr((char *)"Approved",msg)) &&
(!hdr((char *)"RFC-Approved",kmsg)) && (!hdr((char *)"Approved",kmsg)))
newsmode = FALSE;
newsmode = FALSE;
tidyrfc(msg);
fclose(fp);
tidyrfc(kmsg);
tidyrfc(msg);
fclose(fp);
tidyrfc(kmsg);
if (!newsmode) {
result = postemail(nfp, MailFrom, MailTo);
fclose(nfp);
} else {
news_in++;
/*
* The newsfile stays open and will be closed later after processing
* all echomail.
*/
fprintf(nfp, ".\n");
}
if (!newsmode) {
result = postemail(nfp, MailFrom, MailTo);
fclose(nfp);
} else {
news_in++;
/*
* The newsfile stays open and will be closed later after processing
* all echomail.
*/
fprintf(nfp, ".\n");
}
// if (p) Geeft segfault
// free(p);
if (newsgroup)
free(newsgroup);
if (distribution)
free(distribution);
if (moderator)
free(moderator);
rbuf = NULL;
free(temp);
return result;
if (newsgroup)
free(newsgroup);
if (distribution)
free(distribution);
if (moderator)
free(moderator);
rbuf = NULL;
free(temp);
return result;
}

View File

@ -4,7 +4,7 @@
* Purpose ...............: Post newsarticles in temp newsfile.
*
*****************************************************************************
* Copyright (C) 1997-2004
* Copyright (C) 1997-2005
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 Internet: mbroek@users.sourceforge.net
@ -43,121 +43,120 @@ extern int news_bad;
int newspost(void)
{
int start = TRUE;
char *buf, *p;
long curpos, count, seqnr;
FILE *ofp = NULL, *nb;
struct utsname utsbuf;
if (newsopen)
fclose(nfp);
buf = calloc(10240, sizeof(char));
/*
* Now reopen the file for reading. If it fails and
* the file was original closed we leave quiet.
* If the file wasn't open previously but there is
* a file, try to post the articles. They may be
* still here if the newsserver wasn't available.
*/
sprintf(buf, "%s/tmp/newsout", getenv("MBSE_ROOT"));
if ((nfp = fopen(buf, "r")) == NULL) {
if (newsopen)
WriteError("$Can't reopen %s", buf);
free(buf);
return newsopen;
}
IsDoing("Post news");
if (CFG.newsfeed == FEEDINN) {
Syslog('+', "Posting news articles to the NNTP server");
if (nntp_connect() == -1) {
free(buf);
return TRUE;
}
while (fgets(buf, 10240, nfp)) {
if (start) {
if (nntp_cmd((char *)"POST\r\n", 340) != 0) {
WriteError("NNTP POST refused");
free(buf);
return TRUE;
}
}
start = FALSE;
if (!strcmp(buf, ".\n")) {
if (nntp_cmd((char *)".\r\n", 240) == 0) {
news_out++;
} else {
WriteError("NNTP: refused article %d", news_out+1);
news_bad++;
}
start = TRUE;
} else {
/*
* Most NNTP servers like cr/lf after each line.
*/
Striplf(buf);
p = buf+strlen(buf);
*p++ = '\r';
*p++ = '\n';
*p = '\0';
nntp_send(buf);
}
Nopper();
}
nntp_close();
}
/*
* Create newsbatch file.
*/
if ((CFG.newsfeed == FEEDUUCP) || (CFG.newsfeed == FEEDRNEWS)) {
Syslog('m', "Building uncompressed batchfile");
sprintf(buf, "%s/tmp/newsbatch", getenv("MBSE_ROOT"));
if ((ofp = fopen(buf, "w+")) == NULL) {
WriteError("$Can't create %s", buf);
free(buf);
fclose(nfp);
return TRUE;
}
buf = calloc(10240, sizeof(char));
count = curpos = 0;
while (feof(ofp) == 0) {
/*
* Count the total length of the message
*/
while (fgets(buf, 10240, nfp)) {
if (strcmp(buf, ".\n")) {
count += strlen(buf);
} else {
break;
}
}
if (!count)
break;
fseek(nfp, curpos, SEEK_SET);
fprintf(ofp, "#! rnews %ld\n", count);
while (fgets(buf, 10240, nfp)) {
if (strcmp(buf, ".\n")) {
fprintf(ofp, buf);
} else {
break;
}
}
news_out++;
curpos = ftell(nfp);
count = 0;
}
/*
* Rewind the newsbatch and leave it open.
*/
rewind(ofp);
}
int start = TRUE;
char *buf, *p;
long curpos, count, seqnr;
FILE *ofp = NULL, *nb;
struct utsname utsbuf;
if (newsopen)
fclose(nfp);
newsopen = FALSE;
buf = calloc(10240, sizeof(char));
/*
* Now reopen the file for reading. If it fails and
* the file was original closed we leave quiet.
* If the file wasn't open previously but there is
* a file, try to post the articles. They may be
* still here if the newsserver wasn't available.
*/
sprintf(buf, "%s/tmp/newsout", getenv("MBSE_ROOT"));
if ((nfp = fopen(buf, "r")) == NULL) {
if (newsopen)
WriteError("$Can't reopen %s", buf);
free(buf);
return newsopen;
}
IsDoing("Post news");
if (CFG.newsfeed == FEEDINN) {
Syslog('+', "Posting news articles to the NNTP server");
if (nntp_connect() == -1) {
free(buf);
return TRUE;
}
while (fgets(buf, 10240, nfp)) {
if (start) {
if (nntp_cmd((char *)"POST\r\n", 340) != 0) {
WriteError("NNTP POST refused");
free(buf);
return TRUE;
}
}
start = FALSE;
if (!strcmp(buf, ".\n")) {
if (nntp_cmd((char *)".\r\n", 240) == 0) {
news_out++;
} else {
WriteError("NNTP: refused article %d", news_out+1);
news_bad++;
}
start = TRUE;
} else {
/*
* Most NNTP servers like cr/lf after each line.
*/
Striplf(buf);
p = buf+strlen(buf);
*p++ = '\r';
*p++ = '\n';
*p = '\0';
nntp_send(buf);
}
Nopper();
}
nntp_close();
}
/*
* Create newsbatch file.
*/
if ((CFG.newsfeed == FEEDUUCP) || (CFG.newsfeed == FEEDRNEWS)) {
Syslog('m', "Building uncompressed batchfile");
sprintf(buf, "%s/tmp/newsbatch", getenv("MBSE_ROOT"));
if ((ofp = fopen(buf, "w+")) == NULL) {
WriteError("$Can't create %s", buf);
free(buf);
fclose(nfp);
return TRUE;
}
count = curpos = 0;
while (feof(ofp) == 0) {
/*
* Count the total length of the message
*/
while (fgets(buf, 10240, nfp)) {
if (strcmp(buf, ".\n")) {
count += strlen(buf);
} else {
break;
}
}
if (!count)
break;
fseek(nfp, curpos, SEEK_SET);
fprintf(ofp, "#! rnews %ld\n", count);
while (fgets(buf, 10240, nfp)) {
if (strcmp(buf, ".\n")) {
fprintf(ofp, buf);
} else {
break;
}
}
news_out++;
curpos = ftell(nfp);
count = 0;
}
/*
* Rewind the newsbatch and leave it open.
*/
rewind(ofp);
}
fclose(nfp);
newsopen = FALSE;
/*
* Mode rnews, pipe just created newsbatch to rnews.
@ -219,8 +218,11 @@ int newspost(void)
unlink(buf);
}
sprintf(buf, "%s/tmp/newsout", getenv("MBSE_ROOT"));
unlink(buf);
if (! news_bad) {
sprintf(buf, "%s/tmp/newsout", getenv("MBSE_ROOT"));
unlink(buf);
}
free(buf);
return FALSE;
}

View File

@ -176,7 +176,7 @@ char *getrfcchrs(int val)
void Add_Headkludges(faddr *dest, int IsReply)
{
char *temp, *temp2;
char *temp;
unsigned long crc = -1;
time_t tt;
int i;
@ -219,19 +219,12 @@ void Add_Headkludges(faddr *dest, int IsReply)
sprintf(temp, "\001Date: %s", rfcdate(Msg.Written));
MsgText_Add2(temp);
Node = fido2faddr(msgs.Aka);
temp2 = xstrcpy(Msg.From);
for (i = 0; i < strlen(temp2); i++)
if (temp2[i] == ' ')
temp2[i] = '_';
// sprintf(temp, "\001From: %s@%s (%s)", temp2, ascinode(Node, 0x2f), Msg.From);
sprintf(temp, "\001From: %s", Msg.From);
MsgText_Add2(temp);
sprintf(temp, "\001Subject: %s", Msg.Subject);
MsgText_Add2(temp);
// sprintf(temp, "\001Sender: %s@%s (%s)", temp2, ascinode(Node, 0x2f), Msg.From);
sprintf(temp, "\001Sender: %s", Msg.From);
MsgText_Add2(temp);
free(temp2);
tidy_faddr(Node);
MsgText_Add2((char *)"\001To: All");
MsgText_Add2((char *)"\001MIME-Version: 1.0");