home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / wpbif094.zip / biff.cpp next >
C/C++ Source or Header  |  1997-07-02  |  2KB  |  80 lines

  1. //    Copyright VOS 1996
  2. //    Author: Vitaly S. Gumirov
  3. //
  4. // email: vos@ifshop.ict.nsk.su
  5.  
  6.  
  7. #define  INCL_WINWORKPLACE
  8. #define  INCL_DOSPROCESS
  9. #include <os2.h>
  10. #include <stdlib.h>
  11. #include <time.h>
  12. #include <tcpsock.hpp>
  13.  
  14. main(int argc, char *argv[])
  15. {
  16.  
  17.  
  18.     long interval=atol(getenv("POP3_INTERVAL"));
  19.     char *obj_id=strdup(getenv("POP3_WPS_OBJECT"));
  20.     HOBJECT hobj=WinQueryObject(obj_id);
  21.     char title[100], setup_str[100];
  22.  
  23.     if(!hobj) {
  24.       fprintf(stderr, "Object %s not found on your WPS\n", obj_id);
  25.       return 1;
  26.     }
  27.  
  28.     char *no_msgs_icon_file=strdup(getenv("POP3_NO_MAIL_ICON"));
  29.     char *there_msgs_icon_file=strdup(getenv("POP3_MAIL_ICON"));
  30.     char *error_icon_file=strdup(getenv("POP3_ERROR_ICON"));
  31.     
  32.     long old_msgs=-1;
  33.  
  34.     do {
  35.      try {
  36.       POP3Sock pop3d(IP_Name(getenv("POP3_HOST"))
  37.                , getenv("POP3_USER")
  38.                , getenv("POP3_PASS"));
  39.       pop3d.logon();
  40.       long num_msgs;
  41.       printf("There are %d message(s)\n",num_msgs=pop3d.number_of_msgs());
  42.       // flush(stdout);      
  43.       if(old_msgs!=num_msgs) {
  44.           old_msgs=num_msgs;
  45.           switch(num_msgs) {
  46.              case 0:  sprintf(title, getenv("POP3_NO_MSGS_TITLE") );
  47.                       break;
  48.              case 1: sprintf(title, getenv("POP3_1_MSG_TITLE") );
  49.                      break;
  50.              default:  sprintf(title,getenv("POP3_MSGS_TITLE"), num_msgs );
  51.  
  52.             }
  53.           sprintf(setup_str, "TITLE=%s;ICONFILE=%s"
  54.                 , title
  55.                 , (num_msgs)?there_msgs_icon_file : no_msgs_icon_file );
  56.  
  57.           WinSetObjectData(hobj, setup_str);
  58.       }
  59.       pop3d.quit();
  60.      }  catch(TCPSockError& _err) {
  61.          printf("%s", _err.sock_errmsg());
  62.          // flush(stdout);
  63.          sprintf(title, "%s", getenv("POP3_ERROR_TITLE"));
  64.          sprintf(setup_str, "TITLE=%s;ICONFILE=%s"
  65.                 , title
  66.                 , error_icon_file );
  67.  
  68.          WinSetObjectData(hobj, setup_str);
  69.          old_msgs=-1;
  70.      }
  71.  
  72.      DosSleep(interval*1000);
  73.     } while(1);
  74.  
  75.  
  76.  return 0;
  77. }
  78.  
  79.  
  80.