Source:NetHack 5.0.0/src/mail.c
Jump to navigation
Jump to search
Below is the full text to mail.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/mail.c#line12]], for example.
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* NetHack 5.0 mail.c $NHDT-Date: 1762750699 2025/11/09 20:58:19 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.77 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Pasi Kallinen, 2018. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. #ifdef MAIL 9. #ifdef SIMPLE_MAIL 10. # include <fcntl.h> 11. # include <errno.h> 12. #endif /* SIMPLE_MAIL */ 13. #endif /* MAIL */ 14. #ifdef MAIL_STRUCTURES 15. #include "mail.h" 16. #endif 17. 18. #ifdef MAIL 19. /* 20. * Notify user when new mail has arrived. Idea by Merlyn Leroy. 21. * 22. * The mail daemon can move with less than usual restraint. It can: 23. * - move diagonally from a door 24. * - use secret and closed doors 25. * - run through a monster ("Gangway!", etc.) 26. * - run over pools & traps 27. * 28. * Possible extensions: 29. * - Open the file MAIL and do fstat instead of stat for efficiency. 30. * (But sh uses stat, so this cannot be too bad.) 31. * - Examine the mail and produce a scroll of mail named "From somebody". 32. * - Invoke MAILREADER in such a way that only this single mail is read. 33. * - Do something to the text when the scroll is enchanted or cancelled. 34. * - Make the daemon always appear at a stairwell, and have it find a 35. * path to the hero. 36. * 37. * Note by Olaf Seibert: On the Amiga, we usually don't get mail. So we go 38. * through most of the effects at 'random' moments. 39. * Note by Paul Winner: The MSDOS port also 'fakes' the mail daemon at 40. * random intervals. 41. */ 42. 43. staticfn boolean md_start(coord *); 44. staticfn boolean md_stop(coord *, coord *); 45. staticfn boolean md_rush(struct monst *, int, int); 46. staticfn void newmail(struct mail_info *); 47. #if defined(SIMPLE_MAIL) || defined(SERVER_ADMIN_MSG) 48. staticfn void read_simplemail(const char *mbox, boolean adminmsg); 49. #endif 50. 51. #if !defined(UNIX) && !defined(VMS) 52. int mustgetmail = -1; 53. #endif 54. 55. #ifdef UNIX 56. #include <sys/stat.h> 57. #include <pwd.h> 58. /* DON'T trust all Unices to declare getpwuid() in <pwd.h> */ 59. #if !defined(_BULL_SOURCE) && !defined(__sgi) && !defined(_M_UNIX) 60. #if !defined(SUNOS4) && !(defined(ULTRIX) && defined(__GNUC__)) 61. /* DO trust all SVR4 to typedef uid_t in <sys/types.h> (probably to a long) */ 62. #if defined(POSIX_TYPES) || defined(SVR4) || defined(HPUX) 63. extern struct passwd *getpwuid(uid_t); 64. #else 65. extern struct passwd *getpwuid(int); 66. #endif 67. #endif 68. #endif 69. static struct stat omstat, nmstat; 70. static char *mailbox = (char *) 0; 71. static long laststattime; 72. 73. #if !defined(MAILPATH) && defined(AMS) /* Just a placeholder for AMS */ 74. #define MAILPATH "/dev/null" 75. #endif 76. #if !defined(MAILPATH) && (defined(LINUX) || defined(__osf__)) 77. #define MAILPATH "/var/spool/mail/" 78. #endif 79. #if !defined(MAILPATH) && defined(__FreeBSD__) 80. #define MAILPATH "/var/mail/" 81. #endif 82. #if !defined(MAILPATH) && (defined(BSD) || defined(ULTRIX)) 83. #define MAILPATH "/usr/spool/mail/" 84. #endif 85. #if !defined(MAILPATH) && (defined(SYSV) || defined(HPUX)) 86. #define MAILPATH "/usr/mail/" 87. #endif 88. 89. void 90. free_maildata(void) 91. { 92. if (mailbox) 93. free((genericptr_t) mailbox), mailbox = (char *) 0; 94. } 95. 96. void 97. getmailstatus(void) 98. { 99. if (mailbox) { 100. ; /* no need to repeat the setup */ 101. } else if ((mailbox = nh_getenv("MAIL")) != 0) { 102. mailbox = dupstr(mailbox); 103. #ifdef MAILPATH 104. } else { 105. #ifdef AMS 106. struct passwd ppasswd; 107. 108. (void) memcpy(&ppasswd, getpwuid(getuid()), sizeof (struct passwd)); 109. if (ppasswd.pw_dir) { 110. /* note: 'sizeof "LITERAL"' includes +1 for terminating '\0' */ 111. mailbox = (char *) alloc((unsigned) (strlen(ppasswd.pw_dir) 112. + sizeof AMS_MAILBOX)); 113. Strcpy(mailbox, ppasswd.pw_dir); 114. Strcat(mailbox, AMS_MAILBOX); 115. } 116. #else 117. const char *pw_name = getpwuid(getuid())->pw_name; 118. 119. /* note: 'sizeof "LITERAL"' includes +1 for terminating '\0' */ 120. mailbox = (char *) alloc((unsigned) (strlen(pw_name) 121. + sizeof MAILPATH)); 122. Strcpy(mailbox, MAILPATH); 123. Strcat(mailbox, pw_name); 124. #endif /* AMS */ 125. #endif /* MAILPATH */ 126. } 127. 128. debugpline3("mailbox=%c%s%c", 129. mailbox ? '\"' : '<', 130. mailbox ? mailbox : "null", 131. mailbox ? '\"' : '>'); 132. 133. if (mailbox && stat(mailbox, &omstat)) { 134. #ifdef PERMANENT_MAILBOX 135. pline("Cannot get status of MAIL=\"%s\".", mailbox); 136. free_maildata(); /* set 'mailbox' to Null */ 137. #else 138. omstat.st_mtime = 0; 139. #endif 140. } 141. } 142. #endif /* UNIX */ 143. 144. /* 145. * Pick coordinates for a starting position for the mail daemon. Called 146. * from newmail() and newphone(). 147. */ 148. staticfn boolean 149. md_start(coord *startp) 150. { 151. coord testcc; /* scratch coordinates */ 152. int row; /* current row we are checking */ 153. int lax; /* if TRUE, pick a position in sight. */ 154. int dd; /* distance to current point */ 155. int max_distance; /* max distance found so far */ 156. stairway *stway = gs.stairs; 157. 158. /* 159. * If blind and not telepathic, then it doesn't matter what we pick --- 160. * the hero is not going to see it anyway. So pick a nearby position. 161. */ 162. if (Blind && !Blind_telepat) { 163. if (!enexto(startp, u.ux, u.uy, (struct permonst *) 0)) 164. return FALSE; /* no good positions */ 165. return TRUE; 166. } 167. 168. /* 169. * Arrive at an up or down stairwell if it is in line of sight from the 170. * hero. 171. */ 172. while (stway) { 173. if (stway->tolev.dnum == u.uz.dnum 174. && couldsee(stway->sx, stway->sy)) { 175. startp->x = stway->sx; 176. startp->y = stway->sy; 177. return TRUE; 178. } 179. stway = stway->next; 180. } 181. 182. /* 183. * Try to pick a location out of sight next to the farthest position away 184. * from the hero. If this fails, try again, just picking the farthest 185. * position that could be seen. What we really ought to be doing is 186. * finding a path from a stairwell... 187. * 188. * The arrays gv.viz_rmin[] and gv.viz_rmax[] are set even when blind. 189. * These are the LOS limits for each row. 190. */ 191. lax = 0; /* be picky */ 192. max_distance = -1; 193. retry: 194. for (row = 0; row < ROWNO; row++) { 195. if (gv.viz_rmin[row] < gv.viz_rmax[row]) { 196. /* There are valid positions on this row. */ 197. dd = distu(gv.viz_rmin[row], row); 198. if (dd > max_distance) { 199. if (lax) { 200. max_distance = dd; 201. startp->y = row; 202. startp->x = gv.viz_rmin[row]; 203. 204. } else if (enexto(&testcc, gv.viz_rmin[row], row, 205. (struct permonst *) 0) 206. && !cansee(testcc.x, testcc.y) 207. && couldsee(testcc.x, testcc.y)) { 208. max_distance = dd; 209. *startp = testcc; 210. } 211. } 212. dd = distu(gv.viz_rmax[row], row); 213. if (dd > max_distance) { 214. if (lax) { 215. max_distance = dd; 216. startp->y = row; 217. startp->x = gv.viz_rmax[row]; 218. 219. } else if (enexto(&testcc, gv.viz_rmax[row], row, 220. (struct permonst *) 0) 221. && !cansee(testcc.x, testcc.y) 222. && couldsee(testcc.x, testcc.y)) { 223. max_distance = dd; 224. *startp = testcc; 225. } 226. } 227. } 228. } 229. 230. if (max_distance < 0) { 231. if (!lax) { 232. lax = 1; /* just find a position */ 233. goto retry; 234. } 235. return FALSE; 236. } 237. 238. return TRUE; 239. } 240. 241. /* 242. * Try to choose a stopping point as near as possible to the starting 243. * position while still adjacent to the hero. If all else fails, try 244. * enexto(). Use enexto() as a last resort because enexto() chooses 245. * its point randomly, which is not what we want. 246. */ 247. staticfn boolean 248. md_stop(coord *stopp, /* stopping position (we fill it in) */ 249. coord *startp) /* starting position (read only) */ 250. { 251. coordxy x, y, distance, min_distance = -1; 252. 253. for (x = u.ux - 1; x <= u.ux + 1; x++) 254. for (y = u.uy - 1; y <= u.uy + 1; y++) { 255. if (!isok(x, y) || u_at(x, y)) 256. continue; 257. 258. if (accessible(x, y) && !MON_AT(x, y)) { 259. distance = dist2(x, y, startp->x, startp->y); 260. if (min_distance < 0 || distance < min_distance 261. || (distance == min_distance && rn2(2))) { 262. stopp->x = x; 263. stopp->y = y; 264. min_distance = distance; 265. } 266. } 267. } 268. 269. /* If we didn't find a good spot, try enexto(). */ 270. if (min_distance < 0 && !enexto(stopp, u.ux, u.uy, &mons[PM_MAIL_DAEMON])) 271. return FALSE; 272. 273. return TRUE; 274. } 275. 276. /* Let the mail daemon have a larger vocabulary. */ 277. staticfn NEARDATA const char *mail_text[] = { "Gangway!", "Look out!", 278. "Pardon me!" }; 279. #define md_exclamations() (mail_text[rn2(3)]) 280. 281. /* 282. * Make the mail daemon run through the dungeon. The daemon will run over 283. * any monsters that are in its path, but will replace them later. Return 284. * FALSE if the md gets stuck in a position where there is a monster. Return 285. * TRUE otherwise. 286. */ 287. staticfn boolean 288. md_rush(struct monst *md, 289. int tx, int ty) /* destination of mail daemon */ 290. { 291. struct monst *mon; /* displaced monster */ 292. int dx, dy; /* direction counters */ 293. int fx = md->mx, fy = md->my; /* current location */ 294. int nfx = fx, nfy = fy, /* new location */ 295. d1, d2; /* shortest distances */ 296. 297. /* 298. * It is possible that the monster at (fx,fy) is not the md when: 299. * the md rushed the hero and failed, and is now starting back. 300. */ 301. if (m_at(fx, fy) == md) { 302. remove_monster(fx, fy); /* pick up from orig position */ 303. newsym(fx, fy); 304. } 305. 306. /* 307. * At the beginning and exit of this loop, md is not placed in the 308. * dungeon. 309. */ 310. while (1) { 311. /* Find a good location next to (fx,fy) closest to (tx,ty). */ 312. d1 = dist2(fx, fy, tx, ty); 313. for (dx = -1; dx <= 1; dx++) 314. for (dy = -1; dy <= 1; dy++) 315. if ((dx || dy) && isok(fx + dx, fy + dy) 316. && !IS_STWALL(levl[fx + dx][fy + dy].typ)) { 317. d2 = dist2(fx + dx, fy + dy, tx, ty); 318. if (d2 < d1) { 319. d1 = d2; 320. nfx = fx + dx; 321. nfy = fy + dy; 322. } 323. } 324. 325. /* Break if the md couldn't find a new position. */ 326. if (nfx == fx && nfy == fy) 327. break; 328. 329. fx = nfx; /* this is our new position */ 330. fy = nfy; 331. 332. /* Break if the md reaches its destination. */ 333. if (fx == tx && fy == ty) 334. break; 335. 336. mon = m_at(fx, fy); /* save monster at this position */ 337. if (!Deaf) { 338. SetVoice(md, 0, 80, 0); 339. if (mon) 340. verbalize1(md_exclamations()); 341. else if (u_at(fx, fy)) 342. verbalize("Excuse me."); 343. } 344. 345. if (mon) 346. remove_monster(fx, fy); 347. place_monster(md, fx, fy); /* put md down */ 348. newsym(fx, fy); /* see it */ 349. flush_screen(0); /* make sure md shows up */ 350. nh_delay_output(); /* wait a little bit */ 351. 352. /* Remove md from the dungeon. Restore original mon, if necessary. */ 353. remove_monster(fx, fy); 354. if (mon) { 355. if ((mon->mx != fx) || (mon->my != fy)) 356. place_worm_seg(mon, fx, fy); 357. else 358. place_monster(mon, fx, fy); 359. } 360. newsym(fx, fy); 361. } 362. 363. /* 364. * Check for a monster at our stopping position (this is possible, but 365. * very unlikely). If one exists, then have the md leave in disgust. 366. */ 367. if ((mon = m_at(fx, fy)) != 0) { 368. remove_monster(fx, fy); 369. place_monster(md, fx, fy); /* display md with text below */ 370. newsym(fx, fy); 371. if (!Deaf) { 372. SetVoice(md, 0, 80, 0); 373. verbalize("This place's too crowded. I'm outta here."); 374. } else { 375. pline("%s.", Never_mind); 376. } 377. remove_monster(fx, fy); 378. 379. if ((mon->mx != fx) || (mon->my != fy)) /* put mon back */ 380. place_worm_seg(mon, fx, fy); 381. else 382. place_monster(mon, fx, fy); 383. 384. newsym(fx, fy); 385. return FALSE; 386. } 387. 388. place_monster(md, fx, fy); /* place at final spot */ 389. newsym(fx, fy); 390. flush_screen(0); 391. nh_delay_output(); /* wait a little bit */ 392. 393. return TRUE; 394. } 395. 396. /* Deliver a scroll of mail. */ 397. /*ARGSUSED*/ 398. staticfn void 399. newmail(struct mail_info *info) 400. { 401. struct monst *md; 402. coord start, stop; 403. boolean message_seen = FALSE; 404. 405. /* Try to find good starting and stopping places. */ 406. if (!md_start(&start) || !md_stop(&stop, &start)) 407. goto give_up; 408. 409. /* Make the daemon. Have it rush towards the hero. */ 410. if (!(md = makemon(&mons[PM_MAIL_DAEMON], start.x, start.y, NO_MM_FLAGS))) 411. goto give_up; 412. if (!md_rush(md, stop.x, stop.y)) 413. goto go_back; 414. 415. message_seen = TRUE; 416. if (!Deaf) { 417. SetVoice(md, 0, 80, 0); 418. verbalize("%s, %s! %s.", Hello(md), svp.plname, info->display_txt); 419. } else { 420. pline("Message: %s.", info->display_txt); 421. } 422. 423. if (info->message_typ) { 424. struct obj *obj = mksobj(SCR_MAIL, FALSE, FALSE); 425. 426. if (info->object_nam) 427. obj = oname(obj, info->object_nam, ONAME_NO_FLAGS); 428. if (info->response_cmd) 429. new_omailcmd(obj, info->response_cmd); 430. 431. if (!m_next2u(md)) { 432. if (!Deaf) { 433. SetVoice(md, 0, 80, 0); 434. verbalize("Catch!"); 435. } else { 436. /* don't bother with nonverbal alternative ... */ 437. ; 438. } 439. } 440. display_nhwindow(WIN_MESSAGE, FALSE); 441. obj = hold_another_object(obj, "Oops!", (const char *) 0, 442. (const char *) 0); 443. nhUse(obj); 444. } 445. 446. go_back: 447. /* zip back to starting location */ 448. if (!md_rush(md, start.x, start.y)) 449. md->mx = md->my = 0; /* for mongone, md is not on map */ 450. mongone(md); 451. 452. give_up: 453. /* deliver some classes of messages even if no daemon ever shows up */ 454. if (!message_seen && info->message_typ == MSG_OTHER) 455. pline("Hark! \"%s.\"", info->display_txt); 456. } 457. 458. #if !defined(UNIX) && !defined(VMS) 459. 460. void 461. ckmailstatus(void) 462. { 463. if (u.uswallow || !flags.biff) 464. return; 465. if (mustgetmail < 0) { 466. #if defined(AMIGA) || defined(MSDOS) || defined(TOS) 467. mustgetmail = (svm.moves < 2000) ? (100 + rn2(2000)) 468. : (2000 + rn2(3000)); 469. #endif 470. return; 471. } 472. if (--mustgetmail <= 0) { 473. static struct mail_info deliver = { 474. MSG_MAIL, "I have some mail for you", 0, 0 475. }; 476. newmail(&deliver); 477. mustgetmail = -1; 478. } 479. } 480. 481. DISABLE_WARNING_FORMAT_NONLITERAL 482. 483. enum delivery_types { faulty_delivery, normal_delivery, subst_delivery }; 484. 485. /*ARGSUSED*/ 486. void 487. readmail(struct obj *otmp UNUSED) 488. { 489. int i; 490. enum delivery_types delivery = normal_delivery; 491. const char *recipient = 0; 492. static const char *const junk_templates[] = { 493. "%sReport bugs to <%s>.%s", /*** must be first entry ***/ 494. "Please disregard previous letter.", 495. "Welcome to NetHack.", 496. #ifdef AMIGA 497. "Only Amiga makes it possible.", 498. "CATS have all the answers.", 499. #endif 500. "This mail complies with the Yendorian Anti-Spam Act (YASA)", 501. "Please find enclosed a small token to represent your Owlbear", 502. "**FR33 P0T10N 0F FULL H34L1NG**", 503. "Please return to sender (Asmodeus)", 504. /* when enclosed by "It reads: \"...\"", this is too long 505. for an ordinary 80-column display so wraps to a second line 506. (suboptimal but works correctly); 507. dollar sign and fractional zorkmids are inappropriate within 508. nethack but are suitable for typical dysfunctional spam mail */ 509. ("Buy a potion of gain level for only $19.99! " 510. " Guaranteed to be blessed!"), 511. /* DEVTEAM_URL will be substituted for 2nd "%s"; 512. terminating punctuation (formerly "!") has deliberately been 513. omitted so that it can't be mistaken for part of the URL 514. (unfortunately that is still followed by a closing quote--in 515. the pline below, not the data here) */ 516. "%sInvitation: Visit the NetHack web site at %s%s" 517. }; 518. const char *const it_reads = "It reads: \""; 519. 520. i = rn2(SIZE(junk_templates)); 521. if (strchr(junk_templates[i], '%')) { 522. if (i == 0) { 523. recipient = DEVTEAM_EMAIL; 524. delivery = subst_delivery; 525. } else if (strstri(junk_templates[i], "web site")) { 526. recipient = DEVTEAM_URL; 527. delivery = subst_delivery; 528. } else { 529. impossible("fake mail #%d has undefined substitution", i); 530. delivery = faulty_delivery; 531. } 532. } 533. if (Blind) { 534. pline("Unfortunately you cannot see what it says."); 535. } else { 536. if (delivery == subst_delivery) 537. pline(junk_templates[i], it_reads, recipient, "\""); 538. else if (delivery == normal_delivery) 539. pline("%s%s\"", it_reads, junk_templates[i]); 540. } 541. } 542. 543. RESTORE_WARNING_FORMAT_NONLITERAL 544. 545. #endif /* !UNIX && !VMS */ 546. 547. #ifdef UNIX 548. 549. void 550. ckmailstatus(void) 551. { 552. ck_server_admin_msg(); 553. 554. if (!mailbox || u.uswallow || !flags.biff 555. #ifdef MAILCKFREQ 556. || svm.moves < laststattime + MAILCKFREQ 557. #endif 558. ) 559. return; 560. 561. laststattime = svm.moves; 562. if (stat(mailbox, &nmstat)) { 563. #ifdef PERMANENT_MAILBOX 564. pline("Cannot get status of MAIL=\"%s\" anymore.", mailbox); 565. free_maildata(); 566. #else 567. nmstat.st_mtime = 0; 568. #endif 569. } else if (nmstat.st_mtime > omstat.st_mtime) { 570. if (nmstat.st_size) { 571. static struct mail_info deliver = { 572. #ifndef NO_MAILREADER 573. MSG_MAIL, "I have some mail for you", 574. #else 575. /* suppress creation and delivery of scroll of mail */ 576. MSG_OTHER, "You have some mail in the outside world", 577. #endif 578. 0, 0 579. }; 580. newmail(&deliver); 581. } 582. getmailstatus(); /* might be too late ... */ 583. } 584. } 585. 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) { 646. urgent_pline("The voice of %s booms through the caverns:", 647. curline); 648. } else { 649. pline("This message is from '%s'.", curline); 650. pline("It reads:"); 651. } 652. pline("\"%s\"%s", msg, endpunct); 653. 654. seen_one_already = TRUE; 655. #ifdef SIMPLE_MAIL 656. errno = 0; 657. if (!adminmsg) { 658. fl.l_type = F_RDLCK; 659. fcntl(fileno(mb), F_SETLKW, &fl); 660. } 661. #endif 662. } 663. 664. #ifdef SIMPLE_MAIL 665. if (!adminmsg) { 666. fl.l_type = F_UNLCK; 667. fcntl(fileno(mb), F_UNLCK, &fl); 668. } 669. #endif 670. fclose(mb); 671. if (adminmsg) 672. display_nhwindow(WIN_MESSAGE, TRUE); 673. else 674. unlink(mailbox); 675. return; 676. bail: 677. /* bail out _professionally_ */ 678. if (!adminmsg) 679. pline("It appears to be all gibberish."); 680. } 681. 682. #endif /* SIMPLE_MAIL */ 683. 684. void 685. ck_server_admin_msg(void) 686. { 687. #ifdef SERVER_ADMIN_MSG 688. static struct stat ost,nst; 689. static long lastchk = 0; 690. 691. if (svm.moves < lastchk + SERVER_ADMIN_MSG_CKFREQ) return; 692. lastchk = svm.moves; 693. 694. if (!stat(SERVER_ADMIN_MSG, &nst)) { 695. if (nst.st_mtime > ost.st_mtime) 696. read_simplemail(SERVER_ADMIN_MSG, TRUE); 697. ost.st_mtime = nst.st_mtime; 698. } 699. #endif /* SERVER_ADMIN_MSG */ 700. } 701. 702. /*ARGSUSED*/ 703. void 704. readmail(struct obj *otmp UNUSED) 705. { 706. #ifdef DEF_MAILREADER /* This implies that UNIX is defined */ 707. const char *mr = 0; 708. #endif /* DEF_MAILREADER */ 709. #ifdef SIMPLE_MAIL 710. read_simplemail(mailbox, FALSE); 711. return; 712. #endif /* SIMPLE_MAIL */ 713. #ifdef DEF_MAILREADER /* This implies that UNIX is defined */ 714. if (iflags.debug_fuzzer) 715. return; 716. display_nhwindow(WIN_MESSAGE, FALSE); 717. if (!(mr = nh_getenv("MAILREADER"))) 718. mr = DEF_MAILREADER; 719. 720. if (child(1)) { 721. (void) execl(mr, mr, (char *) 0); 722. nh_terminate(EXIT_FAILURE); 723. } 724. #else 725. #ifndef AMS /* AMS mailboxes are directories */ 726. display_file(mailbox, TRUE); 727. #endif /* AMS */ 728. #endif /* DEF_MAILREADER */ 729. 730. /* get new stat; not entirely correct: there is a small time 731. window where we do not see new mail */ 732. getmailstatus(); 733. } 734. 735. #endif /* UNIX */ 736. 737. #ifdef VMS 738. 739. extern struct mail_info *parse_next_broadcast(void); 740. 741. volatile int broadcasts = 0; 742. 743. void 744. ckmailstatus(void) 745. { 746. struct mail_info *brdcst; 747. 748. if (iflags.debug_fuzzer) 749. return; 750. if (u.uswallow || !flags.biff) 751. return; 752. 753. while (broadcasts > 0) { /* process all trapped broadcasts [until] */ 754. broadcasts--; 755. if ((brdcst = parse_next_broadcast()) != 0) { 756. newmail(brdcst); 757. break; /* only handle one real message at a time */ 758. } 759. } 760. } 761. 762. void 763. readmail(struct obj *otmp) 764. { 765. #ifdef SHELL /* can't access mail reader without spawning subprocess */ 766. const char *txt, *cmd; 767. char *p, buf[BUFSZ] = DUMMY, qbuf[BUFSZ]; 768. int len; 769. 770. /* there should be a command in OMAILCMD */ 771. if (has_oname(otmp)) 772. txt = ONAME(otmp); 773. else 774. txt = ""; 775. len = strlen(txt); 776. if (has_omailcmd(otmp)) 777. cmd = OMAILCMD(otmp); 778. if (!cmd || !*cmd) 779. cmd = "SPAWN"; 780. 781. Sprintf(qbuf, "System command (%s)", cmd); 782. getlin(qbuf, buf); 783. if (*buf != '\033') { 784. for (p = eos(buf); p > buf; *p = '\0') 785. if (*--p != ' ') 786. break; /* strip trailing spaces */ 787. if (*buf) 788. cmd = buf; /* use user entered command */ 789. if (!strcmpi(cmd, "SPAWN") || !strcmp(cmd, "!")) 790. cmd = (char *) 0; /* interactive escape */ 791. 792. vms_doshell(cmd, TRUE); 793. (void) sleep(1); 794. } 795. #else 796. nhUse(otmp); 797. #endif /* SHELL */ 798. } 799. 800. #endif /* VMS */ 801. #endif /* MAIL */ 802. 803. /*mail.c*/