home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume3 / pcmail / part07 / scanwork.c < prev    next >
C/C++ Source or Header  |  1989-02-03  |  2KB  |  86 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()       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. /*    Wed Apr  6 00:22:10 MET 1988
  35. /* VERSION/RELEASE
  36. /*    1.4
  37. /*--*/
  38.  
  39. #include <ctype.h>
  40. #include "defs.h"
  41. #include "params.h"
  42. #include "comm.h"
  43. #include "work.h"
  44. #include "path.h"
  45. #include "dir.h"
  46. #include "logs.h"
  47.  
  48. /*
  49. * The present implementation assumes that work for the remote system 
  50. * is in the form of pairs of spool files with names D<seqno> and X<seqno>. 
  51. * The D files contain an electronic mail message, and the X files
  52. * contain the destination. Both have the same <seqno> suffix which
  53. * is just a five-digit sequence number.
  54. * The task of scanwork() thus is trivial: just locate a file of which the
  55. * name begins with a D or X and do some file name parsing.
  56. * The major work is done by rmtname() and sendwork(): depending on the 
  57. * type of file, generate an appropriate remote file name and send the 
  58. * appropriate messages to the remote system.
  59. */
  60.  
  61. /* scanwork - search spool directory for work */
  62.  
  63. public work *scanwork()
  64. {
  65.     register int dd;
  66.     register char *p;
  67.     static work wrk;
  68.  
  69.     dd = opendir(maildir);
  70.     while (p = readdir(dd)) {
  71.     debug(5)("scanwork: file %s\n",p);
  72.     if (index("dxDX",*p)) {
  73.         wrk.type = (islower(*p) ? toupper(*p) : *p);
  74.         wrk.tail = p+1;
  75.         sprintf(wrk.rqst,"S %c%s %s %s - %c%s 0660",
  76.         wrk.type,wrk.tail,rmtname(wrk.type,wrk.tail),
  77.         "uucp",wrk.type,wrk.tail);
  78.         strcpy(wrk.path,fspool(p));
  79.         wrk.fp = fopen(wrk.path,"r");
  80.         break;
  81.     }
  82.     }
  83.     closedir(dd);
  84.     return(*p ? &wrk : NULL);
  85. }
  86.