home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / lm2pmm.zip / lmrxtool.cmd < prev    next >
OS/2 REXX Batch file  |  1997-02-16  |  10KB  |  300 lines

  1. /*
  2. program: lmrxtoo.cmd  
  3. type:    REXXSAA-OS/2, Object Rexx, REXXSAA 6.x
  4. purpose: utilities for dealing with LaMail files
  5. version: 0.0.9
  6. date:    1997-02-10
  7. changed: ---
  8.  
  9. author:  Rony G. Flatscher
  10.          Rony.Flatscher@wu-wien.ac.at
  11.  
  12. needs:   ObjectRexx, installed WPS-support 
  13.  
  14. usage:   "lmmrxtool d", or via a call or ::require
  15.  
  16. All rights reserved, copyrighted 1997, no guarantee that it works without
  17. errors, etc. etc.
  18.  
  19. donated to the public domain granted that you are not charging anything (money
  20. etc.) for it and derivates based upon it, as you did not write it,
  21. etc. if that holds you may bundle it with commercial programs too
  22.  
  23. you may freely distribute this program, granted that no changes are made
  24. to it
  25.  
  26. Please, if you find an error, post me a message describing it, I will
  27. try to fix and rerelease it to the net.
  28. */
  29.  
  30.  
  31. /* initialisation part of this Object Rexx program                              */
  32.  
  33.  
  34.         /* LaMail values, store in .local environment   */
  35. inifile = "USER"; app = "LAM"
  36. inifile = strip_0( SysIni( inifile, app, "LAMIniPath" ) )
  37. .local ~ lam.bFound    = ( inifile <> "ERROR:" )
  38.  
  39. IF .lam.bFound THEN                  /* LaMail not found                     */
  40. DO
  41.    .local ~ lam.IniPath   = inifile
  42.    .local ~ lam.NickName  = strip_0( SysIni( inifile, app, "NAMES"      ) )
  43.    .local ~ lam.Signature = strip_0( SysIni( inifile, app, "NOTESIG"    ) )
  44.    .local ~ lam.Folders   = strip_0( SysIni( inifile, app, "FoldersDir" ) )
  45.    .local ~ lam.Inbox     = strip_0( SysIni( inifile, app, "InboxDir"   ) )
  46.    .local ~ lam.zone      = strip_0( SysIni( inifile, app, "ZONE"       ) )
  47.  
  48.    .local ~ lam.FolderList = get_lamail_folders()
  49. END
  50.  
  51. IF ARG() > 0 THEN                       /* any argument will show LaMail settings found */
  52. DO
  53.    SAY "LaMail - found ? (0 = no):" pp( .lam.bFound   )
  54.    IF .lam.bFound THEN
  55.    DO
  56.       SAY "LaMail - INI-file:        " pp( .lam.IniPath  )
  57.       SAY "LaMail - NickName file:   " pp( .lam.Nickname )
  58.       SAY "LaMail - Signature file:  " pp( .lam.Signature )
  59.       SAY "LaMail - folder directory:" pp( .lam.Folders )
  60.       SAY "LaMail - inbox directory: " pp( .lam.Inbox ) 
  61.       CALL rgf_util
  62.       CALL dump .lam.FolderList
  63.  
  64.       IF ARG( 1 ) > 1 THEN
  65.       DO
  66.          .nickNames ~ NewFromFile               /* read NickName file, create NN-objects        */
  67.          .nickNames ~ dump                      /* dump all nicknames                           */
  68.       END
  69.    END
  70. END
  71.  
  72. EXIT 
  73.  
  74.  
  75. STRIP_0 : PROCEDURE                     /* remove trailing "00"x                */
  76.    RETURN STRIP( ARG( 1 ), "Trailing", "00"x )
  77.  
  78.  
  79. :: REQUIRES rgf_util                    /* needs some of RGF_UTIL's functions   */
  80.  
  81.  
  82. :: ROUTINE PP                           /* cheap pretty-print routine           */
  83.    RETURN "[" || ARG( 1 ) || "]"
  84.                                                                                               
  85.  
  86.  
  87. :: ROUTINE GET_LAMAIL_FOLDERS           /* find out what LaMail folders there are       */
  88.  
  89.    pattern = .lam.Folders || "\*.ndx"        /* look for index files         */
  90.    CALL SysFileTree pattern, "folders.", "FO"
  91.  
  92.    list    = .list ~ new
  93.    DO i = 1 TO folders.0
  94.       PARSE VAR folders.i filestem "." .        /* PARSE filestem               */
  95.       CALL SysFileTree filestem, "aha.", "DO"   /* check for directory itself   */
  96.       IF aha.0 = 1 THEN list ~ insert( aha.1 )  /* save directory for processing */
  97.    END
  98.    RETURN list
  99.  
  100.  
  101.  
  102.  
  103.  
  104. :: ROUTINE Delete_EMail         /* delete e-mail in given directory     */
  105.    USE ARG targDir, bRemoveDir
  106.  
  107.    bRemoveDir = ( bRemoveDir = .true )  /* only remove dir, if flag was explicitly set  */
  108.  
  109.    tmpPattern = targDir || "\*.*"
  110.  
  111.    SAY "Deleting files:" pp( tmpPattern )
  112.  
  113.    CALL SysFileTree tmpPattern, "todelete.", "FO"
  114.    SAY "    total of" pp( todelete.0 ) "files."
  115.  
  116.    DO j = 1 TO todelete.0                 /* delete files                 */
  117.       IF SysFileDelete( todelete.j ) <> 0 THEN
  118.          .logError ~ new( "Error deleting:" pp( todelete.j ) )
  119.    END
  120.  
  121.    IF bRemoveDir THEN                           /* remove directory ?   */
  122.    DO
  123.       SAY "Removing dir:  " pp( targDir )
  124.       IF SysRmDir( targDir ) <> 0 THEN
  125.          .logError ~ new( "Error removing directory:" pp( targDir ) )
  126.    END
  127.    SAY
  128.    RETURN
  129.  
  130.  
  131.  
  132.         /* delete e-mail in directory and subdirectories        */
  133. :: ROUTINE Delete_Dirs          PUBLIC
  134.    USE ARG targDir, bRemoveDir
  135.  
  136.    CALL SysFileTree targDir || "\*", "aha.", "DOS"      /* check for directory itself   */
  137.  
  138.    DO i = aha.0 TO 1 BY -1                              /* walk the dir-list in reverse order   */
  139.       CALL Delete_EMail aha.i, .true
  140.    END
  141.  
  142.    CALL Delete_EMail targDir, bRemoveDir                /* delete e-mail in starting folder too */
  143.  
  144.  
  145.  
  146.  
  147.  
  148. :: ROUTINE Replicate_EMAIL      PUBLIC          /* xcopy directory, rename target       */
  149.    USE ARG source, targDir
  150.  
  151.    /* create targDir directory           */
  152.    IF SysMkDir( targDir ) = 0 THEN              /* create targDir directory      */
  153.       SAY "dir" pp( targDir ) "created."
  154.    ELSE                                         
  155.    DO
  156.       CALL SysFileTree targDir, "files.", "DO"  /* check, whether it exists     */
  157.       IF files.0 = 0 THEN
  158.       DO
  159.          .logError ~ new( "creating dir" pp( targDir ) "FAILED !" )
  160.          RETURN
  161.       END
  162.       SAY "dir" pp( targDir ) "exists already, no need to create it."
  163.    END
  164.    SAY
  165.  
  166.                 /* xcopy                */
  167.    command = "xcopy" source targDir "/s"
  168.    SAY command
  169.    ADDRESS CMD command
  170.    IF rc <> 0 THEN
  171.       .logError ~ new( "Error RC=" || pp( rc ) "while" pp( command ) )
  172.  
  173.                 /* rename               */
  174.    command = "ren" ( targDir || "\*.*" ) ( "*.MSG" )
  175.    ADDRESS CMD command
  176.    IF rc <> 0 THEN
  177.       .logError ~ new( "Error RC=" || pp( rc ) "while" pp( command ) )
  178.    SAY
  179.  
  180.    RETURN
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.         /* class for nick-name entries                                          */
  190. :: CLASS NickNames              PUBLIC
  191.  
  192. :: METHOD INIT                  CLASS 
  193.    EXPOSE nickNameList
  194.    nickNameList = .list ~ new
  195.  
  196. :: METHOD nickNameList           CLASS ATTRIBUTE
  197.  
  198. :: METHOD NewFromFile            CLASS          /* create nickNames from nick-name file         */
  199.  
  200.    self ~ init                                  /* reinitialize                 */
  201.    CALL STREAM .lam.nickName, "C", "OPEN READ"
  202.    bDirty = .false
  203.    DO WHILE CHARS( .lam.nickName ) > 0       /* loop over nickname file              */
  204.       tmpLine = LINEIN( .lam.nickName )      /* read a line                          */
  205.       PARSE VAR tmpLine ":" tag "." value
  206.  
  207.       IF TRANSLATE( tag ) = "NICK" THEN         /* a new nickname arrived               */
  208.       DO
  209.          IF bDirty THEN                         /* an older nickname to be created      */
  210.          DO
  211.             self ~ new( tmpDir )                /* create a nickname object             */
  212.             DROP tmpDir
  213.          END
  214.  
  215.          tmpDir = .directory ~ new              /* create a directory to store nickname entries */
  216.          bDirty = .true
  217.          tmpDir ~ setentry( tag, value )
  218.          ITERATE
  219.       END
  220.  
  221.  
  222.       tmpDir ~ setentry( tag, value )
  223.    END
  224.  
  225.    IF bDirty THEN self ~ new( tmpDir )          /* a leftover :) ?                      */
  226.  
  227.    CALL STREAM .lam.nickName, "C", "CLOSE"
  228.  
  229. :: METHOD dump                  CLASS
  230.    EXPOSE nickNameList
  231.  
  232.    SAY "Dumping all NickName objects, total of" pp( nickNameList ~ items )
  233.  
  234.    DO item OVER nickNameList                    /* loop over list of nicknames          */
  235.       item ~ dump
  236.       SAY
  237.    END
  238.  
  239.  
  240.  
  241. :: METHOD INIT                                  /* initalisation, storing directory for object  */
  242.    EXPOSE  ObjectData 
  243.    USE ARG ObjectData 
  244.  
  245.    self ~ class ~ nickNameList ~ insert( self )     /* add to set stored with class         */
  246.  
  247.  
  248. :: METHOD ObjectData   ATTRIBUTE               /* allow access to nickName             */
  249.  
  250. :: METHOD dump
  251.    EXPOSE ObjectData
  252.  
  253.    SAY LEFT( "NICK", 12) pp( ObjectData ~ nick )
  254.    tmpArray = sortCollection( ObjectData )
  255.    DO i = 1 TO ObjectData ~ items
  256.       IF tmpArray[ i, 1 ] = "NICK" THEN ITERATE
  257.  
  258.       SAY "   " LEFT( tmpArray[ i, 1 ], 8 ) pp( tmpArray[ i, 2 ] )
  259.    END
  260.    RETURN
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267. :: CLASS LogError       PUBLIC  /* class to log noted errors            */
  268.  
  269.         /* -------------------------------------- method definition (class) ----------- */
  270. :: METHOD Init                  CLASS
  271.    EXPOSE ObjectColl
  272.  
  273.    ObjectColl = .list ~ new
  274.  
  275. :: METHOD ObjectColl            CLASS   ATTRIBUTE       /* gathers errors       */
  276.  
  277. :: METHOD dump                  CLASS
  278.    EXPOSE ObjectColl
  279.  
  280.    IF ObjectColl ~ items = 0 THEN RETURN                /* no errors to show    */
  281.  
  282.    CALL BEEP 2000, 250; CALL BEEP 2000, 250; CALL BEEP 2000, 250
  283.  
  284.    CALL LINEOUT STDERR, "Total of" pp( ObjectColl ~ items ) "*ERRORS* noted:"
  285.    CALL LINEOUT STDERR, ""
  286.  
  287.    DO item OVER ObjectColl
  288.       CALL LINEOUT STDERR, "***" item
  289.    END
  290.  
  291.    CALL LINEOUT STDERR, CENTER( " End of dumping all errors ", 60, "-" )
  292.  
  293.  
  294.         /* -------------------------------------- method definition (instance) -------- */
  295. :: METHOD Init          /* save error text with class attribute */
  296.    USE ARG errorTxt
  297.  
  298.    self ~ class ~ ObjectColl ~ insert( errorTxt )
  299.  
  300.