/****** FindParked.pint ************************************************************

    NAME
      $VER: FindParked.pint 1.0 (21.2.96)

    Updated for PINT (22.2.97):
     Magnus Heino (nd95mho@Student.HGS.SE)

    AUTHOR
      Olaf Peters
      Kulmer Str. 7
      28237 Bremen

      op@hb2.maus.de / olf@informatik.uni-bremen.de

    SYNOPSIS
      Find all readable messages that have the "Parked" flag set for the
      current user.


    FUNCTION

      You will be asked if you want to display just the messages you have
      written (i.e. you are owner of) or all messages with the Parked flag
      set.

      The latter option has been implemented, beceause I sometimes use the
      Parked flag as a second postponed flag, so if I just scan for the
      message I'm owner of, I would not see these.


    CONFIGURATION
      to be called from PINT's groupwindow:

      ums.config Example:

      ( PINT.Rexx
        "GroupWindow     F1     UMS:Rexx/FindParked\n"
      )

    NEEDS
      For this script are needed:

      · PINT v2.0
      · UMSServer v11.20 or above (using the UMSDupAccount trick for login)

    BUGS
      none known. Please mail any problems to the above address.

    $HISTORY:

     21.2.96  1.0   : initial

******************************************************************************
*
*/

ProgramName = "FindParked.pint"
lf = '0a'x

/*** Startup ***/

options results

RC = 0
account = 0

signal on BREAK_C
signal on BREAK_D
signal on BREAK_E
signal on BREAK_F
signal on ERROR
signal on HALT
signal on IOERR
signal on SYNTAX

scanning = 0
account  = 0

/*/// "add libs" */

libname = "ums.library"
if ~show("L", "ums.library") then do
  if ~addlib("ums.library", 0, -210, 8) then do
    say "ums.library not found!"
    exit(20)
  end
end
call UMSInitConsts

/*\\\*/

/*/// "duplicate login" */

'info screen'
screen = result

'status'
if result ~= "GROUP" then do
    'request' ProgramName '"*Cancel" "This script may only be called from the groupwindow."'
    call HALT
end

'getaccount'
if (result = "RESULT") | (result = 0) then do
    'request' ProgramName '"*Cancel" "Cannot get account!"'
    call HALT
end ; else
    login = result

account = UMSLogin("", login, "")
if account = 0 then do
    'request' ProgramName '"*Cancel" "Cannot duplicate account!"'
    call HALT
end

/*\\\*/

'request' ProgramName '"**_All|_Own" "All parked messages or just your own?"'

own = (result ~= 1)

/* Clear all flags */
res = UMSSelectFlags(account, "LOCAL", UMSMakeFlags(), UMSMakeFlags(0,1,2),,, "LOCAL", UMSMakeFlags(), UMSMakeFlags())

/* set flag 1 on all parked messages */
res = UMSSelectFlags(account, "LOCAL", UMSMakeFlags(1), UMSMakeFlags(),,, "GLOBAL", UMSMakeFlags(UMSGSTAT_Parked), UMSMakeFlags(UMSGSTAT_Parked))

if own then
    /* set flag 2 on all messages the current user is owner of */
    res = UMSSelectFlags(account, "LOCAL", UMSMakeFlags(2), UMSMakeFlags(),,, "USER", UMSMakeFlags(UMSUSTAT_Owner), UMSMakeFlags(UMSUSTAT_Owner))

if own then
    /* merge the sets to get all parked messages the current user is owner of */
    res = UMSSelectFlags(account, "LOCAL", UMSMakeFlags(0), UMSMakeFlags(),,, "LOCAL", UMSMakeFlags(1,2), UMSMakeFlags(1,2))
else
    res = UMSSelectFlags(account, "LOCAL", UMSMakeFlags(0), UMSMakeFlags(),,, "LOCAL", UMSMakeFlags(1), UMSMakeFlags(1))

if res = 0 then do
    'request' ProgramName '"**Cancel" "No parked messages found."'
    call HALT
end

'beginscan'
scanning = 1

msgnum = 0

do forever
  msgnum = UMSSearchFlags(account, "LOCAL", UMSMakeFlags(0), UMSMakeFlags(0), msgnum)
  if msgnum = 0 then
    leave
  'scanmsg' msgnum
end /* do forever */

/*/// "Final cleanup" */

BREAK_C:
BREAK_D:
BREAK_E:
BREAK_F:
ERROR:
HALT:
IOERR:
SYNTAX:

/*** Logout ***/

if scanning ~= 0 then do
  'endscan'
  scanning = 0
end /* if */

if account ~= 0 then do
  call UMSLogout(account)
  account = 0
end

exit 0

/*** Support ***/

CheckErr: procedure expose account
  err = UMSErrNum(account)
  if err ~= 0 then do
    'request' ProgramName '"*Cancel" "UMS Error #' || err || ': ' || UMSErrTxt(account)'"'
  end
return

/*\\\*/

