home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / ELM23-2 / ELM23-2.ZIP / src / expires.c < prev    next >
C/C++ Source or Header  |  1992-10-04  |  4KB  |  153 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: expires.c,v 4.1 90/04/28 22:43:01 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1986, 1987 Dave Taylor
  8.  *             Copyright (c) 1988, 1989, 1990 USENET Community Trust
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log:    expires.c,v $
  17.  * Revision 4.1  90/04/28  22:43:01  syd
  18.  * checkin of Elm 2.3 as of Release PL0
  19.  *
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** This routine is written to deal with the Expires: header on the
  24.     individual mail coming in.  What it does is to look at the date,
  25.     compare it to todays date, then set the EXPIRED flag on the
  26.     current message if it is true...
  27. **/
  28.  
  29. #include "headers.h"
  30.  
  31. #ifdef I_TIME
  32. #  include <time.h>
  33. #endif
  34. #ifdef I_SYSTIME
  35. #  include <sys/time.h>
  36. #endif
  37.  
  38. #include <ctype.h>
  39.  
  40. #ifdef BSD
  41. #undef toupper
  42. #undef tolower
  43. #endif
  44.  
  45. process_expiration_date(date, message_status)
  46. char *date;
  47. int  *message_status;
  48. {
  49.     struct tm *timestruct;
  50.     long thetime;
  51.     char word1[WLEN], word2[WLEN], word3[WLEN], word4[WLEN], word5[WLEN];
  52.     int  month = 0, day = 0, year = 0, hour = 0, minute = 0;
  53. #ifndef    _POSIX_SOURCE
  54.     struct tm *localtime();
  55.     time_t time();
  56. #endif
  57.  
  58.     /** first step is to break down the date given into MM DD YY HH MM
  59.         format:  The possible formats for this field are, by example:
  60.  
  61.         (1) Mon, Jun 11, 87
  62.         (2) Mon, 11 Jun 87
  63.         (3) Jun 11, 87
  64.         (4) 11 Jun 87
  65.         (5) 11/06/87    <- ambiguous - will be ignored!!
  66.         (6) 8711061248GMT
  67.         (7) Mon, Jun 11, 87 12:48:35 GMT
  68.  
  69.         The reason #5 is considered ambiguous will be made clear
  70.         if we consider a message to be expired on Jan 4, 88:
  71.             01/04/88    in the United States
  72.             04/01/88    in Europe
  73.         so is the first field the month or the day?  Standard prob.
  74.     **/
  75.  
  76.     sscanf(date, "%s %s %s %s %s",
  77.         word1, word2, word3, word4, word5);
  78.  
  79.     if (strlen(word5) != 0) {    /* we have form #7 */
  80.       day   = atoi(word1);
  81.       month = month_number(word2);
  82.       year  = atoi(word3);
  83.       sscanf(word4, "%02d%*c%02d",
  84.            &hour, &minute);
  85.     }
  86.     else if (strlen(word2) == 0) {    /* we have form #6 or form #5 */
  87.       if (isdigit(word1[1]) && isdigit(word1[2]))      /* form #6 */
  88.         sscanf(word1, "%02d%02d%02d%02d%02d%*c",
  89.          &year, &month, &day, &hour, &minute);
  90.     }
  91.     else if (strlen(word4) != 0) {           /* form #1 or form #2 */
  92.       if(isdigit(word2[0])) {           /* form #2 */
  93.           month = month_number(word3);
  94.           day   = atoi(word2);
  95.           year  = atoi(word4);
  96.       } else {                   /* form #1 */
  97.           month = month_number(word2);
  98.           day   = atoi(word3);
  99.           year  = atoi(word4);
  100.       }
  101.     }
  102.     else if (! isdigit(word1[0])) {           /* form #3 */
  103.       month = month_number(word1);
  104.       day   = atoi(word2);
  105.       year  = atoi(word3);
  106.     }
  107.     else {                       /* form #4 */
  108.       day   = atoi(word1);
  109.       month = month_number(word2);
  110.       year  = atoi(word3);
  111.     }
  112.  
  113.     if (day == 0 || year == 0)
  114.       return;            /* we didn't get a valid date */
  115.  
  116.     /** next let's get the current time and date, please **/
  117.  
  118.     thetime = time((long *) 0);
  119.  
  120.     timestruct = localtime(&thetime);
  121.  
  122.     /** and compare 'em **/
  123.  
  124.     if (year > timestruct->tm_year)
  125.       return;
  126.     else if (year < timestruct->tm_year)
  127.       goto expire_message;
  128.  
  129.     if (month > timestruct->tm_mon)
  130.       return;
  131.     else if (month < timestruct->tm_mon)
  132.       goto expire_message;
  133.  
  134.     if (day > timestruct->tm_mday)
  135.       return;
  136.     else if (day < timestruct->tm_mday)
  137.       goto expire_message;
  138.  
  139.     if (hour > timestruct->tm_hour)
  140.       return;
  141.     else if (hour < timestruct->tm_hour)
  142.       goto expire_message;
  143.  
  144.     if (minute > timestruct->tm_min)
  145.       return;
  146.  
  147. expire_message:
  148.  
  149.     /** it's EXPIRED!  Yow!! **/
  150.  
  151.     (*message_status) |= EXPIRED;
  152. }
  153.