home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / MBLIB10 / C_EXAMP / PRINTMSG.C < prev    next >
Text File  |  1993-03-07  |  2KB  |  71 lines

  1. /* WARNING: THIS EXAMPLE IS QUICK & DIRTY!!! Its only purpose is to         */
  2. /* demonstrate how certain MB_lib functions are used and how they work.     */
  3. /* While the code is a functional program, no attempt has been made to      */
  4. /* clean up the code or to streamline it, and I've economized a bit on      */
  5. /* error checking since I've made this in a hurry. However, if you're       */
  6. /* able to use MB_lib, odds are that you also know how to write neat code.  */
  7.  
  8. /* Display messages to a certain user */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "mb_lib.h"
  14.  
  15. long recnr;
  16. MSGHDR_RECORD hdr;
  17. MSGTOIDX_RECORD to;
  18. M_TEXT txt;
  19.  
  20. void printmsg (MSGHDR_RECORD *);    /* Print message on screen */
  21. int printline (char *);             /* Print line to screen    */
  22.  
  23.  
  24. main () {
  25.   if (msg_open ("C:\\MSGBASE")) {
  26.     printf ("Error %d opening message base:\n%s\n", errortype, errorstring);
  27.     exit (1);
  28.   }
  29.   puts ("User name?");
  30.   gets (to);
  31.   printf ("\n\nScanning for unread mail to %s\n", to);
  32.   recnr = msg_firstto (& to);
  33.   while (recnr != -1) {
  34.     msg_read_hdr (recnr, & hdr);     /* Ignore errors for the moment    */
  35.     printmsg (& hdr);                 /* Sloppy, but this is just a demo */
  36.     strcpy (to, "* Received *");
  37.     if (msg_lock ("C:\\RA\\SEMAFORE")) {
  38.       puts ("Error locking message base");
  39.       exit (1);
  40.     }
  41.     msg_write_toidx (recnr, & to);   /* Mark message as received */
  42.     msg_unlock ();                   /* Again, ignore errors     */
  43.     recnr = msg_nextto (recnr);
  44.   }
  45.   msg_close ();
  46.   puts ("Done.");
  47.   return (0);
  48. }
  49.  
  50. void printmsg (MSGHDR_RECORD * hdr) {       /* Print a message on screen */
  51.   printf ("By: %s\n", hdr -> who_from);
  52.   printf ("To: %s\n", hdr -> who_to);
  53.   printf ("Re: %s\n", hdr -> subject);
  54.   printf ("Number: %5d  Board: %3d\n", hdr -> msgnum, hdr -> board);
  55.   puts ("===================================================");
  56.   txt = msg_read_text (hdr);
  57.   if (txt == NULL) {
  58.     printf ("MB_lib error %d: %s\n", errortype, errorstring);
  59.     exit (1);
  60.   }
  61.   txt_dump (txt, printline, 70, NOKLUDGES);   /* Print margin 70, no kludges */
  62. }
  63.  
  64.  
  65. int printline (char * line) {          /* Print a message line on screen */
  66.   puts (line);
  67.   return (0);    /* This always works :-) */
  68. }
  69.  
  70.  
  71.