home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 4
/
CDPD_IV.bin
/
networking
/
uucp
/
amigauucpsrc
/
dnews
/
edit.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-29
|
5KB
|
265 lines
/*
* EDIT (reply, followup)
*/
#include "defs.h"
#include <sys/stat.h>
Prototype void ReplyArticle(short, NGroup *);
Prototype void FollowUpArticle(short, NGroup *);
Prototype void PostArticle(NGroup *);
Local int EditFile(char *);
Local void IncludeSignature(char *, FILE *);
Local void IncludeText(FILE *, FILE *);
void
ReplyArticle(key, grp)
short key;
NGroup *grp;
{
char *fn = TmpFileName("T:DNews");
char *nf = FileForArticle(grp, grp->CurNo);
char *field;
char *user = GetUserName();
FILE *fi = ((nf) ? fopen(nf, "r") : NULL);
FILE *fo;
if (fi == NULL) {
if (nf)
printf("Unable to open %s\n", nf);
return;
}
fo = fopen(fn, "w");
if (fo == NULL) {
printf("Unable to create %s\n", fn);
if (fi)
fclose(fi);
return;
}
/*
* Get Return Address: Reply-To:
* From:
*/
if ((field = FindField(fi, "Reply-To:")) == NULL)
field = FindField(fi, "From:");
if (field) {
fprintf(fo, "To: %s\n", field);
free(field);
} else {
fprintf(fo, "To: \n");
}
if (field = FindField(fi, "Subject:")) {
char *base = field;
while (*field == ' ' || *field == 9)
++field;
if (strnicmp(field, "re:", 3) == 0)
field += 3;
fprintf(fo, "Subject: Re: %s\n", field);
free(base);
} else {
fprintf(fo, "Subject: \n");
}
if (field = FindField(fi, "Message-ID:")) {
fprintf(fo, "References: %s\n", field);
free(field);
}
fprintf(fo, "\n");
if (isupper(key))
IncludeText(fi, fo);
fprintf(fo, "\n");
IncludeSignature(user, fo);
fclose(fo);
if (EditFile(fn)) {
sprintf(TmpBuf, "%s < %s -f %s", GetConfigProgram(SENDMAIL), fn, user);
system(TmpBuf);
}
if (fi)
fclose(fi);
remove(fn);
}
void
FollowUpArticle(key, grp)
short key;
NGroup *grp;
{
char *fn = TmpFileName("T:DNews");
char *nf = FileForArticle(grp, grp->CurNo);
char *field;
char *user = GetUserName();
FILE *fi = ((nf) ? fopen(nf, "r") : NULL);
FILE *fo;
if (fi == NULL) {
if (nf)
printf("Unable to open %s\n", nf);
return;
}
fo = fopen(fn, "w");
if (fo == NULL) {
printf("Unable to create %s\n", fn);
if (fi)
fclose(fi);
return;
}
if (field = FindField(fi, "Newsgroups:")) {
fprintf(fo, "Newsgroups: %s\n", field);
free(field);
} else {
fprintf(fo, "Newsgroups: %s\n", grp->Name);
}
if (field = FindField(fi, "Subject:")) {
char *base = field;
while (*field == ' ' || *field == 9)
++field;
if (strnicmp(field, "re:", 3) == 0)
field += 3;
fprintf(fo, "Subject: Re: %s\n", field);
free(base);
} else {
fprintf(fo, "Subject: \n");
}
if (field = FindField(fi, "Distribution:")) {
fprintf(fo, "Distribution: %s\n", field);
free(field);
} else {
fprintf(fo, "Distribution: world\n");
}
fprintf(fo, "\n");
if (isupper(key)) {
fprintf(fo, "In article ");
if (field = FindField(fi, "Message-ID:")) {
fprintf(fo, "%s ", field);
free(field);
} else {
fprintf(fo, "? ");
}
if (field = FindField(fi, "From:")) {
fprintf(fo, "%s", field);
free(field);
} else {
fprintf(fo, "?");
}
fprintf(fo, " writes:\n");
IncludeText(fi, fo);
}
fprintf(fo, "\n");
IncludeSignature(user, fo);
fclose(fo);
if (EditFile(fn)) {
PostNews(fi, fn);
} else {
remove(fn);
}
if (fi)
fclose(fi);
}
void
PostArticle(grp)
NGroup *grp;
{
char *fn = TmpFileName("T:DNews");
char *nf = (grp) ? FileForArticle(grp, grp->CurNo) : NULL;
char *field;
char *user = GetUserName();
FILE *fi = NULL;
FILE *fo;
if (nf)
fi = fopen(nf, "r");
fo = fopen(fn, "w");
if (fo == NULL) {
printf("Unable to create %s\n", fn);
fclose(fi);
return;
}
fprintf(fo, "Newsgroups: %s\n", (grp) ? grp->Name : "");
fprintf(fo, "Subject: \n");
fprintf(fo, "Distribution: world\n");
fprintf(fo, "\n");
IncludeSignature(user, fo);
fclose(fo);
if (EditFile(fn)) {
PostNews(NULL, fn);
} else {
remove(fn);
}
fclose(fi);
}
static int
EditFile(fn)
char *fn;
{
struct stat s1, s2;
int r = 0;
if (stat(fn, &s1) == 0) {
sprintf(TmpBuf, "%s %s", GetConfig(NEWSEDITOR, GetConfig(EDITOR, "dme")), fn);
system(TmpBuf);
r = 1;
if (stat(fn, &s2) == 0) {
if (s1.st_mtime == s2.st_mtime)
r = 0;
}
if (r == 1)
r = getyn("Send It Off?");
}
return(r);
}
static void
IncludeSignature(user, fo)
char *user;
FILE *fo;
{
FILE *fi;
sprintf(TmpBuf, "%s.signature", user);
fi = openlib(TmpBuf);
if (fi == NULL)
fi = openlib(".signature");
if (fi) {
fputs("--\n", fo);
while (fgets(TmpBuf, sizeof(TmpBuf), fi))
fputs(TmpBuf, fo);
fclose(fi);
} else {
puts("Warning, no .signature file!");
}
}
static void
IncludeText(fi, fo)
FILE *fi;
FILE *fo;
{
if (fi) {
rewind(fi);
while (fgets(TmpBuf, sizeof(TmpBuf), fi) && TmpBuf[0] != '\n');
while (fgets(TmpBuf, sizeof(TmpBuf), fi))
fprintf(fo, ">%s", TmpBuf);
}
}