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

View File

@ -4,7 +4,7 @@
* Purpose ...............: Post newsarticles in temp newsfile. * Purpose ...............: Post newsarticles in temp newsfile.
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2004 * Copyright (C) 1997-2005
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 Internet: mbroek@users.sourceforge.net * Beekmansbos 10 Internet: mbroek@users.sourceforge.net
@ -43,121 +43,120 @@ extern int news_bad;
int newspost(void) int newspost(void)
{ {
int start = TRUE; int start = TRUE;
char *buf, *p; char *buf, *p;
long curpos, count, seqnr; long curpos, count, seqnr;
FILE *ofp = NULL, *nb; FILE *ofp = NULL, *nb;
struct utsname utsbuf; 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);
}
if (newsopen)
fclose(nfp); 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. * Mode rnews, pipe just created newsbatch to rnews.
@ -219,8 +218,11 @@ int newspost(void)
unlink(buf); unlink(buf);
} }
sprintf(buf, "%s/tmp/newsout", getenv("MBSE_ROOT")); if (! news_bad) {
unlink(buf); sprintf(buf, "%s/tmp/newsout", getenv("MBSE_ROOT"));
unlink(buf);
}
free(buf); free(buf);
return FALSE; return FALSE;
} }

View File

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