home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1997 #5 / AmigaPlus_Extra-CD_5-97.iso / online-tools / mail / ems / rexx / dmreply.ems < prev    next >
Text File  |  1993-08-30  |  45KB  |  1,591 lines

  1. /***************/
  2. /* DMreply.ems */
  3. /**********************/
  4. /* Commands:          */
  5. /*                    */
  6. /* EDIT             1 */
  7. /* EDIT_FILE        2 */
  8. /* WRITE            3 */
  9. /* WRITE_FILE       4 */
  10. /* REPLY            5 */
  11. /* REPLY_FORWARD    6 */
  12. /* REPLY_MULTISEND  7 */
  13. /* FORWARD          8 */
  14. /* MULTISEND        9 */
  15. /* RESEND          10 */
  16. /* ARCHIVE         11 */
  17. /* CONFIG          12 */
  18. /*                    */
  19. /* ASK                */
  20. /**********************/
  21. /* Arguments        */
  22. /*                  */
  23. /* NO_REQS          */
  24. /* CARBON_COPY      */
  25. /* REPLY_KLUDGES    */
  26. /* CHOOSE_OPENING   */
  27. /* CHOOSE_COD       */
  28. /* CHOOSE_SIGNATURE */
  29. /* CHOOSE_ORIGIN    */
  30. /**************************************/
  31. /* $VER: DMreply.ems 1.0 (29.08.93)   */
  32. /**************************************/
  33.  
  34. script_name    = 'DMreply'
  35. script_version = 'v1.0'
  36.  
  37.  
  38. options results
  39. signal on error
  40. signal on syntax
  41.  
  42. parse arg session_number src_area msg_num cmd_name cmd_args
  43.  
  44.  
  45. cmd_args = strip( cmd_args, 'B' )
  46.  
  47. if( ~show( 'l', "rexxsupport.library" ) ) then
  48. do
  49.    if( ~addlib( "rexxsupport.library", 0, -30, 0 ) )then
  50.    do
  51.       say "Could not open rexxsupport.library"
  52.       exit 10
  53.    end
  54. end
  55.  
  56. if( ~show( 'l', "ems_rexx.library" ) ) then
  57. do
  58.    if( ~addlib( "ems_rexx.library", 0, -30, 0 ) )then
  59.    do
  60.       say "Could not open ems_rexx.library"
  61.       exit 10
  62.    end
  63. end
  64.  
  65. if datatype( session_number, 'N' ) ~= 1  then signal Usage
  66. if datatype( msg_num       , 'N' ) ~= 1  then signal Usage
  67. if           src_area               = '' then signal Usage
  68.  
  69.  
  70. reply_cfg.         = ''
  71. dst_areas.0        = 0
  72. carbon_copy_name.0 = 0
  73. carbon_copy_addr.0 = 0
  74.  
  75. /*
  76. ** Search for areas of type MAIL
  77. */
  78. call EMS_Areas_Mail( 'areas_mail' )
  79.  
  80.  
  81.  
  82. cmd_num = ParseCommand( src_area, cmd_name, cmd_args )
  83.  
  84. if cmd_num = 0 then signal ScriptExit
  85.  
  86.  
  87. mask = Local_Cfg_Get( 'Cmd_AskAreas' )
  88.  
  89. if mask = 0 then
  90. do
  91.  
  92.    call EMS_Add_To_Stem( 'dst_areas', src_area )
  93.  
  94. end
  95.  
  96. if mask = 1 then
  97. do
  98.  
  99.    if EMS_Area_Select( 'area' ) = 'OK' then call EMS_Add_To_Stem( 'dst_areas', area )
  100.  
  101. end
  102.  
  103. if mask = 2 then
  104. do
  105.  
  106.    area = ''
  107.  
  108.    do while EMS_Area_Select( 'area' ) = 'OK'
  109.  
  110.       call EMS_Add_To_Stem( 'dst_areas', area ); area = ''
  111.  
  112.    end
  113.  
  114. end
  115.  
  116.  
  117. if Local_Cfg_GetBit( 'Cmd_Actions', 'Carbon_Copy' ) = 'TRUE' then
  118. do
  119.  
  120.    addr = ''
  121.  
  122.    do while EMS_User_Select( 'name', 'addr' ) = 'OK'
  123.  
  124.       call EMS_Add_To_Stem( 'carbon_copy_name', name )
  125.       call EMS_Add_To_Stem( 'carbon_copy_addr', addr )
  126.  
  127.       addr = ''
  128.  
  129.    end
  130.  
  131. end
  132.  
  133.  
  134. /* No areas where to write. */
  135. if dst_areas.0 = 0 then signal ScriptExit
  136.  
  137.  
  138. if cmd_num = 12 then /* CONFIG */
  139. do
  140.  
  141.    if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Opening' ) = 'TRUE' then
  142.    do
  143.       call ChooseOpening( src_area, 'TRUE' )
  144.  
  145.       if Local_Cfg_Get( 'Req_Failed' ) = 'TRUE' then signal ScriptExit
  146.    end
  147.  
  148.    if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Signature' ) = 'TRUE' then
  149.    do
  150.       call ChooseSignature( src_area, 'TRUE' )
  151.  
  152.       if Local_Cfg_Get( 'Req_Failed' ) = 'TRUE' then signal ScriptExit
  153.    end
  154.  
  155.    if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_COD' ) = 'TRUE' then
  156.    do
  157.       call ChooseCOD( src_area, 'TRUE' )
  158.  
  159.       if Local_Cfg_Get( 'Req_Failed' ) = 'TRUE' then signal ScriptExit
  160.    end
  161.  
  162.    call Global_Cfg_Set( src_area, 'ReplyKludges'    , Local_Cfg_Get( 'Cfg_ReplyKludges'     ) )
  163.    call Global_Cfg_Set( src_area, 'Opening'         , Local_Cfg_Get( 'Cfg_Opening'          ) )
  164.    call Global_Cfg_Set( src_area, 'Signature'       , Local_Cfg_Get( 'Cfg_Signature'        ) )
  165.    call Global_Cfg_Set( src_area, 'COD'             , Local_Cfg_Get( 'Cfg_COD'              ) )
  166.    call Global_Cfg_Set( src_area, 'ChooseOpening'   , Local_Cfg_Get( 'Cfg_ChooseOpening'    ) )
  167.    call Global_Cfg_Set( src_area, 'ChooseSignature' , Local_Cfg_Get( 'Cfg_ChooseSignature'  ) )
  168.    call Global_Cfg_Set( src_area, 'ChooseCOD'       , Local_Cfg_Get( 'Cfg_ChooseCOD'        ) )
  169.    call Global_Cfg_Set( src_area, 'ChooseOrigin'    , Local_Cfg_Get( 'Cfg_ChooseOrigin'     ) )
  170.    call Global_Cfg_Set( src_area, 'NoDomainInOrigin', Local_Cfg_Get( 'Cfg_NoDomainInOrigin' ) )
  171.  
  172.    signal ScriptExit
  173.  
  174. end
  175.  
  176.  
  177. file = EMS_Var_Local( 'SCRIPT_MSG_FILE' )
  178. if session_number ~= 0 then file = file || session_number
  179.  
  180. call Local_Cfg_Set( 'Msg_File'  , file                          )
  181. call Local_Cfg_Set( 'Sysop_Name', EMS_Var_Local( 'SYSOP_NAME' ) )
  182.  
  183.  
  184. if Local_Cfg_GetBit( 'Cmd_Actions', 'Read_Old_Msg' ) = 'FALSE' then msg_num = 0
  185.  
  186.  
  187. /*
  188. ** Read the message to act on.
  189. */
  190. sel = ''
  191.  
  192. if cmd_num = 2 | cmd_num = 4 then
  193. do
  194.  
  195.    if EMS_Area_File_DBname( src_area ) ~= '' then sel = 'FILE'
  196.  
  197. end
  198. else
  199. do
  200.  
  201.    if EMS_Area_Msg_DBname( src_area ) ~= '' then sel = 'MSG'
  202.  
  203. end
  204.  
  205. if sel = '' then
  206. do
  207.  
  208.    call EMS_Do_Request( "Can't exec requested command (wrong database)!" )
  209.  
  210.    signal ScriptExit
  211.  
  212. end
  213.  
  214. if msg_num ~= 0 then call EMS_Item_Alloc( 'reply_msg', src_area, sel, msg_num )
  215.                 else call EMS_Item_Alloc( 'reply_msg', src_area, sel          )
  216.  
  217. call Local_Cfg_Set( 'Header_From'     , EMS_Item_Header_From(         'reply_msg' ) )
  218. call Local_Cfg_Set( 'Header_To'       , EMS_Item_Header_To(           'reply_msg' ) )
  219. call Local_Cfg_Set( 'Header_Subject'  , EMS_Item_Header_Subject(      'reply_msg' ) )
  220. call Local_Cfg_Set( 'Header_Date'     , EMS_Item_Header_Date_Created( 'reply_msg' ) )
  221. call Local_Cfg_Set( 'Header_Addr_From', EMS_Item_Header_Address_From( 'reply_msg' ) )
  222. call Local_Cfg_Set( 'Header_Addr_To'  , EMS_Item_Header_Address_To(   'reply_msg' ) )
  223.  
  224.  
  225. area_name = dst_areas.1
  226.  
  227. call DeleteMsgFile( file )
  228.  
  229.  
  230. if cmd_num = 11 then /* ARCHIVE */
  231. do
  232.  
  233.    mode.0 = 4
  234.    mode.1 = 'Default'
  235.    mode.2 = 'File (APPEND)'
  236.    mode.3 = 'File (OVERWRITE)'
  237.    mode.4 = 'Printer'
  238.  
  239.    sel = 1
  240.    res = EMS_Do_Choice_Single( 'Archive Message As', 'mode', 'sel' )
  241.  
  242.    if res ~= 'OK' then signal ScriptExit
  243.  
  244.    textDir = EMS_Var_Local( 'SCRIPT_TEXT_DIR' ); if textDir = '' then textDir = 'EMS:'
  245.  
  246.    arcfile = ''
  247.  
  248.    if sel = 4 then arcfile = 'prt:'
  249.  
  250.    if sel = 2 | sel = 3 then
  251.    do
  252.  
  253.       arcfile = textDir
  254.  
  255.       saved_CD = PRAGMA( 'D' )
  256.  
  257.       call PRAGMA( 'D', textDir )
  258.  
  259.       res = EMS_File_Select( 'Select Archive File', 'arcfile' )
  260.  
  261.       call PRAGMA( 'D', saved_CD )
  262.  
  263.       if res ~= 'OK' then signal ScriptExit
  264.  
  265.       if arcfile = '' then sel = 1
  266.  
  267.    end
  268.  
  269.    if arcfile = '' then arcfile = textDir || src_area || '.txt'
  270.  
  271.    if sel = 3 | sel = 4 then file_mode = 'WRITE'
  272.                         else file_mode = 'APPEND'
  273.  
  274.    if file_mode = 'APPEND' & exists( arcfile ) ~= 1 then file_mode = 'WRITE'
  275.  
  276.    if open( 'tempname', arcfile, file_mode ) ~= 1 then
  277.    do
  278.       say "| Can't open '" || arcfile || "' file for output."
  279.       call ScriptExit
  280.    end
  281.  
  282.    from    = overlay( EMS_Item_Header_From(         'reply_msg' ), '                                   ' )
  283.    addfrom =          EMS_Item_Header_Address_From( 'reply_msg'                                          )
  284.    to      = overlay( EMS_Item_Header_To(           'reply_msg' ), '                                   ' )
  285.    addto   =          EMS_Item_Header_Address_To(   'reply_msg'                                          )
  286.    subject =          EMS_Item_Header_Subject(      'reply_msg'                                          )
  287.    date    = overlay( EMS_Item_Header_Date_Created( 'reply_msg' ), '                                   ' )
  288.  
  289.    call writeln( 'tempname', " "                                                                       )
  290.    call writeln( 'tempname', "-------------------------- Archived Message ---------------------------" )
  291.    call writeln( 'tempname', "From   :" || from    || ' at '     || addfrom                            )
  292.    call writeln( 'tempname', "To     :" || to      || ' at '     || addto                              )
  293.    call writeln( 'tempname', "Subject:" || subject                                                     )
  294.    call writeln( 'tempname', "Date   :" || date    || ' Area : ' || src_area                           )
  295.    call writeln( 'tempname', "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" )
  296.    call close(   'tempname'                                                                                          )
  297.  
  298.    call EMS_Item_File_Write( 'reply_msg', 'text', arcfile, 'APPEND' )
  299.       
  300.    signal ScriptExit
  301.  
  302. end
  303.  
  304.  
  305.  
  306. if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Opening' ) = 'TRUE' then call InsertOpening( file, area_name )
  307.  
  308. if Local_Cfg_GetBit( 'Cmd_Actions', 'Quote_Text' ) = 'TRUE' then
  309. do
  310.  
  311.    /*
  312.    ** Get first letter of name and firstname.
  313.    */
  314.    from    = Local_Cfg_Get( 'Header_From' )
  315.    Quoting = substr( from, 1, 1 )
  316.  
  317.    if word( from, 2 ) = '' then Quoting = Quoting || substr(       from, 2  , 1    )
  318.                            else Quoting = Quoting || substr( word( from, 2 ), 1, 1 )
  319.  
  320.    if Local_Cfg_Get( 'Cfg_ReplyKludges' ) = 'TRUE' then format_mode = 'TEARORIGIN SEENBYPATH OTHERKLUDGES'
  321.                                                    else format_mode = ''
  322.  
  323.    call EMS_Item_Lines_Format( 'reply_msg', Quoting || '>',  75, format_mode )
  324.  
  325. end
  326.  
  327.  
  328. call EMS_Item_File_Write( 'reply_msg', 'text', file, 'APPEND' )
  329.  
  330.  
  331. if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Signature' ) = 'TRUE' then call InsertSignature( file, area_name )
  332. if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_COD'       ) = 'TRUE' then call InsertCOD(       file, area_name )
  333.  
  334.  
  335. mode = Local_Cfg_Get( 'Cmd_Header' )
  336. if mode = 2 then
  337. do
  338.  
  339.    call BuildREPLY( 'reply_msg' )
  340.  
  341. end
  342. else
  343. do
  344.  
  345.    res = Local_Cfg_GetBit( 'Cmd_Actions', 'Reduce_Kludges' )
  346.  
  347.    if res = 'TRUE' then call ReduceKludges(         'reply_msg'           )
  348.                    else call EMS_Item_Lines_Delete( 'reply_msg', 'header' )
  349.  
  350. end
  351.  
  352. if Local_Cfg_GetBit( 'Cmd_Actions', 'Reset_FATT' ) = 'TRUE' then
  353. do
  354.  
  355.    call EMS_Item_Header_Flag( 'reply_msg', 'FATT', 'OFF' )
  356.  
  357. end
  358.  
  359. do i=1 to dst_areas.0
  360.  
  361.    area_name = dst_areas.i
  362.  
  363.    call EMS_Item_Area( 'reply_msg', area_name )
  364.  
  365.    /*
  366.    ** Get infos about the message area.
  367.    */
  368.    call Local_Cfg_Set( 'Area_Name',                          area_name     )
  369.    call Local_Cfg_Set( 'Area_Type', upper( EMS_Area_Type(    area_name ) ) )
  370.    call Local_Cfg_Set( 'Area_Addr',        EMS_Area_Address( area_name )   )
  371.  
  372.  
  373.    if Local_Cfg_GetBit( 'Cmd_Actions', 'Reset_Msg_Number' ) = 'TRUE' then call EMS_Item_Number( 'reply_msg', 0 )
  374.  
  375.  
  376.    header = Local_Cfg_Get( 'Cmd_Header' )
  377.  
  378.    if header = 1 then
  379.    do
  380.       call EMS_Item_Header_From(         'reply_msg', Local_Cfg_Get( 'Sysop_Name' ) )
  381.       call EMS_Item_Header_Address_From( 'reply_msg', Local_Cfg_Get( 'Area_Addr'  ) )
  382.       call EMS_Item_Header_Address_To(   'reply_msg', ''                            )
  383.  
  384.    end
  385.  
  386.    if header = 2 then
  387.    do
  388.  
  389.       subject = Local_Cfg_Get( 'Header_Subject' )
  390.  
  391.       if upper( left( subject, 3 ) ) ~= 'RE:' then subject = 'Re:' subject
  392.  
  393.       addr_to   = Local_Cfg_Get( 'Header_Addr_From' )
  394.       addr_area = Local_Cfg_Get( 'Area_Addr'        )
  395.  
  396.       if Local_Cfg_Get( 'Area_Type' ) ~= 'MAIL' & EMS_Address_IsFIDO( addr_area ) = 'TRUE' then addr_from = addr_area
  397.       else                                                                                      addr_from = EMS_Aka_Nearer( addr_to )
  398.  
  399.       call EMS_Item_Header_From(         'reply_msg', Local_Cfg_Get( 'Sysop_Name'  ) )
  400.       call EMS_Item_Header_To(           'reply_msg', Local_Cfg_Get( 'Header_From' ) )
  401.       call EMS_Item_Header_Subject(      'reply_msg',                 subject        )
  402.       call EMS_Item_Header_Address_From( 'reply_msg',                 addr_from      )
  403.       call EMS_Item_Header_Address_To(   'reply_msg',                 addr_to        )
  404.  
  405.    end
  406.  
  407.    dump.0 = 0
  408.  
  409.    call EMS_Item_SeenBy_Set(  'reply_msg', 'dump'        )
  410.    call EMS_Item_Path_Set(    'reply_msg', 'dump'        )
  411.    call EMS_Item_Header_Flag( 'reply_msg', 'SENT', 'OFF' )
  412.  
  413.    if Local_Cfg_Get( 'Area_Type' ) = 'MAIL' then
  414.    do
  415.  
  416.       call EMS_Item_Header_Flag( 'reply_msg', 'PVT', 'ON' )
  417.  
  418.    end
  419.    else
  420.    do
  421.  
  422.       if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Origin' ) = 'TRUE' then call InsertOrigin( 'reply_msg', area_name )
  423.  
  424.    end
  425.  
  426.    if Local_Cfg_GetBit( 'Cmd_Actions', 'Call_Editor' ) = 'TRUE' then
  427.    do
  428.  
  429.       cmd_pre  = EMS_Var_Local( 'SCRIPT_EDITOR_NAME' )
  430.       cmd_post = EMS_Var_Local( 'SCRIPT_EDITOR_ARGS' )
  431.  
  432.       select
  433.          when cmd_num = 1 then do; title = "Edit a Message"           ; mode = ""               ; end
  434.          when cmd_num = 2 then do; title = "Edit a File"              ; mode = ""               ; end
  435.          when cmd_num = 3 then do; title = "Write a Message"          ; mode = ""               ; end
  436.          when cmd_num = 4 then do; title = "Upload a File"            ; mode = ""               ; end
  437.          when cmd_num = 5 then do; title = "Reply to a Message"       ; mode = "NOACTIVE"       ; end
  438.          when cmd_num = 6 then do; title = "Reply&Forward a Message"  ; mode = "NOACTIVE"       ; end
  439.          when cmd_num = 7 then do; title = "Reply&MultiSend a Message"; mode = "NOACTIVE"       ; end
  440.          when cmd_num = 8 then do; title = "Forward a Message"        ; mode = "NOACTIVE NOEDIT"; end
  441.          when cmd_num = 9 then do; title = "Multisend a Message"      ; mode = ""               ; end
  442.          otherwise             do; title = ""                         ; mode = ""               ; end
  443.       end
  444.  
  445.       if title ~= '' then
  446.       do
  447.  
  448.          req_res = EMS_Item_Header_Edit( 'reply_msg', title, mode, cmd_pre file cmd_post )
  449.  
  450.          if req_res ~= 'OK' then call ScriptExit
  451.  
  452.       end
  453.  
  454.       call Local_Cfg_SetBit( 'Cmd_Actions', 'Call_Editor', 'FALSE' )
  455.  
  456.    end
  457.  
  458.    if Local_Cfg_Get( 'Cfg_NoDomainInOrigin' ) = 'TRUE' then call AdjustOrigin( 'reply_msg' )
  459.  
  460.    if exists( file ) then call EMS_Item_File_Read(    'reply_msg', 'text', file )
  461.    else                   call EMS_Item_Lines_Delete( 'reply_msg', 'text'       )
  462.  
  463.    if Local_Cfg_GetBit( 'Cmd_Actions', 'Forward_Banner' ) = 'TRUE' then
  464.    do
  465.  
  466.       line.1 = ' * Forwarded by' Local_Cfg_Get( 'Sysop_Name' ) 'on' Local_Cfg_Get( 'Area_Addr' )
  467.       line.2 = ' * Subj :' Local_Cfg_Set( 'Header_Subject' )
  468.       line.3 = ' * To   :' Local_Cfg_Set( 'Header_To'      ) || ',' Local_Cfg_Get( 'Header_Addr_To'   )
  469.       line.4 = ' * From :' Local_Cfg_Set( 'Header_From'    ) || ',' Local_Cfg_Get( 'Header_Addr_From' )
  470.       line.5 = ' * Area :' src_area
  471.       line.6 = ''
  472.       line.0 = 6
  473.  
  474.       do j=line.0 to 1 by -1
  475.  
  476.          call EMS_Item_Line_Add_Head( 'reply_msg', 'text', line.j )
  477.  
  478.       end
  479.  
  480.    end
  481.  
  482.    /*
  483.    ** Make sure there's an origin for an ECHO message.
  484.    */
  485.    if upper( EMS_Area_Type( area_name ) ) ~= 'MAIL' then
  486.    do
  487.  
  488.       call EMS_Item_Lines_Get( 'reply_msg', 'header', 'lines' )
  489.  
  490.       if EMS_Search_In_Stem( 'lines', ' * Origin: #?' ) = 0 then call InsertOrigin( 'reply_msg', area_name )
  491.  
  492.    end
  493.    /*
  494.    ** and no origin nor tearline for a MAIL message.
  495.    */
  496.    else
  497.    do
  498.  
  499.       call EMS_Item_Lines_Get( 'reply_msg', 'header', 'lines' )
  500.  
  501.       orig_pos = EMS_Search_In_Stem( 'lines', ' * Origin: #?' )
  502.       tear_pos = EMS_Search_In_Stem( 'lines', '--- #?'        )
  503.  
  504.       if orig_pos ~= 0 | tear_pos ~= 0 then
  505.       do
  506.  
  507.          new_lines.0 = 0
  508.  
  509.          do j=1 to lines.0
  510.  
  511.             if j = orig_pos then iterate
  512.             if j = tear_pos then iterate
  513.  
  514.             call EMS_Add_To_Stem( 'new_lines', lines.j )
  515.  
  516.          end
  517.  
  518.          call EMS_Item_Lines_Set( 'reply_msg', 'header', 'new_lines' )
  519.  
  520.          drop new_lines.
  521.  
  522.       end
  523.  
  524.       drop lines.
  525.  
  526.    end
  527.  
  528.    call EMS_Item_Write( 'reply_msg' )
  529.  
  530.    if Local_Cfg_GetBit( 'Cmd_Actions', 'Move_Down_HWM' ) = 'TRUE' then
  531.    do
  532.  
  533.       old_hwm = EMS_Area_HiMark( area_name   )
  534.       new_hwm = EMS_Item_Number( 'reply_msg' ) - 1
  535.  
  536.       if old_hwm > new_hwm then call EMS_Area_HiMark( area_name, new_hwm )
  537.  
  538.    end
  539.  
  540. end
  541.  
  542. call Local_Cfg_Set( 'Header_From'     , EMS_Item_Header_From(         'reply_msg' ) )
  543. call Local_Cfg_Set( 'Header_To'       , EMS_Item_Header_To(           'reply_msg' ) )
  544. call Local_Cfg_Set( 'Header_Subject'  , EMS_Item_Header_Subject(      'reply_msg' ) )
  545. call Local_Cfg_Set( 'Header_Date'     , EMS_Item_Header_Date_Created( 'reply_msg' ) )
  546. call Local_Cfg_Set( 'Header_Addr_From', EMS_Item_Header_Address_From( 'reply_msg' ) )
  547. call Local_Cfg_Set( 'Header_Addr_To'  , EMS_Item_Header_Address_To(   'reply_msg' ) )
  548.  
  549. /***************************************************/
  550. /* Build CC: lines (originally from Bernd Ernesti) */
  551. /***************************************************/
  552. line_pre  = ''
  553. line_cc.0 = 0
  554.  
  555. do i=1 to carbon_copy_name.0
  556.  
  557.    if i == carbon_copy_name.0 then line_end = ''
  558.    else                            line_end = ','
  559.  
  560.    line_post = line_pre || carbon_copy_name.i || line_end
  561.  
  562.    if LENGTH( line_post ) > 70 then
  563.    do
  564.  
  565.       call EMS_Add_To_Stem( 'line_cc', ' CC:' line_pre )
  566.  
  567.       line_post = carbon_copy_name.i || line_end
  568.  
  569.    end
  570.  
  571.    line_pre = line_post
  572.  
  573. end
  574.  
  575. if line_pre ~= '' then call EMS_Add_To_Stem( 'line_cc', ' CC:' line_pre )
  576.  
  577.  
  578. /*
  579. ** Do CARBON COPY only if there's at least one MAIL area.
  580. */
  581. if areas_mail.0 > 0 then
  582. do
  583.  
  584.    do i=1 to carbon_copy_name.0
  585.  
  586.       cc_name = carbon_copy_name.i
  587.       cc_addr = carbon_copy_addr.i
  588.  
  589.       /*
  590.       ** Search nearer MAIL area.
  591.       */
  592.       cc_aka_nearer = EMS_Aka_Nearer( cc_addr )
  593.       cc_area       = areas_mail.1
  594.       do j=1 to areas_mail.0
  595.  
  596.          if EMS_Address_Compare( cc_aka_nearer, EMS_Area_Address( areas_mail.j ) ) = 'TRUE' then
  597.          do
  598.             cc_area = areas_mail.j
  599.             leave
  600.          end
  601.  
  602.       end
  603.  
  604.       /*
  605.       ** Get infos about the message area.
  606.       */
  607.       call Local_Cfg_Set( 'Area_Name', cc_area                     )
  608.       call Local_Cfg_Set( 'Area_Type', 'MAIL'                      )
  609.       call Local_Cfg_Set( 'Area_Addr', EMS_Area_Address( cc_area ) )
  610.  
  611.  
  612.       dump.0 = 0
  613.  
  614.       call EMS_Item_Area(                'reply_msg',                 cc_area       )
  615.       call EMS_Item_Header_From(         'reply_msg', Local_Cfg_Get( 'Sysop_Name' ) )
  616.       call EMS_Item_Header_To(           'reply_msg',                 cc_name       )
  617.       call EMS_Item_Header_Address_From( 'reply_msg', EMS_Aka_Nearer( cc_addr )     )
  618.       call EMS_Item_Header_Address_To(   'reply_msg',                 cc_addr       )
  619.  
  620.       call EMS_Item_SeenBy_Set(          'reply_msg', 'dump'                        )
  621.       call EMS_Item_Path_Set(            'reply_msg', 'dump'                        )
  622.       call EMS_Item_Header_Flag(         'reply_msg', 'SENT', 'OFF'                 )
  623.       call EMS_Item_Header_Flag(         'reply_msg', 'PVT' , 'ON'                  )
  624.  
  625.  
  626.       if exists( file ) then call EMS_Item_File_Read(    'reply_msg', 'text', file )
  627.       else                   call EMS_Item_Lines_Delete( 'reply_msg', 'text'       )
  628.  
  629.       if upper( EMS_Area_Type( area_name ) ) ~= 'MAIL' then
  630.       do
  631.  
  632.          line.1 = ' * Carbon Copy by' Local_Cfg_Get( 'Sysop_Name' ) 'on' Local_Cfg_Get( 'Area_Addr' )
  633.          line.2 = ' * Subj :'         Local_Cfg_Get( 'Header_Subject' )
  634.          line.3 = ' * To   :'         Local_Cfg_Get( 'Header_To'      ) || ',' Local_Cfg_Get( 'Header_Addr_To'   )
  635.          line.4 = ' * From :'         Local_Cfg_Get( 'Header_From'    ) || ',' Local_Cfg_Get( 'Header_Addr_From' )
  636.          line.5 = ' * Area :'         dst_areas.1
  637.          line.6 = ''
  638.          line.0 = 6
  639.  
  640.          do j=line.0 to 1 by -1
  641.  
  642.             call EMS_Item_Line_Add_Head( 'reply_msg', 'text', line.j )
  643.  
  644.          end
  645.  
  646.       end
  647.  
  648.       if line_cc.0 > 0 then
  649.       do
  650.  
  651.          call EMS_Item_Line_Add_Head( 'reply_msg', 'text', '' )
  652.  
  653.          /* CC: lines */
  654.          do j=line_cc.0 to 1 by -1
  655.  
  656.             call EMS_Item_Line_Add_Head( 'reply_msg', 'text', line_cc.j )
  657.  
  658.          end
  659.  
  660.       end
  661.  
  662.       call EMS_Item_Number( 'reply_msg', 0 )
  663.       call EMS_Item_Write(  'reply_msg'    )
  664.  
  665.    end
  666.  
  667. end
  668.  
  669. call DeleteMsgFile( file )
  670.  
  671. call EMS_Item_Free( 'reply_msg' )
  672.  
  673.  
  674. /*************************************************************/
  675. ScriptExit:
  676.  
  677. call EMS_FreeScriptData()
  678. exit 0
  679.  
  680.  
  681. /*************************************************************/
  682. Usage:
  683.  
  684. say 'Usage:' script_name'.ems <session number> <source area name> <message num> [HELP|<command name>] [option ...]'
  685. signal ScriptExit
  686.  
  687.  
  688. /*************************************************************/
  689. error:
  690. syntax:
  691.  
  692. error_text = EMS_LastError()
  693.  
  694. if error_text = '' then error_text = rc ErrorText( rc )
  695.  
  696. say '| ***BREAK: error at' sigl error_text
  697.  
  698. call EMS_FreeScriptData()
  699. exit rc
  700.  
  701.  
  702.  
  703. InsertOpening: procedure EXPOSE reply_cfg.
  704.  
  705.    parse arg file_name , area_name
  706.  
  707.    language = ChooseOpening( area_name, Local_Cfg_Get( 'Cfg_ChooseOpening' ) )
  708.  
  709.    if language = '' then return 0
  710.  
  711.    call EMS_CustomCfg_Get( 'DMreply_Openings', language, 'Lines', 'a' )
  712.  
  713.    from       = Local_Cfg_Get( 'Header_From' )
  714.    from_first = strip( word( from, 1 ), 'B' )
  715.  
  716.    modifiers.1 = 'from_first'; data.1 = from_first
  717.    modifiers.2 = 'from'      ; data.2 = from
  718.    modifiers.3 = 'to'        ; data.3 = Local_Cfg_Get( 'Header_To'        )
  719.    modifiers.4 = 'subject'   ; data.4 = Local_Cfg_Get( 'Header_Subject'   )
  720.    modifiers.5 = 'date'      ; data.5 = Local_Cfg_Get( 'Header_Date'      )
  721.    modifiers.6 = 'addr_from' ; data.6 = Local_Cfg_Get( 'Header_Addr_From' )
  722.    modifiers.7 = 'addr_to'   ; data.7 = Local_Cfg_Get( 'Header_Addr_To'   )
  723.    modifiers.0 = 7           ; data.0 = 7
  724.  
  725.    if open( 'tempfile', file_name, 'W' ) ~= 1 then
  726.    do
  727.  
  728.       say "| Can't open '" || file_name || "' file for output."
  729.  
  730.       call ScriptExit
  731.  
  732.    end
  733.  
  734.    do i=1 to a.0
  735.  
  736.       line = EMS_Translate_Stem( a.i, 'modifiers', 'data' )
  737.  
  738.       call writeln( 'tempfile', line )
  739.  
  740.    end
  741.  
  742.    call writeln( 'tempfile', '' )
  743.    call close(   'tempfile'     )
  744.  
  745.  
  746.    return 0
  747.  
  748.  
  749. ChooseOpening: procedure EXPOSE reply_cfg.
  750.  
  751.    parse arg area_name , choose
  752.  
  753.    language = Local_Cfg_Get( 'Cfg_Opening' )
  754.  
  755.    if language = '' & area_name ~= 'GENERAL' then language = EMS_Area_Language( area_name )
  756.  
  757.    call EMS_CustomCfg_Get( 'DMreply_Openings', '', '', 'a' )
  758.  
  759.    sel = EMS_Search_In_Stem( 'a', language )
  760.  
  761.    if sel ~= 0 then language = a.sel
  762.  
  763.    if choose = 'TRUE' then
  764.    do
  765.  
  766.       call Local_Cfg_Set( 'Req_Failed', 'FALSE' )
  767.  
  768.       res = EMS_Do_Choice_Single( 'Choose Opening For Area' area_name, 'a', 'sel' )
  769.  
  770.       if res = 'OK' then language = a.sel
  771.                     else call Local_Cfg_Set( 'Req_Failed', 'TRUE' )
  772.  
  773.    end
  774.  
  775.    call Local_Cfg_Set( 'Cfg_Opening', language )
  776.  
  777.    return language
  778.  
  779.  
  780. InsertSignature: procedure EXPOSE reply_cfg.
  781.  
  782.    parse arg file_name , area_name
  783.  
  784.    which = ChooseSignature( area_name, Local_Cfg_Get( 'Cfg_ChooseSignature' ) )
  785.  
  786.    call EMS_CustomCfg_Get( 'DMreply_Signs', which, 'Lines', 'a' )
  787.  
  788.  
  789.    if open( 'tempfile', file_name, 'A' ) ~= 1 then
  790.    do
  791.  
  792.       if open( 'tempfile', file_name, 'W' ) ~= 1 then
  793.       do
  794.  
  795.          say "| Can't open '" || file_name || "' file for output."; call ScriptExit
  796.  
  797.       end
  798.  
  799.    end
  800.  
  801.    do i=1 to a.0
  802.  
  803.       call writeln( 'tempfile', a.i )
  804.  
  805.    end
  806.  
  807.    call close( 'tempfile' )
  808.  
  809.    return 0
  810.  
  811.  
  812. ChooseSignature: procedure EXPOSE reply_cfg.
  813.  
  814.    parse arg area_name , choose
  815.  
  816.    which = Local_Cfg_Get( 'Cfg_Signature' )
  817.  
  818.    if which = '' then which = 'Normal'
  819.  
  820.    if choose = 'TRUE' then
  821.    do
  822.  
  823.       call EMS_CustomCfg_Get( 'DMreply_Signs', '', '', 'a' )
  824.  
  825.       sel = EMS_Search_In_Stem( 'a', which )
  826.  
  827.       call Local_Cfg_Set( 'Req_Failed', 'FALSE' )
  828.  
  829.       res = EMS_Do_Choice_Single( 'Choose Signature For Area' area_name, 'a', 'sel' )
  830.  
  831.       if res = 'OK' then which = a.sel
  832.                     else call Local_Cfg_Set( 'Req_Failed', 'TRUE' )
  833.  
  834.       drop a.
  835.  
  836.    end
  837.  
  838.    call Local_Cfg_Set( 'Cfg_Signature', which )
  839.  
  840.    return which
  841.  
  842.  
  843. InsertCOD: procedure EXPOSE reply_cfg.
  844.  
  845.    parse arg file_name , area_name
  846.  
  847.    which = ChooseCOD( area_name, Local_Cfg_Get( 'Cfg_ChooseCOD' ) )
  848.  
  849.    if which = '' then return 0
  850.  
  851.    call EMS_CustomCfg_Search( 'DMreply_COD', which'_#?', 'cods' )
  852.  
  853.    if cods.0 = 0 then return 0
  854.  
  855.    res = CalcRandom( cods.0 )
  856.  
  857.    which = cods.res
  858.  
  859.    if which = '' then return 0
  860.  
  861.    call EMS_CustomCfg_Get( 'DMreply_COD', which, 'Lines', 'a' )
  862.  
  863.    if a.0 = 0 then return 0
  864.  
  865.    if open( 'tempfile', file_name, 'A' ) ~= 1 then
  866.    do
  867.  
  868.       if open( 'tempfile', file_name, 'W' ) ~= 1 then
  869.       do
  870.  
  871.          say "| Can't open '" || file_name || "' file for output."; call ScriptExit
  872.  
  873.       end
  874.    end
  875.  
  876.  
  877.    call writeln( 'tempfile', '' )
  878.  
  879.    do i=1 to a.0
  880.  
  881.       call writeln( 'tempfile', a.i )
  882.  
  883.    end
  884.  
  885.    call writeln( 'tempfile', '' )
  886.  
  887.    call close( 'tempfile' )
  888.  
  889.    return 0
  890.  
  891.  
  892. ChooseCOD: procedure EXPOSE reply_cfg.
  893.  
  894.    parse arg area_name , choose
  895.  
  896.    which = Local_Cfg_Get( 'Cfg_COD' )
  897.  
  898.    call EMS_CustomCfg_Get( 'DMreply_COD', '', '', 'a' )
  899.  
  900.    cods.0 = 0
  901.  
  902.    do i=1 to a.0
  903.  
  904.       parse var a.i name '_'
  905.  
  906.       call EMS_Add_To_Stem( 'cods', name, 'UNIQUE' )
  907.  
  908.    end
  909.  
  910.    sel = EMS_Search_In_Stem( 'cods', which )
  911.  
  912.    call Local_Cfg_Set( 'Req_Failed', 'FALSE' )
  913.  
  914.    if choose = 'TRUE' then
  915.    do
  916.  
  917.       res = EMS_Do_Choice_Single( 'Choose COD For Area' area_name, 'cods', 'sel' )
  918.  
  919.       if res ~= 'OK' then call Local_Cfg_Set( 'Req_Failed', 'TRUE' )
  920.  
  921.    end
  922.  
  923.    if sel ~= 0 then which = cods.sel
  924.                else which = ''
  925.  
  926.    call Local_Cfg_Set( 'Cfg_COD', which )
  927.    return which
  928.  
  929.  
  930. InsertOrigin: procedure EXPOSE reply_cfg. script_name script_version
  931.  
  932.    parse arg msg_name , area_name
  933.  
  934.    a.0 = 0
  935.    sel = -1
  936.  
  937.    call EMS_CustomCfg_Get( 'Origins', area_name, 'Origin', 'a' )
  938.  
  939.    if a.0 = 0 then
  940.    do
  941.  
  942.       call EMS_CustomCfg_Get( 'Origins', 'GENERAL', 'Origin', 'a' )
  943.  
  944.       if a.0 = 0 then call EMS_Add_To_Stem( 'a', EMS_Var_Local( 'ORIGIN_NAME' ) )
  945.  
  946.    end
  947.  
  948.    call Local_Cfg_Set( 'Req_Failed', 'FALSE' )
  949.  
  950.    if Local_Cfg_Get( 'Cfg_ChooseOrigin' ) = 'TRUE' then
  951.    do
  952.  
  953.       res = EMS_Do_Choice_Single( 'Choose Origin For Area' area_name, 'a', 'sel' )
  954.  
  955.       if res ~= 'OK' then
  956.       do
  957.  
  958.          sel = -1
  959.          call Local_Cfg_Set( 'Req_Failed', 'TRUE' )
  960.  
  961.       end
  962.  
  963.    end
  964.  
  965.    if sel = -1 then sel = CalcRandom( a.0 )
  966.  
  967.    call EMS_Item_Line_Unique( msg_name, 'header', '--- '       , '---' script_name script_version                                      )
  968.    call EMS_Item_Line_Unique( msg_name, 'header', ' * Origin: ', ' * Origin: ' || a.sel || ' (' || Local_Cfg_Get( 'Area_Addr' ) || ')' )
  969.  
  970.    call Local_Cfg_Set( 'Cfg_Origin', a.sel )
  971.  
  972.    return 0
  973.  
  974.  
  975. AdjustOrigin: procedure EXPOSE reply_cfg.
  976.  
  977.    parse arg msg_name
  978.  
  979.    call EMS_Item_Lines_Get( msg_name, 'header', 'lines' )
  980.  
  981.    orig_pos = EMS_Search_In_Stem( 'lines', ' * Origin: #?' )
  982.  
  983.    if orig_pos = 0 then return 0
  984.  
  985.    orig = lines.orig_pos; drop lines.
  986.  
  987.    last_pos = lastpos( '(', orig ); if last_pos = 0 then return 0
  988.  
  989.    orig_addr = substr( orig, last_pos     ); parse var orig_addr '(' orig_addr ')'
  990.    orig      = left(   orig, last_pos - 1 )
  991.  
  992.    if EMS_Address_IsFIDO( orig_addr ) ~= 'TRUE' then return 0
  993.  
  994.    parse var orig_addr orig_addr '@'
  995.  
  996.    call EMS_Item_Line_Unique( msg_name, 'header', ' * Origin: ', orig || '(' || orig_addr || ')' )
  997.  
  998.    return 0
  999.  
  1000.  
  1001. BuildREPLY: procedure EXPOSE reply_cfg.
  1002.  
  1003.    parse arg msg_name
  1004.  
  1005.    call EMS_Item_Lines_Get( msg_name, 'header', 'header_lines' )
  1006.  
  1007.    msgid_line = EMS_Search_In_Stem( 'header_lines', '1'X || 'MSGID:#?' )
  1008.  
  1009.    call EMS_Item_Lines_Delete( msg_name, 'header' )
  1010.  
  1011.    if msgid_line ~= 0 then
  1012.    do
  1013.  
  1014.       id = substr( header_lines.msgid_line, 8 )
  1015.  
  1016.       call EMS_Item_Line_Unique( msg_name, 'header', '1'X || 'REPLY:', '1'X || 'REPLY:' || id )
  1017.  
  1018.    end
  1019.  
  1020.    drop msgid_line
  1021.    drop header_lines.
  1022.  
  1023.    return 0
  1024.  
  1025.  
  1026. ReduceKludges: procedure EXPOSE reply_cfg.
  1027.  
  1028.    parse arg msg_name
  1029.  
  1030.    call EMS_Item_Lines_Get( msg_name, 'header', 'old_lines' )
  1031.  
  1032.    new_lines.0 = 0
  1033.  
  1034.    do i=1 to old_lines.0
  1035.  
  1036.       line = upper( old_lines.i )
  1037.  
  1038.       if left( line, 7 ) = '1'X || 'MSGID:'   then iterate
  1039.       if left( line, 5 ) = '1'X || 'EID:'     then iterate
  1040.       if left( line, 5 ) = '1'X || 'VIA:'     then iterate
  1041.       if left( line, 9 ) = '1'X || 'VIA NODE' then iterate
  1042.       if left( line, 5 ) = '1'X || 'PID:'     then iterate
  1043.  
  1044.       call EMS_Add_To_Stem( 'new_lines', old_lines.i )
  1045.  
  1046.    end
  1047.  
  1048.    call EMS_Item_Lines_Set( msg_name, 'header', 'new_lines' )
  1049.  
  1050.    return 0
  1051.  
  1052.  
  1053. DeleteMsgFile: procedure
  1054.  
  1055.    parse arg file
  1056.  
  1057.    if exists( file ) then
  1058.    do
  1059.  
  1060.       cmd_delete = EMS_Var_Local( 'SCRIPT_DELETE_NAME' )
  1061.       address command cmd_delete file
  1062.  
  1063.    end
  1064.  
  1065.    return 0
  1066.  
  1067.  
  1068. ParseCommand: procedure EXPOSE reply_cfg. script_name script_version
  1069.  
  1070.    parse arg area_name , cmd_name , cmd_args
  1071.  
  1072.    cmd_name = upper( cmd_name )
  1073.  
  1074.    /**************************************************************/
  1075.    /* Command definitions:                                       */
  1076.    /*                                                            */
  1077.    /* cmds.x        Cmd_Name                                     */
  1078.    /*                                                            */
  1079.    /* cmds_opt.x.0  Cmd_Header      0=OLD 1=NEW 2=REPLY          */
  1080.    /*                                                            */
  1081.    /* cmds_opt.x.1  Cmd_AskAreas    0=NO  1=ONE 2=MANY           */
  1082.    /*                                                            */
  1083.    /* cmds_opt.x.2  Cmd_Actions     bit  0=Read Old Msg          */
  1084.    /*                               bit  1=Call Editor           */
  1085.    /*                               bit  2=Insert Opening        */
  1086.    /*                               bit  3=Insert Origin         */
  1087.    /*                               bit  4=Insert Signature      */
  1088.    /*                               bit  5=Insert COD            */
  1089.    /*                               bit  6=Quote Text            */
  1090.    /*                               bit  7=Forward Banner        */
  1091.    /*                               bit  8=Move Down HWM         */
  1092.    /*                               bit  9=Carbon Copy           */
  1093.    /*                               bit 10=Reply Kludges         */
  1094.    /*                               bit 11=Reduce Kludges        */
  1095.    /*                               bit 12=Reset FATT            */
  1096.    /*                               bit 13=Reset Msg Number      */
  1097.    /*                                                            */
  1098.    /* cmds_opt.x.3  Cmd_AskFor      bit  0=Do Carbon Copy        */
  1099.    /*                               bit  1=Reply Kludges         */
  1100.    /*                               bit  2=Insert Opening        */
  1101.    /*                               bit  3=Choose Opening        */
  1102.    /*                               bit  4=Insert Signature      */
  1103.    /*                               bit  5=Choose Signature      */
  1104.    /*                               bit  6=Insert COD            */
  1105.    /*                               bit  7=Choose COD            */
  1106.    /*                               bit  8=Choose Origin         */
  1107.    /*                               bit  9=No Domain In Origin   */
  1108.    /*                                                            */
  1109.    /**************************************************************/
  1110.  
  1111.    cmds.1        = 'EDIT'
  1112.    cmds_help.1   = 'Edit an existing message.'
  1113.    cmds_opt.1.0  = 0
  1114.    cmds_opt.1.1  = 0
  1115.    cmds_opt.1.2  = '00000000100100000011'b
  1116.    cmds_opt.1.3  = '00000000001100000000'b
  1117.  
  1118.    cmds.2        = 'EDIT_FILE'
  1119.    cmds_help.2   = 'Edit an existing file.'
  1120.    cmds_opt.2.0  = 0
  1121.    cmds_opt.2.1  = 0
  1122.    cmds_opt.2.2  = '00000000000000000011'b
  1123.    cmds_opt.2.3  = '00000000000000000000'b
  1124.  
  1125.    cmds.3        = 'WRITE'
  1126.    cmds_help.3   = 'Write a new message.'
  1127.    cmds_opt.3.0  = 1
  1128.    cmds_opt.3.1  = 0
  1129.    cmds_opt.3.2  = '00000010000000111010'b
  1130.    cmds_opt.3.3  = '00000000001111110001'b
  1131.  
  1132.    cmds.4        = 'WRITE_FILE'
  1133.    cmds_help.4   = 'Upload a file.'
  1134.    cmds_opt.4.0  = 1
  1135.    cmds_opt.4.1  = 0
  1136.    cmds_opt.4.2  = '00000010000000000010'b
  1137.    cmds_opt.4.3  = '00000000000000000000'b
  1138.  
  1139.    cmds.5        = 'REPLY'
  1140.    cmds_help.5   = 'Reply to a message.'
  1141.    cmds_opt.5.0  = 2
  1142.    cmds_opt.5.1  = 0
  1143.    cmds_opt.5.2  = '00000011000001111111'b
  1144.    cmds_opt.5.3  = '00000000001111111111'b
  1145.  
  1146.    cmds.6        = 'REPLY_FORWARD'
  1147.    cmds_help.6   = 'Reply to a message, but in another area.'
  1148.    cmds_opt.6.0  = 2
  1149.    cmds_opt.6.1  = 1
  1150.    cmds_opt.6.2  = '00000011000011111111'b
  1151.    cmds_opt.6.3  = '00000000001111111111'b
  1152.  
  1153.    cmds.7        = 'REPLY_MULTISEND'
  1154.    cmds_help.7   = 'Reply to a message and send it in many areas.'
  1155.    cmds_opt.7.0  = 2
  1156.    cmds_opt.7.1  = 2
  1157.    cmds_opt.7.2  = '00000011000001111111'b
  1158.    cmds_opt.7.3  = '00000000001111111111'b
  1159.  
  1160.    cmds.8        = 'FORWARD'
  1161.    cmds_help.8   = 'Forward a message without editing.'
  1162.    cmds_opt.8.0  = 0
  1163.    cmds_opt.8.1  = 1
  1164.    cmds_opt.8.2  = '00000010100010000011'b
  1165.    cmds_opt.8.3  = '00000000001000000001'b
  1166.  
  1167.    cmds.9        = 'MULTISEND'
  1168.    cmds_help.9   = 'Write a new message and send it in many areas.'
  1169.    cmds_opt.9.0  = 1
  1170.    cmds_opt.9.1  = 2
  1171.    cmds_opt.9.2  = '00000010000000111010'b
  1172.    cmds_opt.9.3  = '00000000001111110001'b
  1173.  
  1174.    cmds.10       = 'RESEND'
  1175.    cmds_help.10  = 'Resend an old message.'
  1176.    cmds_opt.10.0 = 0
  1177.    cmds_opt.10.1 = 0
  1178.    cmds_opt.10.2 = '00000000100100000001'b
  1179.    cmds_opt.10.3 = '00000000000000000000'b
  1180.  
  1181.    cmds.11       = 'ARCHIVE'
  1182.    cmds_help.11  = 'Archive a message'
  1183.    cmds_opt.11.0 = 0
  1184.    cmds_opt.11.1 = 0
  1185.    cmds_opt.11.2 = '00000000000000000001'b
  1186.    cmds_opt.11.3 = '00000000000000000000'b
  1187.  
  1188.    cmds.12       = 'CONFIG'
  1189.    cmds_help.12  = 'Change the configuration of source area.'
  1190.    cmds_opt.12.0 = 0
  1191.    cmds_opt.12.1 = 0
  1192.    cmds_opt.12.2 = '00000000000000111100'b
  1193.    cmds_opt.12.3 = '00000000001111111110'b
  1194.  
  1195.    cmds.0        = 12
  1196.  
  1197.  
  1198.    
  1199.    opts.1        = 'NO_REQS'
  1200.    opts_help.1   = "Don't ask anything."
  1201.  
  1202.    opts.2        = 'CARBON_COPY'
  1203.    opts_help.2   = 'Do carbon copy.'
  1204.  
  1205.    opts.3        = 'REPLY_KLUDGES'
  1206.    opts_help.3   = 'Reply kludges.'
  1207.  
  1208.    opts.4        = 'INSERT_OPENING'
  1209.    opts_help.4   = 'Insert an automatic opening on reply.'
  1210.  
  1211.    opts.5        = 'CHOOSE_OPENING'
  1212.    opts_help.5   = 'Choose the automatic opening.'
  1213.  
  1214.    opts.6        = 'INSERT_SIGNATURE'
  1215.    opts_help.6   = 'Insert a signature.'
  1216.  
  1217.    opts.7        = 'CHOOSE_SIGNATURE'
  1218.    opts_help.7   = 'Choose the signature.'
  1219.  
  1220.    opts.8        = 'INSERT_COD'
  1221.    opts_help.8   = 'Insert a random Quote Of The Day.'
  1222.  
  1223.    opts.9        = 'CHOOSE_COD'
  1224.    opts_help.9   = 'Choose the Quote Of The Day family.'
  1225.  
  1226.    opts.10       = 'CHOOSE_ORIGIN'
  1227.    opts_help.10  = 'Choose origin.'
  1228.  
  1229.    opts.11       = 'NO_DOMAIN_IN_ORIGIN'
  1230.    opts_help.11  = "Don't put domain in fidonet origins."
  1231.  
  1232.    opts.0        = 11
  1233.  
  1234.  
  1235.  
  1236.    if cmd_name = 'HELP' then
  1237.    do
  1238.  
  1239.       say 'List of commands supported by' script_name script_version || ':'
  1240.       say
  1241.  
  1242.       work_cmds.0 = cmds.0
  1243.       do i=1 to cmds.0
  1244.  
  1245.          work_cmds.i = cmds.i
  1246.  
  1247.       end
  1248.  
  1249.       call EMS_Calc_Stem_Width( 'work_cmds', 'ADAPT' )
  1250.  
  1251.       do i=1 to work_cmds.0
  1252.          say ' ' work_cmds.i '-' cmds_help.i
  1253.       end
  1254.  
  1255.       say
  1256.  
  1257.       drop work_cmds.
  1258.  
  1259.  
  1260.       say
  1261.       say 'List of options:'
  1262.       say
  1263.  
  1264.       work_opts.0 = opts.0
  1265.       do i=1 to opts.0
  1266.  
  1267.          work_opts.i = opts.i
  1268.  
  1269.       end
  1270.  
  1271.       call EMS_Calc_Stem_Width( 'work_opts', 'ADAPT' )
  1272.  
  1273.       do i=1 to work_opts.0
  1274.          say ' ' work_opts.i '-' opts_help.i
  1275.       end
  1276.  
  1277.       drop work_opts.
  1278.  
  1279.       return 0
  1280.  
  1281.    end
  1282.  
  1283.  
  1284.    if cmd_name = 'ASK' | cmd_name = '' then
  1285.    do
  1286.  
  1287.       sel = -1
  1288.       res = EMS_Do_Choice_Single( 'Choose Operation', 'cmds', 'sel' )
  1289.  
  1290.       if res = 'OK' then cmd_name = cmds.sel
  1291.                     else cmd_name = ''
  1292.  
  1293.    end
  1294.  
  1295.    if cmd_name ~= '' then sel = EMS_Search_In_Stem( 'cmds', cmd_name )
  1296.                      else sel = 0
  1297.  
  1298.    if sel ~= 0 then
  1299.    do
  1300.  
  1301.       call Local_Cfg_Set( 'Cmd_Name'    , cmds.sel       )
  1302.       call Local_Cfg_Set( 'Cmd_Header'  , cmds_opt.sel.0 )
  1303.       call Local_Cfg_Set( 'Cmd_AskAreas', cmds_opt.sel.1 )
  1304.       call Local_Cfg_Set( 'Cmd_Actions' , cmds_opt.sel.2 )
  1305.  
  1306.       work_area_name = area_name
  1307.       call EMS_CustomCfg_Get( 'DMreply_Cfg', work_area_name, 'AreaName', 'a' )
  1308.  
  1309.       if a.0 = 0 & cmd_name ~= 'CONFIG' then
  1310.       do
  1311.  
  1312.          call EMS_CustomCfg_Get( 'DMreply_Cfg', 'GENERAL', 'AreaName', 'a' )
  1313.  
  1314.          if a.0 = 0 then work_area_name = ''
  1315.                     else work_area_name = 'GENERAL'
  1316.  
  1317.       end
  1318.  
  1319.                                          status.0  = 'FALSE'
  1320.       choice.1  = 'Do Carbon Copy'     ; status.1  = 'FALSE'
  1321.       choice.2  = 'Reply Kludges'      ; status.2  = 'FALSE'
  1322.       choice.3  = 'Insert Opening'     ; status.3  = 'FALSE'
  1323.       choice.4  = 'Choose Opening'     ; status.4  = 'FALSE'
  1324.       choice.5  = 'Insert Signature'   ; status.5  = 'FALSE'
  1325.       choice.6  = 'Choose Signature'   ; status.6  = 'FALSE'
  1326.       choice.7  = 'Insert COD'         ; status.7  = 'FALSE'
  1327.       choice.8  = 'Choose COD'         ; status.8  = 'FALSE'
  1328.       choice.9  = 'Choose Origin'      ; status.9  = 'FALSE'
  1329.       choice.10 = 'No Domain In Origin'; status.10 = 'FALSE'
  1330.       choice.0  = 10
  1331.  
  1332.       cfg_ReplyKludges     = Global_Cfg_Get( work_area_name, 'ReplyKludges'     ); if cfg_ReplyKludges     = '' then cfg_ReplyKludges     = 'FALSE'
  1333.       cfg_Opening          = Global_Cfg_Get( work_area_name, 'Opening'          )
  1334.       cfg_Signature        = Global_Cfg_Get( work_area_name, 'Signature'        )
  1335.       cfg_COD              = Global_Cfg_Get( work_area_name, 'COD'              )
  1336.       cfg_ChooseOpening    = Global_Cfg_Get( work_area_name, 'ChooseOpening'    ); if cfg_ChooseOpening    = '' then cfg_ChooseOpening    = 'FALSE'
  1337.       cfg_ChooseSignature  = Global_Cfg_Get( work_area_name, 'ChooseSignature'  ); if cfg_ChooseSignature  = '' then cfg_ChooseSignature  = 'FALSE'
  1338.       cfg_ChooseCOD        = Global_Cfg_Get( work_area_name, 'ChooseCOD'        ); if cfg_ChooseCOD        = '' then cfg_ChooseCOD        = 'FALSE'
  1339.       cfg_ChooseOrigin     = Global_Cfg_Get( work_area_name, 'ChooseOrigin'     ); if cfg_ChooseOrigin     = '' then cfg_ChooseOrigin     = 'FALSE'
  1340.       cfg_NoDomainInOrigin = Global_Cfg_Get( work_area_name, 'NoDomainInOrigin' ); if cfg_NoDomainInOrigin = '' then cfg_NoDomainInOrigin = 'FALSE'
  1341.  
  1342.  
  1343.       if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Opening' ) = 'FALSE' then
  1344.       do
  1345.          cfg_Opening       = ''
  1346.          cfg_ChooseOpening = 'FALSE'
  1347.       end
  1348.  
  1349.       if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Signature' ) = 'FALSE' then
  1350.       do
  1351.          cfg_Signature       = ''
  1352.          cfg_ChooseSignature = 'FALSE'
  1353.       end
  1354.  
  1355.       if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_COD' ) = 'FALSE' then
  1356.       do
  1357.          cfg_COD       = ''
  1358.          cfg_ChooseCOD = 'FALSE'
  1359.       end
  1360.  
  1361.       if Local_Cfg_GetBit( 'Cmd_Actions', 'Insert_Origin' ) = 'FALSE' then
  1362.       do
  1363.          cfg_ChooseOrigin = 'FALSE'
  1364.       end
  1365.  
  1366.  
  1367.       if cfg_ReplyKludges     ~= 'FALSE' then status.2  = 'TRUE'
  1368.       if cfg_Opening          ~= ''      then status.3  = 'TRUE'
  1369.       if cfg_ChooseOpening    ~= 'FALSE' then status.4  = 'TRUE'
  1370.       if cfg_Signature        ~= ''      then status.5  = 'TRUE'
  1371.       if cfg_ChooseSignature  ~= 'FALSE' then status.6  = 'TRUE'
  1372.       if cfg_COD              ~= ''      then status.7  = 'TRUE'
  1373.       if cfg_ChooseCOD        ~= 'FALSE' then status.8  = 'TRUE'
  1374.       if cfg_ChooseOrigin     ~= 'FALSE' then status.9  = 'TRUE'
  1375.       if cfg_NoDomainInOrigin ~= 'FALSE' then status.10 = 'TRUE'
  1376.  
  1377.  
  1378.       do while length( cmd_args ) ~= 0
  1379.  
  1380.          parse var cmd_args cmd_arg cmd_args
  1381.  
  1382.          cmd_arg = upper( cmd_arg )
  1383.  
  1384.          if left( cmd_arg, 1 ) = '~' then do; val = 'FALSE'; cmd_arg = delstr( cmd_arg, 1, 1 ); end
  1385.                                      else do; val = 'TRUE'                                    ; end
  1386.  
  1387.          do i=1 to opts.0
  1388.  
  1389.             if cmd_arg = opts.i then do; j = i - 1; status.j = val; end
  1390.  
  1391.          end
  1392.  
  1393.       end
  1394.  
  1395.       if status.0 = 'FALSE' then
  1396.       do
  1397.  
  1398.          j = 0
  1399.          do i=1 to choice.0
  1400.  
  1401.             if bittst( cmds_opt.sel.3, i - 1 ) then
  1402.             do
  1403.  
  1404.                j            = j + 1
  1405.                req_choice.j = choice.i; req_status.j = status.i
  1406.  
  1407.             end
  1408.  
  1409.          end
  1410.  
  1411.          if j ~= 0 then
  1412.          do
  1413.  
  1414.             req_choice.0 = j
  1415.             req_status.0 = j
  1416.  
  1417.             res = EMS_Do_Choice_Multi( 'Options for area' area_name, 'req_choice', 'req_status' )
  1418.  
  1419.             if res ~= 'OK' then return 0
  1420.  
  1421.             j = 0
  1422.             do i=1 to choice.0
  1423.  
  1424.                if bittst( cmds_opt.sel.3, i - 1 ) then
  1425.                do
  1426.  
  1427.                   j        = j + 1;
  1428.                   status.i = req_status.j
  1429.  
  1430.                end
  1431.  
  1432.             end
  1433.  
  1434.          end
  1435.  
  1436.       end
  1437.  
  1438.       cfg_ReplyKludges     = status.2
  1439.       cfg_ChooseOpening    = status.4
  1440.       cfg_ChooseSignature  = status.6
  1441.       cfg_ChooseCOD        = status.8
  1442.       cfg_ChooseOrigin     = status.9
  1443.       cfg_NoDomainInOrigin = status.10
  1444.  
  1445.       call Local_Cfg_SetBit( 'Cmd_Actions', 'Carbon_Copy'     , status.1 )
  1446.       call Local_Cfg_SetBit( 'Cmd_Actions', 'Insert_Opening'  , status.3 )
  1447.       call Local_Cfg_SetBit( 'Cmd_Actions', 'Insert_Signature', status.5 )
  1448.       call Local_Cfg_SetBit( 'Cmd_Actions', 'Insert_COD'      , status.7 )
  1449.  
  1450.       if status.3 = 'FALSE' then cfg_Opening   = ''
  1451.       if status.5 = 'FALSE' then cfg_Signature = ''
  1452.       if status.7 = 'FALSE' then cfg_COD       = ''
  1453.  
  1454.       call Local_Cfg_Set( 'Cfg_ReplyKludges'    , cfg_ReplyKludges     )
  1455.       call Local_Cfg_Set( 'Cfg_Opening'         , cfg_Opening          )
  1456.       call Local_Cfg_Set( 'Cfg_Signature'       , cfg_Signature        )
  1457.       call Local_Cfg_Set( 'Cfg_COD'             , cfg_COD              )
  1458.       call Local_Cfg_Set( 'Cfg_ChooseOpening'   , cfg_ChooseOpening    )
  1459.       call Local_Cfg_Set( 'Cfg_ChooseSignature' , cfg_ChooseSignature  )
  1460.       call Local_Cfg_Set( 'Cfg_ChooseCOD'       , cfg_ChooseCOD        )
  1461.       call Local_Cfg_Set( 'Cfg_ChooseOrigin'    , cfg_ChooseOrigin     )
  1462.       call Local_Cfg_Set( 'Cfg_NoDomainInOrigin', cfg_NoDomainInOrigin )
  1463.  
  1464.    end
  1465.  
  1466.  
  1467.    return sel
  1468.  
  1469.  
  1470. Local_Cfg_Set: procedure EXPOSE reply_cfg.
  1471.  
  1472.    parse arg name , value
  1473.  
  1474.    old_value = reply_cfg.name
  1475.  
  1476.    reply_cfg.name = value
  1477.  
  1478.    return old_value
  1479.  
  1480.  
  1481. Local_Cfg_Get: procedure EXPOSE reply_cfg.
  1482.  
  1483.    parse arg name
  1484.  
  1485.    return reply_cfg.name
  1486.  
  1487.  
  1488. Local_Cfg_SetBit: procedure EXPOSE reply_cfg.
  1489.  
  1490.    parse arg name , mask , status
  1491.  
  1492.    if status = 'TRUE'  then status = 1
  1493.    if status = 'FALSE' then status = 0
  1494.  
  1495.    select
  1496.       when mask = 'Read_Old_Msg'     then bit =  0
  1497.       when mask = 'Call_Editor'      then bit =  1
  1498.       when mask = 'Insert_Opening'   then bit =  2
  1499.       when mask = 'Insert_Origin'    then bit =  3
  1500.       when mask = 'Insert_Signature' then bit =  4
  1501.       when mask = 'Insert_COD'       then bit =  5
  1502.       when mask = 'Quote_Text'       then bit =  6
  1503.       when mask = 'Forward_Banner'   then bit =  7
  1504.       when mask = 'Move_Down_HWM'    then bit =  8
  1505.       when mask = 'Carbon_Copy'      then bit =  9
  1506.       when mask = 'Reply_Kludges'    then bit = 10
  1507.       when mask = 'Reduce_Kludges'   then bit = 11
  1508.       when mask = 'Reset_FATT'       then bit = 12
  1509.       when mask = 'Reset_Msg_Number' then bit = 13
  1510.       otherwise                      return 0
  1511.    end
  1512.  
  1513.    if status = 0 then reply_cfg.name = bitclr( reply_cfg.name, bit )
  1514.                  else reply_cfg.name = bitset( reply_cfg.name, bit )
  1515.  
  1516.    return 0
  1517.  
  1518. Local_Cfg_GetBit: procedure EXPOSE reply_cfg.
  1519.  
  1520.    parse arg name , mask
  1521.  
  1522.    select
  1523.       when mask = 'Read_Old_Msg'     then bit =  0
  1524.       when mask = 'Call_Editor'      then bit =  1
  1525.       when mask = 'Insert_Opening'   then bit =  2
  1526.       when mask = 'Insert_Origin'    then bit =  3
  1527.       when mask = 'Insert_Signature' then bit =  4
  1528.       when mask = 'Insert_COD'       then bit =  5
  1529.       when mask = 'Quote_Text'       then bit =  6
  1530.       when mask = 'Forward_Banner'   then bit =  7
  1531.       when mask = 'Move_Down_HWM'    then bit =  8
  1532.       when mask = 'Carbon_Copy'      then bit =  9
  1533.       when mask = 'Reply_Kludges'    then bit = 10
  1534.       when mask = 'Reduce_Kludges'   then bit = 11
  1535.       when mask = 'Reset_FATT'       then bit = 12
  1536.       when mask = 'Reset_Msg_Number' then bit = 13
  1537.       otherwise                      return 0
  1538.    end
  1539.  
  1540.    status = bittst( reply_cfg.name, bit )
  1541.  
  1542.    if status = 1 then return 'TRUE'
  1543.  
  1544.    return 'FALSE'
  1545.  
  1546. Global_Cfg_Set: procedure
  1547.  
  1548.    parse arg area_name , field , value
  1549.  
  1550.    if area_name = '' then return 0
  1551.  
  1552.    a.0 = 1
  1553.    a.1 = value
  1554.  
  1555.    call EMS_CustomCfg_Set( 'DMreply_Cfg', area_name, field, 'a' )
  1556.  
  1557.    return 0
  1558.  
  1559. Global_Cfg_Get: procedure
  1560.  
  1561.    parse arg area_name , field
  1562.  
  1563.    if area_name = '' then return ''
  1564.  
  1565.    call EMS_CustomCfg_Get( 'DMreply_Cfg', area_name, field, 'a' )
  1566.  
  1567.    if a.0 >= 1 then return a.1
  1568.  
  1569.    return ''
  1570.  
  1571. CalcRandom: procedure
  1572.  
  1573.    parse arg limit
  1574.  
  1575.    seed = getclip( 'LAST_RANDOM_SEED'  )
  1576.    last = getclip( 'LAST_RANDOM_VALUE' )
  1577.  
  1578.    if seed = '' | seed = 0 then seed = Time( 'S' )
  1579.    if last = ''            then last = 0
  1580.  
  1581.    parse var seed seed '.'
  1582.  
  1583.    seed = randu( seed )
  1584.    num  = ((seed * limit * 2) // (limit * 2)) % 2
  1585.    num  = ((num  + last     ) //  limit     ) + 1
  1586.  
  1587.    call setclip( 'LAST_RANDOM_SEED' , seed * num / limit * 86400 )
  1588.    call setclip( 'LAST_RANDOM_VALUE', num                        )
  1589.  
  1590.    return num
  1591.