| 586 | #if defined(SIMPLE_MAIL) || defined(SERVER_ADMIN_MSG) |
| 587 | |
| 588 | void |
| 589 | read_simplemail(const char *mbox, boolean adminmsg) |
| 590 | { |
| 591 | FILE *mb = fopen(mbox, "r"); |
| 592 | char curline[128], *msg; |
| 593 | boolean seen_one_already = FALSE; |
| 594 | #ifdef SIMPLE_MAIL |
| 595 | struct flock fl = { 0 }; |
| 596 | #endif |
| 597 | |
| 598 | if (!mb) |
| 599 | goto bail; |
| 600 | |
| 601 | #ifdef SIMPLE_MAIL |
| 602 | fl.l_type = F_RDLCK; |
| 603 | fl.l_whence = SEEK_SET; |
| 604 | fl.l_start = 0; |
| 605 | fl.l_len = 0; |
| 606 | errno = 0; |
| 607 | #endif |
| 608 | |
| 609 | /* Allow this call to block. */ |
| 610 | if (!adminmsg |
| 611 | #ifdef SIMPLE_MAIL |
| 612 | && fcntl(fileno(mb), F_SETLKW, &fl) == -1 |
| 613 | #endif |
| 614 | ) |
| 615 | goto bail; |
| 616 | |
| 617 | while (fgets(curline, 128, mb) != NULL) { |
| 618 | const char *endpunct; |
| 619 | int msglen; |
| 620 | |
| 621 | if (!adminmsg) { |
| 622 | #ifdef SIMPLE_MAIL |
| 623 | fl.l_type = F_UNLCK; |
| 624 | fcntl(fileno(mb), F_UNLCK, &fl); |
| 625 | #endif |
| 626 | There("is a%s message on this scroll.", |
| 627 | seen_one_already ? "nother" : ""); |
| 628 | } |
| 629 | msg = strchr(curline, ':'); |
| 630 | |
| 631 | /* if incorrectly formatted, or message is empty (':' and '\n' take |
| 632 | up 2 chars, so must have at least 3 to be nonempty), give up */ |
| 633 | if (!msg || (msglen = (int) strlen(msg)) < 3) |
| 634 | goto bail; |
| 635 | |
| 636 | *msg = '\0'; |
| 637 | msg++, msglen--; |
| 638 | msg[msglen - 1] = '\0'; /* kill newline */ |
| 639 | |
| 640 | /* supply ending punctuation only if the message doesn't have any */ |
| 641 | endpunct = ""; |
| 642 | if (!strchr(".!?", msg[msglen - 2])) |
| 643 | endpunct = "."; |
| 644 | |
| 645 | if (adminmsg) { |