home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / MAXMAILP.ZIP / CONFIG.C < prev    next >
C/C++ Source or Header  |  1991-01-01  |  29KB  |  886 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*    Config.c    User configuration routines for Maxmail                   */
  4. /*                Version 1.0                                               */
  5. /****************************************************************************/
  6. #if defined OS2
  7.   #define INCL_DOS
  8.   #define INCL_DOSDATETIME
  9.   #include <os2.h>
  10. #endif
  11.  
  12. #include "MaxMail.h"
  13.  
  14. int msgnum,handle,areas_sel;
  15. int Usercount;
  16. char msgstr[81];
  17. struct user_cfg uscfg;
  18. struct msgupd_st *msgupd;
  19. struct msgupd_st *prev;
  20.  
  21. void getconfig(void)
  22. {
  23.    char *p;
  24.    int x;
  25.  
  26.    areas_sel = FALSE;
  27.    handle = sopen(CfgFile,O_RDWR | O_BINARY | O_CREAT,SH_DENYNO,S_IWRITE);
  28.    lseek(handle,(long) (UserCfgnum * sizeof(struct user_cfg)),SEEK_SET);        /* Append to tail of file */
  29.    read(handle,(char *) &USERCFG,sizeof(struct user_cfg));
  30.  
  31.     /* Now ask user to set up message areas to read */
  32.    if (update & USRCFG_FUPD) {
  33.       strout("\r\n\r\nSysop has changed available message areas. You are required to enter\r\n");
  34.       strout("configuration again.\r\n");
  35.       memset(&USERCFG.msgarea1,0,64);        /* Clear out table */
  36.       memset(&USERCFG.msgarea2,0,64);        /* Clear out table */
  37.    }
  38.    strout("\r\nMAXMAIL User configuration");
  39.    strout("\r\n--------------------------\r\n");
  40.    get_msgareas();
  41.    strout("\r\nHang on, I'm scanning the message areas you selected.....\r\n");
  42.    USERCFG.totareas = build_areas();
  43.  
  44. /* Now get the defaul packer type */
  45.    get_packer(TRUE);
  46.  
  47. /* Now get default download protocol */
  48.    get_proto(TRUE);
  49.  
  50.    x = USRCFG_UPD;
  51.    x ^= 0xffff;
  52.    update &= x;
  53.    if (USERCFG.flags & USRCFG_UPD)
  54.       USERCFG.flags &= x;        /* Turn off update flags */
  55.    x = USRCFG_FUPD;
  56.    x ^= 0xffff;
  57.    update &= x;
  58.    if (USERCFG.flags & USRCFG_FUPD)
  59.       USERCFG.flags &= x;        /* Turn off forced update flags */
  60.    close(handle);
  61. }
  62.  
  63. void list_config()
  64. {
  65.    struct packer_st *pack1;
  66.    struct proto_st  *proto1;
  67.  
  68.    strout("\r\nYour current MaxMail configuration\r\n");
  69.    strout("-------------------------------------------------------\r\n");
  70.  
  71.    strout("Message areas selected:\r\n");
  72.    show_areas(FALSE);
  73.    proto1 = get_curprotolnk();
  74.    pack1 = get_curpacklnk();
  75.  
  76.    if (USERCFG.protocol)
  77.       sprintf(temp,"\r\nDefault protocol: %s\r\n",proto1->protoname);
  78.    else strcpy(temp,"\r\n\Default protocol: NONE, always ask.\r\n");
  79.    strout(temp);
  80.    if (USERCFG.packer)
  81.       sprintf(temp,"Default packer: %s\r\n",pack1->packname);
  82.    else strcpy(temp,"Default packer: NONE, always ask.\r\n");
  83.    strout(temp);
  84.    strout("-------------------------------------------------------\r\n");
  85. }
  86.  
  87. int new_user(int filenum)
  88. {
  89.    int x,y;
  90.  
  91.    x = 0;
  92.    update |= USRCFG_UPD;        /* Force the user to update his configuration */
  93.  
  94. /* Seek to start of file and count records */
  95.    if(lseek(filenum,0L,SEEK_SET) >= 0L)     {    /* Rewind to begginning */
  96.       y = read(filenum,(char *) &uscfg,sizeof(struct user_cfg));
  97.       while (y == sizeof(struct user_cfg)) {
  98.          x++;        /* Simple count */
  99.          y = read(filenum,(char *) &uscfg,sizeof(struct user_cfg));
  100.       }
  101.    }
  102.    return(x);
  103. }
  104.  
  105. void update_usercfg(int filenum)
  106. {
  107.    lseek(filenum,(long) (UserCfgnum * sizeof(struct user_cfg)),SEEK_SET);        /* Append to tail of file */
  108.    write(filenum,(char *) &USERCFG,sizeof(struct user_cfg));
  109. }
  110.  
  111. /* Convert message number to bitmap location and turn it on */
  112. void msgmark(int num)
  113. {
  114.    word *bitp;
  115.    int x,mask;
  116.  
  117.    if (isskiparea(num))
  118.       return;
  119.    
  120.    bitp = &USERCFG.msgarea1[num / 16];        /* Point to proper slot, 16 bits per slot */
  121.    mask = 1;
  122.    for (x=0; x < (num % 16); x++)
  123.       mask = mask << 1;
  124.    *bitp = *bitp | mask;        /* Turn it on */
  125.    areas_sel = TRUE;
  126.    return;
  127. }
  128.  
  129. /* Convert message number to bitmap location and turn it off */
  130. void msgunmark(int num)
  131. {
  132.    word *bitp;
  133.    int x,mask;
  134.    
  135.    bitp = &USERCFG.msgarea1[num / 16];        /* Point to proper slot, 16 bits per slot */
  136.    mask = 1;
  137.    for (x=0; x < (num % 16); x++)
  138.       mask = mask << 1;
  139.    mask ^= 0xffff;
  140.    *bitp = *bitp & mask;        /* Turn it off */
  141.    return;
  142. }
  143.  
  144. void get_msgareas()
  145. {
  146.    char *p;
  147.    int x,first;
  148.  
  149.    msgnum = 0;
  150.    first = TRUE;
  151.    screen_areas(FALSE);
  152.    strout("\r\nEnter message area numbers, seperated by space or ','\r\n");
  153.    strout("Press ENTER key without numbers, if you don't want to change areas\r\n\r\n");
  154.    timeremain();
  155.    strout("--> ");
  156.    strin(msgstr);
  157.    strout("\r\n");
  158.    p = strtok(msgstr," ,\0");
  159.    while (p) {
  160.       if (strcmp(";",p) == 0) 
  161.          break;
  162.       if (isdigit(*p)) {
  163.          msgnum = atoi(p);
  164.          if (PackDone) {
  165.             PackDone = FALSE;
  166.             unlink(ArcFile);        /* Erase it and start over */
  167.          }
  168.          if (first) {
  169.             first = FALSE;
  170.             memset(&USERCFG.msgarea1,0,64);
  171.          }
  172.          msgmark(msgnum);        /* Flag it */
  173.       }
  174.       p = strtok(NULL," ,\0");
  175.    }
  176. }
  177.  
  178.  
  179. int screen_areas(int flag)
  180. {
  181.    int  x,keys,col,inchr;
  182.    int  msgpos;
  183.    int areas;
  184.  
  185.    rewind(afile);        /* Start at top again */
  186.    fread(&AREA,astrlen,1,afile);
  187.    areas = 0;
  188.    while (1) {
  189.       msgpos = 0;
  190.       col = 0;
  191.       while (!feof(afile) && (msgpos < 20)) {
  192.          keys = AREA.msglock;
  193.          if (!keys)         /* No locks for this area */
  194.             keys = TRUE;
  195.          else {        /* User must have same locks */
  196.             keys = AREA.msglock & LastUser.key;
  197.             if (keys != AREA.msglock)
  198.                keys = FALSE;
  199.          }
  200.          x = atoi(AREA.name);        /* Get Message area */
  201.          if (isskiparea(x))
  202.             keys = FALSE;         /* If Sysop set skip, don't show this area */
  203.          if (AREA.msgpath[0] && (LastUser.priv >= AREA.msgpriv) && keys ) { 
  204.             if (flag) {        /* If true show areas we don't already have selected */
  205.                x = atoi(AREA.name);
  206.                if (is_selarea(x)) {        /* We already have this area */
  207.                   fread(&AREA,astrlen,1,afile);        /* Read next area */
  208.                   while ((atoi(AREA.name) > MaxScan) && !feof(afile)) 
  209.                      fread(&AREA,astrlen,1,afile);        /* Read next area */
  210.                   continue;
  211.                }
  212.             }
  213.             areas++;
  214.             if (!col) {     /* 1st column */
  215.                strncpy(temp,AREA.msginfo,20);
  216.                temp[20] = 0;
  217.                sprintf(msgstr,"[%s] %s",AREA.name,temp);
  218.                x = strlen(msgstr);
  219.                while (x++ < 26) 
  220.                   strcat(msgstr," ");        /* Pad it for formatting */
  221.             }
  222.             else {        /* 2nd or 3rd column */
  223.                strncpy(temp1,AREA.msginfo,20);
  224.                temp1[20] = 0;
  225.                sprintf(temp,"[%s] %s",AREA.name,temp1);
  226.                x = strlen(temp);
  227.                while (x++ < 26) 
  228.                   strcat(temp," ");        /* Pad it for formatting */
  229.                strcat(msgstr,temp);
  230.                if (col == 2) {
  231.                   strcat(msgstr,"\r\n");
  232.                   strout(msgstr);
  233.                   msgpos++;        /* Another row is spit out */
  234.                   col = -1;
  235.                }
  236.             }
  237.             col++;
  238.          }
  239.          fread(&AREA,astrlen,1,afile);        /* Read next area */
  240.          while ((atoi(AREA.name) > MaxScan) && !feof(afile)) 
  241.             fread(&AREA,astrlen,1,afile);        /* Read next area */
  242.       }
  243.       if (col) {        /* Some message areas left */
  244.          strcat(msgstr,"\r\n");
  245.          strout(msgstr);
  246.       }
  247.       if (!feof(afile)) {        /* More areas than a pageful */
  248.          strout("\r\nMore areas? [y,N] ");
  249.          x = chrin();
  250.          inchr = toupper(x);
  251.          if (inchr == 'Y' ) {
  252.             strout("\r\n\r\n");
  253.             continue;
  254.          }
  255.          else break;
  256.       }
  257.       else break;
  258.    }
  259.    return areas;
  260. }
  261.  
  262. void get_proto(int flag)
  263. {
  264.    strout("\r\n\r\nEnter default protocol to use\r\n");
  265.    strout("-----------------------------\r\n");
  266.    display_protos();
  267.    if (flag)
  268.       strout("[0] Always ask\r\n");
  269.    while (1) {
  270.       strout("\r\n");
  271.       timeremain();
  272.       strout("--> ");
  273.       strin(msgstr);
  274.       if(isdigit(msgstr[0])) {
  275.          if (msgstr[0] <= ('0' + totprotocols))
  276.             break;
  277.       }
  278.    }
  279.    USERCFG.protocol = (byte) atoi(strtok(msgstr," \n"));
  280. }
  281.  
  282. void get_packer(int flag)
  283. {
  284.    byte x;
  285.  
  286.    x = 0;
  287.    strout("\r\n\r\nEnter packing method you wish to use\r\n");
  288.    strout("------------------------------------\r\n");
  289.    display_packers();
  290.    if (flag)
  291.       strout("[0] Always ask\r\n");
  292.    while (1) {
  293.       strout("\r\n");
  294.       timeremain();
  295.       strout("--> ");
  296.       strin(msgstr);
  297.       if(isdigit(msgstr[0])) {
  298.          if (msgstr[0] <= ('0' + totpackers) ) {
  299.             x = atoi(strtok(msgstr," \n"));
  300.             break;
  301.          }
  302.       }
  303.    }
  304.  
  305.    if (USERCFG.packer != x && PackDone) {
  306.       PackDone = FALSE;
  307.       unlink(ArcFile);        /* Erase it and start over */
  308.       msgupd = MSGUPD_1;
  309.       while (msgupd) {
  310.          msgupd->update = FALSE;
  311.          msgupd = msgupd->next;
  312.       }
  313.    }
  314.    USERCFG.packer = x;
  315. }
  316.  
  317. int reset_config(void)
  318. {
  319.    int x;
  320.    long pos;
  321.  
  322.    Usercount = 0;
  323.    x = sopen(CfgFile,O_RDWR | O_BINARY | O_CREAT,SH_DENYWR,S_IWRITE);
  324.    if (x == -1) {
  325.       strout("\r\nError opening config file! Try later.\r\n");
  326.       return(FALSE);
  327.    }
  328.    logit("Sysop is reseting all current users",'#');
  329.    lseek(x,0L,SEEK_SET);        /* Rewind to begginning */
  330.    read(x,(char *) &uscfg,sizeof(struct user_cfg));
  331.    while (!eof(x)) {
  332.       pos = tell(x) - (long) sizeof(struct user_cfg);    /* Get position */
  333.       if (uscfg.name[0]) {
  334.          Usercount++;
  335.          uscfg.flags |= USRCFG_UPD;
  336.          USERCFG.flags |= USRCFG_UPD;        /* Update our record too! */
  337.          lseek(x,pos,SEEK_SET);     /* Rewind back to this record */
  338.          write(x,(char *) &uscfg,sizeof(struct user_cfg));
  339.       }
  340.       read(x,(char *) &uscfg,sizeof(struct user_cfg)); /* Next record */
  341.    }
  342.    close(x);
  343.    return(TRUE);
  344. }
  345.  
  346. int delete_users(void)
  347. {
  348.    int x,User;
  349.    char resp;
  350.    char *p1;
  351.    struct user_cfg USCFG;
  352.  
  353.    if (test_task())
  354.       strout("\r\nSorry, but someone else is using MaxMail currently. Try later!\r\n");
  355.    strout("Enter user's name ---> ");
  356.    strin(temp);
  357.    if (!IsLocal)
  358.       strout("\r\n");
  359.    p1 = strtok(temp,"\t\r\n");
  360.    if (p1) {
  361.       if (strcmpi(p1,LastUser.name) == 0) {
  362.          strout("Whoah there pardner! You can't delete yourself!\r\n");
  363.          return FALSE;
  364.       }
  365.       x = sopen(CfgFile,O_RDWR | O_BINARY | O_CREAT,SH_DENYNO,S_IWRITE);
  366.       if (x == -1)
  367.          aborterror(FILEOPEN,"Error opening/creating User config file");
  368.       User = find_config(x,p1,&USCFG);
  369.       if (User < 0) {
  370.          strout("Sorry but that user name does not exist.\r\n");
  371.       }
  372.       else {
  373.          strout("User is now being deleted.\r\n");
  374.          sprintf(temp1,"Sysop is deleting user: %s",p1);
  375.          logit(temp1,'#');
  376.          USCFG.isused = 0;
  377.          memset(USCFG.name,0,36);        /* Delete */
  378.          lseek(x,(long) User * sizeof(struct user_cfg),SEEK_SET);
  379.          write(x,(char *) &USCFG,sizeof(struct user_cfg));
  380.       }
  381.       close(x);
  382.    }
  383.    return(TRUE);
  384. }
  385.  
  386. void user_stats()
  387. {
  388.    int x,row,handle,y;
  389.    struct tm  *newtime;
  390.    char ttemp[40];
  391.    char *month;
  392.    char *day;
  393.    struct packer_st *packer1;
  394.    struct proto_st *proto1;
  395.  
  396.    if (!Usercount) {        /* We have to count the active users */
  397.       handle = sopen(CfgFile,O_RDWR | O_BINARY,SH_DENYNO,S_IREAD);
  398.       if (handle == -1) {
  399.          strout("\r\nError opening config file! Try later.\r\n");
  400.          return;
  401.       }
  402.       y = read(handle,(char *) &uscfg,sizeof(struct user_cfg));
  403.       while (y == sizeof(struct user_cfg)) {
  404.          if (uscfg.name[0])
  405.             Usercount++;
  406.          y = read(handle,(char *) &uscfg,sizeof(struct user_cfg));
  407.       }
  408.       lseek(handle,0L,SEEK_SET);        /* Rewind file */
  409.    }
  410.    else {
  411.       handle = sopen(CfgFile,O_RDWR | O_BINARY,SH_DENYNO,S_IREAD);
  412.       if (handle == -1) {
  413.          strout("\r\nError opening config file! Try later.\r\n");
  414.          return;
  415.       }
  416.    }
  417.    sprintf(temp,"\r\nCurrently, there are %d active users for MaxMail.\r\n",Usercount);
  418.    strout(temp);
  419.  
  420. /* Read all the users and display pertinent data */
  421.  
  422.    while (1) {
  423.       y = read(handle,(char *) &uscfg,sizeof(struct user_cfg));
  424.       strout("_______________________________________________________________________________\r\n");
  425.       strout("User Name                            Lasttime  Calls  Success  Packer  Protocol\r\n");
  426.       strout("-------------------------------------------------------------------------------\r\n");
  427.       row = 3;
  428.       while (row < 23 && y == sizeof(struct user_cfg)) {
  429.          while (!uscfg.isused && y == sizeof(struct user_cfg)) {
  430.             y = read(handle,(char *) &uscfg,sizeof(struct user_cfg));
  431.          }
  432.          if (y != sizeof(struct user_cfg)) 
  433.             break;
  434.          strcpy(temp,uscfg.name);
  435.          while (strlen(temp) < 37)
  436.             strcat(temp," ");
  437.          newtime = localtime(&uscfg.lasttime);
  438.          strcpy(ttemp,asctime(newtime));
  439.          strtok(ttemp," ");               /* Strip Day of week */
  440.          month = strtok(NULL," ");
  441.          day = strtok(NULL," ");
  442.          if (uscfg.calls < uscfg.packcount)
  443.             uscfg.calls = uscfg.packcount;
  444.          if (!uscfg.calls)
  445.             uscfg.calls = 1;
  446.          sprintf(temp1,"%s %s    %5d  %5d    ",month,day,uscfg.calls,uscfg.packcount);
  447.          strcat(temp,temp1);
  448.          x = USERCFG.packer;
  449.          USERCFG.packer = uscfg.packer;     /* Temporary fix */
  450.          packer1 = get_curpacklnk();
  451.          if (packer1 == NULL)
  452.             strcat(temp,"None  ");
  453.          else {
  454.             strcpy(temp1,packer1->packname);
  455.             day = strtok(temp1," ");         /* Get 1st name only */
  456.             while (strlen(day) < 6)
  457.                strcat(day," ");
  458.             strcat(temp,day);
  459.          }
  460.          USERCFG.packer = x;
  461.          strcat(temp,"  ");
  462.          x = USERCFG.protocol;
  463.          USERCFG.protocol = uscfg.protocol;     /* Temporary fix */
  464.          proto1 = get_curprotolnk();
  465.          if (proto1 == NULL)
  466.             strcat(temp,"None  ");
  467.          else {
  468.             strcpy(temp1,proto1->protoname);
  469.             day = strtok(temp1," ");         /* Get 1st name only */
  470.             strcat(temp,day);
  471.          }
  472.          USERCFG.protocol = x;
  473.          temp[79] = 0;
  474.          strcat(temp,"\r\n");
  475.          strout(temp);
  476.          row++;
  477.          y = read(handle,(char *) &uscfg,sizeof(struct user_cfg));
  478.       }
  479.       if (y == sizeof(struct user_cfg)) {        /* Still more records */
  480.          strout("\r\nPress ESC to stop or any other key for more");
  481.          x = chrin();
  482.          strout("\r\n");
  483.          if (x == 0x1b) 
  484.             break;
  485.       }
  486.       else break;
  487.    }
  488.    close(handle);
  489. }
  490.  
  491. void del_msgareas(void)
  492. {
  493.    char *p;
  494.    int x;
  495.  
  496.    strout("\r\nYour currently selected message areas\r\n");
  497.    strout("-----------------------------------------\r\n");
  498.    show_areas(FALSE);
  499.    strout("\r\nEnter message area(s) you wish to delete\r\n");
  500.    timeremain();
  501.    strout("--> ");
  502.    strin(msgstr);
  503.    strout("\r\n");
  504.    p = strtok(msgstr," ,\0");
  505.    while (p) {/* This used to be (*p && p) but *p becomes a segment violation
  506.                  when its checked for a value that it no longer has */
  507.       if (isdigit(*p)) {
  508.          msgnum = atoi(p);
  509.          x = is_selarea(msgnum);
  510.          if(x) {
  511.             msgunmark(msgnum);        /* Delete it */
  512.             x--;
  513.             msgupd = MSGUPD_1;
  514.             if (!x)
  515.                MSGUPD_1 = msgupd->next;
  516.             else {
  517.                while (x) {
  518.                   prev = msgupd;
  519.                   msgupd = msgupd->next;
  520.                   x--;
  521.                }
  522.                prev->next = msgupd->next;        /* Skip current one */
  523.             }
  524.             free(msgupd);
  525.             if (PackDone) {
  526.                unlink(ArcFile);        /* Erase it and start over */
  527.                while (msgupd) {
  528.                   msgupd->update = FALSE;
  529.                   msgupd = msgupd->next;
  530.                }
  531.                PackDone = FALSE;
  532.             }
  533.          }
  534.       }
  535.       if (p) /* Only do this if p, otherwise segement violation occurs */
  536.         p = strtok(NULL," ,\0");
  537.    }
  538. }
  539.  
  540. void add_msgareas(void)
  541. {
  542.    char *p;
  543.    struct msgupd_st *new;
  544.    int first;
  545.  
  546.    first = TRUE;
  547.    strout("\r\nYour currently selected message areas\r\n");
  548.    strout("-----------------------------------------\r\n");
  549.    show_areas(FALSE);
  550.    strout("\r\nOther message areas available\r\n");
  551.    strout("-----------------------------------------\r\n");
  552.    if(screen_areas(TRUE)) {
  553.       strout("\r\nEnter message area(s) you wish to add\r\n");
  554.       timeremain();
  555.       strout("--> ");
  556.       strin(msgstr);
  557.       strout("\r\n");
  558.       p = strtok(msgstr," ,\0");
  559.       while (p) { /* Same as del messages while (*p).  Had to take it out */
  560.          if (isdigit(*p)) {
  561.             msgnum = atoi(p);
  562.             if(!is_selarea(msgnum)) {
  563.                msgupd = MSGUPD_1;
  564.                if (first) {
  565.                   strout("\r\nHang on, I'm scanning the message areas you selected.....\r\n");
  566.                   first = FALSE;
  567.                }
  568.                new = build1_area(msgnum);
  569.                /* The following code has changed to again protect the pointer
  570.                   msgupd for segment violations.  To test this, run your old
  571.                   code in codeview and watch what happens to msgupd when you
  572.                   try to add an area that is greater than msgupd->areano.  It
  573.                   basically points to nothing and in DOS, it does not care,
  574.                   but when running under OS2, it halts with a trap 13. */
  575.                if (new) {
  576.                   if (msgupd) {
  577.                     if (msgnum < msgupd->areano)
  578.                       MSGUPD_1 = new;
  579.                     else {
  580.                       prev = msgupd;
  581.                       if (msgupd){
  582.                         while (msgupd->areano < msgnum) {
  583.                           prev = msgupd;
  584.                           msgupd = msgupd->next;
  585.                           if (!msgupd)
  586.                              break;
  587.                         }
  588.                       }
  589.                       prev->next = new;
  590.                     }
  591.                   } else
  592.                      MSGUPD_1 = new;
  593.                   msgmark(msgnum);        /* Add it */
  594.                   new->next = msgupd;        /* Now we're inserted */
  595.                   if (PackDone && (new->startmsg < new->himsg)) {
  596.                      unlink(ArcFile);        /* Erase it and start over */
  597.                      while (msgupd) {
  598.                         msgupd->update = FALSE;
  599.                         msgupd = msgupd->next;
  600.                      }
  601.                      PackDone = FALSE;
  602.                   }
  603.                }
  604.             }
  605.          }
  606.          if (p)
  607.            p = strtok(NULL," ,\0");
  608.          else
  609.            break;
  610.       }
  611.    }
  612.    else strout("Sorry, you have no other areas you can add at this time.\r\n");
  613. }
  614.  
  615. void edit_msgptrs(void)
  616. {
  617.    char *p1;
  618.    char resp;
  619.    int firsttime;
  620.    int good = TRUE;
  621.    int doupdate = FALSE;
  622.  
  623.    while (good) {
  624.       firsttime = TRUE;
  625.       msgupd = MSGUPD_1;
  626.       while (msgupd) {
  627.          if (firsttime) {
  628.             strout("\r\n---------------------------------------------------");
  629.             strout("\r\nCurrently selected            Start    High   New  ");
  630.             strout("\r\nMessage Areas                   Msg     Msg   Msgs ");
  631.             strout("\r\n---------------------------------------------------\r\n");
  632.             firsttime = FALSE;
  633.          }
  634.          fseek(afile,msgupd->areaindex,SEEK_SET);
  635.          fread(&AREA,astrlen,1,afile);
  636.          strncpy(temp1,AREA.msginfo,24);
  637.          temp1[24] = 0;
  638.          while (strlen(temp1) < 24)
  639.             strcat(temp1," ");
  640.          sprintf(temp,"[%03d] %s %04d    %04d   %04d\r\n",atoi(AREA.name),temp1,msgupd->startmsg,msgupd->himsg,msgupd->msgcount);      
  641.          strout(temp);
  642.          msgupd = msgupd->next;
  643.       }
  644.       if (firsttime) {
  645.          strout("\r\nYou have no currently selected message areas\r\n");
  646.          return;
  647.       }
  648.       else {
  649.          strout("---------------------------------------------------\r\n");
  650.          strout("\r\nEnter message area # you wish to change start msg #\r\n");
  651.          strout("Or type Q or press ENTER to exit back to main menu\r\n\r\n");
  652.          timeremain();
  653.          strout("Message area to change --> ");
  654.          strin(temp);
  655.          p1 = strtok(temp," \t\r\n");
  656.          if (p1) {
  657.             resp = toupper(*p1);
  658.             if (resp == 'Q')
  659.                good = FALSE;
  660.             else {        /* Parse out message area */
  661.                msgupd = find_area(atoi(p1));
  662.                if (isdigit(resp) && msgupd) {
  663.                   strout("\r\n                              Start    High   New  ");
  664.                   strout("\r\nMessage Area                    Msg     Msg   Msgs \r\n");
  665.                   strout("---------------------------------------------------\r\n");
  666.                   fseek(afile,msgupd->areaindex,SEEK_SET);
  667.                   fread(&AREA,astrlen,1,afile);
  668.                   strncpy(temp1,AREA.msginfo,24);
  669.                   temp1[24] = 0;
  670.                   while (strlen(temp1) < 24)
  671.                      strcat(temp1," ");
  672.                   sprintf(temp,"[%03d] %s %04d    %04d   %04d\r\n",
  673.                      atoi(AREA.name),temp1,msgupd->startmsg,msgupd->himsg,msgupd->msgcount);      
  674.                   strout(temp);
  675.                   strout("\r\n");
  676.                   timeremain();
  677.                   strout("Start message # --> ");
  678.                   strin(temp);
  679.                   if (!IsLocal)
  680.                      strout("\r\n");
  681.                   p1 = strtok(temp," \t\r\n");
  682.                   if (p1) {
  683.                      firsttime = atoi(p1);
  684.                      if (isdigit(*p1) && (firsttime != msgupd->startmsg)) {
  685.                         firsttime = firsttime >= 1 ? firsttime : 1;
  686.                         firsttime = firsttime <= msgupd->himsg ? firsttime : msgupd->himsg;
  687.                         msgupd->startmsg = firsttime;
  688.                         msgupd->msgcount = msgupd->himsg - msgupd->startmsg;
  689.                         if (msgupd->msgcount < 0)
  690.                            msgupd->msgcount = 0;
  691.                         doupdate = TRUE;
  692.                         msgupd->readmsgs = 0;
  693.                         if (PackDone) {
  694.                            PackDone = FALSE;
  695.                            unlink(ArcFile);        /* Erase it and start over */
  696.                         }
  697.                         else if (msg_update)
  698.                            msgupd->update = TRUE;
  699.                      }
  700.                   }
  701.                }
  702.             }
  703.          }
  704.          else good = FALSE;
  705.       }
  706.    }
  707.    if (doupdate)
  708.       update_msgs();
  709. }
  710.  
  711. /* Delete users who are no longer active on Maximus user file */
  712.  
  713. void kill_oldusers(void)
  714. {
  715.    int handl1,handl2;
  716.    int x,y;
  717.    long pos;
  718.  
  719.    if (test_task())
  720.       strout("\r\nSorry, but someone else is using MaxMail currently. Try later!\r\n");
  721.  
  722.    handl1 = sopen(CfgFile,O_RDWR | O_BINARY,SH_DENYWR,S_IWRITE);
  723.    if (handl1 == -1) {
  724.       strout("\r\nCan't write to user file");
  725.       aborterror(FILEOPEN,"Error opening User config file");
  726.    }
  727.  
  728.    handl2 = sopen(PRM(user_file),O_RDWR | O_BINARY,SH_DENYNO,S_IREAD);
  729.    if (handl1 == -1) {
  730.       strout("\r\nCan't open User.bbs file\r\n");
  731.       close(handl1);
  732.    }
  733.    y = read(handl1,(char *) &uscfg,sizeof(struct user_cfg));
  734.    x = 0;
  735.    while (y == sizeof(struct user_cfg)) {
  736.       if (uscfg.isused) {
  737.          if (!find_realuser(uscfg.name,handl2)) {
  738.             uscfg.isused = 0;
  739.             uscfg.name[0] = 0;        /* Null out name */
  740.             pos = tell(handl1) - (long) sizeof(struct user_cfg);    /* Get position */
  741.             lseek(handl1,pos,SEEK_SET);     /* Rewind back to this record */
  742.             write(handl1,(char *) &uscfg,sizeof(struct user_cfg));
  743.             x++;
  744.          }
  745.       }
  746.       y = read(handl1,(char *) &uscfg,sizeof(struct user_cfg));
  747.    }
  748.    close(handl1);
  749.    close(handl2);
  750.    if (x) {
  751.       sprintf(temp,"You have deleted %d users from config file.\r\n",x);
  752.       strout(temp);
  753.       sprintf(temp,"A sysop has deleted %d users from config file",x);
  754.       logit(temp,'#');
  755.    }
  756.    else strout("No users are inactive at this time.\r\n");
  757. }
  758.  
  759. /* See if another MaxMail user is currently active */
  760. int test_task(void)
  761. {
  762.    int x;
  763.  
  764. #if defined OS2
  765.    FILEFINDBUF c_file;
  766.    USHORT HANDLE = 0xffff;
  767.    unsigned count = 1;
  768. #else
  769.    struct find_t c_file;
  770. #endif
  771.  
  772.    sprintf(temp,"MxMlAct.%03d",Task);        /* Create a task id */
  773.    unlink(temp);        /* Delete our own task file */
  774.  
  775. #if defined OS2
  776.    if (DosFindFirst((char far *) "MxMlAct.*", (USHORT far *) &HANDLE,
  777.    0x0, (FILEFINDBUF far *) &c_file, sizeof(c_file),
  778.    (unsigned far *) &count,0L) == 0) {
  779. #else
  780.    if (_dos_findfirst("MxMlAct.*",_A_NORMAL,&c_file) == 0) { /* Uh oh. Someone else is using MaxMail! */
  781. #endif
  782.       x = sopen(temp,O_RDWR | O_BINARY | O_CREAT,SH_DENYWR,S_IWRITE);
  783.       close(x);        /* Re-Create task file */
  784.       return(TRUE);
  785.    }
  786.  
  787.    x = sopen(temp,O_RDWR | O_BINARY | O_CREAT,SH_DENYWR,S_IWRITE);
  788.    close(x);        /* Re-Create task file */
  789.  
  790. #if defined OS2
  791.    DosFindClose(HANDLE);
  792. #endif
  793.    return(FALSE);
  794. }
  795.  
  796.  
  797. void examine_user(void)
  798. {
  799.    int x,y,User,mask,bitloop,areas;
  800.    int handl1;
  801.    int col,line,anum;
  802.    long lerr;
  803.    char resp;
  804.    char *p1;
  805.    word *bitp;
  806.  
  807.    strout("Enter user's name ---> ");
  808.    strin(temp);
  809.    if (!IsLocal)
  810.       strout("\r\n");
  811.    p1 = strtok(temp,"\t\r\n");
  812.    if (p1) {
  813.       handl1 = sopen(CfgFile,O_RDWR | O_BINARY | O_CREAT,SH_DENYNO,S_IREAD);
  814.       if (handl1 == -1)
  815.          aborterror(FILEOPEN,"Error opening User config file");
  816.       User = find_config(handl1,p1,&uscfg);
  817.       if (User < 0) {
  818.          strout("Sorry but that user name does not exist.\r\n");
  819.       }
  820.       else {        /* Display possible message areas */
  821.          col = 0;
  822.          line = 0;
  823.          areas = 0;
  824.          for (bitloop=0; bitloop < 64; bitloop++ ) {
  825.             bitp = &uscfg.msgarea1[bitloop];
  826.             mask = 1;
  827.             for (x=0; x < 16; x++) {        /* Bitmask loop */
  828.                if (*bitp & mask) {        /* User selected area */
  829.                   if (!areas) {        /* First time */
  830.                      strout("\r\nUser message areas: \r\n");
  831.                      strout("-------------------\r\n");
  832.                      rewind(afile);        /* Rewind AREA file */
  833.                   }
  834.                   areas++;
  835.                   anum = bitloop * 1;
  836.                   anum += x;        /* Compute logical area number */
  837.                   y = fread(&AREA,astrlen,1,afile);
  838.                   while (y == 1) {
  839.                      if (anum == atoi(AREA.name)) {
  840.                         if (!col) {     /* 1st column */
  841.                            strncpy(temp,AREA.msginfo,20);
  842.                            temp[20] = 0;
  843.                            sprintf(msgstr,"[%s] %s",AREA.name,temp);
  844.                            y = strlen(msgstr);
  845.                            while (y++ < 26) 
  846.                               strcat(msgstr," ");        /* Pad it for formatting */
  847.                         }
  848.                         else {        /* 2nd or 3rd column */
  849.                            strncpy(temp1,AREA.msginfo,20);
  850.                            temp1[20] = 0;
  851.                            sprintf(temp,"[%s] %s",AREA.name,temp1);
  852.                            y = strlen(temp);
  853.                            while (y++ < 26) 
  854.                               strcat(temp," ");        /* Pad it for formatting */
  855.                            strcat(msgstr,temp);
  856.                            if (col == 2) {
  857.                               strcat(msgstr,"\r\n");
  858.                               strout(msgstr);
  859.                               line++;        /* Another row is spit out */
  860.                               if (line > 23) {
  861.                                  strout("\r\nPress any key");
  862.                                  chrin();
  863.                                  strout("\r\n");
  864.                                  line = 0;
  865.                               }
  866.                               col = -1;
  867.                            }
  868.                         }
  869.                         col++;
  870.                         break;
  871.                      }
  872.                      y = fread(&AREA,astrlen,1,afile);
  873.                   }
  874.                }
  875.                mask = mask << 1;
  876.             }
  877.          }
  878.          if (col) {
  879.             strcat(msgstr,"\r\n");
  880.             strout(msgstr);
  881.          }
  882.       }
  883.       close(handl1);
  884.    }
  885. }
  886.