home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / pcmail / main / scanwork.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  3.0 KB  |  99 lines

  1. /*++
  2. /* NAME
  3. /*      scanwork 3
  4. /* SUMMARY
  5. /*      search spool directory for outbound messages
  6. /* PROJECT
  7. /*      pc-mail
  8. /* PACKAGE
  9. /*      cico
  10. /* SYNOPSIS
  11. /*    #include "work.h"
  12. /*
  13. /*      work *scanwork()
  14. /* DESCRIPTION
  15. /*      scanwork() searches the spool directory for files to be sent to
  16. /*    the remote system. If a file is found, scanwork() attempts to
  17. /*    open that file. A null pointer is returned if no work was found.
  18. /*
  19. /*    The result is normally used by sendwork().
  20. /* FUNCTIONS AND MACROS
  21. /*      scandir(), newseqno(), fspool()
  22. /* SEE ALSO
  23. /*      sendwork()      send spool file to remote host
  24. /*      getwork()       receive remote spool file
  25. /*      rmtname()       local spool-file to remote-file name mapping
  26. /* AUTHOR(S)
  27. /*      W.Z. Venema
  28. /*      Eindhoven University of Technology
  29. /*      Department of Mathematics and Computer Science
  30. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  31. /* CREATION DATE
  32. /*      Sat Mar 28 17:28:09 GMT+1:00 1987
  33. /* LAST MODIFICATION
  34. /*    90/01/22 13:02:31
  35. /* VERSION/RELEASE
  36. /*    2.1
  37. /*--*/
  38.  
  39. #include <stdio.h>
  40. #include <ctype.h>
  41.  
  42. #include "defs.h"
  43. #include "params.h"
  44. #include "comm.h"
  45. #include "work.h"
  46. #include "path.h"
  47. #include "ndir.h"
  48. #include "logs.h"
  49.  
  50.  /*
  51.   * The present implementation assumes that work for the remote system is in
  52.   * the form of pairs of spool files with names d<seqno> and x<seqno>.
  53.   * 
  54.   * The d files contain an electronic mail message, and the x files contain the
  55.   * destination. Both have the same <seqno> suffix which is just a five-digit
  56.   * sequence number.
  57.   * 
  58.   * The task of scanwork() thus is trivial: just locate a file of which the name
  59.   * begins with a d or x and do some file name parsing. The major work is
  60.   * done by rmtname() and sendwork(): depending on the type of file, generate
  61.   * an appropriate remote file name and send the appropriate messages to the
  62.   * remote system.
  63.   *
  64.   * After a file has been transmitted it is renamed to reflect the "Sent"
  65.   * status.
  66.   */
  67.  
  68. /* scanwork - search spool directory for work */
  69.  
  70. public work *scanwork()
  71. {
  72.     register DIR *dp;
  73.     register struct direct *de;
  74.     static work wrk;            /* overwritten each time */
  75.     static char unsent[] = "DdXx";    /* prefixes for unsent messages */
  76.     char   *p_unsent;            /* pointer into unsent array */
  77.     static char sent[] = "qqrr";    /* prefixes for sent messages */
  78.  
  79.     if ((dp = opendir(maildir)) == 0) {
  80.     return (0);
  81.     } else {
  82.     while (de = readdir(dp)) {
  83.         debug(5) ("scanwork: file %s\n", de->d_name);
  84.         if (((p_unsent = index(unsent, wrk.type = de->d_name[0])) != 0)
  85.         && (wrk.seqno = seqno(de->d_name))) {
  86.         strcpy(wrk.path, fspool(de->d_name));
  87.         strcpy(wrk.sent, fspool(strcons(SPOOLFMT,
  88.                       sent[p_unsent - unsent], wrk.seqno)));
  89.         sprintf(wrk.rqst, "S %s %s %s - %s 0660", de->d_name,
  90.             rmtname(wrk.type, wrk.seqno), "uucp", de->d_name);
  91.         wrk.fp = fopen(wrk.path, "r");
  92.         break;
  93.         }
  94.     }
  95.     closedir(dp);
  96.     return (de ? &wrk : NULL);
  97.     }
  98. }
  99.