home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / pmm15u11.zip / CHANGE.PAS < prev    next >
Pascal/Delphi Source File  |  1997-01-16  |  2KB  |  58 lines

  1. program PMMail_Sent_Status_Changer_1_1;
  2.  
  3. (* This proggy changes the status of all messages in a PMMail 1.5 message directory to
  4. 'sent'.  Useful when rebuilding the index of the Sent Mail folder or migrating it from
  5. PMMail 1.1 where PMMail 1.5 gives the messages the 'read' status.
  6.  
  7. Copyright 1996-1997 Samuel Audet <guardia@cam.org>   distribute freely! *)
  8.  
  9. uses strings;
  10.  
  11. const bagname = 'folder.bag'; (* index filenames *)
  12.       bakname = 'folder.bak';
  13.  
  14. var bag,tmp_file : text;
  15.     statpos  : pchar;
  16.     temp     : array[0..400] of char;  (* Enlarge if an entry of folder.bag is bigger. *)
  17.     filename,changedir : string;
  18.  
  19. begin
  20.    Writeln('PMMail 1.5 Utilities 1.1, Sent Status Changer - Copyright 1996-1997 Samuel Audet');
  21.    changedir := paramstr(1);
  22.    if (changedir <> '') and (copy(changedir,length(changedir),1) <> '\')
  23.       then changedir := changedir + '\';  (* command line parameter formatting *)
  24.    assign(bag,changedir + bagname);   (* Renames the original folder.bag to folder.bak, and *)
  25.    {$I-} rename(bag,changedir + bakname); {$I+} (* opens writing to folder.bag. *)
  26.    case ioresult of
  27.       2: if changedir = ''
  28.             then begin writeln('Error: ' + bagname + ' does not exist in the current directory'); halt; end
  29.             else begin writeln('Error: ' + bagname + ' does not exist in ' + changedir); halt; end;
  30.       3: begin writeln('Error: the directory ' + changedir + ' does not exist'); halt; end;
  31.       5: begin
  32.             assign(bag,changedir + bakname);
  33.             erase(bag);
  34.             assign(bag,changedir + bagname);
  35.             rename(bag,changedir + bakname);
  36.          end;
  37.    end;
  38.    assign(tmp_file,changedir + bagname);
  39.    reset(bag);
  40.    rewrite(tmp_file);
  41.  
  42.    while not eof(bag) do
  43.    begin
  44.       readln(bag,temp);
  45.       statpos := strscan(temp,chr(222));
  46.       if statpos = nil then writeln('Error: bad entry in ' + changedir + bagname) else
  47.          begin
  48.             statpos := statpos - 1;
  49.             statpos^  := '3';           (* change the current message status to 'sent' *)
  50.             writeln(tmp_file,temp);
  51.          end;
  52.    end;
  53.  
  54.    close(bag);
  55.    close(tmp_file);
  56.    erase(bag);
  57. end.
  58.