1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
|
/* $Id: respond.c,v 3.0 1992/02/01 03:09:32 davison Trn $
*/
/* This software is Copyright 1991 by Stan Barber.
*
* Permission is hereby granted to copy, reproduce, redistribute or otherwise
* use this software as long as: there is no monetary profit gained
* specifically from the use or reproduction or this software, it is not
* sold, rented, traded or otherwise marketed, and this copyright notice is
* included prominently in any copy made.
*
* The authors make no claims as to the fitness or correctness of this software
* for any use whatsoever, and it is provided as is. Any use of this software
* is at the user's own risk.
*/
#include "EXTERN.h"
#include "common.h"
#include "intrp.h"
#include "cache.h"
#include "head.h"
#include "term.h"
#include "ngdata.h"
#include "ng.h"
#include "util.h"
#include "util2.h"
#include "trn.h"
#include "artio.h"
#include "nntp.h"
#include "final.h"
#include "decode.h"
#include "charsubst.h"
#include "INTERN.h"
#include "respond.h"
static char nullart[] = "\nNull article\n";
bool cut_line();
void
respond_init()
{
if (actfp)
export("NEWSACTIVE", filexp(ACTIVE));
}
int
save_article()
{
bool_int use_pref;
register char *s, *c;
char altbuf[CBUFLEN];
int iter;
bool interactive = (buf[1] == FINISHCMD);
char cmd = *buf;
if (!finish_command(interactive)) /* get rest of command */
return SAVE_ABORT;
if ((use_pref = isupper(cmd)) != 0)
cmd = tolower(cmd);
parseheader(art);
#ifdef MIMESTORE
savefrom = (!mime_article && (cmd == 'w' || cmd == 'e'))
#else
savefrom = (cmd == 'w' || cmd == 'e')
#endif
? htype[PAST_HEADER].ht_minpos : 0;
if (artopen(art) == Nullfp) {
#ifdef VERBOSE
IF(verbose)
fputs("\n\
Saving null articles is not very productive! :-)\n\
",stdout) FLUSH;
ELSE
#endif
#ifdef TERSE
fputs(nullart,stdout) FLUSH;
#endif
return SAVE_DONE;
}
if (chdir(cwd)) {
printf(nocd,cwd) FLUSH;
sig_catcher(0);
}
if (cmd == 'e') { /* is this an extract command? */
static bool custom_extract = FALSE;
int cnt = 0;
bool found_cut = FALSE;
char art_buf[LBUFLEN], *cmdstr;
s = buf+1; /* skip e */
while (*s == ' ') s++; /* skip leading spaces */
safecpy(altbuf,filexp(s),sizeof altbuf);
s = altbuf;
if (*s) {
cmdstr = cpytill(buf,s,'|'); /* check for | */
s = buf + strlen(buf)-1;
while (*s == ' ') s--; /* trim trailing spaces */
*++s = '\0';
if (*cmdstr) {
s = cmdstr+1; /* skip | */
while (*s == ' ') s++;
if (*s) { /* if new command, use it */
if (extractprog)
free(extractprog);
extractprog = savestr(s); /* put extracter in %e */
}
else
cmdstr = extractprog;
}
else
cmdstr = Nullch;
s = buf;
}
else {
if (extractdest)
strcpy(s, extractdest);
if (custom_extract)
cmdstr = extractprog;
else
cmdstr = Nullch;
}
if (cmdstr) {
if (strEQ(extractprog,"-"))
cmdstr = Nullch;
else if (decode_fp != Nullfp)
decode_end();
}
custom_extract = (cmdstr != 0);
seekart((long)savefrom);
if (*s != '/') { /* relative path? */
c = (s==buf ? altbuf : buf);
interp(c, (sizeof buf), getval("SAVEDIR",SAVEDIR));
if (makedir(c,MD_DIR)) /* ensure directory exists */
strcpy(c,cwd);
if (*s) {
while (*c) c++;
*c++ = '/';
strcpy(c,s); /* add filename */
}
s = (s==buf ? altbuf : buf);
}
if (*s != '/') { /* path still relative? */
c = (s==buf ? altbuf : buf);
sprintf(c, "%s/%s", cwd, s);
s = c; /* absolutize it */
}
if (decode_fp != Nullfp) {
printf("Continuing %s:%s\n", decode_fname,
cmd != '\0' && strNE(extractdest,s) ?
" (Ignoring conflicting directory)" : nullstr ) FLUSH;
#ifdef USE_NNTP
nntp_finishbody(FB_SILENT);
#endif
if (decode_type == UUDECODE)
uudecode(artfp);
else
unship(artfp);
}
else {
if (extractdest)
free(extractdest);
s = extractdest = savestr(s); /* make it handy for %E */
if (makedir(s, MD_DIR)) { /* ensure directory exists */
int_count++;
#ifdef USE_NNTP
nntp_finishbody(FB_SILENT);
#endif
return SAVE_DONE;
}
if (chdir(s)) {
printf(nocd,s) FLUSH;
sig_catcher(0);
}
s = getwd(buf); /* simplify path for output */
while(readart(art_buf,LBUFLEN) != Nullch) {
if (*art_buf <= ' ')
continue; /* Ignore empty or initially-whitespace lines */
#ifdef MIMESTORE
if (mime_article) {
char oldmode = mode;
if (!custom_extract) {
printf("Extracting MIME article into %s:\n", s) FLUSH;
extractprog = savestr(filexp(getval("MIMESTORE",MIMESTORE)));
}
else
printf("Extracting MIME article into %s using %s\n",
s, extractprog) FLUSH;
cnt = 0;
#ifdef USE_NNTP
nntp_finishbody(FB_SILENT);
#endif
interp(cmd_buf, sizeof cmd_buf,
getval("EXMIMESAVER",EXMIMESAVER));
termlib_reset();
mode = 'x';
resetty(); /* restore tty state */
doshell(SH,cmd_buf);
noecho(); /* revert to cbreaking */
crmode();
termlib_init();
mode = oldmode;
break;
}
#endif
if (found_cut && custom_extract) {
printf("Extracting data into %s using %s:\n",
s, extractprog) FLUSH;
goto extract_it;
}
if (((*art_buf == '#' || *art_buf == ':')
&& (strnEQ(art_buf+1, "! /bin/sh", 9)
|| strnEQ(art_buf+1, "!/bin/sh", 8)
|| strnEQ(art_buf+2, "This is ", 8)))
|| strnEQ(art_buf, "sed ", 4)
|| strnEQ(art_buf, "cat ", 4)
|| strnEQ(art_buf, "echo ", 5)) {
savefrom = tellart()-strlen(art_buf)-NL_SIZE+1;
seekart((long)savefrom);
if (custom_extract) {
printf("Extracting shar into %s using %s:\n",
s, extractprog) FLUSH;
goto extract_it;
}
/* Check for special-case of shar'ed-uuencoded file */
while(readart(art_buf,LBUFLEN) != Nullch) {
if (*art_buf == '#' || *art_buf == ':'
|| strnEQ(art_buf, "echo ", 5)
|| strnEQ(art_buf, "sed ", 4))
continue;
if (strnEQ(art_buf, "Xbegin ", 7)) {
decode_type = UUDECODE;
goto decode_it;
}
break;
}
printf("Extracting shar into %s:\n", s) FLUSH;
if (extractprog)
free(extractprog);
extractprog = savestr(filexp(getval("UNSHAR",UNSHAR)));
extract_it:
cnt = 0;
#ifdef USE_NNTP
nntp_finishbody(FB_SILENT);
#endif
interp(cmd_buf,(sizeof cmd_buf),getval("EXSAVER",EXSAVER));
termlib_reset();
resetty(); /* restore tty state */
doshell(SH,cmd_buf);
noecho(); /* revert to cbreaking */
crmode();
termlib_init();
break;
}
else
if (!custom_extract
&& (strEQ(art_buf,"$\n")
|| strEQ(art_buf,"$ f\n"))) {
savefrom = tellart()-strlen(art_buf)-NL_SIZE+1;
if (found_cut
|| (readart(art_buf,LBUFLEN) != Nullch
&& (strnEQ(art_buf, "ship ", 5)
|| strnEQ(art_buf, "cont ", 5)))) {
decode_type = UNSHIP;
goto decode_it;
}
}
else
if (!custom_extract
&& (strEQ(art_buf,"table\n")
|| strnEQ(art_buf,"begin ", 6))) {
decode_type = UUDECODE;
savefrom = tellart()-strlen(art_buf)-NL_SIZE+1;
decode_it:
printf("Extracting %s file into %s:\n",
decode_type == UNSHIP? "shipped":"uuencoded", s) FLUSH;
if (extractprog)
free(extractprog);
extractprog = savestr("-");
seekart((long)savefrom);
cnt = 0;
#ifdef USE_NNTP
nntp_finishbody(FB_SILENT);
#endif
if (decode_type == UUDECODE) {
uud_start();
uudecode(artfp);
} else
unship(artfp);
break;
}
else {
if (cut_line(art_buf)) {
savefrom = tellart();
found_cut = TRUE;
}
else if (found_cut || ++cnt == 300) {
break;
}
}
}/* while */
if (cnt) {
if (custom_extract)
printf("Didn't find cut line for extraction to '%s'.\n",
extractprog) FLUSH;
else
printf("Unable to determine type of file.\n") FLUSH;
}
}/* if */
}
else if ((s = index(buf,'|')) != Nullch) {
/* is it a pipe command? */
s++; /* skip the | */
while (*s == ' ') s++;
safecpy(altbuf,filexp(s),sizeof altbuf);
if (savedest)
free(savedest);
savedest = savestr(altbuf);
#ifdef USE_NNTP
nntp_finishbody(FB_SILENT);
#endif
interp(cmd_buf, (sizeof cmd_buf), getval("PIPESAVER",PIPESAVER));
/* then set up for command */
termlib_reset();
resetty(); /* restore tty state */
if (use_pref) /* use preferred shell? */
doshell(Nullch,cmd_buf);
/* do command with it */
else
doshell(sh,cmd_buf); /* do command with sh */
noecho(); /* and stop echoing */
crmode(); /* and start cbreaking */
termlib_init();
}
else { /* normal save */
bool there, mailbox;
char *savename = getval("SAVENAME",SAVENAME);
s = buf+1; /* skip s or S */
if (*s == '-') { /* if they are confused, skip - also */
#ifdef VERBOSE
IF(verbose)
fputs("Warning: '-' ignored. This isn't readnews.\n",stdout)
FLUSH;
ELSE
#endif
#ifdef TERSE
fputs("'-' ignored.\n",stdout) FLUSH;
#endif
s++;
}
for (; *s == ' '; s++); /* skip spaces */
safecpy(altbuf,filexp(s),sizeof altbuf);
s = altbuf;
if (*s != '/') {
interp(buf, (sizeof buf), getval("SAVEDIR",SAVEDIR));
if (makedir(buf,MD_DIR)) /* ensure directory exists */
strcpy(buf,cwd);
if (*s) {
for (c = buf; *c; c++) ;
*c++ = '/';
strcpy(c,s); /* add filename */
}
s = buf;
}
for (iter = 0;
(there = stat(s,&filestat) >= 0) && S_ISDIR(filestat.st_mode);
iter++) { /* is it a directory? */
c = (s+strlen(s));
*c++ = '/'; /* put a slash before filename */
interp(c, s==buf?(sizeof buf):(sizeof altbuf),
iter ? "News" : savename );
/* generate a default name somehow or other */
}
makedir(s,MD_FILE);
if (*s != '/') { /* relative path? */
c = (s==buf ? altbuf : buf);
sprintf(c, "%s/%s", cwd, s);
s = c; /* absolutize it */
}
if (savedest)
free(savedest);
s = savedest = savestr(s); /* doesn't move any more */
/* make it handy for %b */
if (!there) {
if (mbox_always)
mailbox = TRUE;
else if (norm_always)
mailbox = FALSE;
else {
char *dflt = (instr(savename,"%a", TRUE) ? "nyq" : "ynq");
sprintf(cmd_buf,
"\nFile %s doesn't exist--\n use mailbox format?",s);
reask_save:
in_char(cmd_buf, 'M', dflt);
putchar('\n') FLUSH;
#ifdef VERIFY
printcmd();
#endif
if (*buf == 'h') {
#ifdef VERBOSE
IF(verbose)
printf("\n\
Type y to create %s as a mailbox.\n\
Type n to create it as a normal file.\n\
Type q to abort the save.\n\
",s) FLUSH;
ELSE
#endif
#ifdef TERSE
fputs("\n\
y to create mailbox.\n\
n to create normal file.\n\
q to abort.\n\
",stdout) FLUSH;
#endif
goto reask_save;
}
else if (*buf == 'n') {
mailbox = FALSE;
}
else if (*buf == 'y') {
mailbox = TRUE;
}
else if (*buf == 'q') {
goto s_bomb;
}
else {
fputs(hforhelp,stdout) FLUSH;
settle_down();
goto reask_save;
}
}
}
else if (S_ISCHR(filestat.st_mode))
mailbox = FALSE;
else {
int tmpfd;
tmpfd = open(s,0);
if (tmpfd == -1)
mailbox = FALSE;
else {
if (read(tmpfd,buf,LBUFLEN)) {
c = buf;
if (!isspace(MBOXCHAR)) /* if non-zero, */
while (isspace(*c)) /* check the first character */
c++;
mailbox = (*c == MBOXCHAR);
} else {
mailbox = mbox_always; /* if zero length, recheck -M */
}
close(tmpfd);
}
}
safecpy(cmd_buf, filexp(mailbox ?
getval("MBOXSAVER",MBOXSAVER) :
getval("NORMSAVER",NORMSAVER) ), sizeof cmd_buf);
/* format the command */
#ifdef USE_NNTP
nntp_finishbody(FB_SILENT);
#endif
termlib_reset();
resetty(); /* make terminal behave */
if (doshell(use_pref?Nullch:SH,cmd_buf)) {
termlib_init();
fputs("Not saved",stdout);
} else {
termlib_init();
printf("%s to %s %s",
there?"Appended":"Saved",
mailbox?"mailbox":"file",
s);
}
if (interactive)
putchar('\n') FLUSH;
noecho(); /* make terminal do what we want */
crmode();
}
s_bomb:
#ifdef USE_NNTP
if (chdir(spool)) {
#else
if (chdir(spool) || chdir(ngdir)) {
#endif
printf(nocd,ngdir) FLUSH;
sig_catcher(0);
}
#ifdef USE_NNTP
nntp_finishbody(FB_SILENT);
#endif
return SAVE_DONE;
}
int
cancel_article()
{
char *ngs_buf;
char *from_buf;
char *reply_buf;
int myuid = getuid();
int r = -1;
if (artopen(art) == Nullfp) {
#ifdef VERBOSE
IF(verbose)
fputs("\n\
Canceling null articles is your idea of fun? :-)\n\
",stdout) FLUSH;
ELSE
#endif
#ifdef TERSE
fputs(nullart,stdout) FLUSH;
#endif
return r;
}
reply_buf = fetchlines(art,REPLY_LINE);
from_buf = fetchlines(art,FROM_LINE);
ngs_buf = fetchlines(art,NGS_LINE);
if (!instr(from_buf,phostname,FALSE) ||
(!instr(from_buf,loginName,TRUE) &&
!instr(reply_buf,loginName,TRUE) &&
#ifdef NEWS_ADMIN
myuid != newsuid &&
#endif
myuid != ROOTID ) ) {
#ifdef DEBUG
if (debug)
printf("\n%s@%s != %s\n",loginName,phostname,from_buf) FLUSH;
#endif
#ifdef VERBOSE
IF(verbose)
fputs("\nYou can't cancel someone else's article\n",stdout)
FLUSH;
ELSE
#endif
#ifdef TERSE
fputs("\nNot your article\n",stdout) FLUSH;
#endif
}
else {
tmpfp = fopen(headname,"w"); /* open header file */
if (tmpfp == Nullfp) {
printf(cantcreate,headname) FLUSH;
goto no_cancel;
}
interp(buf, (sizeof buf), getval("CANCELHEADER",CANCELHEADER));
fputs(buf,tmpfp);
fclose(tmpfp);
fputs("\nCanceling...\n",stdout) FLUSH;
r = doshell(sh,filexp(getval("CANCEL",CANCEL)));
}
no_cancel:
free(ngs_buf);
free(from_buf);
free(reply_buf);
return r;
}
int
supersede_article() /* Supersedes: */
{
char *ngs_buf;
char *from_buf;
char *reply_buf;
int myuid = getuid();
int r = -1;
bool incl_body = (*buf == 'Z');
if (artopen(art) == Nullfp) {
#ifdef VERBOSE
IF(verbose)
fputs("\n\
Superceding null articles is your idea of fun? :-)\n\
",stdout) FLUSH;
ELSE
#endif
#ifdef TERSE
fputs(nullart,stdout) FLUSH;
#endif
return r;
}
reply_buf = fetchlines(art,REPLY_LINE);
from_buf = fetchlines(art,FROM_LINE);
ngs_buf = fetchlines(art,NGS_LINE);
if (!instr(from_buf,phostname,FALSE) ||
(!instr(from_buf,loginName,TRUE) &&
!instr(reply_buf,loginName,TRUE) &&
#ifdef NEWS_ADMIN
myuid != newsuid &&
#endif
myuid != ROOTID ) ) {
#ifdef DEBUG
if (debug)
printf("\n%s@%s != %s\n",loginName,phostname,from_buf) FLUSH;
#endif
#ifdef VERBOSE
IF(verbose)
fputs("\nYou can't supersede someone else's article\n",stdout)
FLUSH;
ELSE
#endif
#ifdef TERSE
fputs("\nNot your article\n",stdout) FLUSH;
#endif
}
else {
tmpfp = fopen(headname,"w"); /* open header file */
if (tmpfp == Nullfp) {
printf(cantcreate,headname) FLUSH;
goto no_commute;
}
interp(buf, (sizeof buf), getval("SUPERSEDEHEADER",SUPERSEDEHEADER));
fputs(buf,tmpfp);
if (incl_body && artfp != Nullfp) {
parseheader(art);
seekart((long)htype[PAST_HEADER].ht_minpos);
while (readart(buf,LBUFLEN) != Nullch) {
fputs(buf,tmpfp);
}
}
fclose(tmpfp);
safecpy(cmd_buf,filexp(getval("NEWSPOSTER",NEWSPOSTER)),
sizeof cmd_buf);
invoke(cmd_buf,origdir);
r = 0;
}
no_commute:
free(ngs_buf);
free(from_buf);
free(reply_buf);
return r;
}
void
reply()
{
bool incl_body = (*buf == 'R');
#ifdef CHARSUBST
char hbuf[4*LBUFLEN];
#endif
char *maildoer = savestr(getval("MAILPOSTER",MAILPOSTER));
artopen(art);
tmpfp = fopen(headname,"w"); /* open header file */
if (tmpfp == Nullfp) {
printf(cantcreate,headname) FLUSH;
goto no_reply;
}
interp(buf, (sizeof buf), getval("MAILHEADER",MAILHEADER));
fputs(buf,tmpfp);
if (!instr(maildoer,"%h",TRUE))
#ifdef VERBOSE
IF(verbose)
printf("\n%s\n(Above lines saved in file %s)\n",buf,headname)
FLUSH;
ELSE
#endif
#ifdef TERSE
printf("\n%s\n(Header in %s)\n",buf,headname) FLUSH;
#endif
if (incl_body && artfp != Nullfp) {
interp(buf, (sizeof buf), getval("YOUSAID",YOUSAID));
fprintf(tmpfp,"%s\n",buf);
parseheader(art);
seekart((long)htype[PAST_HEADER].ht_minpos);
while (readart(buf,LBUFLEN) != Nullch) {
#ifdef CHARSUBST
strcharsubst(buf,hbuf);
fprintf(tmpfp,"%s%s",indstr,hbuf);
#else
fprintf(tmpfp,"%s%s",indstr,buf);
#endif
}
fprintf(tmpfp,"\n");
}
fclose(tmpfp);
safecpy(cmd_buf,filexp(maildoer),sizeof cmd_buf);
invoke(cmd_buf,origdir);
UNLINK(headname); /* kill the header file */
no_reply:
free(maildoer);
}
void
forward()
{
#ifdef CHARSUBST
char hbuf[4*LBUFLEN];
#endif
char *maildoer = savestr(getval("FORWARDPOSTER",FORWARDPOSTER));
artopen(art);
tmpfp = fopen(headname,"w"); /* open header file */
if (tmpfp == Nullfp) {
printf(cantcreate,headname) FLUSH;
goto no_forward;
}
interp(buf, (sizeof buf), getval("FORWARDHEADER",FORWARDHEADER));
fputs(buf,tmpfp);
if (!instr(maildoer,"%h",TRUE))
#ifdef VERBOSE
IF(verbose)
printf("\n%s\n(Above lines saved in file %s)\n",buf,headname)
FLUSH;
ELSE
#endif
#ifdef TERSE
printf("\n%s\n(Header in %s)\n",buf,headname) FLUSH;
#endif
if (artfp != Nullfp) {
interp(buf, (sizeof buf), getval("FORWARDMSG",FORWARDMSG));
if (*buf)
fprintf(tmpfp,"%s\n",buf);
parseheader(art);
seekart(0L);
while (readart(buf,LBUFLEN) != Nullch) {
#ifdef CHARSUBST
strcharsubst(buf,hbuf);
fprintf(tmpfp,"%s",hbuf);
#else
fprintf(tmpfp,"%s",buf);
#endif
}
interp(buf, (sizeof buf), getval("FORWARDMSGEND",FORWARDMSGEND));
if (*buf)
fprintf(tmpfp,"%s\n",buf);
}
fclose(tmpfp);
safecpy(cmd_buf,filexp(maildoer),sizeof cmd_buf);
invoke(cmd_buf,origdir);
UNLINK(headname); /* kill the header file */
no_forward:
free(maildoer);
}
void
followup()
{
bool incl_body = (*buf == 'F');
char hbuf[4*LBUFLEN]; /* four times the old size */
ART_NUM oldart = art;
if (!incl_body && art <= lastart) {
in_answer("\n\nAre you starting an unrelated topic? [ynq] ", 'F');
setdef(buf,"y");
if (*buf == 'q') /*TODO: need to add 'h' also */
return;
if (*buf != 'n')
art = lastart + 1;
}
artopen(art);
tmpfp = fopen(headname,"w");
if (tmpfp == Nullfp) {
printf(cantcreate,headname) FLUSH;
art = oldart;
return;
}
interp(hbuf, (sizeof hbuf), getval("NEWSHEADER",NEWSHEADER));
fprintf(tmpfp,"%s",hbuf);
if (incl_body && artfp != Nullfp) {
#ifdef VERBOSE
if (verbose)
fputs("\n\
(Be sure to double-check the attribution against the signature, and\n\
trim the quoted article down as much as possible.)\n\
",stdout) FLUSH;
#endif
interp(buf, (sizeof buf), getval("ATTRIBUTION",ATTRIBUTION));
fprintf(tmpfp,"%s\n",buf);
parseheader(art);
seekart((long)htype[PAST_HEADER].ht_minpos);
while (readart(buf,LBUFLEN) != Nullch) {
#ifdef CHARSUBST
strcharsubst(buf,hbuf);
fprintf(tmpfp,"%s%s",indstr,hbuf);
#else
fprintf(tmpfp,"%s%s",indstr,buf);
#endif
}
fprintf(tmpfp,"\n");
}
fclose(tmpfp);
safecpy(cmd_buf,filexp(getval("NEWSPOSTER",NEWSPOSTER)),sizeof cmd_buf);
invoke(cmd_buf,origdir);
UNLINK(headname);
art = oldart;
}
void
invoke(cmd,dir)
char *cmd,*dir;
{
char oldmode = mode;
if (chdir(dir)) {
printf(nocd,dir) FLUSH;
return;
}
termlib_reset();
mode = 'x';
#ifdef VERBOSE
IF(verbose)
printf("\n(leaving cbreak mode; cwd=%s)",dir);
ELSE
#endif
#ifdef TERSE
printf("\n(-cbreak; cwd=%s)",dir);
#endif
#ifdef DEBUG
if (debug)
printf("\nInvoking command: %s",cmd);
#endif
printf("\n\n") FLUSH;
resetty(); /* make terminal well-behaved */
doshell(sh,cmd); /* do the command */
noecho(); /* set no echo */
crmode(); /* and cbreak mode */
#ifdef VERBOSE
IF(verbose)
fputs("\n(re-entering cbreak mode)\n",stdout) FLUSH;
ELSE
#endif
#ifdef TERSE
fputs("\n(+cbreak)\n",stdout) FLUSH;
#endif
termlib_init();
mode = oldmode;
#ifdef USE_NNTP
if (chdir(spool)) {
#else
if (chdir(spool) || chdir(ngdir)) {
#endif
printf(nocd,ngdir) FLUSH;
sig_catcher(0);
}
}
/*
** cut_line() determines if a line is meant as a "cut here" marker.
** Some examples that we understand:
**
** BEGIN--cut here--cut here
**
** ------------------ tear at this line ------------------
**
** #----cut here-----cut here-----cut here-----cut here----#
*/
bool
cut_line(str)
char *str;
{
char *cp, got_flag;
char word[80];
int dash_cnt, equal_cnt, other_cnt;
/* Disallow any single-/double-quoted, parenthetical or c-commented
** string lines. Make sure it has the cut-phrase and at least six
** '-'s or '='s. If only four '-'s are present, check for a duplicate
** of the cut phrase. If over 20 unknown characters are encountered,
** assume it isn't a cut line. If we succeed, return TRUE.
*/
for (cp = str, dash_cnt = equal_cnt = other_cnt = 0; *cp; cp++) {
switch (*cp) {
case '-':
dash_cnt++;
break;
case '=':
equal_cnt++;
break;
case '/':
if(*(cp+1) != '*') {
break;
}
case '"':
case '\'':
case '(':
case ')':
case '[':
case ']':
case '{':
case '}':
return FALSE;
default:
other_cnt++;
break;
}
}
if (dash_cnt < 4 && equal_cnt < 6)
return FALSE;
got_flag = 0;
for (*(cp = word) = '\0'; *str; str++) {
if (islower(*str))
*cp++ = *str;
else if (isupper(*str))
*cp++ = tolower(*str);
else {
if (*word) {
*cp = '\0';
switch (got_flag) {
case 2:
if (!strcmp(word, "line")
|| !strcmp(word, "here"))
if ((other_cnt -= 4) <= 20)
return TRUE;
break;
case 1:
if (!strcmp(word, "this")) {
got_flag = 2;
other_cnt -= 4;
}
else if (!strcmp(word, "here")) {
other_cnt -= 4;
if ((dash_cnt >= 6 || equal_cnt >= 6)
&& other_cnt <= 20)
return TRUE;
dash_cnt = 6;
got_flag = 0;
}
break;
case 0:
if (!strcmp(word, "cut")
|| !strcmp(word, "snip")
|| !strcmp(word, "tear")) {
got_flag = 1;
other_cnt -= strlen(word);
}
break;
}
*(cp = word) = '\0';
}
}
} /* for *str */
return FALSE;
}
|