home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxvim.zip / MSGREAD.CMD < prev    next >
OS/2 REXX Batch file  |  1994-08-09  |  16KB  |  375 lines

  1. /** Msgread.cmd **/
  2. /*********************************************/
  3. /*                                           */
  4. /* Command line syntax:                      */
  5. /*                                           */
  6. /* msgread db_path user_password user_name   */
  7. /*                                           */
  8. /*                                           */
  9. /*********************************************/
  10. ARG db_path user_pw user_name
  11. '@echo off'
  12. '@cls'
  13. Say 'RexxVIM Message Read Demonstration Program'
  14. Say
  15.  
  16. /* Unload the function upon error */
  17. SIGNAL ON ERROR NAME done
  18.  
  19. /* Prompt for the parameters if not passed on the */
  20. /* command line                                   */
  21. if LENGTH(STRIP(db_path)) = 0 then do
  22.    Say 'Enter Postoffice Directory -'
  23.    PARSE PULL db_path .
  24.    Say
  25.    Say 'Enter User Name -'
  26.    PARSE PULL user_name
  27.    Say 'Enter Password -'
  28.    PARSE PULL user_pw
  29. end  /* Do */
  30.  
  31.  
  32. /* Load the RexxVIM extensions to Rexx */
  33. rc = RxFuncAdd('RxVIMLoadFuncs', 'REXXVIM', 'RxVIMLoadFuncs')
  34. if rc <> 0 then do
  35.    Say
  36.    Say 'RexxVIM failed to load, return code' rc
  37.    Say
  38.    Say 'Functions have been released.  Retry program.'
  39.    signal done
  40. end  /* Do */
  41. call RxVIMLoadFuncs
  42. Say 'Functions are now loaded'
  43. Say
  44.  
  45.  
  46. /* Initialize the VIM subsystem */
  47. rc = RxVIMInitialize()
  48. if (rc > 0) then call vimerr
  49.  
  50.  
  51. /* Open a session with the postoffice using the parameters */
  52. /* provided by the user                                    */
  53. rc = RxVIMOpenSession(db_path,user_name,user_pw,Session)
  54. if (rc > 0) then call vimerr
  55.  
  56.  
  57. /* Open the default message container -- Inbox */
  58. rc = RxVIMOpenMessageContainer(Session,'','Inbox')
  59. if (rc > 0) then call vimerr
  60.  
  61.  
  62. /* Display all messages in Inbox if they exist */
  63.  
  64.      /* Enumerate messages in container -- Inbox */
  65.      pos = ''                           /* Start at the beginning of the container */
  66.      skipcnt = 1                        /* Move forward through the container one at a time */
  67.      mcount  = 1                        /* Retrieve 1 message for each call */
  68.      filter  = 'VIMSEL_NO_FILTER'       /* No filter, return all messages in inbox */
  69.      fdata   = ''                       /* No filter data */
  70.      flags   = 'VIM_NO_FLAGS'           /* No enumeration flags, return all messages in inbox */
  71.      more    = ''                       /* Set the value of more to nul */
  72.      action  = 'N'                      /* Set the value of repeat loop indicator to N */
  73.  
  74.      AttrDesc.0 = 3                               /* Retrieve 3 attributes for each message */
  75.      AttrDesc.1.Selector = 'VIMSEL_REF'           /* 1st attribute is the message reference number */
  76.      AttrDesc.1.Buffer   = 'MsgRefNo'             /* store results in this stem variable */
  77.      AttrDesc.2.Selector = 'VIMSEL_SUBJECT'       /* 2nd attribute is the message subject */
  78.      AttrDesc.2.Buffer   = 'Subject'              /* store results in this stem variable */
  79.      AttrDesc.3.Selector = 'VIMSEL_UNREAD_MAIL'   /* 3rd attribute is if unread */
  80.      AttrDesc.3.Buffer   = 'Unread'               /* store results in this stem variable */
  81.  
  82.      do until TRANSLATE(SUBSTR(action,1,1)) = 'X'
  83.  
  84.           /* Continue retrieving message info until user enters N */
  85.  
  86.           rc = RxVIMEnumerateMessages(Inbox,'pos',skipcnt,'AttrDesc','mcount',filter,fdata,flags,'more')
  87.           if (rc > 0) then call vimerr
  88.  
  89.           /* Display results */
  90.          'cls'
  91.           Say 'RexxVIM - (c) Innovative Business Technologies, Inc'
  92.           Say
  93.           Say 'Message Read Demo'
  94.           Say
  95.           Say '--------------------------------------------------------'
  96.           Say '    Message =' MsgRefNo.1
  97.           Say '    Subject =' Subject.1
  98.           Say '    Unread  =' Unread.1
  99.           Say '--------------------------------------------------------'
  100.           Say
  101.           Say 'Select an action for this message'
  102.           Say
  103.           Say '   N - Display the next message'
  104.           Say '   I - Display message items'
  105.           Say '   A - Display message recipients'
  106.           Say '   R - Read the first 60 characters of first message item'
  107.           Say '   E - Extract the message to the EXTRACT.tst file'
  108.           Say '   L - Display the message items for the extracted file'
  109.           Say '   X - Exit demo now'
  110.           Say
  111.           Say 'Enter your selection below:'
  112.           PULL action
  113.  
  114.           /* Process the selection entered.  X will fall through the select statement */
  115.           select
  116.              when TRANSLATE(SUBSTR(action,1,1)) = 'I' then do
  117.                 /* Open message */
  118.                 rc = RxVIMOpenMessage(Inbox,MsgRefNo.1,'','MsgHandle')
  119.                 if (rc > 0) then call vimerr
  120.  
  121.                 /* Retrieve all of the items for this message */
  122.                 ipos      = ''
  123.                 icount   = 20
  124.                 imore    = ''
  125.                 ItemDesc = ''
  126.                 ifilter   = 'VIMSEL_NO_FILTER'
  127.                 ifdata    = ''
  128.  
  129.                 rc = RxVIMEnumerateMessageItems(MsgHandle,'ipos',1,'icount','ItemDesc',,
  130.                                                 ifilter,ifdata,'imore')
  131.                 if (rc > 0) then call vimerr
  132.  
  133.                 'cls'
  134.                 Say 'RexxVIM - (c) Innovative Business Technologies, Inc'
  135.                 Say
  136.                 Say ' Message Information with Item Detail'
  137.                 Say '--------------------------------------------------------'
  138.                 Say '    Message =' MsgRefNo.1
  139.                 Say '    Subject =' Subject.1
  140.                 Say '    Unread  =' Unread.1
  141.                 Say '--------------------------------------------------------'
  142.  
  143.                 loopcnt = 1
  144.                 do while (loopcnt <= icount)
  145.                    /* Display each item descriptor entry */
  146.                    Say '    Item Class  -' ItemDesc.loopcnt.CLASS
  147.                    Say '    Item Type   -' ItemDesc.loopcnt.TYPE
  148.                    Say '    Item Name   -' ItemDesc.loopcnt.NAME
  149.                    Say '    Item Path   -' ItemDesc.loopcnt.PATH
  150.                    Say '    Item Size   -' ItemDesc.loopcnt.SIZE
  151.                    Say '    Item Ref No -' ItemDesc.loopcnt.REF
  152.                    Say '--------------------------------------------------------'
  153.  
  154.                    loopcnt = loopcnt + 1
  155.                 end /* do */
  156.                 'pause'
  157.                 /* Close the message */
  158.                 rc = RxVIMCloseMessage(MsgHandle)
  159.                 if (rc > 0) then call vimerr
  160.              end  /* Do */
  161.              when TRANSLATE(SUBSTR(action,1,1)) = 'R' then do
  162.                 /* Open message */
  163.                 rc = RxVIMOpenMessage(Inbox,MsgRefNo.1,'','MsgHandle')
  164.                 if (rc > 0) then call vimerr
  165.  
  166.                 /* Retrieve all of the items for this message */
  167.                 ipos      = ''
  168.                 icount    = 20
  169.                 imore     = ''
  170.                 ItemDesc  = ''
  171.                 ifilter   = 'VIMSEL_CLASS'        /* Filter on item class */
  172.                 ifdata    = 'VIMSEL_NOTE_PART'    /* Retrieve only text items */
  173.  
  174.                 rc = RxVIMEnumerateMessageItems(MsgHandle,'ipos',1,'icount','ItemDesc',,
  175.                                                 ifilter,ifdata,'imore')
  176.                 if (rc > 0) then call vimerr
  177.                 /* Retrieve the text for the first message item */
  178.                 tconvert          = 'VIM_TEXT'         /* Use text conversion   */
  179.                 tflags            = ''                 /* No conversion flags   */
  180.  
  181.                 /* Open the first message item */
  182.                 rc = RxVIMOpenMessageItem(MsgHandle,ItemDesc.1.REF,tconvert,tflags,'ItemPtr')
  183.                 if (rc > 0) then call vimerr
  184.  
  185.                 /* Read the text from the open message */
  186.                 BufDesc.Buffer    = 'ItemText'         /* Return buffer name    */
  187.                 BufDesc.Size      = 60                 /* Size of return buffer */
  188.  
  189.                 rc = RxVIMReadMessageItem(ItemPtr,'BufDesc')
  190.  
  191.                 'cls'
  192.                 Say 'RexxVIM - (c) Innovative Business Technologies, Inc'
  193.                 Say
  194.                 Say ' Message Information with Item Detail'
  195.                 Say '--------------------------------------------------------'
  196.                 Say '    Message =' MsgRefNo.1
  197.                 Say '    Subject =' Subject.1
  198.                 Say '    Unread  =' Unread.1
  199.                 Say '--------------------------------------------------------'
  200.  
  201.                 /* Display each item descriptor entry */
  202.                 Say '    Item Class  -' ItemDesc.1.CLASS
  203.                 Say '    Item Type   -' ItemDesc.1.TYPE
  204.                 Say '    Item Name   -' ItemDesc.1.NAME
  205.                 Say '    Item Path   -' ItemDesc.1.PATH
  206.                 Say '    Item Size   -' ItemDesc.1.SIZE
  207.                 Say '    Item Ref No -' ItemDesc.1.REF
  208.                 Say '--------------------------------------------------------'
  209.                 Say ' Message Contents for first item (max 60 characters) -'
  210.                 Say
  211.                 Say SUBSTR(ItemText,1,60)
  212.                 Say '--------------------------------------------------------'
  213.                 'pause'
  214.  
  215.                 /* Close the message item */
  216.                 rc = RxVIMCloseMessageItem( ItemPtr )
  217.                 if (rc > 0) then call vimerr
  218.  
  219.                 /* Close the message */
  220.                 rc = RxVIMCloseMessage(MsgHandle)
  221.                 if (rc > 0) then call vimerr
  222.              end  /* Do */
  223.              when TRANSLATE(SUBSTR(action,1,1)) = 'A' then do
  224.                 /* Open message */
  225.                 rc = RxVIMOpenMessage(Inbox,MsgRefNo.1,'','MsgHandle')
  226.                 if (rc > 0) then call vimerr
  227.  
  228.                 /* Retrieve all of the items for this message */
  229.                 Receipt.0 = 1                               /* Retrieve 1 attributes for each recipient */
  230.                 Receipt.1.Selector = 'VIMSEL_NAME'          /* 1st attribute is the addressee */
  231.                 Receipt.1.Buffer   = 'SentTo'               /* store results in this stem variable */
  232.                 rtype   = 'VIMSEL_TO'
  233.                 rpos    = ''
  234.                 rcount  = 20
  235.                 rmore   = ''
  236.  
  237.                 rc = RxVIMEnumerateMessageRecipients(MsgHandle,rtype,'rpos',1,'Receipt','rcount','rmore')
  238.                 if (rc > 0) then call vimerr
  239.  
  240.                 'cls'
  241.                 Say 'RexxVIM - (c) Innovative Business Technologies, Inc'
  242.                 Say
  243.                 Say ' Message Information with Item Detail'
  244.                 Say '--------------------------------------------------------'
  245.                 Say '    Message =' MsgRefNo.1
  246.                 Say '    Subject =' Subject.1
  247.                 Say '    Unread  =' Unread.1
  248.                 Say '--------------------------------------------------------'
  249.  
  250.                 loopcnt = 1
  251.                 do while (loopcnt <= rcount)
  252.                    /* Display each item descriptor entry */
  253.                    Say '    Sent To  -' SentTo.loopcnt
  254.                    Say '--------------------------------------------------------'
  255.  
  256.                    loopcnt = loopcnt + 1
  257.                 end /* do */
  258.                 'pause'
  259.                 /* Close the message */
  260.                 rc = RxVIMCloseMessage(MsgHandle)
  261.                 if (rc > 0) then call vimerr
  262.              end  /* Do */
  263.              when TRANSLATE(SUBSTR(action,1,1)) = 'E' then do
  264.                 /* Open message */
  265.                 rc = RxVIMOpenMessage(Inbox,MsgRefNo.1,'','MsgHandle')
  266.                 if (rc > 0) then call vimerr
  267.  
  268.                 /* Extract the message to the file EXTRACT.tst */
  269.                 'erase extract.tst'
  270.                 rc = RxVIMExtractMessage(MsgHandle,'VIM_NO_FLAGS','extract.tst')
  271.                 if (rc > 0) then call vimerr
  272.  
  273.                 /* Close the message */
  274.                 rc = RxVIMCloseMessage(MsgHandle)
  275.                 if (rc > 0) then call vimerr
  276.              end  /* Do */
  277.              when TRANSLATE(SUBSTR(action,1,1)) = 'L' then do
  278.                 /* Open extracted message */
  279.                 rc = RxVIMOpenExtractedMessage(Session,'extract.tst','MsgHandle')
  280.                 if (rc > 0) then call vimerr
  281.  
  282.                 /* Retrieve all of the items for this message */
  283.                 ipos      = ''
  284.                 icount   = 20
  285.                 imore    = ''
  286.                 ItemDesc = ''
  287.                 ifilter   = 'VIMSEL_NO_FILTER'
  288.                 ifdata    = ''
  289.  
  290.                 rc = RxVIMEnumerateMessageItems(MsgHandle,'ipos',1,'icount','ItemDesc',,
  291.                                                 ifilter,ifdata,'imore')
  292.                 if (rc > 0) then call vimerr
  293.  
  294.                 'cls'
  295.                 Say 'RexxVIM - (c) Innovative Business Technologies, Inc'
  296.                 Say
  297.                 Say ' Message Information with Item Detail'
  298.                 Say '--------------------------------------------------------'
  299.                 Say '    Extracted Message = EXTRACT.tst'
  300.                 Say '--------------------------------------------------------'
  301.  
  302.                 loopcnt = 1
  303.                 do while (loopcnt <= icount)
  304.                    /* Display each item descriptor entry */
  305.                    Say '    Item Class  -' ItemDesc.loopcnt.CLASS
  306.                    Say '    Item Type   -' ItemDesc.loopcnt.TYPE
  307.                    Say '    Item Name   -' ItemDesc.loopcnt.NAME
  308.                    Say '    Item Path   -' ItemDesc.loopcnt.PATH
  309.                    Say '    Item Size   -' ItemDesc.loopcnt.SIZE
  310.                    Say '    Item Ref No -' ItemDesc.loopcnt.REF
  311.                    Say '--------------------------------------------------------'
  312.  
  313.                    loopcnt = loopcnt + 1
  314.                 end /* do */
  315.                 'pause'
  316.                 /* Close the message */
  317.                 rc = RxVIMCloseMessage(MsgHandle)
  318.                 if (rc > 0) then call vimerr
  319.              end  /* Do */
  320.           otherwise
  321.           end  /* select */
  322.  
  323.           /* End the loop if no more messages to retrieve */
  324.           if more = 'False' then do
  325.              Say 'All messages have been retrieved'
  326.              action = 'X'
  327.           end  /* Do */
  328.  
  329.      end /* do */
  330.  
  331.  
  332. /* Close the message container -- Inbox */
  333. rc = RxVIMCloseMessageContainer(Inbox)
  334. if (rc > 0) then call vimerr
  335.  
  336.  
  337. /* Close the session with the postoffice */
  338. rc = RxVIMCloseSession(Session)
  339. if (rc > 0) then call vimerr
  340.  
  341.  
  342. /* Terminate the active VIM subsystem connection */
  343. rc = RxVIMTerminate()
  344. if (rc > 0) then call vimerr
  345. signal done
  346.  
  347.  
  348. /***** VIMErr *******/
  349.  
  350. /* If an error occurs, this function will return the text */
  351. /* associated with the error.  Extended text may be       */
  352. /* displayed if it exists for the specified error.        */
  353.  
  354. VIMERR:
  355.  
  356. erc = RxVIMStatusText(Session,rc,'Status')
  357. Say
  358. Say '|-Error Information ------------------------------------|'
  359. Say '  Error Text -' status.1
  360. Say
  361. Say '  Ext Status -' status.2
  362. rc = RxVIMTerminate()
  363. signal done
  364.  
  365.  
  366. /* The done section will unload the RexxVIM extensions */
  367. /* and exit the program                                */
  368. DONE:
  369. /*** Drop all of the external functions ***/
  370. call RxVIMDropFuncs
  371. Say '|-------------------------------------------------------|'
  372. Say 'Demo Complete.  All functions released'
  373. 'pause'
  374. exit
  375.