home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / COMMS / PSIONMAI / PMFULLSO / MAILRDR / SCCS / S.MAI < prev    next >
Encoding:
Text File  |  1995-07-11  |  92.7 KB  |  4,803 lines

  1. h18934
  2. s 00020/00059/01695
  3. d D 2.7 95/07/11 18:46:21 tim 20 19
  4. c header window now works properley, fixed the key values to work correctly. dogreet now presents a test window
  5. e
  6. s 00005/00005/01749
  7. d D 2.6 95/07/11 14:10:07 tim 19 18
  8. c the up and down arrows on the headers screen now works
  9. c still need to fix the displayed headers
  10. e
  11. s 00021/00008/01733
  12. d D 2.5 95/07/10 21:48:56 tim 18 17
  13. c now prints the status and also blanks out the rest of the screen if there 
  14. c are spare lines
  15. e
  16. s 00052/00066/01689
  17. d D 2.4 95/07/10 21:28:03 tim 17 16
  18. c this version compiles OK, testing is now needed
  19. e
  20. s 00393/00191/01362
  21. d D 2.3 95/07/10 20:42:33 tim 16 15
  22. c added mechanism for printing a scrolling list, hotkey support for moving in it and changes all user io to be window / dialog based
  23. c *** CHANGED *** 95/07/10 20:43:54 tim
  24. c added some more window sturr and added code for mofing up / down the list.
  25. c need to add code for window display etc and interaction with the user
  26. e
  27. s 00088/00180/01465
  28. d D 2.2 95/07/10 14:18:04 tim 15 14
  29. c added some more window sturr and added code for mofing up / down the list.
  30. c need to add code for window display etc and interaction with the user
  31. e
  32. s 00077/00310/01568
  33. d D 2.1 95/07/10 13:28:03 tim 14 13
  34. c removed all the debugging code (it does not work very well with the window system)
  35. c started adding the main menu stuff
  36. c NOTE this version WILL NEVER compile
  37. e
  38. s 00000/00000/01878
  39. d D 1.13 95/07/10 12:15:38 tim 13 12
  40. c nothing
  41. e
  42. s 00004/00003/01874
  43. d D 1.12 95/07/10 10:38:34 tim 12 11
  44. c various bits of tidying up
  45. e
  46. s 00025/00015/01852
  47. d D 1.11 95/07/10 10:09:42 tim 11 10
  48. c cpy file now works
  49. e
  50. s 00010/00031/01857
  51. d D 1.10 95/07/07 18:08:41 tim 10 9
  52. c cpy file now works
  53. e
  54. s 00063/00018/01825
  55. d D 1.9 95/07/04 21:01:02 tim 9 8
  56. c the size of input lines are now based on a define HDRLEN.
  57. c another attempt at fixing the cpyfile code
  58. e
  59. s 00012/00005/01831
  60. d D 1.8 95/06/29 19:18:23 tim 8 7
  61. c the word stuff now works properly and operates on text files just have to fix the cpyfile stuff and add the help, might be an idea to remove the debugging stuff as well in mainloop but not for a while
  62. e
  63. s 00094/00027/01742
  64. d D 1.7 95/06/29 17:43:52 tim 7 6
  65. c Full functionality now OK appart from including emails and the fact that word writes out modified files in word not txt format
  66. e
  67. s 00201/00040/01568
  68. d D 1.6 95/06/28 19:50:56 tim 6 5
  69. c file functions appart from cpyfile now work
  70. e
  71. s 00185/00083/01423
  72. d D 1.5 95/06/28 14:53:26 tim 5 4
  73. c linked list code seems to work
  74. e
  75. s 00014/00013/01492
  76. d D 1.4 95/06/27 21:15:52 tim 4 3
  77. c header printing code now works
  78. e
  79. s 00433/00054/01072
  80. d D 1.3 95/06/27 20:55:06 tim 3 2
  81. c basic loading and writting of meta files now works, basic ll functions related to that now work
  82. e
  83. s 01009/00004/00117
  84. d D 1.2 95/06/27 15:59:19 tim 2 1
  85. c expanded to include the basic system
  86. e
  87. s 00121/00000/00000
  88. d D 1.1 95/06/22 17:59:59 tim 1 0
  89. c initial setup, just to check we can call word from within an app
  90. c *** CHANGED *** 95/06/22 18:01:06 tim
  91. c 
  92. e
  93. u
  94. U
  95. f e 0
  96. t
  97. T
  98. I 2
  99. /* start of include files */
  100. E 2
  101. I 1
  102. #include <plib.h>
  103. I 14
  104. D 17
  105. #include <p_std.h>
  106. E 17
  107. E 14
  108. #include <wlib.h>
  109. I 2
  110. #include <hwif.h>
  111.  
  112. /* end of include files */
  113.  
  114. /* start of structure definitions */
  115.  
  116. /* initial data */
  117. struct mydata {
  118.     TEXT myaddr[50] ;
  119.     TEXT mypath[P_FNAMESIZE] ;
  120.     } ;
  121. D 9
  122.     
  123. E 9
  124. I 9
  125. /* how large should the header lines be */
  126. #define HDRLEN 100    
  127. E 9
  128. /* linked list data definitions */
  129. struct ll {
  130.    TEXT datafile[13] ; /* <name>.<ext>\0 where name is upto 8 chars and ext is 3 chars, total 11 plis the . and the \0 gives 13 */
  131. D 9
  132.    TEXT to[100] ;
  133.    TEXT from[100] ;
  134.    TEXT subject[100] ;
  135.    TEXT cc[100] ;
  136.    TEXT bcc[100] ;
  137. E 9
  138. I 9
  139.    TEXT to[HDRLEN] ;
  140.    TEXT from[HDRLEN] ;
  141. D 10
  142.    TEXT subjectHDRLEN100] ;
  143. E 10
  144. I 10
  145.    TEXT subject[HDRLEN] ;
  146. E 10
  147.    TEXT cc[HDRLEN] ;
  148.    TEXT bcc[HDRLEN] ;
  149. E 9
  150.    INT status ;
  151.    INT read ;
  152.    INT no ;
  153.    INT count ;
  154.    struct mydata * mydata ;
  155.    struct ll * next ;
  156.    } ;
  157.  
  158. /* end of struct definitions */
  159.  
  160.  
  161. /* start of defines */
  162.  
  163. I 6
  164. D 7
  165. #define RUNONSUN
  166. E 7
  167. I 7
  168. /* #define RUNONSUN */
  169. E 7
  170.  
  171. E 6
  172. /* list printing definitions */
  173. #define PDATAFILE 0x1
  174. #define PTO 0x2
  175. #define PFROM 0x4
  176. #define PSUBJECT 0x8
  177. #define PCC 0x10
  178. #define PBCC 0x20
  179. #define PSTATUS 0x40
  180. #define PREAD 0x80
  181. #define PNO 0x100
  182. #define PCOUNT 0x200
  183. #define PACTIVE 0x400
  184. #define PIGNORE 0x800
  185. #define PDELETED 0x1000
  186. D 3
  187. /* general defines *l/
  188. E 3
  189. I 3
  190. /* general defines */
  191. E 3
  192. #define TRUE 1
  193. #define FALSE 0
  194. I 3
  195. D 5
  196. #define ERR -1
  197. E 5
  198. I 5
  199. #define FILEERR -1
  200. #define MEMERR -2
  201. #define IERR -3
  202. E 5
  203. E 3
  204.  
  205. /* locations of the meta files */
  206. #define METAIN "LOC::M:\\MAILDIR\\IN.MTA"
  207. #define METAOUT "LOC::M:\\MAILDIR\\OUT.MTA"
  208. I 7
  209.  
  210. /* location of the word app */
  211. D 8
  212. #define WORDCMD "ROM::WORD.APP"
  213. E 8
  214. I 8
  215. #define MAILRDRCMD "ROM::WORD.APP"
  216. /* the name to match the name on the system screen
  217.    as this is compiled into the alias file it is probabaly not something you
  218.    will change unless you also rename the mailrdr.ma and mailrdr.pic files
  219.    as well as changing the mailrdr.ma file */
  220. #define MAILRDRNAME "Mailrdr"
  221. #define MAILRDREXT ".msg"
  222. E 8
  223. E 7
  224. /* default name for output files */
  225. D 3
  226. #define OUTSKELETON "out.msg"
  227. E 3
  228. I 3
  229. D 6
  230. #define OUTSKELETON "out*.msg"
  231. E 6
  232. I 6
  233. D 7
  234. #define OUTSKELETON "out%d.msg"
  235. E 7
  236. I 7
  237. D 9
  238. #define OUTSKELETON "OUT%d.TXT"
  239. E 9
  240. I 9
  241. #define OUTSKELETON "OUT%d.MSG"
  242. E 9
  243. E 7
  244. E 6
  245. E 3
  246.  
  247. I 9
  248. D 11
  249. /* start and end include messages */
  250. #define STARTINCL "--- Begin Included Message ---\n"
  251. #define ENDINCL "--- End Included Message ---\n"
  252.  
  253. E 11
  254. /* max line length */
  255. #define MAXLINE 1024
  256. E 9
  257. /* ll status values */
  258. #define ACTIVE 0
  259. #define IGNORE -1
  260. #define DELETED -2
  261. /* ll new / read */
  262. #define RD -1
  263. #define NEW -2
  264.  
  265. I 6
  266. D 14
  267. /* debug status */
  268. #ifdef RUNONSUN
  269. #define cmddbg TRUE 
  270. #define lldbg FALSE 
  271. #define mtadbg FALSE 
  272. #define topdbg TRUE 
  273. #define procdbg TRUE 
  274. #define inpdbg TRUE 
  275. #define filedbg TRUE 
  276. #define ancdbg FALSE
  277. #else
  278. #define cmddbg FALSE 
  279. #define lldbg FALSE 
  280. #define mtadbg FALSE 
  281. #define topdbg FALSE 
  282. D 7
  283. #define procdbg TRUE 
  284. E 7
  285. I 7
  286. #define procdbg FALSE 
  287. E 7
  288. #define inpdbg FALSE 
  289. D 9
  290. #define filedbg FALSE 
  291. E 9
  292. I 9
  293. D 10
  294. #define filedbg TRUE 
  295. E 10
  296. I 10
  297. #define filedbg FALSE 
  298. E 10
  299. E 9
  300. #define ancdbg FALSE
  301. #endif
  302. E 14
  303. E 6
  304.  
  305. I 6
  306. /* max number of outgoing emails */
  307. #define MAXEMAILOUT 100
  308.  
  309. I 16
  310. /* stuff relating to the number of lines in the header window */
  311. #define ITEMS_ON_SCREEN 5
  312. D 18
  313. #define ITEMS_ON_HALF_SCREEN 2
  314. E 18
  315. I 18
  316. D 20
  317. #define ITEMS_ON_HALF_SCREEN ((ITEMS_ON_SCREEN -1) /2)
  318. E 20
  319. I 20
  320. #define ITEMS_ON_HALF_SCREEN 2
  321. E 20
  322. E 18
  323. E 16
  324.  
  325. I 16
  326. /* how much to increase the y location when printing the headers */
  327. #define HDRINCR 11
  328.  
  329. E 16
  330. E 6
  331. /* End of defines */
  332.  
  333. /* Start of Global data */
  334.  
  335. /* pointers to the in and out list and the list we are currently working on */
  336. struct ll * inlist ;
  337. struct ll * outlist ;
  338. struct ll * currlist ;
  339. I 3
  340. D 6
  341. /* debug status */
  342. INT cmddbg = TRUE ;
  343. D 5
  344. INT lldbg = TRUE ;
  345. INT mtadbg = TRUE ;
  346. E 5
  347. I 5
  348. INT lldbg = FALSE ;
  349. INT mtadbg = FALSE ;
  350. E 5
  351. INT topdbg = TRUE ;
  352. INT procdbg = TRUE ;
  353. INT inpdbg = TRUE ;
  354. INT filedbg = TRUE ;
  355. D 4
  356. INT ancdbg = TRUE ;
  357. E 4
  358. I 4
  359. INT ancdbg = FALSE ;
  360. E 6
  361. E 4
  362. E 3
  363.  
  364. I 14
  365. /* menu stuff, first define the commands array */
  366. LOCAL_D TEXT *cmds[]= {
  367.     "vView Current", /* these will go under the Current Functions submenu */
  368.     "dDelete Current",
  369.     "uUndelete Current",
  370.     "mModify Header",
  371.     "nNew Email", /* these will go under the Compose submenu */
  372.     "rReply to sender",
  373.     "aReply to all",
  374.     "xExit and save state", /* these will go under the special menu */
  375.     "cExit and lose state",
  376.     "sSwitch between lists",
  377.     NULL };
  378. /* this defines how the commands menu will be presented */
  379. LOCAL_D H_MENU_DATA mdata[] = {
  380.     "Current Email", 4,
  381.     "Compose",3,
  382.     "Special",3,
  383.     NULL };
  384.     
  385. /* pointers to the arrays. DO NOT CHANGE THESE NAMES OR DEFINITIONS as they
  386.    are used by the psion ROM to do menus etc. */
  387. GLDEF_D TEXT ** _cmds=(&cmds[0]) ;
  388. GLDEF_D H_MENU_DATA * _mdata=(&mdata[0]) ;
  389. /* the current mail number */
  390. INT mailno ; 
  391.  
  392. /* the main window */
  393. UINT MainWid ;
  394. I 16
  395.  
  396. /* the status window */
  397. W_WINDATA wdstatus ;
  398. UINT gcstatus ;
  399. G_GC gdstatus ;
  400. INT winstatus ;
  401. /* the headers window */
  402. W_WINDATA wdhdr ;
  403. UINT gchdr ;
  404. G_GC gdhdr ;
  405. INT winhdr ;
  406.  
  407. D 20
  408. /* welcome strings */
  409. TEXT * welc1 = "Psion SMTP Offline mail reader" ;
  410. TEXT * welc2 = "Version %I%, (C) Tim Graves, Sun Microsystems" ;
  411. D 17
  412. TEXT * welc3 = "Press any key to continue"
  413. TEST * spacestr = "                              " ;
  414. E 17
  415. I 17
  416. TEXT * welc3 = "Press any key to continue" ;
  417. E 20
  418. I 20
  419. /* used to remove waste from the end of a line */
  420. E 20
  421. D 18
  422. TEXT * blank = "                              " ;
  423. E 18
  424. I 18
  425. TEXT * blank = "                                       " ;
  426. E 18
  427. E 17
  428.  
  429. E 16
  430. E 14
  431. /* End of Global data */
  432.  
  433. /* Start of function definitions */
  434.  
  435. /* main and top level functions */
  436. E 2
  437. VOID main(VOID);
  438. VOID doword(TEXT * fname) ;
  439. I 2
  440. VOID initwins(VOID) ;
  441. I 16
  442. VOID initmywins(VOID) ;
  443. E 16
  444. VOID dogreet(VOID) ;
  445. D 3
  446. VOID initlist(VOID) ;
  447. VOID mainloop(VOID) ;
  448. VOID dotidy(VOID) ;
  449. E 3
  450. I 3
  451. INT initlist(VOID) ;
  452. INT mainloop(VOID) ;
  453. INT dotidy(VOID) ;
  454. E 3
  455. VOID shutwins(VOID) ;
  456. I 14
  457. D 16
  458. /* these functions relate to the window stuff */
  459. E 16
  460. LOCAL_C VOID ManageCommand(INT keycode) ; /* decide what to do with a command */
  461. I 16
  462. /* these functions relate to the window stuff */
  463. VOID statusmsg(TEXT * str) ;
  464. VOID redolist(VOID) ;
  465. INT askincl(VOID) ; /* ask if we want to include the current email */
  466. E 16
  467. E 14
  468. /* the following relate to the commands for modifying the mailbox in view */
  469. VOID readmail(INT mailno, struct ll * llptr) ; /* bring up a viewer */
  470. VOID wrtemail(INT mailno, struct ll * llptr) ; /* wtite / reply */
  471. VOID delmail (INT mailno, struct ll * llptr) ; /* delete the mail from the internal linked lists */
  472. VOID udelmail (INT mailno, struct ll * llptr) ; /* undelete the mail from the internal linked lists */
  473.  
  474. /* stuff for starting / other processes */
  475. E 2
  476. INT buildcmd(TEXT cmdbyte, TEXT * appname, TEXT * appext, TEXT * appalias, TEXT * fname, TEXT * cmdline) ;
  477. INT runcmd(TEXT * appname, TEXT * cmdline, INT cmdlen) ;
  478. I 2
  479.  
  480. /* the following are commands that work on the mailbox files */
  481. INT delfile(struct ll * llcur, struct ll * llstart) ; /* delete the actual email file */
  482. INT newfile(struct ll * llcur, struct ll * llstart) ; /* create a new empty email file and return the name */
  483. INT cpyfile (struct ll * newll, struct ll * outhead, struct ll * origll, struct ll * inhead) ;/* cpyfile - copy from the file in origll to the file in newll assume the file exists */
  484. I 6
  485. INT fileexist(TEXT * fname) ; /* does the file given in fname exist return TRUE or FALSE if any other error than E_FILE_NXIST return FILEERR */
  486. E 6
  487.  
  488.  
  489. I 6
  490.  
  491. E 6
  492. /* the following work on the meta file */
  493. INT readmeta(TEXT * fname, struct ll * itemlist) ; /* read in the data descriptions */
  494. INT wrtmeta(TEXT * fname, struct ll * itemlist) ; /* write the data descriptions out */
  495. INT readhdr(VOID * fd, struct ll * itemlist) ; /* read the from, subject and return path etc from the data file */
  496. INT wrthdr(VOID * fd, struct ll * itemlist) ; /* write a subject and destination etc to the data file */
  497. INT getf(VOID * fd, TEXT * line) ; /* read a line of text from file handle */
  498. INT putf(VOID * fd, TEXT * line) ; /* write a line of text to file handle */
  499.  
  500. /* commands to manipulate the linked list */
  501. struct ll * llnew(VOID) ;
  502. struct ll * llnofind(INT no, struct ll * llstart) ;
  503. VOID llfill(struct ll * llptr, TEXT * datafile, TEXT * to, TEXT * from, TEXT * subject, TEXT * cc, TEXT * bcc, INT status, INT read, INT no) ;
  504. VOID llfree (struct ll * llptr) ;
  505. VOID lladd(struct ll * newll, struct ll * startll) ;
  506. VOID llinit(VOID);
  507. VOID llcopy(struct ll * out, struct ll * in) ; /* copy the strings in an entry */
  508. D 6
  509. VOID prgemail(struct ll * llptr) ;
  510. E 6
  511. I 6
  512. INT prgemail(struct ll * llptr) ;
  513. E 6
  514. VOID llprint(struct ll * startll, INT mask, INT startno, INT endno); /* print the list at start ll, according to the mask, between the numbers startno and end no */
  515. D 16
  516. VOID llprinta(struct ll * llptr, INT mask) ; /* print the ll structure according to the mask */
  517. VOID disphdrs(struct ll * llptr, INT startno, INT endno) ; /* display the usual header information */
  518. E 16
  519. I 16
  520. VOID llprinta(struct ll * llptr, INT mask, TEXT * str) ; /* print the ll structure according to the mask */
  521. VOID disphdrs(struct ll * llptr) ; /* display the usual header information */
  522. E 16
  523. INT llvalid(INT mailno, struct ll * llptr) ; /* is mailno in the list and marked as ACTIVE ? */
  524. I 3
  525. VOID lldump(struct ll * llptr) ; /* print the current ll entry */
  526. VOID lldmpall(struct ll * llptr) ; /* print the entire ll list */
  527. E 3
  528.  
  529.  
  530. /* functions for reading headers from the user */
  531. D 16
  532. VOID putnonl (TEXT * line) ; /* print output without a newline */
  533. VOID getinp(TEXT * in) ; /* getinp, read a line from the keyboard */
  534. VOID getbcc (TEXT * bcc) ; /* bcc list */
  535. VOID getcc (TEXT * cc) ; /* cc list */
  536. VOID getsub(TEXT * sub) ; /* subject */
  537. VOID getto(TEXT * to) ; /* target address */
  538. VOID getinfo(TEXT * request, TEXT * target) ; /* read a line of text, if there is data in there use that as a default */
  539. E 16
  540. VOID gethdr(struct ll * in) ; /* fill in a data entry with user information */
  541.  
  542. /* functions for creating new emails and replys */
  543. INT newemail(INT mailno, struct ll * startll, INT incl) ; /* newemail, new list entry, fill it in then write the email */
  544. INT repall(INT mailno, struct ll * startll, INT incl) ; /* repall, reply to the sender and all other recievers */
  545. INT repfrom(INT mailno, struct ll * startll, INT incl) ; /* repfrom, reply to the sender only */
  546.  
  547. D 16
  548. /* command handlers */
  549. VOID getcmd(TEXT * cmd) ; /* read the command from the input line */
  550. E 16
  551.  
  552. /* End of function definitions */
  553.  
  554. /* start of actual code */
  555.  
  556. /* start of linked list code */
  557.  
  558. /* display the usual header information */
  559. D 16
  560. VOID disphdrs(struct ll * llptr, INT startno, INT endno) 
  561. E 16
  562. I 16
  563. VOID disphdrs(struct ll * llptr) 
  564. E 16
  565. {
  566. D 16
  567.     INT mask ;
  568. E 16
  569. I 16
  570.     INT mask, startno, endno ;
  571. E 16
  572. I 3
  573. D 14
  574.     if (lldbg == TRUE)
  575.         p_printf("CALL: disphdrs (llptr = OMITTED, starton = %d, endno = %d)", startno, endno) ;
  576. E 14
  577. E 3
  578.     /* if llptr is inlist include from, otherwise include to */
  579.     if (llptr == inlist)
  580. D 12
  581.         mask = PFROM ;
  582. E 12
  583. I 12
  584.         mask = PFROM | PREAD ;
  585. E 12
  586.     else
  587.         mask = PTO ;
  588.     /* add the other stuff */
  589. D 12
  590.     mask = mask | PNO | PSUBJECT | PREAD | PACTIVE ;
  591. E 12
  592. I 12
  593. D 16
  594.     mask = mask | PNO | PSUBJECT | PACTIVE ;
  595. E 12
  596.     /* startno MUST be 1 or higher */
  597.     if (startno < 1)
  598. E 16
  599. I 16
  600. D 18
  601.     mask = mask | PNO | PSUBJECT | PACTIVE | PDELETED ;
  602. E 18
  603. I 18
  604.     mask = mask | PNO | PSUBJECT | PACTIVE | PDELETED | PSTATUS ;
  605. E 18
  606. D 17
  607.     /* try to print ITEMS_IN_LIST emails we check for sanity of startno and endno later*/
  608.     /* if we are at the begining print the first ITEMS_IN_LIST emails
  609.     if (mailno < (ITEMS_IN_HALF_LIST + 1))
  610. E 17
  611. I 17
  612.     /* try to print ITEMS_ON_SCREEN emails we check for sanity of startno and endno later*/
  613.     startno = mailno - ITEMS_ON_HALF_SCREEN ;
  614.     endno = mailno + ITEMS_ON_HALF_SCREEN ;
  615. D 20
  616.     /* if we are at the begining print the first ITEMS_ON_SCREEN emails
  617. D 18
  618.     if (mailno < (ITEMS_ON_HALF_SCREEN + 1))
  619. E 18
  620. I 18
  621.     if (mailno <= (ITEMS_ON_HALF_SCREEN))
  622. E 20
  623. I 20
  624.     /* if we are at the begining print the first ITEMS_ON_SCREEN emails */
  625.     if (mailno <= ITEMS_ON_HALF_SCREEN)
  626. E 20
  627. E 18
  628. E 17
  629.     {
  630. E 16
  631.         startno = 1 ;
  632. I 4
  633. D 16
  634.     /* endno should be less or equal to llptr->count */
  635.     if (endno > llptr->count)
  636.         endno = llptr->count ;
  637. E 16
  638. I 16
  639. D 17
  640.         endno = ITEMS_IN_LIST ;
  641. E 17
  642. I 17
  643.         endno = ITEMS_ON_SCREEN ;
  644. E 17
  645.     }
  646. D 17
  647.     else if ((mailno + ITEMS_IN_HALF_LIST +1) > currlist->count) 
  648. E 17
  649. I 17
  650. D 18
  651.     if ((mailno + ITEMS_ON_HALF_SCREEN +1) > currlist->count) 
  652. E 18
  653. I 18
  654. D 19
  655.     if ((mailno + ITEMS_ON_HALF_SCREEN) > currlist->count) 
  656. E 19
  657. I 19
  658. D 20
  659.     else if (mailno > (currlist->count - ITEMS_ON_HALF_SCREEN)) 
  660. E 20
  661. I 20
  662.     if ((mailno + ITEMS_ON_HALF_SCREEN) >= currlist->count) 
  663. E 20
  664. E 19
  665. E 18
  666. E 17
  667.     {
  668.         endno = currlist->count ;
  669. D 17
  670.         startno = endno - ITEMS_IN_LIST ;
  671. E 17
  672. I 17
  673. D 18
  674.         startno = endno - ITEMS_ON_SCREEN ;
  675. E 18
  676. I 18
  677.         startno = (endno - ITEMS_ON_SCREEN) +1 ;
  678. E 18
  679. E 17
  680.     }
  681. D 17
  682.     else
  683.     {
  684.         startno = mailno - ITEMS_IN_HALF_LIST ;
  685.         endno = mailno + ITEMS_IN_HALF_LIST ;
  686.     }
  687. E 17
  688.     /* check for sanity in the start and end numbers */
  689.     if (startno < 1)
  690.         startno = 1;
  691.     if (endno > currlist->count)
  692.         endno = currlist->count ;
  693. E 16
  694. E 4
  695.     llprint(llptr, mask, startno, endno) ;
  696. }
  697. D 3
  698.  
  699. E 3
  700. I 3
  701. D 14
  702. /* print the entire ll list */
  703. VOID lldmpall(struct ll * llptr)  
  704. {
  705.     while (llptr != NULL)
  706.     {
  707.         lldump(llptr) ;
  708.         llptr = llptr->next ;
  709.     }
  710. }
  711. E 14
  712. E 3
  713. /* print the list at start ll, according to the mask, between the numbers startno and end no */
  714. VOID llprint(struct ll * startll, INT mask, INT startno, INT endno) 
  715. {
  716. I 16
  717.     TEXT tmp[200], tmp1[300] ;
  718. D 18
  719.     INT ystart,doprint ;
  720. E 18
  721. I 18
  722.     INT ystart,doprint, prtct ;
  723. E 18
  724.     G_GC gc ;
  725.     ystart = HDRINCR ;
  726. I 18
  727.     prtct = 0 ;
  728. E 18
  729. E 16
  730. I 3
  731. D 14
  732.     if (lldbg == TRUE)
  733.         p_printf("CALL: llprint (startll = OMITTED, mask = %x, startno = %d, endno = %d)", mask, startno, endno) ;
  734. E 14
  735. E 3
  736.     while (startll != NULL)
  737.     {
  738. I 16
  739.         doprint = FALSE ;
  740. E 16
  741.         if ((startll->no >= startno) && (startll->no <= endno))
  742. D 4
  743.             llprinta(startll, mask) ;
  744. E 4
  745. I 4
  746.         {
  747.             /* should we be printing this record ? */
  748.             if ((mask & PACTIVE) && (startll->status == ACTIVE))
  749. D 16
  750.                 llprinta(startll, mask) ;
  751. E 16
  752. I 16
  753.             {
  754.                 llprinta(startll, mask, tmp) ;
  755.                 doprint = TRUE ;
  756.             }
  757. E 16
  758. D 14
  759.             else if ((mask & PIGNORE) && (startll->status == IGNORE))            llprinta(startll, mask) ;
  760. E 14
  761. I 14
  762.             else if ((mask & PIGNORE) && (startll->status == IGNORE))
  763. D 16
  764.                 llprinta(startll, mask) ;
  765. E 16
  766. I 16
  767.             {
  768.                 llprinta(startll, mask, tmp) ;
  769.                 doprint = TRUE ;
  770.             }
  771. E 16
  772. E 14
  773.             else if ((mask & PDELETED) && (startll->status == DELETED))
  774. D 16
  775.                 llprinta(startll, mask) ;
  776. E 16
  777. I 16
  778.             {
  779.                 llprinta(startll, mask, tmp) ;
  780.                 doprint = TRUE ;
  781.             }
  782. E 16
  783.         }
  784. I 16
  785.         if (doprint == TRUE)
  786.         {
  787. I 18
  788. D 19
  789.             ptrct ++ ;
  790. E 19
  791. I 19
  792.             prtct ++ ;
  793. E 19
  794. E 18
  795.             if (mailno == startll->no) /* this line needs to be in bold */
  796.             {
  797.                 gc.style = G_STY_NORMAL | G_STY_BOLD ;
  798.                 gSetGC(gchdr, G_GC_MASK_STYLE, &gc) ;
  799.             }
  800.             else /* not the current email */
  801.             {
  802. D 17
  803.                 gc.styls = G_STY_NORMAL ;
  804. E 17
  805. I 17
  806.                 gc.style = G_STY_NORMAL ;
  807. E 17
  808.                 gSetGC(gchdr, G_GC_MASK_STYLE, &gc) ;
  809.             }
  810. D 17
  811.             p_scpym(tmp1, tmp, spacestr, NULL) ; /* remove any chars at the end of the line */
  812. E 17
  813. I 17
  814.             p_scpym(tmp1, tmp, blank, NULL) ; /* remove any chars at the end of the line */
  815. E 17
  816.             gPrintClipText(5, ystart, tmp1, p_slen(tmp1), 230) ;
  817.             ystart += HDRINCR ;
  818.         }
  819. E 16
  820. E 4
  821.         startll = startll->next ;
  822.     }
  823. I 18
  824.     /* empty out the other stuff on the screen */
  825.     if ( prtct < ITEMS_ON_SCREEN)
  826.     {
  827.         p_scpym(tmp1, blank, blank, NULL) ;
  828.         while (prtct < ITEMS_ON_SCREEN)
  829.         {
  830.             gPrintClipText(5, ystart, tmp1, p_slen(tmp1), 230) ;
  831.             ystart += HDRINCR ;
  832.             prtct ++ ;
  833.         }
  834.     }
  835. E 18
  836. }
  837.  
  838. /* print the structure according to the mask */
  839. D 16
  840. VOID llprinta(struct ll * llptr, INT mask)
  841. E 16
  842. I 16
  843. VOID llprinta(struct ll * llptr, INT mask, TEXT * str)
  844. E 16
  845. {
  846. D 16
  847.     TEXT tmp[100] ;
  848. E 16
  849. I 5
  850.     TEXT outline[1024] ;
  851. I 16
  852.     TEXT tmp[100] ;
  853. E 16
  854. E 5
  855. I 3
  856. D 14
  857.     if (lldbg == TRUE)
  858.         p_printf("CALL: llprinta (llptr = OMITTED, mask = %x", mask) ;
  859. E 14
  860. I 5
  861.     outline[0] = '\0' ;
  862. E 5
  863. E 3
  864. D 4
  865.     /* should we be printing this record ? */
  866.     if (!((llptr->status == ACTIVE) && (mask & PACTIVE)))
  867.         return ;
  868.     if (!((llptr->status == IGNORE) && (mask & PIGNORE)))
  869.         return ;
  870.     if (!((llptr->status == DELETED) && (mask & PDELETED)))
  871.         return ;
  872. E 4
  873.     /* print llptr according to the mask */
  874.     if (mask & PNO)
  875.     {
  876.         p_atos(tmp, "%d", llptr->no) ;
  877. D 5
  878.         putnonl(tmp) ;
  879. E 5
  880. I 5
  881.         p_scatm(outline, tmp, " ", NULL) ;
  882. E 5
  883.     }
  884. I 11
  885.     if (mask & PREAD)
  886.     {
  887.         if (llptr->read == RD)
  888.             p_scatm(outline, "R", " ", NULL) ;
  889.         else
  890.             p_scatm(outline, "N", " ", NULL) ;
  891.     }
  892. I 16
  893.     if (mask & PSTATUS)
  894.     {
  895.         if (llptr->status == ACTIVE)
  896. D 20
  897.             p_scatm(outline, "A", " ", NULL) ;
  898. E 20
  899. I 20
  900.             p_scatm(outline, " ", " ", NULL) ;
  901. E 20
  902.         else if (llptr->status == IGNORE)
  903.             p_scatm(outline, "I", " ", NULL) ;
  904.         else if (llptr->status == DELETED)
  905.             p_scatm(outline, "D", " ", NULL) ;
  906.     }
  907. E 16
  908. E 11
  909.     if (mask & PDATAFILE)
  910. D 5
  911.         putnonl(llptr->datafile) ;
  912. E 5
  913. I 5
  914.         p_scatm(outline, llptr->datafile, " ", NULL) ;
  915. E 5
  916.     if (mask & PTO)
  917. D 5
  918.         putnonl(llptr->to) ;
  919. E 5
  920. I 5
  921.         p_scatm(outline, llptr->to, " ", NULL) ;
  922. E 5
  923.     if (mask & PFROM)
  924. D 5
  925.         putnonl(llptr->from) ;
  926. E 5
  927. I 5
  928.         p_scatm(outline, llptr->from, " ", NULL) ;
  929. E 5
  930.     if (mask & PSUBJECT)
  931. D 5
  932.         putnonl(llptr->subject) ;
  933. E 5
  934. I 5
  935. D 20
  936.         p_scatm(outline, llptr->subject, " ", NULL) ;
  937. E 20
  938. I 20
  939.         p_scatm(outline, ": ",llptr->subject, " ", NULL) ;
  940. E 20
  941. E 5
  942.     if (mask & PCC)
  943. D 5
  944.         putnonl(llptr->cc) ;
  945. E 5
  946. I 5
  947.         p_scatm(outline, llptr->cc, " ", NULL) ;
  948. E 5
  949.     if(mask & PBCC)
  950. D 5
  951.         putnonl(llptr->bcc) ;
  952. E 5
  953. I 5
  954.         p_scatm(outline, llptr->bcc, " ", NULL) ;
  955. E 5
  956. D 16
  957.     if (mask & PSTATUS)
  958.     {
  959.         if (llptr->status == ACTIVE)
  960. D 5
  961.             putnonl("ACTIVE") ;
  962. E 5
  963. I 5
  964.             p_scatm(outline, "ACTIVE", " ", NULL) ;
  965. E 5
  966.         else if (llptr->status == IGNORE)
  967. D 5
  968.             putnonl("IGNORE") ;
  969. E 5
  970. I 5
  971.             p_scatm(outline, "IGNORE", " ", NULL) ;
  972. E 5
  973.         else if (llptr->status == DELETED)
  974. D 5
  975.             putnonl("DELETED") ;
  976. E 5
  977. I 5
  978.             p_scatm(outline, "DELETED", " ", NULL) ;
  979. E 5
  980.     }
  981. E 16
  982. D 11
  983.     if (mask & PREAD)
  984.     {
  985.         if (llptr->read == RD)
  986. D 5
  987.             putnonl("READ") ;
  988. E 5
  989. I 5
  990.             p_scatm(outline, "READ", " ", NULL) ;
  991. E 5
  992.         else
  993. D 5
  994.             putnonl("NEW") ;
  995. E 5
  996. I 5
  997.             p_scatm(outline, "NEW", " ", NULL) ;
  998. E 5
  999.     }
  1000. E 11
  1001.     if (mask & PCOUNT)
  1002.     {
  1003.         p_atos(tmp, "%d", llptr->count) ;
  1004. D 5
  1005.         putnonl(tmp) ;
  1006. E 5
  1007. I 5
  1008.         p_scatm(outline, tmp, " ", NULL) ;
  1009. E 5
  1010.     }
  1011. D 16
  1012.     /* print the newline */
  1013. D 5
  1014.     p_printf("") ;
  1015. E 5
  1016. I 5
  1017.     putnonl(outline) ;
  1018. E 16
  1019. I 16
  1020.     p_scpy(str, outline) ;
  1021. E 16
  1022. E 5
  1023. }
  1024. I 3
  1025. D 14
  1026. /* print the current ll entry */
  1027. VOID lldump(struct ll * llptr)
  1028. {
  1029.     if (lldbg == TRUE)
  1030.         p_printf("CALL: lldump (llptr = OMITTED)") ;
  1031.     if (llptr == NULL)
  1032.     {
  1033.         p_printf("Pointer is NULL") ;
  1034.         return ;
  1035.     }
  1036.     p_printf("Datafile is: %s", llptr->datafile) ;
  1037.     p_printf("To is: %s", llptr->to) ;
  1038.     p_printf("From is: %s", llptr->from ) ;
  1039.     p_printf("Subject is: %s", llptr->subject) ;
  1040.     /* pause before the next list */
  1041.     p_getch() ;
  1042.     p_printf("CC is: %s", llptr->cc) ;
  1043.     p_printf("Bcc is: %s", llptr->bcc) ;
  1044.     /* status */
  1045.     if (llptr->status == ACTIVE)
  1046.         p_printf("Status is: ACTIVE") ;
  1047.     else if (llptr->status == DELETED)
  1048.         p_printf("Status is: DELETED") ;
  1049.     else if (llptr->status == IGNORE)
  1050.         p_printf("Status is: IGNORE") ;
  1051.     else
  1052.         p_printf("Status is invalid (%d)", llptr->status) ;
  1053.     /* read */
  1054.     if (llptr->read == RD)
  1055.         p_printf("Read is: RD") ;
  1056.     else if (llptr->read == NEW)
  1057.         p_printf("Read is: NEW") ;
  1058.     else
  1059.         p_printf("Read is invalid (%d)", llptr->read) ;
  1060.     p_getch() ;
  1061.     p_printf("No is: %d", llptr->no) ;
  1062.     p_printf("Count is: %d", llptr->count) ;
  1063.     if (llptr->mydata == NULL)
  1064.         p_printf("Mydata is: NULL") ;
  1065.     else
  1066.     {
  1067.         p_printf("Mydata->myaddr is: %s", llptr->mydata->myaddr) ;
  1068.         p_printf("Mydata->mypath is: %s", llptr->mydata->mypath) ;
  1069.     }
  1070.     if (llptr->next == NULL)
  1071.         p_printf("Next is: NULL") ;
  1072.     else
  1073.         p_printf("Next is: Non NULL") ;
  1074.     p_getch() ;
  1075. }
  1076.  
  1077. E 14
  1078. E 3
  1079. /* this command scans the linked lists looking for a deleted entry. the associated file is then deleted */
  1080. D 6
  1081. VOID prgemail(struct ll * llptr)
  1082. E 6
  1083. I 6
  1084. INT prgemail(struct ll * llptr)
  1085. E 6
  1086. {
  1087.     struct ll * llstart ;
  1088. I 6
  1089.     INT ret ;
  1090. E 6
  1091. I 3
  1092. D 14
  1093.     if (cmddbg == TRUE)
  1094.         p_printf("CALL: prgemail (llstart = OMITTED)") ;
  1095. E 14
  1096. E 3
  1097.     llstart = llptr ;
  1098.     while(llptr != NULL)
  1099.     {
  1100.         if(llptr->status == DELETED)
  1101. D 6
  1102.             delfile(llptr, llstart) ;
  1103. E 6
  1104. I 6
  1105.         {
  1106.             ret = delfile(llptr, llstart) ;
  1107.             if (ret == FILEERR)
  1108.             {
  1109. D 17
  1110.                 p_print("FILE ERROR: prgemail, error in deleting message file %s", llptr->datafile) ;
  1111.                 if (cmddbg == TRUE)
  1112.                     p_getch() ;
  1113. E 17
  1114. I 17
  1115.                 uDisplayText("FILE ERROR: prgemail,","error in deleting message file", llptr->datafile, NULL) ;
  1116. E 17
  1117.                 return(FILEERR) ;
  1118.             }
  1119.         }
  1120. E 6
  1121.         llptr = llptr->next ;
  1122.     }
  1123. I 6
  1124.     return(TRUE) ;
  1125. E 6
  1126. }
  1127. /* fill in a ll entry based on the arguments */
  1128. VOID llfill(struct ll * llptr, TEXT * datafile, TEXT * to, TEXT * from, TEXT * subject, TEXT * cc, TEXT * bcc, INT status, INT read, INT no)
  1129. {
  1130. I 3
  1131. D 14
  1132.     if (lldbg == TRUE)
  1133.         p_printf("CALL llfill (llptr = OMITTED, datafile = %s, to = %s, from = %s, subject = %s, cc = %s, bcc = %s, status = %d, read = %d, no = %d)", datafile, to, from, subject, cc, bcc, status, read, no) ;
  1134. E 14
  1135. E 3
  1136.     p_scpy(llptr->datafile, datafile) ;
  1137.     p_scpy(llptr->to, to) ;
  1138.     p_scpy(llptr->from, from) ;
  1139.     p_scpy(llptr->subject, subject) ;
  1140.     p_scpy(llptr->cc, cc) ;
  1141.     p_scpy(llptr->bcc, bcc) ;
  1142.     llptr->status = status ;
  1143.     llptr->read = read ;
  1144.     llptr->no = no ;
  1145. I 5
  1146. D 14
  1147.     if (lldbg == TRUE)
  1148.     {
  1149.         p_printf("filled in structure is");
  1150.         lldump(llptr) ;
  1151.     }
  1152. E 14
  1153. E 5
  1154. }
  1155. /* find a list entry based on the number */
  1156. struct ll * llnofind(INT no, struct ll * llstart)
  1157. {
  1158.     struct ll * llcurrnt ;
  1159. I 3
  1160. D 14
  1161.     if (lldbg == TRUE)
  1162.         p_printf("CALL: llnofind(no = %d, llstart = OMITTED)", no) ;
  1163. E 14
  1164. E 3
  1165.     llcurrnt = llstart ;
  1166.     while(llcurrnt->no != no)
  1167.     {
  1168. I 5
  1169. D 14
  1170.         if (lldbg == TRUE)
  1171.         {
  1172.             p_printf("llnofind is working on") ;
  1173.             lldump(llcurrnt) ;
  1174.         }
  1175. E 14
  1176. E 5
  1177.         if(llcurrnt->next == NULL)
  1178. I 5
  1179.         {
  1180. D 14
  1181.             if (lldbg == TRUE)
  1182.                 p_printf("llnofind returns NULL");
  1183. E 14
  1184. E 5
  1185.             return(NULL) ;
  1186. I 5
  1187.         }
  1188. E 5
  1189.         llcurrnt = llcurrnt->next ;
  1190. I 5
  1191.  
  1192. E 5
  1193.     }
  1194.     /* to have got here we must havea match if we could not find a match we would already havereturned NULL */
  1195. I 5
  1196. D 14
  1197.     if (lldbg == TRUE)
  1198.     {
  1199.         p_printf("llnofind returns the following");
  1200.         lldump(llcurrnt) ;
  1201.     }
  1202. E 14
  1203. E 5
  1204.     return(llcurrnt) ;
  1205. }
  1206.         
  1207. /* this adds the newll to the end of the list at startll */
  1208. VOID lladd(struct ll * newll, struct ll * startll)
  1209. {
  1210.     struct ll * llcurrnt ;
  1211. I 3
  1212. D 14
  1213.     if (lldbg == TRUE)
  1214. D 5
  1215.         p_printf("lladd (newll = OMITTED, startll = OMITTED") ;
  1216. E 5
  1217. I 5
  1218.         p_printf("lladd (newll = OMITTED, startll = OMITTED)") ;
  1219. E 14
  1220. E 5
  1221. E 3
  1222.     llcurrnt = startll ;
  1223. D 5
  1224.     /* scan down the list lokking for NULL)
  1225. E 5
  1226. I 5
  1227.     /* scan down the list lokking for NULL) */
  1228. E 5
  1229.     while(llcurrnt->next != NULL)
  1230. I 5
  1231.     {
  1232. E 5
  1233.         llcurrnt = llcurrnt->next ;
  1234. I 5
  1235.     }
  1236. E 5
  1237.     /* we are at the end of the list add the entry */
  1238.     llcurrnt->next = newll ;
  1239.     /* increment the total in the list counter, held in the first entry in the list only */
  1240.     startll->count ++ ;
  1241. }
  1242. /* this function creates the initial in and out list entries */
  1243. VOID llinit(VOID)
  1244. {
  1245. I 3
  1246. D 14
  1247.     if (lldbg == TRUE)
  1248.         p_printf("CALL: llinit()") ;
  1249. E 14
  1250. E 3
  1251.     inlist = llnew() ;
  1252.     outlist = llnew() ;
  1253.     inlist->mydata = p_alloc(sizeof(struct mydata)) ;
  1254.     outlist->mydata = p_alloc(sizeof(struct mydata)) ;
  1255. }
  1256.  
  1257. /* linked list functions */
  1258. /* llnew, create space and fill with defaults */
  1259. struct ll * llnew(VOID)
  1260. {
  1261.     struct ll * llptr;
  1262. I 3
  1263. D 14
  1264.     if (lldbg == TRUE)
  1265.         p_printf("CALL: llnew()") ;
  1266. E 14
  1267. E 3
  1268.     llptr = p_alloc(sizeof(struct ll)) ;
  1269.     llptr->datafile[0] = '\0' ;
  1270.     llptr->to[0] = '\0' ;
  1271.     llptr->from[0] = '\0' ;
  1272.     llptr->subject[0] = '\0' ;
  1273.     llptr->cc[0] = '\0' ;
  1274.     llptr->bcc[0] = '\0' ;
  1275.     llptr->status = IGNORE ;
  1276.     llptr->read = NEW ;
  1277.     llptr->next = NULL ;
  1278.     llptr->no = 0 ;
  1279.     llptr->count = 0 ;
  1280.     llptr->mydata = NULL ;
  1281.     return(llptr) ;
  1282. }
  1283. D 6
  1284. VOID llcopy (struct ll * in, struct ll * out)
  1285. E 6
  1286. I 6
  1287. VOID llcopy (struct ll * out, struct ll * in)
  1288. E 6
  1289. {
  1290. I 3
  1291. D 14
  1292.     if (lldbg == TRUE)
  1293. I 5
  1294.     {
  1295. E 5
  1296.         p_printf("CALL: llcopy (in = OMITTED, out = OMITTED)") ;
  1297. I 5
  1298.         p_printf("input is ") ;
  1299.         lldump(in) ;
  1300. E 14
  1301. D 17
  1302.     }
  1303. E 17
  1304. E 5
  1305. E 3
  1306.     /* copy the strings but status etc remains untouched */
  1307.     p_scpy(out->datafile, in->datafile) ;
  1308.     p_scpy(out->to, in->to) ;
  1309.     p_scpy(out->from, in->from) ;
  1310.     p_scpy(out->subject, in->subject) ;
  1311.     p_scpy(out->cc, in->cc) ;
  1312.     p_scpy(out->bcc, in->bcc) ;
  1313. I 5
  1314. D 14
  1315.     if (lldbg == TRUE)
  1316.     {
  1317.         p_printf("output is ") ;
  1318.         lldump(out) ;
  1319.     }
  1320. E 14
  1321. E 5
  1322. }
  1323. /* llfree, free llptr and everything it points to */
  1324. VOID llfree (struct ll * llptr) 
  1325. {
  1326.     struct ll * llnext;
  1327. I 3
  1328. D 14
  1329.     if (lldbg == TRUE)
  1330.         p_printf("CALL: llfree(llptr = OMITTED)");
  1331. E 14
  1332. E 3
  1333.     /* free the mydata section only on the first item */
  1334.     p_free(llptr->mydata) ;
  1335.     llnext = llptr;
  1336.     while(llptr != NULL)
  1337.     {
  1338.         llnext = llptr->next ;
  1339.         p_free(llptr) ;
  1340.         llptr = llnext ;
  1341.     }
  1342. }
  1343. /* is mailno in the list and marked as ACTIVE ? */
  1344. INT llvalid(INT mailno, struct ll * llptr)
  1345. {
  1346. I 16
  1347.     TEXT tmp[50] ;
  1348. E 16
  1349. I 3
  1350. D 14
  1351.     if (lldbg == TRUE)
  1352.         p_printf("CALL: llvalid(mailno = %d, llptr = OMITTED)", mailno) ;
  1353. E 14
  1354. E 3
  1355.     llptr = llnofind(mailno, llptr) ;
  1356.     if (llptr != NULL)
  1357.     {
  1358.         if (llptr->status != ACTIVE)
  1359.         {
  1360. D 16
  1361.             p_printf("%d is not an active message", mailno) ;
  1362. E 16
  1363. I 16
  1364.             p_atos(tmp, "%d is not an active message", mailno) ;
  1365.             uDisplayText(tmp, NULL) ;
  1366. E 16
  1367.             return(FALSE) ;
  1368.         }
  1369.         else
  1370.         {
  1371.             return(TRUE) ;
  1372.         }
  1373.     }
  1374.     else
  1375.     {
  1376. D 16
  1377.         p_printf("%d is not a valid message", mailno) ;
  1378. E 16
  1379. I 16
  1380.         p_atos(tmp, "%d is not a valid message", mailno) ;
  1381.         uDisplayText(tmp, NULL) ;
  1382. E 16
  1383.         return(FALSE) ;
  1384.     }
  1385. }
  1386.  
  1387. /* end of linked list code */
  1388.  
  1389. /* start of top level functions */
  1390.  
  1391. I 15
  1392. /* create the graphics context */
  1393. VOID CreateGC(VOID)
  1394. {
  1395.     INT hgc ;
  1396.     hgc = gCreateGC0(MainWid) ;
  1397.     if (hgc < 0)
  1398.         p_exit(hgc) ;
  1399. }
  1400. E 15
  1401. D 16
  1402. /* setup the windows etc. */
  1403. E 16
  1404. I 16
  1405. /* do the basic window setup */
  1406. E 16
  1407. VOID initwins(VOID)
  1408. {
  1409. I 15
  1410. D 17
  1411.     INT command ;
  1412. E 17
  1413. I 17
  1414.  
  1415. E 17
  1416.     uCommonInit() ; /* connect to the window system etc */
  1417.     MainWid=uFindMainWid() ; /* figure out what the main window is */
  1418.     CreateGC() ;
  1419. D 16
  1420.     gBorder(W_BORD_CORNER_4) ; /* make the window look nice */
  1421.     wsEnable() ; /* start talking to the window system */
  1422. E 16
  1423. D 17
  1424.     command = hCrackCommandLine() ; /* do the command line and make 
  1425. E 17
  1426. I 17
  1427.     hCrackCommandLine() ; /* do the command line and make 
  1428. E 17
  1429.                                        ourselves available for recieveing 
  1430.                                        commands such as exit etc */
  1431. I 16
  1432. }
  1433.  
  1434. /* setup the windows etc. */
  1435. VOID initmywins(VOID)
  1436. {
  1437. E 16
  1438. E 15
  1439. I 3
  1440. D 14
  1441.     if (topdbg == TRUE)
  1442.         p_printf("CALL: initwins()");
  1443. E 14
  1444. E 3
  1445.     /* create the windows */
  1446. I 16
  1447.     /* the status window */
  1448.     /* geometry information */
  1449.     wdstatus.extent.tl.x = 0 ;
  1450.     wdstatus.extent.tl.y = 0 ;
  1451.     wdstatus.extent.width = 240 ;
  1452. D 19
  1453.     wdstatus.extent.height = 19 ;
  1454. E 19
  1455. I 19
  1456.     wdstatus.extent.height = 18 ;
  1457. E 19
  1458.     wdstatus.flags = W_WIN_PRIORITY ;
  1459.     wdstatus.mouse_icon = 0 ;
  1460.     wdstatus.filler = 0 ;
  1461.     wdstatus.background = W_WIN_BACK_BITMAP ;
  1462.     /* graphics context definitions (how to draw) specification */
  1463.     gdstatus.gmode = G_TRMODE_SET ;
  1464.     gdstatus.textmode = G_TRMODE_REPL ;
  1465.     gdstatus.style = G_STY_NORMAL ;
  1466.     gdstatus.filler = 0 ;
  1467. D 17
  1468.     gdstatus.fond = WS_FONT_BASE ;
  1469. E 17
  1470. I 17
  1471.     gdstatus.font = WS_FONT_BASE ;
  1472. E 17
  1473.     /* create the window */
  1474. D 17
  1475.     winstatus = wCreateWindow(MainWid, W_WIN_EXTENT | W_WIN_BACKGROUND, &wdstatus,1)
  1476. E 17
  1477. I 17
  1478.     winstatus = wCreateWindow(MainWid, W_WIN_EXTENT | W_WIN_BACKGROUND, &wdstatus,1) ;
  1479. E 17
  1480.     /* make it real in the windows tree */
  1481.     wInitialiseWindowTree(winstatus) ;
  1482.     /* create the graphics context */
  1483.     gcstatus = gCreateGC(winstatus, G_GC_MASK_GMODE | G_GC_MASK_TEXTMODE | G_GC_MASK_STYLE, &gdstatus) ;
  1484.     /* make the window visible */
  1485. D 17
  1486.     wMakeVisible(winpath) ;
  1487. E 17
  1488. I 17
  1489.     wMakeVisible(winstatus) ;
  1490. E 17
  1491.     /* make the current context the one we will use */
  1492.     gSetGC0(gcstatus) ;
  1493.     /* put a border around the current context */
  1494. D 17
  1495.     gBorder(W_BORD_CUSHION|W__BORD_CORNER_4) ;
  1496. E 17
  1497. I 17
  1498.     gBorder(W_BORD_CUSHION|W_BORD_CORNER_4) ;
  1499. E 17
  1500.     
  1501.     /* the header window */
  1502.     /* geometry information */
  1503.     wdhdr.extent.tl.x = 0 ;
  1504.     wdhdr.extent.tl.y = 21 ;
  1505.     wdhdr.extent.width = 240 ;
  1506. D 17
  1507.     wdhdr.extent.height = 59 ; /
  1508. E 17
  1509. I 17
  1510.     wdhdr.extent.height = 59 ; 
  1511. E 17
  1512.     wdhdr.flags = W_WIN_PRIORITY ;
  1513.     wdhdr.mouse_icon = 0 ;
  1514.     wdhdr.filler = 0 ;
  1515.     wdhdr.background = W_WIN_BACK_BITMAP ;
  1516.     /* graphics context definitions (how to draw) specification for normal text */
  1517.     gdhdr.gmode = G_TRMODE_SET ;
  1518.     gdhdr.textmode = G_TRMODE_REPL ;
  1519.     gdhdr.style = G_STY_NORMAL ;
  1520.     gdhdr.filler = 0 ;
  1521. D 17
  1522.     gdhdr.fond = WS_FONT_BASE ;
  1523. E 17
  1524. I 17
  1525.     gdhdr.font = WS_FONT_BASE ;
  1526. E 17
  1527.     /* create the window */
  1528. D 17
  1529.     winhdr = wCreateWindow(MainWid, W_WIN_EXTENT | W_WIN_BACKGROUND, &wdhdr,1)
  1530. E 17
  1531. I 17
  1532.     winhdr = wCreateWindow(MainWid, W_WIN_EXTENT | W_WIN_BACKGROUND, &wdhdr,1) ;
  1533. E 17
  1534.     /* make it real in the windows tree */
  1535.     wInitialiseWindowTree(winhdr) ;
  1536.     /* create the graphics context for normal text */
  1537.     gchdr = gCreateGC(winhdr, G_GC_MASK_GMODE | G_GC_MASK_TEXTMODE | G_GC_MASK_STYLE, &gdhdr) ;    
  1538.     /* make the window visible */
  1539. D 17
  1540.     wMakeVisible(winpath) ;
  1541. E 17
  1542. I 17
  1543.     wMakeVisible(winhdr) ;
  1544. E 17
  1545.     /* make the current context the one we will use */
  1546.     gSetGC0(gchdr) ;
  1547.     /* put a border around the current context */
  1548. D 17
  1549.     gBorder(W_BORD_CUSHION|W__BORD_CORNER_4) ;
  1550. E 17
  1551. I 17
  1552.     gBorder(W_BORD_CUSHION|W_BORD_CORNER_4) ;
  1553. E 17
  1554.     
  1555. E 16
  1556. }
  1557.  
  1558. I 16
  1559.  
  1560. E 16
  1561. /* close down the windows */
  1562. VOID shutwins(VOID) 
  1563. {
  1564. I 3
  1565. D 14
  1566.     if (topdbg == TRUE)
  1567.         p_printf("CALL: shutwins()");
  1568. E 14
  1569. E 3
  1570.     /* shutdown any windows etc */
  1571. I 16
  1572.     wCloseWindowTree(MainWid) ;
  1573. E 16
  1574. }
  1575.  
  1576. /* print out who we are and the version number */
  1577. VOID dogreet(VOID)
  1578. {
  1579. I 3
  1580. D 14
  1581.     if (topdbg == TRUE)
  1582.         p_printf("CALL: dogreet()") ;
  1583. E 14
  1584. E 3
  1585. D 16
  1586.     p_printf("Psion SMTP Offline mail reader") ;
  1587.     p_printf("Version %I%, (C) Tim Graves, Sun Microsystems") ;
  1588. E 16
  1589. I 16
  1590. D 20
  1591.     W_WINDATA wdgreet ;
  1592.     UINT gcgreet ;
  1593.     INT wingreet ;
  1594.     G_GC gdgreet ;
  1595.     WMSG_KEY key ;
  1596.     /* create a window and say hello */
  1597.     /* create the window */
  1598.     /* geometry information */
  1599.     wdgreet.extent.tl.x = 0 ;
  1600.     wdgreet.extent.tl.y = 0 ;
  1601.     wdgreet.extent.width = 240 ;
  1602. D 17
  1603.     wdgreet.extent.height = 80 ; /
  1604. E 17
  1605. I 17
  1606.     wdgreet.extent.height = 80 ; 
  1607. E 17
  1608.     wdgreet.flags = W_WIN_PRIORITY ;
  1609.     wdgreet.mouse_icon = 0 ;
  1610.     wdgreet.filler = 0 ;
  1611.     wdgreet.background = W_WIN_BACK_BITMAP ;
  1612.     /* graphics context definitions (how to draw) specification */
  1613.     gdgreet.gmode = G_TRMODE_SET ;
  1614.     gdgreet.textmode = G_TRMODE_REPL ;
  1615.     gdgreet.style = G_STY_UNDERLINE | G_STY_DOUBLE | G_STY_ITALIC | G_STY_UNDERLINE | G_STY_BOLD;
  1616.     gdgreet.filler = 0 ;
  1617. D 17
  1618.     gdgreet.fond = WS_FONT_BASE ;
  1619. E 17
  1620. I 17
  1621.     gdgreet.font = WS_FONT_BASE ;
  1622. E 17
  1623.     /* create the window */
  1624. D 17
  1625.     wingreet = wCreateWindow(MainWid, W_WIN_EXTENT | W_WIN_BACKGROUND, &wdgreet,1)
  1626. E 17
  1627. I 17
  1628.     wingreet = wCreateWindow(MainWid, W_WIN_EXTENT | W_WIN_BACKGROUND, &wdgreet,1) ;
  1629. E 17
  1630.     /* make it real in the windows tree */
  1631.     wInitialiseWindowTree(wingreet) ;
  1632.     /* create the graphics context */
  1633. D 17
  1634.     gcgreet = gCreateGC(wingreet, G_GC_MASK_GMODE | G_GC_MASK_TEXTMODE | G_GC_MASK_STYLE, &gdpath) ;
  1635. E 17
  1636. I 17
  1637.     gcgreet = gCreateGC(wingreet, G_GC_MASK_GMODE | G_GC_MASK_TEXTMODE | G_GC_MASK_STYLE, &gdgreet) ;
  1638. E 17
  1639.     /* make the window visible */
  1640. D 17
  1641.     wMakeVisible(winpath) ;
  1642. E 17
  1643. I 17
  1644.     wMakeVisible(wingreet) ;
  1645. E 17
  1646.     /* make the current context the one we will use */
  1647.     gSetGC0(gcgreet) ;
  1648.     /* put a border around the current context */
  1649. D 17
  1650.     gBorder(W_BORD_CUSHION|W__BORD_CORNER_4) ;
  1651. E 17
  1652. I 17
  1653.     gBorder(W_BORD_CUSHION|W_BORD_CORNER_4) ;
  1654. E 17
  1655.  
  1656.     /* actualy do the printing */
  1657.     gPrintClipText(10, 30, welc1, p_slen(welc1), 220) ;
  1658.     gPrintClipText(10, 50, welc2, p_slen(welc2), 220) ;
  1659.     gPrintClipText(10, 70, welc3, p_slen(welc3), 220) ;
  1660.     /* hang around for the key press */
  1661.     uGetKey(&key) ;
  1662.     /* destroy this window and all associated data */
  1663.     wCloseWindowTree((UINT) wingreet) ;
  1664. E 20
  1665. I 20
  1666.     uDisplayText("Psion Offline SMTP Mail Reader", "(C) by Tim Graves,","Sun Microsystems","Version %I%", "Press Return to continue", NULL) ;
  1667. E 20
  1668. E 16
  1669. }
  1670.  
  1671. /* read the incomming meta file and display the list of emails */
  1672. D 3
  1673. VOID initlist(VOID)
  1674. E 3
  1675. I 3
  1676. INT initlist(VOID)
  1677. E 3
  1678. {
  1679. I 3
  1680.     INT ret ;
  1681. D 16
  1682.     if (topdbg == TRUE)
  1683.         p_printf("CALL: initlist()") ;
  1684. E 16
  1685. E 3
  1686.     llinit() ;
  1687. I 16
  1688. D 17
  1689.     startusmsg("Reading mta lists") ;
  1690. E 17
  1691. I 17
  1692.     statusmsg("Reading mta lists") ;
  1693. E 17
  1694. E 16
  1695.     /* first read the incomming meta data file */
  1696. D 3
  1697.     readmeta(METAIN, inlist) ;
  1698. E 3
  1699. I 3
  1700.     ret = readmeta(METAIN, inlist) ;
  1701. D 5
  1702.     if (ret == ERR)
  1703. E 5
  1704. I 5
  1705.     if (ret == FILEERR)
  1706. E 5
  1707.     {
  1708. D 16
  1709.         p_printf("FILE ERROR: initlist, error in reading metafile %s", METAIN) ;
  1710. E 16
  1711. I 16
  1712.         uDisplayText("FILE ERROR: initlist,","error in reading metafile", METAIN, NULL) ;
  1713. E 16
  1714. D 5
  1715.         return (ERR) ;
  1716. E 5
  1717. I 5
  1718.         return (FILEERR) ;
  1719. E 5
  1720.     }
  1721. I 5
  1722.     if (ret == MEMERR)
  1723.     {
  1724. D 16
  1725.         p_printf("MEMORY ERROR: initlist, error in reading metafile %s", METAIN) ;
  1726. E 16
  1727. I 16
  1728.         uDisplayText("MEMORY ERROR: initlist,","error in reading metafile", METAIN, NULL) ;
  1729. E 16
  1730.         return(MEMERR) ;
  1731.     }
  1732. E 5
  1733. E 3
  1734.     /* then the outgoing data file */
  1735. D 3
  1736.     readmeta(METAOUT, outlist) ;
  1737. E 3
  1738. I 3
  1739.     ret = readmeta(METAOUT, outlist) ;
  1740. D 5
  1741.     if (ret == ERR)
  1742. E 5
  1743. I 5
  1744.     if (ret == FILEERR)
  1745. E 5
  1746.     {
  1747. D 16
  1748.         p_printf("FILE ERROR: initlist, error in reading metafile %s", METAIN) ;
  1749. E 16
  1750. I 16
  1751.         uDisplayText("FILE ERROR: initlist,","error in reading metafile", METAIN, NULL) ;
  1752. E 16
  1753. D 5
  1754.         return (ERR) ;
  1755. E 5
  1756. I 5
  1757.         return (FILEERR) ;
  1758. E 5
  1759.     }
  1760. I 5
  1761.     if (ret == MEMERR)
  1762.     {
  1763. D 16
  1764.         p_printf("MEMORY ERROR: initlist, error in reading metafile %s", METAOUT) ;
  1765. E 16
  1766. I 16
  1767.         uDisplayText("MEMORY ERROR: initlist,","error in reading metafile", METAOUT, NULL) ;
  1768. E 16
  1769.         return(MEMERR) ;
  1770.     }
  1771. E 5
  1772. E 3
  1773.     /* start working with the incomming list */
  1774.     currlist = inlist ;
  1775. I 16
  1776.     if (currlist->count > 0)
  1777.         mailno = 1 ;
  1778.     else
  1779.         mailno = 0 ;
  1780. E 16
  1781.     /* display the list first*/
  1782. D 16
  1783.     disphdrs(currlist, 1, 10) ;
  1784. E 16
  1785. I 16
  1786. D 17
  1787.     redolist(currlist) ;
  1788. E 17
  1789. I 17
  1790.     redolist() ;
  1791. E 17
  1792. E 16
  1793. I 5
  1794.     return(TRUE) ;
  1795. E 5
  1796. }
  1797.  
  1798. D 14
  1799. /* wait for a command then do it */
  1800. E 14
  1801. I 14
  1802. /* wait for a command then do it this is taken directly from the 
  1803.    developers kit demo code */
  1804. E 14
  1805. D 3
  1806. VOID mainloop(VOID)
  1807. E 3
  1808. I 3
  1809. INT mainloop(VOID)
  1810. E 3
  1811. {
  1812. I 14
  1813.     INT ret ;
  1814.     WMSG_KEY key ;
  1815.     FOREVER
  1816.     {
  1817.         uGetKey(&key) ;
  1818.         if (key.keycode&W_EVENT_KEY) /* call from the system screen, we are only interested in the shutdown
  1819.                          as we done accept new or open functions */
  1820.         {
  1821.             if (key.keycode==CONS_EVENT_COMMAND) /* exit and save our state */
  1822.                 return(TRUE) ;
  1823.         }
  1824.         else if (key.keycode&W_SPECIAL_KEY) /* psion-? accelerator */
  1825.         {
  1826.             /* check for x or q (exit and save or crash out) as we handle these here */
  1827.             ret = key.keycode&(~W_SPECIAL_KEY) ;
  1828. D 20
  1829.             if (ret == 'q')
  1830. E 20
  1831. I 20
  1832.             if (ret == 'x')
  1833. E 20
  1834.                 return (TRUE) ;
  1835.             else if (ret == 'c')
  1836.                 return(IERR) ;
  1837.             else
  1838.                 ManageCommand(ret) ;
  1839. D 17
  1840.         else if (key.keycode == W_KEY_MENU && !(key.modifiers&W_CTRL_MODIFIER)) /* menu button */
  1841. E 17
  1842. I 17
  1843.         }
  1844.         else if ((key.keycode == W_KEY_MENU) && !(key.modifiers&W_CTRL_MODIFIER)) /* menu button */
  1845. E 17
  1846.         {
  1847.             ret = uPresentMenus() ;
  1848.             if (ret > 0)
  1849.             {
  1850.                 /* check for x or q (exit and save or crash out) as we handle these here */
  1851. D 20
  1852.                 if (ret == 'q')
  1853. E 20
  1854. I 20
  1855.                 if (ret == 'x')
  1856. E 20
  1857.                     return (TRUE) ;
  1858.                 else if (ret == 'c')
  1859.                     return(IERR) ;
  1860.                 else
  1861.                     ManageCommand(ret) ;
  1862. I 17
  1863.             }
  1864. E 17
  1865.         }
  1866. I 15
  1867.         /* we know the keycode is not a system screen function, psion-? key on menu button
  1868.            see if it is a movement key (up, down, page up, page down or modified with ctrl */
  1869.         else
  1870.         {
  1871.             switch (key.keycode)
  1872.             {
  1873.                 case W_KEY_UP:
  1874.                     if (key.modifiers&W_CTRL_MODIFIER) /* go to the bottom of the current page */
  1875. D 16
  1876.                         mailno -= (ITEMS_ON_SCREEN -1) / 2 ;
  1877. E 16
  1878. I 16
  1879.                         mailno -= ITEMS_ON_HALF_SCREEN ;
  1880. E 16
  1881.                     else
  1882.                         mailno -- ;
  1883.                     break ;
  1884.                 case W_KEY_DOWN:
  1885.                     if (key.modifiers&W_CTRL_MODIFIER) /* go to the top of the current page */
  1886. D 16
  1887.                         mailno += (ITEMS_ON_SCREEN -1) /2 ;
  1888. E 16
  1889. I 16
  1890.                         mailno += ITEMS_ON_HALF_SCREEN  ;
  1891. E 16
  1892.                     else
  1893.                         mailno ++ ;
  1894.                     break ;
  1895.                 case W_KEY_PAGE_UP:
  1896.                     if (key.modifiers&W_CTRL_MODIFIER) /* go to the first entry */
  1897.                         mailno = 1 ;
  1898.                     else
  1899.                         mailno -= ITEMS_ON_SCREEN ;
  1900.                     break ;
  1901.                 case W_KEY_PAGE_DOWN:
  1902.                     if (key.modifiers&W_CTRL_MODIFIER) /* go to the last entry */
  1903.                         mailno = currlist->count ;
  1904.                     else
  1905.                         mailno += ITEMS_ON_SCREEN ;
  1906.                     break ;
  1907.             }
  1908.             /* make sure that mail no is within the current email range */
  1909.             if (mailno < 1)
  1910.                 mailno = 1 ;
  1911.             if (mailno > currlist->count)
  1912.                 mailno = currlist->count ;
  1913.         }
  1914.         redolist() ; /* the likley hood is that the list will have changed so redraw it */
  1915. E 15
  1916.     }
  1917. }
  1918.  
  1919. LOCAL_C VOID ManageCommand(INT keycode)
  1920. {
  1921. E 14
  1922. D 15
  1923.     TEXT cmd[10], * cmdptr ;
  1924.     INT ret, mailno ;
  1925. E 15
  1926. I 15
  1927. D 17
  1928.     INT ret, intl;
  1929. E 17
  1930. I 17
  1931.     INT  incl;
  1932. E 17
  1933. E 15
  1934.     struct ll * llptr ;
  1935. D 15
  1936.     WORD wmailno ;
  1937. I 3
  1938. D 14
  1939.     if (topdbg == TRUE)
  1940.         p_printf("CALL: mainloop()") ;
  1941. E 14
  1942. E 3
  1943.     cmd[0] = '\0' ;
  1944.     cmdptr = cmd ;
  1945.     /* loop around untill we get to a quit */
  1946.     ret = TRUE ;
  1947.     mailno = -1 ;
  1948.     while(ret == TRUE)
  1949. E 15
  1950. I 15
  1951.     switch (keycode)
  1952. E 15
  1953.     {
  1954. D 15
  1955.         getcmd(cmd) ;
  1956.         /* the main switch */
  1957.         /* q - quit */
  1958.         if (cmd[0] == 'q')
  1959.         {
  1960.             ret = FALSE ;
  1961.             continue ;
  1962.         }
  1963.         /* <number> set the current number */
  1964.         if (p_isdigit(cmd[0]))
  1965.         {
  1966. I 6
  1967.             cmdptr = cmd ;
  1968. E 6
  1969.             p_stoi(&cmdptr, &wmailno) ;
  1970. I 8
  1971.             mailno = (INT) wmailno ;
  1972. E 8
  1973. D 7
  1974.             mailno = (INT) wmailno ;
  1975. E 7
  1976. I 3
  1977.             p_printf("Current email number is %d", mailno) ;
  1978.             llptr = llnofind(mailno, currlist) ;
  1979.             if (llptr == NULL)
  1980.             {
  1981.                 p_printf("WARNING: email number %d does not exist", mailno) ;
  1982.             }
  1983.             else if (llptr->status == DELETED)
  1984.             {
  1985.                 p_printf("WARNING: email number %d is deleted", mailno) ;
  1986. I 7
  1987.                 continue ;
  1988. E 7
  1989.             }
  1990.             else if (llptr->status == IGNORE)
  1991.             {
  1992.                 p_printf("WARNING: email number %d is reserved for internal use", mailno) ;
  1993. I 7
  1994.                 continue ;
  1995. E 7
  1996.             }
  1997.             else if (llptr->status != ACTIVE)
  1998.             {
  1999.                 p_printf("INTERNAL ERROR: mainloop, email number %d has an invalid status flag (%d), panic exit", mailno, llptr->status) ;
  2000. D 5
  2001.                 return(ERR) ;
  2002. E 5
  2003. I 5
  2004.                 return(IERR) ;
  2005. E 5
  2006.             }
  2007. E 3
  2008.             continue ;
  2009.         }
  2010. I 7
  2011.         /* v - view the email */
  2012.         if (cmd[0] == 'v')
  2013.         {
  2014.             if (llvalid(mailno, currlist))
  2015.             {
  2016.                 readmail(mailno, currlist) ;
  2017.             }
  2018.             continue ;
  2019.         }
  2020. E 7
  2021.         /* n - newemail, force this onto the outlist */
  2022.         if (cmd[0] == 'n')
  2023.         {
  2024.             /* if the next char is i include the current email */
  2025.             if (cmd[1] == 'i')
  2026.             {
  2027.                 if (llvalid(mailno, currlist))
  2028.                 {
  2029.                     newemail(mailno, currlist, TRUE) ;
  2030.                 }
  2031.             }
  2032.             else
  2033.             {
  2034.                 newemail(mailno, currlist, FALSE) ;
  2035.             }
  2036.             continue ;
  2037.         }
  2038.         /* r - reply to sender */
  2039.         if (cmd[0] == 'r')
  2040.         {
  2041.             if (llvalid(mailno, currlist))
  2042.             {
  2043.                 /* if the second char is i include the 
  2044.                    current email */
  2045.                 if (cmd[1] == 'i')
  2046.                     repfrom(mailno, currlist, TRUE) ;
  2047.                 else
  2048.                     repfrom(mailno, currlist, FALSE) ;
  2049.             }
  2050.             continue ;
  2051.         }
  2052.         /* R - reply to all */
  2053.         if (cmd[0] == 'R')
  2054.         {
  2055.             if (llvalid(mailno, currlist))
  2056.             {
  2057.                 
  2058.                 /* if the second char is i include the 
  2059.                    current email */
  2060.                 if (cmd[1] == 'i')
  2061.                     repall(mailno, currlist, TRUE) ;
  2062.                 else
  2063.                     repall(mailno, currlist, FALSE) ;
  2064.             }
  2065.             continue ;
  2066.         }
  2067.         /* D - delete email */
  2068.         if (cmd[0] == 'D')
  2069.         {
  2070.             if (llvalid(mailno, currlist))
  2071.             {
  2072.                 delmail(mailno, currlist) ;
  2073. I 6
  2074.                 p_printf("Email %d is marked as deleted", mailno) ;
  2075. E 6
  2076.             }
  2077.             continue ;
  2078.         }
  2079.         /* U - undelete email */
  2080.         if (cmd[0] == 'U')
  2081.         {
  2082.             llptr = llnofind(mailno, currlist) ;
  2083.             if (llptr == NULL)
  2084.             {
  2085.                 p_printf("message %d does not exist", mailno) ;
  2086.                 continue ;
  2087.             }
  2088.             if (llptr->status != DELETED)
  2089.             {
  2090.                 p_printf("message number %d is not deleted, camt undelete", mailno) ;
  2091.                 continue ;
  2092.             }
  2093. E 15
  2094. I 15
  2095.         /* functions from the current email list */
  2096.         case 'v': /* v - view the email */
  2097.             readmail(mailno, currlist) ;
  2098.             break ;
  2099.         case 'd': /* d - delete email */
  2100.             delmail(mailno, currlist) ;
  2101.             break ;
  2102.         case 'u': /* u - undelete email */
  2103. E 15
  2104.             udelmail(mailno, currlist) ;
  2105. I 6
  2106. D 15
  2107.             p_printf("Email %d is marked as undeleted", mailno) ;
  2108. E 6
  2109.             continue ;
  2110.         }
  2111.         /* h - print current headers */
  2112.         if (cmd[0] == 'h')
  2113.         {
  2114.             disphdrs(currlist, mailno - 5, mailno + 5) ;
  2115.             continue ;
  2116.         }
  2117.         /* ? - help */
  2118.         if (cmd[0] == '?')
  2119.         {
  2120. D 11
  2121.             p_printf("Help not implemented") ;
  2122. E 11
  2123. I 11
  2124.             p_printf("<number> - sets the current email") ;
  2125.             p_printf("n - new email");
  2126.             p_printf("ni - new email including current") ;
  2127.             p_printf("r - reply to sender") ;
  2128.             p_printf("ri - reply to sender including current") ;
  2129.             p_getch() ;
  2130.             p_printf("R - reply to all") ;
  2131.             p_printf("Ri - reply to all including current") ;
  2132.             p_printf("D - delete current") ;
  2133.             p_printf("U - Undelete current") ;
  2134.             p_printf("h - print headers") ;
  2135.             p_getch() ;
  2136.             p_printf("S - switch between incomming and outgoing list") ;
  2137.             p_printf("? - help") ;
  2138.             p_printf("q - quit, save changes") ;
  2139.             p_printf("c - crash out losing changes") ;
  2140. E 11
  2141.             continue ;
  2142.         }
  2143.         /* S - switch from the inlist to the outlist */
  2144.         if (cmd[0] == 'S')
  2145.         {
  2146. E 15
  2147. I 15
  2148.             break ;
  2149.         case 'm': /* modify the current header */
  2150. I 16
  2151.             /* this is pointless unless we are dealing with the outgoing list. So */
  2152.             if (currlist == inlist)
  2153.             {
  2154.                 uDisplayText("You Cannot modify the headers", "In the incomming list", "(Its a pointless exercise)", NULL) ;
  2155.                 break ;
  2156.             }
  2157. E 16
  2158.             llptr = llnofind(mailno, currlist) ;
  2159.             gethdr(llptr) ;
  2160.             break ;
  2161.         /* functions from the compose email list */
  2162.         case 'n': /* new email */
  2163.             incl = askincl() ;
  2164.             newemail(mailno, currlist, incl) ;
  2165.             break ;
  2166.         case 'r': /* r - reply to sender */
  2167.             incl = askincl() ;
  2168.             repfrom(mailno, currlist, incl) ;
  2169.             break;
  2170.         case 'a': /* a - reply to all */
  2171.             incl = askincl() ;
  2172.             repall(mailno, currlist, incl) ;
  2173.             break ;
  2174.         /* functions from the special email list - NOTE x and c are dealt with earlier in the mainloop code */
  2175.         case 's': /* s - switch from the inlist to the outlist */
  2176. E 15
  2177.             if (currlist == inlist)
  2178.             {
  2179. D 16
  2180.                 p_printf("Switching to the outgoing mail file") ;
  2181. E 16
  2182. I 16
  2183.                 uDisplayText("Switching to the outgoing mail file", NULL) ;
  2184. E 16
  2185.                 currlist = outlist ;
  2186.             }
  2187.             else
  2188.             {
  2189. D 16
  2190.                 p_printf("Switching to the incomming mail file") ;
  2191. E 16
  2192. I 16
  2193.                 uDisplayText("Switching to the incomming mail file", NULL) ;
  2194. E 16
  2195.                 currlist = inlist ;
  2196.             }
  2197.             mailno = 1 ;
  2198. D 15
  2199.             disphdrs(currlist, 1, 10) ;
  2200.             continue ;
  2201.         }
  2202. I 3
  2203.         /* debug stuff print the current list head */
  2204.         if (cmd[0] == 'i')
  2205.         {
  2206.             lldump(currlist) ;
  2207.             continue ;
  2208.         }
  2209.         /* print the full current list */
  2210.         if (cmd[0]  == 'I')
  2211.         {
  2212.             lldmpall(currlist) ;
  2213.             continue ;
  2214.         }
  2215.         /* more debug - crash out without printing anything */
  2216. D 11
  2217.         if (cmd[0] == 'c')
  2218. E 11
  2219. I 11
  2220.         if (cmd[0] == 'C')
  2221. E 11
  2222.         {
  2223. D 5
  2224.             return (ERR) ;
  2225. E 5
  2226. I 5
  2227.             return (IERR) ;
  2228. E 5
  2229.         }
  2230. E 15
  2231. I 15
  2232.             break ;
  2233. E 15
  2234. E 3
  2235. D 5
  2236.     }            
  2237. E 5
  2238. I 5
  2239.     }
  2240. D 15
  2241.     return(ret) ;            
  2242. E 15
  2243. I 15
  2244.     return ;            
  2245. E 15
  2246. E 5
  2247.         
  2248. }
  2249.  
  2250. /* delete any deleted files, write out the updated meta files */
  2251. D 3
  2252. VOID dotidy(VOID)
  2253. E 3
  2254. I 3
  2255. INT dotidy(VOID)
  2256. E 3
  2257. {
  2258. I 3
  2259.     INT ret ;
  2260. D 14
  2261.     if (topdbg == TRUE)
  2262.         p_printf("CALL dotidy()") ;
  2263. E 14
  2264. E 3
  2265.     /* purge the deleted incomming emails */
  2266. I 16
  2267. D 17
  2268.     statusmsg("Deleting unwanted message files")
  2269. E 17
  2270. I 17
  2271.     statusmsg("Deleting unwanted message files") ;
  2272. E 17
  2273. E 16
  2274. D 6
  2275.     prgemail(inlist) ;
  2276. E 6
  2277. I 6
  2278.     ret = prgemail(inlist) ;
  2279.     if (ret == FILEERR)
  2280.     {
  2281. D 16
  2282.         p_printf("FILE ERROR: dotidy, error in purging input list datafiles") ;
  2283. E 16
  2284.         return(FILEERR) ;
  2285.     }
  2286. E 6
  2287.     /* purge any deleted outgoing emails */
  2288. D 6
  2289.     prgemail(outlist) ;
  2290. E 6
  2291. I 6
  2292.     ret = prgemail(outlist) ;
  2293.     if (ret == FILEERR)
  2294.     {
  2295. D 16
  2296.         p_printf("FILE ERROR: dotidy, error in purging output list datafiles") ;
  2297. E 16
  2298.         return(FILEERR) ;
  2299.     }
  2300. E 6
  2301.     /* write the incomming list back out */
  2302. I 16
  2303.     statusmsg("Saving mta lists") ;
  2304. E 16
  2305. D 3
  2306.     wrtmeta(METAIN, inlist) ;
  2307. E 3
  2308. I 3
  2309.     ret = wrtmeta(METAIN, inlist) ;
  2310. D 5
  2311.     if (ret == ERR)
  2312. E 5
  2313. I 5
  2314.     if (ret == FILEERR)
  2315. E 5
  2316.     {
  2317. D 16
  2318.         p_printf("FILE ERROR: dotidy, error in writting metafile %s", METAIN) ;
  2319. E 16
  2320. D 5
  2321.         return(ERR) ;
  2322. E 5
  2323. I 5
  2324.         return(FILEERR) ;
  2325. E 5
  2326.     }
  2327. E 3
  2328.     /* finaly the outgoing list */
  2329.     wrtmeta(METAOUT, outlist) ;
  2330. I 3
  2331. D 5
  2332.     if (ret == ERR)
  2333. E 5
  2334. I 5
  2335.     if (ret == FILEERR)
  2336. E 5
  2337.     {
  2338. D 16
  2339.         p_printf("FILE ERROR: dotidy, error in writting metafile %s", METAOUT) ;
  2340. E 16
  2341. D 5
  2342.         return(ERR) ;
  2343. E 5
  2344. I 5
  2345.         return(FILEERR) ;
  2346. E 5
  2347.     }
  2348. E 3
  2349.     /* free the data in the list */
  2350. I 16
  2351.     statusmsg("Freeing Memory") ;
  2352. E 16
  2353.     llfree(inlist) ;
  2354.     llfree(outlist) ;
  2355. I 5
  2356.     return(TRUE) ;
  2357. E 5
  2358. }
  2359.     
  2360.     
  2361. /* write the meta files out */
  2362. E 2
  2363.  void main(void)
  2364. {
  2365. I 3
  2366.     INT ret ;
  2367. D 14
  2368.     if (topdbg == TRUE)
  2369.         p_printf("CALL: main()") ;
  2370. E 14
  2371. E 3
  2372. D 2
  2373.     /* call the word application on the filename m:\mail\m1.mes */
  2374.     /* assumes the file exists */
  2375.     doword("LOC::M:\\MAIL\\M1.MES") ;
  2376. E 2
  2377. I 2
  2378. D 15
  2379.     /* setup the windows */
  2380. E 15
  2381. I 15
  2382.     /* setup the windows etc*/
  2383. E 15
  2384.     initwins() ;
  2385. I 6
  2386.     /* say Hi */
  2387.     dogreet() ;
  2388. I 16
  2389.     /* Load my windows */
  2390.     initmywins() ;
  2391. E 16
  2392. E 6
  2393.     /* read the list of incomming mail */
  2394. D 3
  2395.     initlist() ;
  2396. E 3
  2397. I 3
  2398.     ret = initlist() ;
  2399. D 5
  2400.     if (ret == ERR)
  2401. E 5
  2402. I 5
  2403.     if (ret == FILEERR)
  2404. E 5
  2405.     {
  2406. D 16
  2407.         p_printf("FILE ERROR: main, error in loading meta lists") ;
  2408.         p_getch() ;
  2409. E 16
  2410. I 16
  2411.         uDisplayText("FILE ERROR: main, error","in loading meta lists", NULL) ;
  2412. E 16
  2413.         return ;
  2414.     }
  2415. I 5
  2416.     if (ret == MEMERR)
  2417.     {
  2418. D 16
  2419.         p_printf("FILE ERROR: main, error in loading meta lists") ;
  2420.         p_getch() ;
  2421. E 16
  2422. I 16
  2423.         uDisplayText("MEMORY ERROR: main, error","in loading meta lists", NULL) ;
  2424. E 16
  2425.         return ;
  2426.     }
  2427.     if (ret != TRUE)
  2428.     {
  2429. D 16
  2430.         p_printf("UNKNOWN ERROR: main, error in loading meta lists") ;
  2431.         p_getch() ;
  2432. E 16
  2433. I 16
  2434.         uDisplayText("UNKNOWN ERROR: main, error","in loading meta lists", NULL) ;
  2435. E 16
  2436.         return ;
  2437.     }
  2438. E 5
  2439. E 3
  2440.     /* main select / chose / do loop */
  2441. D 3
  2442.     mainloop() ;
  2443. E 3
  2444. I 3
  2445.     ret = mainloop() ;
  2446. D 5
  2447.     if (ret == ERR)
  2448. E 5
  2449. I 5
  2450.     if (ret == IERR)
  2451. E 5
  2452.     {
  2453. D 16
  2454.         p_printf("INTERNAL ERROR: panic exit (metafiles not written)") ;
  2455.         p_getch() ;
  2456. E 16
  2457. I 16
  2458.         uDisplayText("INTERNAL ERROR: panic exit","(metafiles not written)", NULL) ;
  2459. E 16
  2460.         return ;
  2461.     }
  2462. I 5
  2463.     else if (ret == FILEERR)
  2464.     {
  2465. D 16
  2466.         p_printf("FILE ERROR: panic exit (metafiles not written)") ;
  2467.         p_getch() ;
  2468. E 16
  2469. I 16
  2470.         uDisplayText("FILE ERROR: panic exit","(metafiles not written)", NULL) ;
  2471. E 16
  2472.         return ;
  2473.     }
  2474.     else if (ret == MEMERR)
  2475.     {
  2476. D 16
  2477.         p_printf("MEMORY ERROR: panic exit (metafiles not written)") ;
  2478.         p_getch() ;
  2479. E 16
  2480. I 16
  2481.         uDisplayText("MEMORY ERROR: panic exit","(metafiles not written)", NULL) ;
  2482. E 16
  2483.         return ;
  2484.     }
  2485.     else if ((ret != TRUE) && (ret != FALSE))
  2486.     {
  2487. D 16
  2488.         p_printf("UNKNOWN ERROR: panic exit (metafiles not written)") ;
  2489.         p_getch() ;
  2490. E 16
  2491. I 16
  2492.         uDisplayText("UNKNOWN ERROR: panic exit","(metafiles not written)", NULL) ;
  2493. E 16
  2494.         return ;
  2495.     }
  2496. E 5
  2497. E 3
  2498.     /* tidy up after us */
  2499. D 3
  2500.     dotidy() ;
  2501. E 3
  2502. I 3
  2503.     ret = dotidy() ;
  2504. D 5
  2505.     if (ret == ERR)
  2506. E 5
  2507. I 5
  2508.     if (ret == IERR)
  2509. E 5
  2510.     {
  2511. I 5
  2512. D 16
  2513.         p_printf("INTERNAL ERROR: main, error in writting meta lists") ;
  2514.         p_getch() ;
  2515. E 16
  2516. I 16
  2517.         uDisplayText("INTERNAL ERROR: main, error","in writting meta lists", NULL) ;
  2518. E 16
  2519.         return ;
  2520.     }
  2521.     if (ret == MEMERR)
  2522.     {
  2523. D 16
  2524.         p_printf("MEMORY ERROR: main, error in writting meta lists") ;
  2525.         p_getch() ;
  2526. E 16
  2527. I 16
  2528.         uDisplayText("MEMORY ERROR: main, error","in writting meta lists", NULL) ;
  2529. E 16
  2530.         return ;
  2531.     }
  2532.     if (ret == FILEERR)
  2533.     {
  2534. E 5
  2535. D 16
  2536.         p_printf("FILE ERROR: main, error in writting meta lists") ;
  2537.         p_getch() ;
  2538. E 16
  2539. I 16
  2540.         uDisplayText("FILE ERROR: main, error","in writting meta lists", NULL) ;
  2541. E 16
  2542.         return ;
  2543.     }
  2544. I 5
  2545.     if (ret != TRUE)
  2546.     {
  2547. D 16
  2548.         p_printf("UNKNOWN ERROR: main, error in writting meta lists") ;
  2549.         p_getch() ;
  2550. E 16
  2551. I 16
  2552.         uDisplayText("UNKNOWN ERROR: main, error","in writting meta lists", NULL) ;
  2553. E 16
  2554.         return ;
  2555.     }
  2556. E 5
  2557. E 3
  2558.     /* close down the windows etc */
  2559.     shutwins() ;
  2560. E 2
  2561. }
  2562.  
  2563. I 2
  2564. /* end of top level code */
  2565.  
  2566. D 16
  2567. /* start of commands code */
  2568. /* prompt and then read in a command, if the command is "q" return FALSE, otherwise return (TRUE) */
  2569. VOID getcmd(TEXT * cmd)
  2570. {
  2571. I 3
  2572. D 14
  2573.     if (cmddbg == TRUE)
  2574.         p_printf("CALL: getcmd()") ;
  2575. E 14
  2576. E 3
  2577. D 12
  2578.     putnonl(">") ;
  2579. E 12
  2580. I 12
  2581.     p_putch('>') ;
  2582.     p_putch(' ') ;
  2583. E 12
  2584.     getinp(cmd) ;
  2585. }
  2586.     
  2587. /* end of commands code */
  2588.  
  2589. E 16
  2590. /* start of process related code */
  2591. D 7
  2592.  
  2593. E 7
  2594. I 7
  2595. D 14
  2596. #ifdef RUNONSUN
  2597. /* if we are running on the sun dont call word, just display the file */
  2598. E 14
  2599. I 14
  2600. /* do the word stuff */
  2601. E 14
  2602. E 7
  2603. E 2
  2604. VOID doword(TEXT * fname)
  2605. {
  2606. I 7
  2607. D 14
  2608.     VOID * infd ;
  2609.     INT ret ;
  2610.     TEXT buff[P_FBLKSIZE] ;
  2611.     
  2612.     if (procdbg == TRUE)
  2613.         p_printf("CALL: doword(fname = %s), sun version", fname) ;
  2614.     ret = p_open(&infd, fname, P_FTEXT | P_FSHARE) ;
  2615.     if (ret < 0)
  2616.     {
  2617.         p_printf("FILE ERROR: doword (sun version), error in opening %s for read", fname) ;
  2618.         p_errs(buff, ret) ;
  2619.         p_printf("%s", buff) ;
  2620.         return ;
  2621.     }
  2622.     ret = 0 ;
  2623.     while (ret >= 0)
  2624.     {
  2625.         ret = p_read(infd, buff, P_FBLKSIZE) ;
  2626.         /* terminate the string */
  2627.         buff[ret] = '\0' ;
  2628.         putnonl(buff) ;
  2629.         p_getch() ;
  2630.     }
  2631.     p_close(infd) ;
  2632. }
  2633. #else
  2634. /* we are compiling for the psion, realy do the word stuff */
  2635. VOID doword(TEXT * fname)
  2636. {
  2637. E 14
  2638. E 7
  2639. D 16
  2640.     TEXT cmdline[127] ;
  2641. E 16
  2642. I 16
  2643.     TEXT cmdline[127], tmp[50] ;
  2644. E 16
  2645. D 17
  2646.     INT i ;
  2647. E 17
  2648.     INT cmdlen ;
  2649.  
  2650. I 3
  2651. D 14
  2652.     if (procdbg == TRUE)
  2653. D 7
  2654.         p_printf("CALL: doword(fname = %s)", fname) ;
  2655. E 7
  2656. I 7
  2657.         p_printf("CALL: doword(fname = %s), psion version", fname) ;
  2658. E 14
  2659. E 7
  2660. E 3
  2661.     /* build the command line */
  2662. D 7
  2663.     p_printf("Building command line\n") ;
  2664.     cmdlen = buildcmd('O',"Mailread", ".mes", NULL, fname, cmdline) ;
  2665.     for (i = 0 ; i < cmdlen; i++)
  2666. E 7
  2667. I 7
  2668. D 8
  2669.     cmdlen = buildcmd('O',"Program", ".txt", NULL, fname, cmdline) ;
  2670. E 8
  2671. I 8
  2672.     cmdlen = buildcmd('O',MAILRDRNAME, MAILRDREXT, "Q", fname, cmdline) ;
  2673. E 8
  2674. D 14
  2675.     if (procdbg == TRUE)
  2676. E 7
  2677.     {
  2678. D 7
  2679.         p_printf("cmdline[%d] = %d (%c)\n", i, cmdline[i], cmdline[i]) ;
  2680.         p_sleep((ULONG)5) ;
  2681. E 7
  2682. I 7
  2683.         for (i = 0 ; i < cmdlen; i++)
  2684.         {
  2685.             p_printf("cmdline[%d] = %d (%c)\n", i, cmdline[i], cmdline[i]) ;
  2686.             p_getch() ;
  2687.         }
  2688. E 7
  2689.     }
  2690. E 14
  2691. D 7
  2692.     p_printf("Running command\n") ;
  2693.     runcmd("ROM::WORD.APP", cmdline, cmdlen) ;
  2694.     p_printf("Finished") ;
  2695.     p_sleep((ULONG)10) ;
  2696. E 7
  2697. I 7
  2698. D 8
  2699.     p_printf("Running word, YOU MUST QUIT WORD do not press any system key") ;
  2700.     runcmd(WORDCMD, cmdline, cmdlen) ;
  2701.     p_printf("Returned from word") ;
  2702. E 8
  2703. I 8
  2704. D 16
  2705.     p_printf("Running %s", MAILRDRNAME ) ;
  2706. E 16
  2707. I 16
  2708.     p_atos(tmp, "Running %s", MAILRDRNAME ) ;
  2709.     statusmsg(tmp) ;
  2710. E 16
  2711.     runcmd(MAILRDRCMD, cmdline, cmdlen) ;
  2712. D 16
  2713.     p_printf("Returned from %s", MAILRDRNAME) ;
  2714. E 16
  2715. I 16
  2716.     p_atos(tmp, "Returned from %s", MAILRDRNAME) ;
  2717. D 17
  2718.     statusmsg(tmp)
  2719. E 17
  2720. I 17
  2721.     statusmsg(tmp) ;
  2722. E 17
  2723. E 16
  2724. E 8
  2725. E 7
  2726. }
  2727. D 7
  2728.  
  2729. E 7
  2730. I 7
  2731. D 14
  2732. #endif
  2733. E 14
  2734. I 14
  2735.  
  2736. E 14
  2737. E 7
  2738. INT runcmd(TEXT * appname, TEXT * cmdline, INT cmdlen) 
  2739. {
  2740.     HANDLE pid ;
  2741.     WORD stat ;
  2742. D 3
  2743.     
  2744. E 3
  2745. I 3
  2746. D 14
  2747.     if (procdbg == TRUE)
  2748.         p_printf("CALL: runcmd (appname = %s, cmdline = %s, cmdlen = %d)", appname, cmdline, cmdlen) ;
  2749. E 14
  2750. E 3
  2751.     /* create the process */
  2752.     if ((pid = p_execc(appname, cmdline, cmdlen)) <0)
  2753.         return(pid) ;
  2754.     
  2755.     /* we want to monitor it */
  2756.     p_logona(pid, &stat) ;
  2757.  
  2758.     /* start the process up */
  2759.     p_presume(pid) ;
  2760.  
  2761.     /* wait for it to finish */
  2762.     p_waitstat(&stat) ;
  2763.  
  2764.     return(stat >> 8) ;
  2765. }
  2766.  
  2767. INT buildcmd(TEXT cmdbyte, TEXT * appname, TEXT * appext, TEXT * appalias, TEXT * fname, TEXT * cmdline)
  2768. {
  2769.     TEXT * cmdptr;
  2770.     INT cmdlen ;
  2771.  
  2772. I 3
  2773. D 14
  2774.     if (procdbg == TRUE)
  2775.         p_printf("CALL: buildcmd (cmdbyte = %c, appname = %s, appext = %s, appalias = NULL or should be, fname = %s, cmdline = OMITTED)", cmdbyte, appname, appext, fname) ;
  2776. E 14
  2777. E 3
  2778.     /* initialisation */
  2779.     cmdlen = 0 ;
  2780.     cmdptr = cmdline ;
  2781.     /* do the command byte */
  2782.         /* insert it */
  2783.         * cmdptr = cmdbyte ;
  2784.         /* the length has just been increased */
  2785.         cmdlen ++ ;
  2786.         /* move cmdptr allong one to skip over the command */
  2787.         cmdptr ++ ;
  2788.     /* insert the appname */
  2789.         /* insert it */
  2790.         p_scpy(cmdptr, appname) ;
  2791.         /* move over it and the \0 */
  2792.         cmdptr = cmdptr + p_slen(appname) +1 ;
  2793.         /* add the length and the \0 to the total length */
  2794.         cmdlen = cmdlen + p_slen(appname) +1 ;
  2795.     /* insert the extension and other stuff if appext is non NULL */
  2796.     if (appext != NULL)
  2797.     {
  2798.         /* insert the extension */
  2799.         p_scpy(cmdptr, appext) ;
  2800.         /* move over it BUT NOT THE NULL (we may have an alias)*/
  2801.         cmdptr = cmdptr + p_slen(appext) ;
  2802.         /* add the length to the total length */
  2803.         cmdlen = cmdlen + p_slen(appext) ;
  2804.  
  2805.         /* if the alias is non NULL add it */
  2806.         if (appalias != NULL) 
  2807.         {
  2808.             /* insert a space */
  2809.             *cmdptr = ' ' ;
  2810.             /* move over the space */
  2811.             cmdptr ++ ;
  2812.             /* add the space to the total length */
  2813.             cmdlen ++ ;
  2814.             /* insert the appalias */
  2815.             p_scpy(cmdptr, appalias) ;
  2816.             /* move over the alias BUT NOT THE NULL (then is dealt with below)*/
  2817.             cmdptr = cmdptr + p_slen(appalias) ;
  2818.             /* increment the total length */
  2819.             cmdlen = cmdlen + p_slen(appalias) ;
  2820.         }
  2821.  
  2822.         /* because we have not accounted for the \0 at the end of the appext / appext+appalias
  2823.            move over it now */
  2824.         cmdptr ++ ;
  2825.         cmdlen ++ ;
  2826.  
  2827.         /* if there is a filename add it */
  2828.         if (fname != NULL)
  2829.         {
  2830.             /*insert the filename */
  2831.             p_scpy(cmdptr, fname) ;
  2832. D 2
  2833.             /* add the length and the \0 to the total length */
  2834. E 2
  2835. I 2
  2836.             /* add the length and vFα \0 to the total length */
  2837. E 2
  2838.             cmdlen = cmdlen + p_slen(fname) + 1 ;
  2839.             /* we done need to move cmdptr as we are at the end of the operatrion */
  2840.         }
  2841.     }
  2842.     /* return with the length of the assembled string */
  2843.     return(cmdlen) ;
  2844. }
  2845. I 2
  2846.  
  2847. /* end of process related code */
  2848.  
  2849. /* start of writting email code */
  2850. /* repfrom, reply to the sender only */
  2851. INT repfrom(INT mailno, struct ll * startll, INT incl)
  2852. {
  2853.     struct ll * newll, *repmail ;
  2854.     TEXT tmp[100] ;
  2855. I 6
  2856.     INT ret ;
  2857. E 6
  2858. I 3
  2859. D 14
  2860.     if (cmddbg == TRUE)
  2861.         p_printf("CALL: repfrom (mailno %d, startll = OMITTED, incl = %d)", mailno, incl) ;
  2862. E 14
  2863. E 3
  2864.     /* create the new list entry */
  2865.     newll = llnew() ;
  2866.     /* locate the origional email */
  2867.     repmail = llnofind(mailno, startll) ;
  2868.     /* copy the data */
  2869.     llcopy(newll, repmail) ;
  2870.     /* add Reto the start of the subject */
  2871. D 7
  2872.     p_scpym(tmp, "RE ", newll->subject, NULL) ;
  2873. E 7
  2874. I 7
  2875.     p_scpym(tmp, "Re: ", newll->subject, NULL) ;
  2876. E 7
  2877.     p_scpy(newll->subject, tmp) ;
  2878.     /* copy the from into the to list */
  2879.     p_scpy(newll->to, newll->from) ;
  2880.     /* put our name in the from field */
  2881.     p_scpy(newll->from, startll->mydata->myaddr) ;
  2882.     /* empty the cc and bcc fields */
  2883.     newll->cc[0] = '\0' ;
  2884.     newll->bcc[0] = '\0' ;
  2885.     /* create the related file */
  2886. D 6
  2887.     if (newfile(newll, outlist)== FALSE)
  2888. E 6
  2889. I 6
  2890.     if ((ret = newfile(newll, outlist)) != TRUE)
  2891. E 6
  2892.     {
  2893.         p_free(newll) ;
  2894. D 6
  2895.         return(FALSE) ;
  2896. E 6
  2897. I 6
  2898.         if (ret == FILEERR)
  2899. D 16
  2900.             p_printf("FILE ERROR: repfrom, newfile returned FILEERR") ;
  2901. E 16
  2902. I 16
  2903.             uDisplayText("FILE ERROR: repfrom,","newfile returned FILEERR", NULL) ;
  2904. E 16
  2905.         else
  2906. D 16
  2907.             p_printf("INTERNAL ERROR: repfrom, newfile returned an unexpected error code %d", ret) ;
  2908. E 16
  2909. I 16
  2910.             uDisplayText("INTERNAL ERROR: repfrom,","newfile returned an unexpected error code", NULL) ;
  2911. E 16
  2912.         return(ret) ;
  2913. E 6
  2914.     }
  2915.     /* if incl is TRUE copy from the origional to the new data file */
  2916.     if (incl == TRUE)
  2917. D 6
  2918.         cpyfile(newll,outlist , repmail, startll) ;
  2919. E 6
  2920. I 6
  2921.     {
  2922.         if ((ret = cpyfile(newll,outlist , repmail, startll)) != TRUE)
  2923.         {
  2924.             p_free(newll) ;
  2925. D 7
  2926.             if (ret == FILEERROR)
  2927. E 7
  2928. I 7
  2929.             if (ret == FILEERR)
  2930. E 7
  2931. D 16
  2932.                 p_printf("FILE ERROR: repfrom, cpyfile returned FILEERR") ;
  2933. E 16
  2934. I 16
  2935.                 uDisplayText("FILE ERROR: repfrom,","cpyfile returned FILEERR", NULL) ;
  2936. E 16
  2937.             else
  2938. D 16
  2939.                 p_printf("INTERNAL ERROR: repfrom, cpyfile returned an unexpected error code %d", ret) ;
  2940. E 16
  2941. I 16
  2942.                 uDisplayText("INTERNAL ERROR: repfrom,","cpyfile returned an unexpected error code", NULL) ;
  2943. E 16
  2944.             return(ret) ;
  2945.         }
  2946.     }
  2947. E 6
  2948.     /* make the email active */
  2949.     newll->status = ACTIVE ;
  2950.     /* get the header information */
  2951.     gethdr(newll) ;
  2952.     /* get the sequence number */
  2953.     newll->no = outlist->count +1 ;
  2954.     /* add this email to the outgoing list */
  2955.     lladd(newll, outlist) ;
  2956. I 6
  2957. D 17
  2958.     if (cmddbg == TRUE)
  2959.         lldump(newll) ;
  2960. E 17
  2961. E 6
  2962.     /* call the editor do do the work */
  2963.     wrtemail(newll->no, outlist) ;
  2964. }
  2965.  
  2966. /* repall, reply to the sender and all other recievers */
  2967. INT repall(INT mailno, struct ll * startll, INT incl)
  2968. {
  2969.     struct ll * newll, *repmail ;
  2970.     TEXT tmp[100] ;
  2971. I 3
  2972. D 14
  2973.     if (cmddbg == TRUE)
  2974.         p_printf("CALL: repall(mailno = %d, startll = OMITTED, incl = %d)", mailno, incl) ;
  2975. E 14
  2976. E 3
  2977.     /* create the new list entry */
  2978.     newll = llnew() ;
  2979.     /* locate the origional email */
  2980.     repmail = llnofind(mailno, startll) ;
  2981.     /* copy the data */
  2982.     llcopy(newll, repmail) ;
  2983.     /* add Reto the start of the subject */
  2984. D 7
  2985.     p_scpym(tmp, "RE ", newll->subject, NULL) ;
  2986. E 7
  2987. I 7
  2988.     p_scpym(tmp, "Re: ", newll->subject, NULL) ;
  2989. E 7
  2990.     p_scpy(newll->subject, tmp) ;
  2991.     /* add the from to the to list */
  2992.     p_scpym(tmp, newll->from, " ", newll->to, NULL) ;
  2993.     p_scpy(newll->to, tmp) ;
  2994.     /* put our name in the from field */
  2995.     p_scpy(newll->from, startll->mydata->myaddr) ;
  2996.     /* create the related file */
  2997.     if (newfile(newll, outlist)== FALSE)
  2998.     {
  2999.         p_free(newll) ;
  3000.         return(FALSE) ;
  3001.     }
  3002.     /* if incl is TRUE copy from the origional to the new data file */
  3003.     if (incl == TRUE)
  3004.         cpyfile(newll, outlist, repmail, startll) ;
  3005.     /* make the email active */
  3006.     newll->status = ACTIVE ;
  3007.     /* get the header information */
  3008.     gethdr(newll) ;
  3009.     /* get the sequence number */
  3010.     newll->no = outlist->count +1 ;
  3011.     /* add this email to the outgoing list */
  3012.     lladd(newll, outlist) ;
  3013. I 6
  3014. D 14
  3015.     if (cmddbg == TRUE)
  3016.         lldump(newll) ;
  3017. E 14
  3018. E 6
  3019.     /* call the editor do do the work */
  3020.     wrtemail(newll->no, outlist) ;
  3021. }
  3022. /* newemail, new list entry, fill it in then write the email */
  3023. INT newemail(INT mailno, struct ll * startll, INT incl)
  3024. {
  3025.     struct ll * newll, * repmail ;
  3026. I 5
  3027.     INT ret ;
  3028. E 5
  3029. I 3
  3030. D 14
  3031.     if (cmddbg == TRUE)
  3032.         p_printf("CALL: newemail(mailno = %d, startll = OMITTED, incl = %d)", mailno, incl) ;
  3033. E 14
  3034. E 3
  3035.     newll = llnew() ;
  3036.     /* instal our address into the from field */
  3037.     p_scpy(newll->from, startll->mydata->myaddr) ;
  3038.     /* create the related file */
  3039. D 3
  3040.     if (newfile(newll, outlist)== FALSE)
  3041. E 3
  3042. I 3
  3043. D 5
  3044.     if (newfile(newll, outlist) == FALSE)
  3045. E 5
  3046. I 5
  3047.     if (newfile(newll, outlist) == FILEERR)
  3048. E 5
  3049. E 3
  3050.     {
  3051. I 3
  3052. D 16
  3053.         p_printf("FILE ERROR: newemail, error in creating new email file") ;
  3054. E 16
  3055. I 16
  3056.         uDisplayText("FILE ERROR: newemail,","error in creating new email file", NULL) ;
  3057. E 16
  3058. E 3
  3059.         p_free(newll) ;
  3060. D 5
  3061.         return(FALSE) ;
  3062. E 5
  3063. I 5
  3064.         return(FILEERR) ;
  3065. E 5
  3066.     }
  3067.     /* if incl is true we need to copy the given email */
  3068.     if (incl == TRUE)
  3069.     {
  3070.         repmail = llnofind(mailno, startll) ;
  3071. D 5
  3072.         cpyfile(newll, outlist, repmail, startll) ;
  3073. E 5
  3074. I 5
  3075.         ret = cpyfile(newll, outlist, repmail, startll) ;
  3076.         if (ret == FILEERR)
  3077.         {
  3078. D 16
  3079.             p_printf("FILE ERROR: newemail, error in cerating copy file for include") ;
  3080. E 16
  3081. I 16
  3082.             uDisplayText("FILE ERROR: newemail,","error in creating copy file for include", NULL) ;
  3083. E 16
  3084.             return(FILEERR) ;
  3085.         }
  3086. E 5
  3087.     }
  3088.     /* make the email active */
  3089.     newll->status = ACTIVE ;
  3090.     /* get the header information */
  3091.     gethdr(newll) ;
  3092.     /* get the sequence number */
  3093.     newll->no = outlist->count +1 ;
  3094.     /* add this email to the outgoing list */
  3095.     lladd(newll, outlist) ;
  3096. I 6
  3097. D 14
  3098.     if (cmddbg == TRUE)
  3099.         lldump(newll) ;
  3100. E 14
  3101. E 6
  3102.     /* call the editor do do the work */
  3103.     wrtemail(newll->no, outlist) ;
  3104. }
  3105. /* end of email writting code */
  3106.  
  3107. /* start of header from user code */
  3108. /* fill in a data entry with user information */
  3109. VOID gethdr(struct ll * in)
  3110. {
  3111. I 3
  3112. D 14
  3113.     if (inpdbg == TRUE)
  3114. I 6
  3115.     {
  3116. E 6
  3117.         p_printf("CALL: gethdr (in = OMITTED)");
  3118. I 6
  3119.         p_printf("Starcture at start is") ;
  3120.         lldump(in) ;
  3121.     }
  3122. E 14
  3123. E 6
  3124. E 3
  3125. D 16
  3126.     getto(in->to) ;
  3127.     getsub(in->subject) ;
  3128.     getcc(in->cc) ;
  3129.     getbcc(in->bcc) ;
  3130. E 16
  3131. I 16
  3132. D 17
  3133.     TEXT to[HDRLEN+1], from[HDRLEN+1], cc [HDRLEN+1], bcc[HDRLEN+1] ;
  3134.     H_DIALOG_SEDIT eto, esubject, ecc, ebcc ;
  3135. E 17
  3136. I 17
  3137.     TEXT to[HDRLEN+1], subject[HDRLEN+1], cc [HDRLEN+1], bcc[HDRLEN+1] ;
  3138.     H_DI_SEDIT eto, esubject, ecc, ebcc ;
  3139. E 17
  3140.     /* convert from zero terminated strings (ala C) to byte count srtings (ala OPL) */
  3141.     uZTStoBCS(to, in->to) ;
  3142.     uZTStoBCS(subject, in->subject) ;
  3143.     uZTStoBCS(cc, in->cc) ;
  3144.     uZTStoBCS(bcc, in->bcc) ;
  3145.     /* build the dialog structures */
  3146.     /* the to structure */
  3147.     eto.str = &to[0] ;
  3148.     eto.len = HDRLEN ;
  3149.     eto.width = 30 ;
  3150.     /* subject structure */
  3151.     esubject.str = &subject[0] ;
  3152.     esubject.len = HDRLEN ;
  3153.     esubject.width = 30 ;
  3154.     /* cc structure */
  3155.     ecc.str = &cc[0] ;
  3156.     ecc.len = HDRLEN ;
  3157.     ecc.width = 30 ;
  3158.     /* bcc structure */
  3159.     ebcc.str = &bcc[0] ;
  3160.     ebcc.len = HDRLEN ;
  3161.     ebcc.width = 30 ;
  3162.     
  3163.     /* build the dialog */
  3164.     uOpenDialog("Please enter the header information") ;
  3165.     /* add the initial header information to it */
  3166. D 17
  3167.     uAddDialogItem(H_DIALOG_SEDIT, "     To: ", eto) ;
  3168.     uAddDialogItem(H_DIALOG_SEDIT, "Subject: ", esubject) ;
  3169.     uAddDialogItem(H_DIALOG_SEDIT, "     Cc: ", ecc) ;
  3170.     uAddDialogItem(H_DIALOG_SEDIT, "    Bcc: ", ebcc) ;
  3171. E 17
  3172. I 17
  3173.     uAddDialogItem(H_DIALOG_SEDIT, "To:", &eto) ;
  3174.     uAddDialogItem(H_DIALOG_SEDIT, "Subject:", &esubject) ;
  3175.     uAddDialogItem(H_DIALOG_SEDIT, "Cc:", &ecc) ;
  3176.     uAddDialogItem(H_DIALOG_SEDIT, "Bcc:", &ebcc) ;
  3177. E 17
  3178.     /* run the dialog */
  3179.     uRunDialog() ;
  3180.     /* unpack the resulting strings this is realy daft having parts of the dialog ZTS and parts BCS */
  3181.     /* terminate them first */
  3182.     to[((INT)to[0])+1] = '\0' ;
  3183.     subject[((INT) subject[0])+1] = '\0' ;
  3184.     cc[((INT) cc[0])+1] = '\0' ;
  3185.     bcc[((INT) bcc[0]) +1] = '\0' ;
  3186.     /* copy the strings back */
  3187.     p_scpy(in->to, &to[1]) ;
  3188.     p_scpy(in->subject, &subject[1]) ;
  3189.     p_scpy(in->cc, &cc[1]) ;
  3190.     p_scpy(in->bcc, &bcc[1]) ;    
  3191. E 16
  3192. I 6
  3193. D 7
  3194.     if (inpdbg == TRUE) ;
  3195. E 7
  3196. I 7
  3197. D 14
  3198.     if (inpdbg == TRUE) 
  3199. E 7
  3200.     {
  3201.         p_printf("gethdr ll struct at end is") ;
  3202.         lldump(in) ;
  3203.     }
  3204. E 14
  3205. E 6
  3206. }
  3207.  
  3208. D 16
  3209. /* read a line of text, if there is data in there use that as a default */
  3210. VOID getinfo(TEXT * request, TEXT * target)
  3211. {
  3212.     TEXT tmp [100] ;
  3213. I 3
  3214. D 14
  3215.     if (inpdbg == TRUE)
  3216.         p_printf("CALL: getinfo (request = %s, target = %s)", request, target) ;
  3217. E 14
  3218. E 3
  3219.     /* are we given an empty string ? */
  3220. D 6
  3221.     if(p_slen(target) == 0)
  3222. E 6
  3223. I 6
  3224.     if(target[0] == '\0')
  3225. E 6
  3226.     {
  3227.         p_printf("Please enter the %s", request) ;
  3228.         getinp(target) ;
  3229.     }
  3230.     else
  3231.     {
  3232. D 6
  3233.         p_printf("Please enter a new %s or hit return \nTo accept the existing value of %s", target) ;
  3234. E 6
  3235. I 6
  3236. D 7
  3237.         p_printf("Please enter a new %s or hit return to accept the existing value of %s", request, target) ;
  3238. E 7
  3239. I 7
  3240.         p_printf("Please enter a new %s or hit return to accept the existing value (%s)", request, target) ;
  3241. E 7
  3242. E 6
  3243.         getinp(tmp) ;
  3244.         if (p_slen(tmp) != 0)
  3245.             p_scpy(target, tmp) ;
  3246.     }
  3247. }
  3248. /* target address */
  3249. VOID getto(TEXT * to)
  3250. {
  3251. I 3
  3252. D 14
  3253.     if (inpdbg == TRUE)
  3254.         p_printf("CALL: getto(to = %s)", to);
  3255. E 14
  3256. E 3
  3257.     getinfo("destination address", to) ;
  3258. }
  3259. /* subject */
  3260. VOID getsub(TEXT * sub)
  3261. {
  3262. I 3
  3263. D 14
  3264.     if (inpdbg == TRUE)
  3265.         p_printf("CALL: getsub (sub = %s)", sub) ;
  3266. E 14
  3267. E 3
  3268.     getinfo("subject", sub) ;
  3269. }
  3270. /* cc list */
  3271. VOID getcc (TEXT * cc)
  3272. {
  3273. I 3
  3274. D 14
  3275.     if (inpdbg == TRUE)
  3276.         p_printf("CALL: getcc (cc = %s)", cc) ;
  3277. E 14
  3278. E 3
  3279.     getinfo("Cc List", cc);
  3280. }
  3281. /* bcc list */
  3282. VOID getbcc (TEXT * bcc)
  3283. {
  3284. I 3
  3285. D 14
  3286.     if (inpdbg == TRUE)
  3287.         p_printf("CALL: getbcc (bcc = %s)", bcc) ;
  3288. E 14
  3289. E 3
  3290.     getinfo("Bcc List", bcc) ;
  3291. }
  3292. E 16
  3293. /* end of header from user code */
  3294.  
  3295. /* start of functions for working the mailbox in view */
  3296. /* bring up a mail reader */
  3297. VOID readmail(INT mailno, struct ll * llstart)
  3298. {
  3299.     struct ll * llentry ;
  3300.     TEXT fname [P_FNAMESIZE] ;
  3301. I 3
  3302. D 14
  3303.     if (cmddbg == TRUE)
  3304.         p_printf("CALL readmail (mailno = %d, llstart = OMITTED)", mailno) ;
  3305. E 14
  3306. E 3
  3307.     if ((llentry = llnofind(mailno, llstart)) == NULL)
  3308.         return ;
  3309. I 7
  3310. D 14
  3311.     if (cmddbg == TRUE)
  3312.     {
  3313.         p_printf("Working on email ll") ;
  3314.         lldump(llentry) ;
  3315.     }
  3316. E 14
  3317. E 7
  3318.     if (llentry->status != ACTIVE)
  3319.         return ;
  3320.     /* build up the name */
  3321. D 7
  3322.     p_scpym(fname, llstart->mydata->mypath, llentry->datafile) ;
  3323. E 7
  3324. I 7
  3325.     p_scpym(fname, llstart->mydata->mypath, llentry->datafile, NULL) ;
  3326. D 14
  3327.     if (cmddbg == TRUE)
  3328.         p_printf("Reading file %s", fname) ;
  3329. E 14
  3330. E 7
  3331.     /* call up the editor */
  3332.     doword(fname) ;
  3333.     /* OK we've read the mail, mark it as read */
  3334.     llentry->read = RD ;
  3335. }
  3336. /* write a mail reply, the corresponding linked list
  3337.    entry exists as does the file, so ensure that
  3338.    it is listed as active after the edit */
  3339. VOID wrtemail(INT mailno, struct ll * llstart)
  3340. {
  3341.     struct ll * llentry ;
  3342.     TEXT fname [P_FNAMESIZE] ;
  3343. I 3
  3344. D 14
  3345.     if (cmddbg == TRUE)
  3346.         p_printf("CALL wrtemail (mailno = %d, llstart = OMITTED)", mailno) ;
  3347. E 14
  3348. E 3
  3349.     if((llentry = llnofind(mailno, llstart)) == NULL)
  3350.         return ;
  3351. I 7
  3352. D 14
  3353.     if (cmddbg == TRUE)
  3354.     {
  3355.         p_printf("ll structure for mail no %d is", mailno) ;
  3356.         lldump(llentry) ;
  3357.     }
  3358. E 14
  3359. E 7
  3360.     /* build up the name */
  3361. D 7
  3362.     p_scpym(fname, llstart->mydata->mypath, llentry->datafile) ;
  3363. E 7
  3364. I 7
  3365.     p_scpym(fname, llstart->mydata->mypath, llentry->datafile, NULL) ;
  3366. D 14
  3367.     if (cmddbg == TRUE)
  3368.     {
  3369.         p_printf("working on name %s", fname) ;
  3370.         p_getch() ;
  3371.     }
  3372. E 14
  3373. E 7
  3374.     /* call up the editor */
  3375.     doword(fname) ;
  3376. I 7
  3377. D 14
  3378.     if (cmddbg == TRUE)
  3379.         p_printf("wrtemail, returned from doword") ;
  3380. E 14
  3381. E 7
  3382.     /* OK we've got a file ensure it's active */
  3383.     llentry->status = ACTIVE ;
  3384. }
  3385. /* delete a mail from the linked lists */
  3386. VOID delmail (INT mailno, struct ll * llstart)
  3387. {
  3388.     struct ll * llentry ;
  3389. I 3
  3390. D 14
  3391.     if (cmddbg == TRUE)
  3392.         p_printf("CALL delmail (mailno = %d, llstart = OMITTED)", mailno) ;
  3393. E 14
  3394. E 3
  3395.     if ((llentry = llnofind(mailno, llstart)) == NULL)
  3396.         return ;
  3397.     llentry->status = DELETED ;
  3398. }
  3399. /* undelete the mail from the internal linked lists */
  3400. VOID udelmail (INT mailno, struct ll * llptr)
  3401. {
  3402.     struct ll * llentry ;
  3403. I 3
  3404. D 14
  3405.     if (cmddbg == TRUE)
  3406.         p_printf("CALL udelmail (mailno = %d, llptr = OMITTED)", mailno) ;
  3407. E 14
  3408. E 3
  3409.     if ((llentry = llnofind(mailno, llptr)) == NULL)
  3410.         return ;
  3411.     llentry->status = ACTIVE ;
  3412. }
  3413. /* end of functions for working the mailbox in view */
  3414.  
  3415. /* start of ancilary data file functions */
  3416. /* delfile - physicaly delete the data file */
  3417. INT delfile(struct ll * llcur, struct ll * llstart)
  3418. {
  3419.     TEXT dfname[P_FNAMESIZE] ;
  3420. I 3
  3421. D 14
  3422.     if (filedbg == TRUE)
  3423.         p_printf("CALL: delfile (llcur = OMITTED, llstart = OMITTED)");
  3424. E 14
  3425. E 3
  3426.     /* build up the filesname */
  3427.     p_scpym(dfname, llstart->mydata->mypath, llcur->datafile, NULL) ;
  3428.     if (p_delete(dfname) == 0)
  3429.         return(TRUE) ;
  3430.     else
  3431. D 6
  3432.         return(FALSE) ;
  3433. E 6
  3434. I 6
  3435.     {
  3436. D 16
  3437.         p_printf("FILE ERROR: delfile, error in deleting file %s", dfname) ;
  3438. E 16
  3439. I 16
  3440.         uDisplayText("FILE ERROR: delfile,","error in deleting file", dfname, NULL) ;
  3441. E 16
  3442.         return(FILEERR) ;
  3443.     }
  3444. E 6
  3445. }
  3446.  
  3447. /* cpyfile - copy from the file in origll to the file in newll 
  3448.    assume the file exists */
  3449. INT cpyfile (struct ll * newll, struct ll * outhead, struct ll * origll, struct ll * inhead)
  3450. {
  3451.     VOID * infd, * outfd ;
  3452.     INT ret ;
  3453.     TEXT infname[P_FNAMESIZE] , outfname[P_FNAMESIZE] ;
  3454. D 9
  3455.     TEXT buff [P_FBLKSIZE] ;
  3456. E 9
  3457. I 9
  3458. D 10
  3459.     TEXT buff [MAXLINE] ;
  3460. E 10
  3461. I 10
  3462.     TEXT buff [P_FMAXRSIZE], tmp[P_FMAXRSIZE+3] ;
  3463. E 10
  3464. E 9
  3465. I 3
  3466. D 14
  3467.     if (filedbg == TRUE)
  3468.         p_printf("CALL: cpyfile (newll = OMITTED, outhead = OMITTED origll = OMITTED, inhead = OMITTED)");
  3469. E 14
  3470. E 3
  3471.     /* munge the filenames */
  3472.     p_scpym(infname, inhead->mydata->mypath, origll->datafile, NULL) ;
  3473.     p_scpym(outfname, outhead->mydata->mypath, newll->datafile, NULL) ;
  3474. I 6
  3475. D 14
  3476.     if (filedbg == TRUE)
  3477.     {
  3478.         p_printf("infname is %s", infname) ;
  3479.         p_printf("outfname is %s", outfname) ;
  3480.         p_getch() ;
  3481.     }
  3482. E 14
  3483. E 6
  3484.     /* open the files */
  3485. D 7
  3486.     ret = p_open(&infd, infname, P_FOPEN | P_FSTREAM | P_FSHARE) ;
  3487. E 7
  3488. I 7
  3489. D 10
  3490.     ret = p_open(&infd, infname, P_FOPEN | P_FSTREAM_TEXT | P_FSHARE) ;
  3491. E 10
  3492. I 10
  3493.     ret = p_open(&infd, infname, P_FTEXT | P_FSHARE) ;
  3494. E 10
  3495. E 7
  3496. D 6
  3497.     ret = p_open(&outfd, outfname, P_FOPEN | P_FSTREAM | P_FUPDATE) ;
  3498. E 6
  3499. I 6
  3500.     if (ret != 0)
  3501.     {
  3502. D 7
  3503.         p_printf("FILE ERROR: cpyfile, error in opening %s as input", infname) ;
  3504. E 7
  3505. I 7
  3506. D 16
  3507.         p_printf("FILE ERROR: cpyfile, error in opening %s as input", infname) ;    
  3508. E 16
  3509.         p_errs(buff, ret) ;
  3510. D 16
  3511.         p_printf("%s", buff) ;
  3512. E 16
  3513. I 16
  3514.         uDisplayText("FILE ERROR: cpyfile,","error in opening input", infname, buff, NULL) ;    
  3515. E 16
  3516. E 7
  3517.         return(FILEERR) ;
  3518.     }
  3519. D 7
  3520.     ret = p_open(&outfd, outfname, P_FOPEN | P_FSTREAM | P_FREPLACE) ;
  3521. E 7
  3522. I 7
  3523. D 10
  3524.     ret = p_open(&outfd, outfname, P_FOPEN | P_FSTREAM_TEXT | P_FREPLACE) ;
  3525. E 10
  3526. I 10
  3527.     ret = p_open(&outfd, outfname, P_FTEXT | P_FUPDATE | P_FREPLACE) ;
  3528. E 10
  3529. E 7
  3530.     if (ret != 0)
  3531.     {
  3532. D 16
  3533.         p_printf("FILE ERROR: cpyfile, error in opening %s as output", outfname) ;
  3534. E 16
  3535. I 7
  3536.         p_errs(buff, ret) ;
  3537. D 16
  3538.         p_printf("%s", buff) ;
  3539. E 16
  3540. I 16
  3541.         uDisplayText("FILE ERROR: cpyfile,","error in opening output", outfname, buff, NULL) ;
  3542. E 16
  3543. E 7
  3544.         p_close(infd) ;
  3545.         return(FILEERR) ;
  3546.     }
  3547. I 9
  3548. D 10
  3549.     /* Insert the start infoamation */
  3550.     ret = p_write(outfd, STARTINCL, p_slen(STARTINCL)) ;
  3551.     if (ret < 0)
  3552.     {
  3553.         p_printf("FILE ERROR: cpyfile, error in writting include start(%d)", ret) ;
  3554.         P_errs(buff, ret) ;
  3555.         p_printf("%s", buff) ;
  3556.         p_close(infd) ;
  3557.         p_close(outfd) ;
  3558.         return(FILEERR) ;
  3559.     }
  3560. E 10
  3561. E 9
  3562. E 6
  3563.     /* copy the files */
  3564.     ret = 1 ;
  3565.     while(ret >= 0)
  3566.     {
  3567. D 9
  3568.         ret = p_read(infd, buff, P_FBLKSIZE) ;
  3569. E 9
  3570. I 9
  3571. D 10
  3572.         ret = p_read(infd, buff, MAXLINE) ;
  3573. E 9
  3574.         if (ret <= 0)
  3575. E 10
  3576. I 10
  3577.         ret = p_read(infd, buff, P_FMAXRSIZE) ;
  3578.         if (ret < 0)
  3579. E 10
  3580. I 9
  3581.         {
  3582. D 14
  3583.             if (filedbg == TRUE)
  3584.             {
  3585.                 p_printf("finished copy, ret is %d", ret) ;
  3586.                 p_errs(buff, ret) ;
  3587.                 p_printf("%s", buff) ;
  3588.                 p_getch() ;
  3589.             }
  3590. E 14
  3591. E 9
  3592.             break ;
  3593. I 9
  3594.         }
  3595.         /* terminate the string */
  3596.         buff[ret] = '\0' ;
  3597. I 10
  3598.         p_scpym(tmp, "> ", buff, NULL) ;
  3599. E 10
  3600. D 14
  3601.         if (filedbg == TRUE)
  3602.         {
  3603. D 10
  3604.             p_printf(":%s:", buff) ;
  3605. E 10
  3606. I 10
  3607.             p_printf(":%s:", tmp) ;
  3608. E 10
  3609.             p_getch() ;
  3610.         }
  3611. E 14
  3612. E 9
  3613. D 10
  3614.         p_write(outfd, buff, ret) ;
  3615.     }
  3616. I 9
  3617.     /* write the end information */
  3618.     ret = p_write(outfd, ENDINCL, p_slen(ENDINCL)) ;
  3619.     if (ret < 0)
  3620.     {
  3621.         p_printf("FILE ERROR: cpyfile, error in writting include end") ;
  3622.         p_errs(buff, ret) ;
  3623.         p_printf("%s", buff) ;
  3624.         p_close(infd) ;
  3625.         p_close(outfd) ;
  3626.         return(FILEERR) ;
  3627. E 10
  3628. I 10
  3629.         p_write(outfd, tmp, p_slen(tmp)) ;
  3630. E 10
  3631.     }
  3632. E 9
  3633.     /* close the files */
  3634.     p_close(infd) ;
  3635.     p_close(outfd) ;
  3636.     return(TRUE) ;
  3637. }
  3638.     
  3639.     
  3640. /* newfile, determine a safe new filename and create it */
  3641. INT newfile(struct ll * llcur, struct ll * llstart)
  3642. {
  3643. D 6
  3644.     TEXT myname[P_FNAMESIZE+1],  *myptr;
  3645. E 6
  3646. I 6
  3647.     TEXT mytempl[P_FNAMESIZE+1],  tmppath[P_FNAMESIZE+1];
  3648. E 6
  3649.     VOID * fd ;
  3650. D 3
  3651.     INT fstart, flen ;
  3652. E 3
  3653. I 3
  3654. D 6
  3655.     INT fstart, flen, ret ;
  3656. E 3
  3657.     P_FPARSE crk ;
  3658. E 6
  3659. I 6
  3660.     INT ret, i ;
  3661. E 6
  3662. I 3
  3663. D 14
  3664.     if (filedbg == TRUE)
  3665.         p_printf("CALL: newfile(llcur = OMITTED, llstart = OMITTED)") ;
  3666. E 14
  3667. E 3
  3668. D 6
  3669.     /* build up the name */
  3670.     p_scpym(myname, llstart->mydata->mypath, OUTSKELETON, NULL) ;
  3671. D 3
  3672.     if (p_open(&fd, myname, P_FCREATE | P_FUNIQUE) >= 0)
  3673. E 3
  3674. I 3
  3675.     if ((ret = p_open(&fd, myname, P_FCREATE | P_FUNIQUE)) >= 0)
  3676. E 6
  3677. I 6
  3678.     /* build up the name OUTSKELETON is assumed to contain a %d */
  3679.     p_scpym(mytempl, llstart->mydata->mypath, OUTSKELETON, NULL) ;
  3680.     for (i = 0 ; i < MAXEMAILOUT ; i ++ )
  3681.     {    
  3682.         /* basicaly run around untill we have a number for i
  3683.            that does not corespond to a file name */
  3684.         p_atos(tmppath, mytempl, i) ;
  3685. D 14
  3686.         if (filedbg == TRUE)
  3687.         {
  3688.             p_printf("newfile is working on %s", tmppath) ;
  3689.             p_getch() ;
  3690.         }
  3691.             
  3692. E 14
  3693.         ret = fileexist(tmppath) ;
  3694.         if (ret == TRUE)
  3695.         {
  3696.             /* the file exists, continue */
  3697. D 14
  3698.             if (filedbg == TRUE)
  3699.             {
  3700.                 p_printf("FILE: %s exists", tmppath) ;
  3701.             }
  3702. E 14
  3703.             continue ;
  3704.         }
  3705.         else if (ret == FALSE)
  3706.         {
  3707.             /* the file does not exist */
  3708. D 14
  3709.             if (filedbg == TRUE)
  3710.             {
  3711.                 p_printf("FILE: %s does not exist", tmppath) ;
  3712.             }
  3713. E 14
  3714.             break ;
  3715.         }
  3716.         else
  3717.         {
  3718. D 16
  3719.             p_printf("FILE ERROR: newemail, Directory, Device or other error recieved from fileexists when testing %s", tmppath) ;
  3720. E 16
  3721. I 16
  3722.             uDisplayText("FILE ERROR: newemail,","Directory, Device or other error","recieved from fileexists when testing", tmppath, NULL) ;
  3723. E 16
  3724.             return(FILEERR) ;
  3725.         }
  3726.     }
  3727.     if (i >= MAXEMAILOUT)
  3728. E 6
  3729. E 3
  3730.     {
  3731. I 6
  3732. D 16
  3733.         p_printf("FILE ERROR: newfile, maximum of %d outgoing emails exceeded (%s)", MAXEMAILOUT, tmppath) ;
  3734. E 16
  3735. I 16
  3736.         uDisplayText("FILE ERROR: newfile,","maximum number outgoing emails exceeded", tmppath, NULL) ;
  3737. E 16
  3738.         return(FILEERR) ;
  3739.     }
  3740. D 7
  3741.     if ((ret = p_open(&fd, tmppath, P_FCREATE | P_FSTREAM)) >= 0)
  3742. E 7
  3743. I 7
  3744. D 9
  3745.     if ((ret = p_open(&fd, tmppath, P_FCREATE | P_FSTREAM_TEXT)) >= 0)
  3746. E 9
  3747. I 9
  3748.     if ((ret = p_open(&fd, tmppath, P_FCREATE | P_FTEXT)) >= 0)
  3749. E 9
  3750. E 7
  3751.     {
  3752. E 6
  3753.         p_close(fd) ;
  3754. D 6
  3755.         /* figure out the name that we have created */
  3756.         p_fparse(myname, NULL, myname, &crk) ;
  3757.         /* the filename starts at the total of system+device+path and 
  3758.            is name+ext long */
  3759.         fstart = (INT) (crk.system + crk.device + crk.path) ;
  3760.         flen = (INT) (crk.name + crk.ext) ;
  3761.         /* munge myname as required */
  3762.         myptr = &myname[fstart] ;
  3763.         myptr[flen] = '\0' ;
  3764.         p_scpy(llcur->datafile, myptr) ;
  3765. E 6
  3766. I 6
  3767.         p_atos(llcur->datafile, OUTSKELETON, i) ;
  3768. E 6
  3769.         return(TRUE) ;
  3770.     }
  3771.     else
  3772. I 3
  3773.     {
  3774. D 6
  3775.         p_printf("FILE ERROR: newfile, error in creating new file %s", myname) ;
  3776. E 6
  3777. I 6
  3778. D 16
  3779.         p_printf("FILE ERROR: newfile, error in creating new file %s", mytempl) ;
  3780. E 16
  3781. I 16
  3782.         uDisplayText("FILE ERROR: newfile,","error in creating new file", mytempl, NULL) ;
  3783. E 16
  3784. E 6
  3785. E 3
  3786. D 5
  3787.         return(FALSE) ;
  3788. E 5
  3789. I 5
  3790.         return(FILEERR) ;
  3791. E 5
  3792. I 3
  3793.     }
  3794. E 3
  3795. }
  3796. /* end of ancilary data file functions */
  3797.  
  3798. /* start of meta file operations code */
  3799. /* the meta file consists of line terminated data in the following format */
  3800. /* the full path component, E.g. LOC::M\MAIL\ */
  3801. /* mu current email adress, e.g. tim.graves@uk.sun.com the following repeated */
  3802. /* datafile name, E.g. in1.msg or out1.msg */
  3803. /* to, a list of recieved addresses, e.g. tim.graves@uk.sun.com MUST contain at least one address */
  3804. /* from, the origionator of the email */
  3805. /* subject, obvious */
  3806. /* cc, the cc list */
  3807. /* bcc, the bcc list (empty on reciept */
  3808. /* read, N if the email is unread, R if read */
  3809. /*at the end of the repeats */
  3810. /* END */
  3811. /* No other items */
  3812. /* */
  3813. /* read in the data descriptions */
  3814. INT readmeta(TEXT * fname, struct ll * itemlist)
  3815. {
  3816.     VOID * fd ;
  3817.     INT ret ;
  3818. I 3
  3819. D 14
  3820.     if (mtadbg == TRUE)
  3821.         p_printf("CALL: readmeta (fname = %s, itemlist = OMITTED)", fname) ;
  3822. E 14
  3823. E 3
  3824.     ret = p_open(&fd, fname, P_FTEXT | P_FSHARE) ;
  3825.     if (ret < 0)
  3826. D 3
  3827.         return (FALSE) ;
  3828. E 3
  3829. I 3
  3830.     {
  3831. D 16
  3832.         p_printf("FILE ERROR:  readmeta, error in opening %s", fname) ;
  3833. E 16
  3834. I 16
  3835.         uDisplayText("FILE ERROR:  readmeta,","error in opening", fname, NULL) ;
  3836. E 16
  3837. D 5
  3838.         return (ERR) ;
  3839. E 5
  3840. I 5
  3841.         return (FILEERR) ;
  3842. E 5
  3843.     }
  3844. E 3
  3845.     /* load the one off data */
  3846. I 3
  3847.     ret = getf(fd, itemlist->mydata->mypath) ;
  3848.     if ( ret == FALSE)
  3849.     {
  3850. D 16
  3851.         p_printf("FILE ERROR: readmeta, error in reading my path from %s", fname) ;
  3852. E 16
  3853. I 16
  3854.         uDisplayText("FILE ERROR: readmeta,","error in reading my path from", fname, NULL) ;
  3855. E 16
  3856. D 5
  3857.         return(ERR) ;
  3858. E 5
  3859. I 5
  3860.         return(FILEERR) ;
  3861. E 5
  3862.     }
  3863. E 3
  3864.     getf(fd, itemlist->mydata->myaddr) ;
  3865. D 3
  3866.     getf(fd, itemlist->mydata->mypath) ;
  3867.     while(readhdr(fd, itemlist)== TRUE)
  3868. E 3
  3869. I 3
  3870.     if (ret == FALSE)
  3871.     {
  3872. D 16
  3873.         p_printf("FILE ERROR: readmeta, error in reading my address from %s", fname) ;
  3874. E 16
  3875. I 16
  3876.         uDisplayText("FILE ERROR: readmeta,","error in reading my address from", fname, NULL) ;
  3877. E 16
  3878. D 5
  3879.         return(ERR) ;
  3880. E 5
  3881. I 5
  3882.         return(FILEERR) ;
  3883. E 5
  3884.     }
  3885.     while((ret = readhdr(fd, itemlist))== TRUE)
  3886. E 3
  3887.         ;
  3888.     p_close(fd) ;
  3889. I 3
  3890. D 5
  3891.     if (ret == ERR)
  3892. E 5
  3893. I 5
  3894.     if (ret == FILEERR)
  3895. E 5
  3896.     {
  3897. D 4
  3898.         p_printf("FILE ERROR: readmeta, error in reading meat record from %s", fname) ;
  3899. E 4
  3900. I 4
  3901. D 16
  3902.         p_printf("FILE ERROR: readmeta, error in reading meta record from %s", fname) ;
  3903. E 16
  3904. I 16
  3905.         uDisplayText("FILE ERROR: readmeta,","error in reading meta record from", fname, NULL) ;
  3906. E 16
  3907. E 4
  3908. D 5
  3909.         return(ERR) ;
  3910. E 5
  3911. I 5
  3912.         return(FILEERR) ;
  3913. E 5
  3914.     }
  3915. E 3
  3916.     return(TRUE) ;
  3917. }
  3918.  
  3919. /* write the data descriptions out */
  3920. INT wrtmeta(TEXT * fname, struct ll * itemlist) 
  3921. {
  3922.     VOID * fd ;
  3923.     INT ret ;
  3924. I 6
  3925.         
  3926. E 6
  3927. D 3
  3928.     p_delete(fname) ; /* delete the origional file */
  3929. E 3
  3930. I 3
  3931. D 14
  3932.     if (mtadbg == TRUE)
  3933.         p_printf("CALL: wrtmeta (fname = %s, itemlist = OMITTED)", fname) ;
  3934. E 14
  3935.     ret = p_delete(fname) ; /* delete the origional file */
  3936.     if (ret < 0)
  3937.     {
  3938. D 16
  3939.         p_printf("FILE ERROR: wrtmeta, error in deleting %s prior to output", fname) ;
  3940. E 16
  3941. I 16
  3942.         uDisplayText("FILE ERROR: wrtmeta,","error in deleting",fname,"prior to output", NULL) ;
  3943. E 16
  3944. D 5
  3945.         return(ERR) ;
  3946. E 5
  3947. I 5
  3948.         return(FILEERR) ;
  3949. E 5
  3950.     }
  3951. E 3
  3952.     ret = p_open(&fd, fname, P_FTEXT | P_FUPDATE | P_FREPLACE) ;
  3953.     if (ret < 0)
  3954. D 3
  3955.         return(FALSE) ;
  3956. E 3
  3957. I 3
  3958.     {
  3959. D 16
  3960.         p_printf("FILE ERROR: wrtmeta, error in opening %s for output", fname) ;
  3961. E 16
  3962. I 16
  3963.         uDisplayText("FILE ERROR: wrtmeta,","error in opening", fname, "for output", NULL) ;
  3964. E 16
  3965.         p_close(fd) ;
  3966. D 5
  3967.         return(ERR) ;
  3968. E 5
  3969. I 5
  3970.         return(FILEERR) ;
  3971. E 5
  3972.     }
  3973. E 3
  3974.     /* write the one off data */
  3975. D 3
  3976.     putf(fd, itemlist->mydata->myaddr) ;
  3977.     putf(fd, itemlist->mydata->mypath) ;
  3978. E 3
  3979. I 3
  3980.     ret = putf(fd, itemlist->mydata->mypath) ;
  3981. D 5
  3982.     if (ret == ERR)
  3983. E 5
  3984. I 5
  3985.     if (ret == FILEERR)
  3986. E 5
  3987.     {
  3988. D 16
  3989.         p_printf("FILE ERROR: wrtmeta, error in writting my path to %s", fname) ;
  3990. E 16
  3991. I 16
  3992.         uDisplayText("FILE ERROR: wrtmeta,","error in writting my path to", fname, NULL) ;
  3993. E 16
  3994.         p_close(fd) ;
  3995. D 5
  3996.         return(ERR) ;
  3997. E 5
  3998. I 5
  3999.         return(FILEERR) ;
  4000. E 5
  4001.     }
  4002.     ret = putf(fd, itemlist->mydata->myaddr) ;
  4003. D 5
  4004.     if (ret == ERR)
  4005. E 5
  4006. I 5
  4007.     if (ret == FILEERR)
  4008. E 5
  4009.     {
  4010. D 16
  4011.         p_printf("FILE ERROR: wrtmeta, error in writting my address to %s", fname) ;
  4012. E 16
  4013. I 16
  4014.         uDisplayText("FILE ERROR: wrtmeta,","error in writting my address to", fname, NULL) ;
  4015. E 16
  4016.         p_close(fd) ;
  4017. D 5
  4018.         return(ERR) ;
  4019. E 5
  4020. I 5
  4021.         return(FILEERR) ;
  4022. E 5
  4023.     }
  4024. E 3
  4025.     while(itemlist != NULL)
  4026. D 3
  4027.         wrthdr(fd, itemlist) ;
  4028.     putf(fd, "END") ;
  4029. E 3
  4030. I 3
  4031.     {
  4032.         ret = wrthdr(fd, itemlist) ;
  4033. D 5
  4034.         if (ret == ERR)
  4035. E 5
  4036. I 5
  4037.         if (ret == FILEERR)
  4038. E 5
  4039.             break ;
  4040.         itemlist = itemlist->next ;
  4041.     }
  4042. D 5
  4043.     if (ret == ERR)
  4044. E 5
  4045. I 5
  4046.     if (ret == FILEERR)
  4047. E 5
  4048.     {
  4049. D 16
  4050.         p_printf("FILE ERROR: wrtmeta, error in writting record to %s", fname) ;
  4051. E 16
  4052. I 16
  4053.         uDisplayText("FILE ERROR: wrtmeta,","error in writting record to", fname, NULL) ;
  4054. E 16
  4055.         p_close(fd) ;
  4056. D 5
  4057.         return(ERR) ;
  4058. E 5
  4059. I 5
  4060.         return(FILEERR) ;
  4061. E 5
  4062.     }
  4063.     ret = putf(fd, "END") ;
  4064. D 5
  4065.     if (ret == ERR)
  4066. E 5
  4067. I 5
  4068.     if (ret == FILEERR)
  4069. E 5
  4070.     {
  4071. D 16
  4072.         p_printf("FILE ERROR: wrtmeta, error in writting terminator (END) to %s", fname) ;
  4073. E 16
  4074. I 16
  4075.         uDisplayText("FILE ERROR: wrtmeta,","error in writting terminator (END) to", fname, NULL) ;
  4076. E 16
  4077.         p_close(fd) ;
  4078. D 5
  4079.         return(ERR) ;
  4080. E 5
  4081. I 5
  4082.         return(FILEERR) ;
  4083. E 5
  4084.     }
  4085. E 3
  4086.     p_close(fd) ;
  4087.     return(TRUE) ;
  4088. }
  4089.  
  4090. /* read the from, subject and return path etc from the data file */
  4091. INT readhdr(VOID * fd, struct ll * itemlist)
  4092. {
  4093.     struct ll * newll ;
  4094.     TEXT datafile[20] ;
  4095. D 9
  4096.     TEXT to[100] ;
  4097.     TEXT from[100] ;
  4098.     TEXT subject[100];
  4099.     TEXT cc[100];
  4100.     TEXT bcc[100];
  4101.     TEXT cread[100] ;
  4102. E 9
  4103. I 9
  4104.     TEXT to[HDRLEN] ;
  4105.     TEXT from[HDRLEN] ;
  4106.     TEXT subject[HDRLEN];
  4107.     TEXT cc[HDRLEN];
  4108.     TEXT bcc[HDRLEN];
  4109.     TEXT cread[HDRLEN] ;
  4110. E 9
  4111. D 3
  4112.     INT read ;
  4113.     
  4114. E 3
  4115. I 3
  4116.     INT read, ret ;
  4117. D 14
  4118.     if (mtadbg == TRUE)
  4119.         p_printf("CALL: readhdr(fd = OMITTED, itemlist = OMITTED)");
  4120. E 14
  4121. E 3
  4122.     /* read in an entry */
  4123. D 3
  4124.     getf(fd, datafile) ;
  4125. E 3
  4126. I 3
  4127.     ret = getf(fd, datafile) ;
  4128. D 5
  4129.     if (ret == ERR)
  4130. E 5
  4131. I 5
  4132.     if (ret == FILEERR)
  4133. E 5
  4134.     {
  4135. D 16
  4136.         p_printf("FILE ERROR: readhdr, error in reading datafile") ;
  4137. E 16
  4138. I 16
  4139.         uDisplayText("FILE ERROR: readhdr,","error in reading datafile", NULL) ;
  4140. E 16
  4141. D 5
  4142.         return(ERR) ;
  4143. E 5
  4144. I 5
  4145.         return(FILEERR) ;
  4146. E 5
  4147.     }
  4148. E 3
  4149.     if (p_scmp(datafile, "END") == 0)
  4150.         return(FALSE) ;
  4151. D 3
  4152.     getf(fd, to) ;
  4153.     getf(fd, from) ;
  4154.     getf(fd, subject) ;
  4155.     getf(fd, cc) ;
  4156.     getf(fd, bcc) ;
  4157.     getf(fd, cread) ;
  4158.     
  4159. E 3
  4160. I 3
  4161.     ret = getf(fd, to) ;
  4162. D 5
  4163.     if (ret == ERR)
  4164. E 5
  4165. I 5
  4166.     if (ret == FILEERR)
  4167. E 5
  4168.     {
  4169. D 16
  4170.         p_printf("FILE ERROR: readhdr, error in reading to") ;
  4171. E 16
  4172. I 16
  4173.         uDisplayText("FILE ERROR: readhdr,","error in reading to", NULL) ;
  4174. E 16
  4175. D 5
  4176.         return(ERR) ;
  4177. E 5
  4178. I 5
  4179.         return(FILEERR) ;
  4180. E 5
  4181.     }
  4182.     ret = getf(fd, from) ;
  4183. D 5
  4184.     if (ret == ERR)
  4185. E 5
  4186. I 5
  4187.     if (ret == FILEERR)
  4188. E 5
  4189.     {
  4190. D 16
  4191.         p_printf("FILE ERROR: readhdr, error in reading from") ;
  4192. E 16
  4193. I 16
  4194.         uDisplayText("FILE ERROR: readhdr,","error in reading from", NULL) ;
  4195. E 16
  4196. D 5
  4197.         return(ERR) ;
  4198. E 5
  4199. I 5
  4200.         return(FILEERR) ;
  4201. E 5
  4202.     }
  4203.     ret = getf(fd, subject) ;
  4204. D 5
  4205.     if (ret == ERR)
  4206. E 5
  4207. I 5
  4208.     if (ret == FILEERR)
  4209. E 5
  4210.     {
  4211. D 16
  4212.         p_printf("FILE ERROR: readhdr, error in reading subject") ;
  4213. E 16
  4214. I 16
  4215.         uDisplayText("FILE ERROR: readhdr,","error in reading subject", NULL) ;
  4216. E 16
  4217. D 5
  4218.         return(ERR) ;
  4219. E 5
  4220. I 5
  4221.         return(FILEERR) ;
  4222. E 5
  4223.     }
  4224.     ret = getf(fd, cc) ;
  4225. D 5
  4226.     if (ret == ERR)
  4227. E 5
  4228. I 5
  4229.     if (ret == FILEERR)
  4230. E 5
  4231.     {
  4232. D 16
  4233.         p_printf("FILE ERROR: readhdr, error in reading cc") ;
  4234. E 16
  4235. I 16
  4236.         uDisplayText("FILE ERROR: readhdr,","error in reading cc", NULL) ;
  4237. E 16
  4238. D 5
  4239.         return(ERR) ;
  4240. E 5
  4241. I 5
  4242.         return(FILEERR) ;
  4243. E 5
  4244.     }
  4245.     ret = getf(fd, bcc) ;
  4246. D 5
  4247.     if (ret == ERR)
  4248. E 5
  4249. I 5
  4250.     if (ret == FILEERR)
  4251. E 5
  4252.     {
  4253. D 16
  4254.         p_printf("FILE ERROR: readhdr, error in reading bcc") ;
  4255. E 16
  4256. I 16
  4257.         uDisplayText("FILE ERROR: readhdr,","error in reading bcc", NULL) ;
  4258. E 16
  4259. D 5
  4260.         return(ERR) ;
  4261. E 5
  4262. I 5
  4263.         return(FILEERR) ;
  4264. E 5
  4265.     }
  4266.     ret = getf(fd, cread) ;
  4267. D 5
  4268.     if (ret == ERR)
  4269. E 5
  4270. I 5
  4271.     if (ret == FILEERR)
  4272. E 5
  4273.     {
  4274. D 16
  4275.         p_printf("FILE ERROR: readhdr, error in reading read") ;
  4276. E 16
  4277. I 16
  4278.         uDisplayText("FILE ERROR: readhdr,","error in reading read", NULL) ;
  4279. E 16
  4280. D 5
  4281.         return(ERR) ;
  4282. E 5
  4283. I 5
  4284.         return(FILEERR) ;
  4285. E 5
  4286.     }    
  4287. E 3
  4288.     if (cread[0] == 'R')
  4289.         read = RD ;
  4290.     else
  4291.         read = NEW ;
  4292.     
  4293.     /* get a new ll structure */
  4294.     newll = llnew ();
  4295.     /* fill in the structure */
  4296. D 4
  4297.     llfill(newll, datafile, to, from, subject, cc, bcc, ACTIVE, read, itemlist->no + 1) ;
  4298.     /* apply the sequence number */
  4299.     newll->no = itemlist->count + 1 ;
  4300. E 4
  4301. I 4
  4302.     llfill(newll, datafile, to, from, subject, cc, bcc, ACTIVE, read, itemlist->count + 1) ;
  4303. E 4
  4304.     /* add the new item into the list */
  4305.     lladd(newll, itemlist) ;
  4306.     return(TRUE) ;
  4307. }
  4308. /* write a subject and destination etc to the data file */
  4309. INT wrthdr(VOID * fd, struct ll * item)
  4310. {
  4311.     INT ret ;
  4312. D 3
  4313.     ret = TRUE ;
  4314. E 3
  4315. I 3
  4316. D 14
  4317.     if (mtadbg == TRUE)
  4318.         p_printf("CALL: wrthdr(fd = OMITTED, item = OMITTED)");
  4319. E 14
  4320. E 3
  4321.     /* only outut the record if its active */
  4322.     if (item->status != ACTIVE)
  4323.         return(TRUE) ;
  4324. D 3
  4325.     putf(fd, item->datafile);
  4326.     putf(fd, item->to) ;
  4327.     putf(fd, item->from) ;
  4328.     putf(fd, item->subject) ;
  4329.     putf(fd, item->cc) ;
  4330.     putf(fd, item->bcc) ;
  4331. E 3
  4332. I 3
  4333.     ret = putf(fd, item->datafile);
  4334. D 5
  4335.     if ( ret == ERR)
  4336. E 5
  4337. I 5
  4338.     if ( ret == FILEERR)
  4339. E 5
  4340.     {
  4341. D 16
  4342.         p_printf("FILE ERROR: wrthdr, error in writting datafile (%s)", item->datafile) ;
  4343. E 16
  4344. I 16
  4345.         uDisplayText("FILE ERROR: wrthdr,","error in writting datafile", item->datafile, NULL) ;
  4346. E 16
  4347. D 5
  4348.         return(ERR) ;
  4349. E 5
  4350. I 5
  4351.         return(FILEERR) ;
  4352. E 5
  4353.     }
  4354.     ret = putf(fd, item->to) ;
  4355. D 5
  4356.     if ( ret == ERR)
  4357. E 5
  4358. I 5
  4359.     if ( ret == FILEERR)
  4360. E 5
  4361.     {
  4362. D 16
  4363.         p_printf("FILE ERROR: wrthdr, error in writting to (%s)", item->to) ;
  4364. E 16
  4365. I 16
  4366.         uDisplayText("FILE ERROR: wrthdr,","error in writting to", item->to, NULL) ;
  4367. E 16
  4368. D 5
  4369.         return(ERR) ;
  4370. E 5
  4371. I 5
  4372.         return(FILEERR) ;
  4373. E 5
  4374.     }
  4375.     ret = putf(fd, item->from) ;
  4376. D 5
  4377.     if ( ret == ERR)
  4378. E 5
  4379. I 5
  4380.     if ( ret == FILEERR)
  4381. E 5
  4382.     {
  4383. D 16
  4384.         p_printf("FILE ERROR: wrthdr, error in writting from (%s)", item->from) ;
  4385. E 16
  4386. I 16
  4387.         uDisplayText("FILE ERROR: wrthdr,","error in writting from", item->from, NULL) ;
  4388. E 16
  4389. D 5
  4390.         return(ERR) ;
  4391. E 5
  4392. I 5
  4393.         return(FILEERR) ;
  4394. E 5
  4395.     }
  4396.     ret = putf(fd, item->subject) ;
  4397. D 5
  4398.     if ( ret == ERR)
  4399. E 5
  4400. I 5
  4401.     if ( ret == FILEERR)
  4402. E 5
  4403.     {
  4404. D 16
  4405.         p_printf("FILE ERROR: wrthdr, error in writting subject (%s)", item->subject) ;
  4406. E 16
  4407. I 16
  4408.         uDisplayText("FILE ERROR: wrthdr,","error in writting subject", item->subject, NULL) ;
  4409. E 16
  4410. D 5
  4411.         return(ERR) ;
  4412. E 5
  4413. I 5
  4414.         return(FILEERR) ;
  4415. E 5
  4416.     }
  4417.     ret = putf(fd, item->cc) ;
  4418. D 5
  4419.     if ( ret == ERR)
  4420. E 5
  4421. I 5
  4422.     if ( ret == FILEERR)
  4423. E 5
  4424.     {
  4425. D 16
  4426.         p_printf("FILE ERROR: wrthdr, error in writting cc (%s)", item->cc) ;
  4427. E 16
  4428. I 16
  4429.         uDisplayText("FILE ERROR: wrthdr,","error in writting cc", item->cc, NULL) ;
  4430. E 16
  4431. D 5
  4432.         return(ERR) ;
  4433. E 5
  4434. I 5
  4435.         return(FILEERR) ;
  4436. E 5
  4437.     }
  4438.     ret = putf(fd, item->bcc) ;
  4439. D 5
  4440.     if ( ret == ERR)
  4441. E 5
  4442. I 5
  4443.     if ( ret == FILEERR)
  4444. E 5
  4445.     {
  4446. D 16
  4447.         p_printf("FILE ERROR: wrthdr, error in writting bcc (%s)", item->bcc) ;
  4448. E 16
  4449. I 16
  4450.         uDisplayText("FILE ERROR: wrthdr,","error in writting bcc", item->bcc, NULL) ;
  4451. E 16
  4452. D 5
  4453.         return(ERR) ;
  4454. E 5
  4455. I 5
  4456.         return(FILEERR) ;
  4457. E 5
  4458.     }
  4459. E 3
  4460.     if (item->read == RD)
  4461. D 3
  4462.         putf(fd, "R") ;
  4463. E 3
  4464. I 3
  4465.         ret = putf(fd, "R") ;
  4466. E 3
  4467.     else
  4468. D 3
  4469.         putf(fd, "N") ;
  4470.     return(ret) ;
  4471. E 3
  4472. I 3
  4473.         ret = putf(fd, "N") ;
  4474. D 5
  4475.     if ( ret == ERR)
  4476. E 5
  4477. I 5
  4478.     if ( ret == FILEERR)
  4479. E 5
  4480.     {
  4481. D 16
  4482.         p_printf("FILE ERROR: wrthdr, error in writting read (%s)", item->read == RD ? "R" : "N") ;
  4483. E 16
  4484. I 16
  4485.         uDisplayText("FILE ERROR: wrthdr,","error in writting read", item->read == RD ? "R" : "N", NULL) ;
  4486. E 16
  4487. D 5
  4488.         return(ERR) ;
  4489. E 5
  4490. I 5
  4491.         return(FILEERR) ;
  4492. E 5
  4493.     }
  4494.     return(TRUE) ;
  4495. E 3
  4496. }
  4497. /* end of meta file operations code */
  4498.  
  4499. /* start of ancillary file and keyboard IO code */
  4500. /* read a line of text from file handle */
  4501. INT getf(VOID * fd, TEXT * line)
  4502. {
  4503.     INT ret ;
  4504. I 3
  4505. D 14
  4506.     if (ancdbg == TRUE)
  4507.         p_printf("CALL: getf(fd = OMITTED, line = OMITTED)");
  4508. E 14
  4509. E 3
  4510. D 9
  4511.     ret = p_read(fd, (VOID *) line, 100) ;
  4512. E 9
  4513. I 9
  4514.     ret = p_read(fd, (VOID *) line, HDRLEN) ;
  4515. E 9
  4516.     if (ret < 0)
  4517. D 3
  4518.         return(FALSE) ;
  4519.     else
  4520.         return(TRUE) ;
  4521. E 3
  4522. I 3
  4523. D 5
  4524.         return(ERR) ;
  4525. E 5
  4526. I 5
  4527.         return(FILEERR) ;
  4528. E 5
  4529.     line[ret] = '\0' ;
  4530. D 16
  4531.     if (ancdbg == TRUE)
  4532.     {
  4533.         p_printf("ret is %d, line is :%s:", ret, line) ;
  4534.         p_getch() ;
  4535.     }
  4536. E 16
  4537.  
  4538.     return(TRUE) ;
  4539. E 3
  4540. }
  4541. /* write a line of text to file handle */
  4542. INT putf(VOID * fd, TEXT * line)
  4543. {
  4544.     INT ret ;
  4545. I 3
  4546. D 14
  4547.     if (ancdbg == TRUE)
  4548.         p_printf("CALL: putf (fd = OMITTED, line = %s)", line) ;
  4549. E 14
  4550. E 3
  4551.     ret = p_write(fd, (VOID *) line, p_slen(line)) ;
  4552.     if (ret < 0)
  4553. D 3
  4554.         return(FALSE) ;
  4555.     else
  4556.         return(TRUE) ;
  4557. E 3
  4558. I 3
  4559. D 5
  4560.         return(ERR) ;
  4561. E 5
  4562. I 5
  4563.         return(FILEERR) ;
  4564. E 5
  4565. D 16
  4566.     if (ancdbg == TRUE)
  4567.     {
  4568.         p_printf("ret is %d, line is :%s:", ret, line) ;
  4569.         p_getch() ;
  4570.     }
  4571. E 16
  4572.  
  4573.     return(TRUE) ;
  4574. E 3
  4575. }
  4576.  
  4577. D 17
  4578. /* getinp, read a line from the keyboard */
  4579. VOID getinp(TEXT * in)
  4580. {
  4581. I 3
  4582. D 14
  4583.     if (ancdbg == TRUE)
  4584.         p_printf("CALL: getinp(in = OMITTED)");
  4585. E 14
  4586. E 3
  4587.     p_gets(in) ;
  4588. }
  4589.  
  4590. E 17
  4591. D 16
  4592. /* print output without a newline */
  4593. VOID putnonl (TEXT * line)
  4594. {
  4595. I 3
  4596. D 14
  4597.     if (ancdbg == TRUE)
  4598.         p_printf("CALL: putnonl(line = %s)", line);
  4599. E 14
  4600. E 3
  4601.     p_puts(line) ;
  4602. D 11
  4603.     p_puts(" ") ;
  4604. E 11
  4605. }
  4606. E 16
  4607. /* end of ancillary file and keyboard IO code */
  4608. I 6
  4609. /* does the file given in fname exist return TRUE or FALSE
  4610.    if any other error than E_FILE_NXIST return FILEERR */
  4611. INT fileexist(TEXT * fname)
  4612. {
  4613.     P_INFO pinf ;
  4614.     INT ret ;
  4615. D 14
  4616.     
  4617.     if (filedbg == TRUE)
  4618.         p_printf("CALL: fileexist(fname = %s)", fname) ;
  4619. E 14
  4620.     ret = p_finfo(fname, &pinf) ;
  4621.     if (ret == 0)
  4622.     {
  4623. D 14
  4624.         if (filedbg == TRUE)
  4625.             p_printf("FILE %s exists", fname) ;
  4626. E 14
  4627.         return(TRUE) ;
  4628.     }
  4629.     else if (ret == E_FILE_NXIST)
  4630.     {
  4631. D 14
  4632.         if (filedbg == TRUE)
  4633.             p_printf("FILE %s does not exist", fname) ;
  4634. E 14
  4635.         return(FALSE) ;
  4636.     }
  4637.     else if ((ret == E_FILE_DEVICE) || (ret == E_FILE_NOTREADY) || (ret == E_FILE_DIR))
  4638.     {
  4639.         /* this is a major problem with the path */
  4640. D 11
  4641.         p_printf("FILE ERROR: fileexist, Directory or Device does not exist", fname) ;
  4642. E 11
  4643. I 11
  4644. D 16
  4645.         p_printf("FILE ERROR: fileexist, Directory or Device does not exist (%s)", fname) ;
  4646. E 16
  4647. I 16
  4648.         uDisplayText("FILE ERROR: fileexist,","Directory or Device does not exist", fname, NULL) ;
  4649. E 16
  4650. E 11
  4651.         return(FILEERR) ;
  4652.     }
  4653.     else /* some other unexpected error */
  4654.     {
  4655. D 16
  4656.         p_printf("FILE ERROR: fileexist, unxepected error code from p_finfo") ;
  4657. E 16
  4658. I 16
  4659.         uDisplayText("FILE ERROR: fileexist,","unxepected error code from p_finfo", NULL) ;
  4660. E 16
  4661.         return(FILEERR) ;
  4662.     }
  4663. I 16
  4664. }
  4665. /* start of window functions */
  4666. /* Print the output list */
  4667. VOID redolist(VOID)
  4668. {
  4669.     TEXT str[100] ;
  4670. I 20
  4671.     UINT border ;
  4672. E 20
  4673.     /* print the headers around the current email */
  4674.     /* disphdrs will arrange for the current item to be bold and ITEMS_IN_LIST 
  4675.        to be printed (if possible ) */
  4676.     disphdrs(currlist) ;
  4677.     /* do the borders, aqquire the current gc */
  4678.     gSetGC0(gchdr) ;
  4679.     /* if mailno is greater then ITEMS_IN_HALF_LIST + 1 then put an up arrow 
  4680. D 19
  4681.        on the display */
  4682. E 19
  4683. I 19
  4684.        on the display if there are items on the bottom of the display */
  4685. I 20
  4686.     border = W_BORD_CUSHION|W_BORD_CORNER_4 ;
  4687. E 20
  4688. E 19
  4689. D 17
  4690.     if (mailno > (ITEMS_IN_HALF_LIST +1)
  4691.         gBorder(W_BORD_CUSHION|W__BORD_CORNER_4|W_BORD_TOP_ON) ;
  4692. E 17
  4693. I 17
  4694.     if (mailno > (ITEMS_ON_HALF_SCREEN +1))
  4695. D 20
  4696.         gBorder(W_BORD_CUSHION|W_BORD_CORNER_4|W_BORD_TOP_ON) ;
  4697. E 20
  4698. I 20
  4699.         border = border | W_BORD_TOP_ON ;
  4700. E 20
  4701. E 17
  4702.     else
  4703. D 17
  4704.         gBorder(W_BORD_CUSHION|W__BORD_CORNER_4|W_BORD_TOP_OFF) ;
  4705.     /* if currlist->count - mailno is greater than ITEMS_IN_HALF LIST + 1 then put a 
  4706. E 17
  4707. I 17
  4708. D 20
  4709.         gBorder(W_BORD_CUSHION|W_BORD_CORNER_4|W_BORD_TOP_OFF) ;
  4710. E 20
  4711. I 20
  4712.         border = border |W_BORD_TOP_OFF ;
  4713. E 20
  4714.     /* if currlist->count - mailno is greater than ITEMS_ON_HALF_SCREEN + 1 then put a 
  4715. E 17
  4716.        down arrow on the display */
  4717. D 17
  4718.     if ((currlist->count - mailno) > (ITEMS_IN_HALF_LIST +1))
  4719.         gBorder(W_BORD_CUSHION|W__BORD_CORNER_4|W_BORD_BOT_ON) ;
  4720. E 17
  4721. I 17
  4722. D 19
  4723.     if ((currlist->count - mailno) > (ITEMS_ON_HALF_SCREEN +1))
  4724. E 19
  4725. I 19
  4726.     if (mailno < (currlist->count - ITEMS_ON_HALF_SCREEN))
  4727. E 19
  4728. D 20
  4729.         gBorder(W_BORD_CUSHION|W_BORD_CORNER_4|W_BORD_BOT_ON) ;
  4730. E 20
  4731. I 20
  4732.         border = border |W_BORD_BOT_ON ;
  4733. E 20
  4734. E 17
  4735.     else
  4736. D 17
  4737.         gBorder(W_BORD_CUSHION|W__BORD_CORNER_4|W_BORD_BOT_OFF) ;
  4738. E 17
  4739. I 17
  4740. D 20
  4741.         gBorder(W_BORD_CUSHION|W_BORD_CORNER_4|W_BORD_BOT_OFF) ;
  4742. E 20
  4743. I 20
  4744.         border = border |W_BORD_BOT_OFF ;
  4745. E 20
  4746. E 17
  4747.  
  4748. I 20
  4749.     gBorder(border) ;
  4750. E 20
  4751.     /* update the status message */
  4752.     p_atos(str, "%s, Mail no %d of %d", currlist == inlist ? "Incomming list" : "Outgoing List", mailno, currlist->count) ;
  4753.     statusmsg(str) ;
  4754. }
  4755.     
  4756.  
  4757. VOID statusmsg(TEXT * str)
  4758. {
  4759. D 18
  4760.     TEXT tmp[200] ;
  4761. E 18
  4762. I 18
  4763.     TEXT tmp[300] ;
  4764. I 20
  4765.     /* get hold of the current context */
  4766. E 20
  4767. E 18
  4768.     gSetGC0(gcstatus) ;
  4769. I 20
  4770.     /* sometimes the border gets trashed so rederw it */
  4771.     gBorder(W_BORD_CUSHION|W_BORD_CORNER_4) ;
  4772. E 20
  4773. D 17
  4774.     p_scpym(tmp, str, spacestr, NULL) ;
  4775. E 17
  4776. I 17
  4777.     p_scpym(tmp, str, blank, NULL) ;
  4778. E 17
  4779.     gPrintClipText(5,12,tmp, p_slen(tmp), 220) ;
  4780. }
  4781.  
  4782. INT askincl()
  4783. {
  4784.     struct ll * llptr ;
  4785.     INT ret ;
  4786.     
  4787.     /* only include the current email if mailno is valid */
  4788.     llptr = llnofind(mailno, currlist) ;
  4789.     if (llptr == NULL)
  4790.         return(FALSE) ;
  4791.     uOpenDialog("Include Current Email ?") ;
  4792.     uAddButtonList("Yes", 'y', "No", 'n', NULL) ;
  4793.     ret = uRunDialog() ;
  4794.     if (ret == 'y')
  4795.         return(TRUE) ;
  4796.     else
  4797.         return(FALSE) ;
  4798. E 16
  4799. }
  4800. E 6
  4801. E 2
  4802. E 1
  4803.