home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / comm / ems-1.0.lha / EMS / Rexx / Multisend.ems < prev    next >
Text File  |  1993-08-29  |  5KB  |  175 lines

  1. /*****************/
  2. /* Multisend.ems */
  3. /**************************************************************************/
  4. /*                                                                        */
  5. /* Multisend config file format:                                          */
  6. /*                                                                        */
  7. /* NAME    = the string that identifies a multisend session.              */
  8. /*                                                                        */
  9. /* FROM    = the 'From' field of the messages.                            */
  10. /* SUBJECT = the 'Subject' field of the messages.                         */
  11. /* ORIGIN  = optional origin line.                                        */
  12. /* TO      = the destination of a message, <name> ^ <address> ^ [<area>]  */
  13. /*           where: <name>    is the 'To' field of the message.           */
  14. /*                  <address> is the 'To' address.                        */
  15. /*                  <area>    is the area of the message.                 */
  16. /*                                                                        */
  17. /*           (leaving empty the area causes a netmail multisend).         */
  18. /*                                                                        */
  19. /* Ex: To="All^^Test" -> echo message in area 'Test'                      */
  20. /*     To="Davide Massarenti^2:332/505@fidonet.org^" -> mail message.     */
  21. /*                                                                        */
  22. /*                                                                        */
  23. /**************************************************************************/
  24. /* $VER: Multisend.ems 1.0 (29.08.93)  */
  25. /***************************************/
  26.  
  27. options results
  28. signal on error
  29. signal on syntax
  30.  
  31. parse arg which files
  32.  
  33. if( ~show( 'l', "ems_rexx.library" ) ) then
  34. do
  35.    if( ~addlib( "ems_rexx.library", 0, -30, 0 ) )then
  36.    do
  37.       say "Could not open ems_rexx.library"
  38.       exit 10
  39.    end
  40. end
  41.  
  42. /*trace r*/
  43.  
  44. files = strip( files, 'B' )
  45.  
  46. if files = '' then
  47. do
  48.  
  49.    say "Usage: MultiSend.ems <setting's part> <file to send> [<file to send> ...]"
  50.    signal ExitScript
  51.  
  52. end
  53.  
  54. file.0 = 0
  55.  
  56. do while length( files ) ~= 0
  57.  
  58.    parse var files name files
  59.  
  60.    if exists( name ) = 0 then
  61.    do
  62.  
  63.       say "Can't find file <" || name || ">"
  64.       signal ExitScript
  65.  
  66.    end
  67.  
  68.    call EMS_Add_To_Stem( 'file', name, 'UNIQUE' )
  69.  
  70. end
  71.  
  72.  
  73. cfg_version  = '1.0'
  74. cfg_name     = 'MultiSend'
  75. cfg_mail     = FindMailArea()
  76. cfg_def_orig = EMS_Var_Local( 'ORIGIN_NAME' )
  77.  
  78.  
  79. call EMS_CustomCfg_Search( cfg_name, which, 'items' )
  80.  
  81. do i=1 to items.0
  82.  
  83.    item_from.0 = 0
  84.    item_subj.0 = 0
  85.    item_to.0   = 0
  86.    item_orig.0 = 0
  87.  
  88.    if EMS_CustomCfg_Get( cfg_name, items.i, 'From'   , 'item_from' ) != 'OK' | item_from.0 = 0 then iterate
  89.    if EMS_CustomCfg_Get( cfg_name, items.i, 'Subject', 'item_subj' ) != 'OK' | item_subj.0 = 0 then iterate
  90.    if EMS_CustomCfg_Get( cfg_name, items.i, 'To'     , 'item_to'   ) != 'OK' | item_to.0   = 0 then iterate
  91.    if EMS_CustomCfg_Get( cfg_name, items.i, 'Origin' , 'item_orig' ) != 'OK'                   then iterate
  92.  
  93.    if item_from.0 ~= 0 then msg_from = item_from.1
  94.    if item_subj.0 ~= 0 then msg_subj = item_subj.1
  95.    if item_orig.0 ~= 0 then msg_orig = item_orig.1
  96.                        else msg_orig = cfg_def_orig
  97.  
  98.    do j=1 to item_to.0
  99.  
  100.       parse var item_to.j msg_to '^' msg_to_addr '^' msg_area
  101.  
  102.       if msg_area = '' then msg_area = cfg_mail
  103.  
  104.       /*
  105.       ** Get infos about the message area.
  106.       */
  107.       area_type = EMS_Area_Type(    msg_area )
  108.       area_addr = EMS_Area_Address( msg_area )
  109.  
  110.       call EMS_Item_Alloc(               'write_msg', msg_area, 'msg' )
  111.       call EMS_Item_Header_From(         'write_msg', msg_from        )
  112.       call EMS_Item_Header_To(           'write_msg', msg_to          )
  113.       call EMS_Item_Header_Subject(      'write_msg', msg_subj        )
  114.       call EMS_Item_Header_Address_From( 'write_msg', area_addr       )
  115.       call EMS_Item_Header_Address_To(   'write_msg', area_addr       )
  116.  
  117.       if upper( area_type ) = 'MAIL' then
  118.       do
  119.  
  120.          call EMS_Item_Header_Flag(       'write_msg', 'PVT', 'TRUE' )
  121.          call EMS_Item_Header_Address_To( 'write_msg', msg_to_addr   )
  122.  
  123.       end
  124.       else
  125.       do
  126.  
  127.          call EMS_Item_Line_Unique( 'write_msg', 'header', '--- '       , '--- MultiSend v' || cfg_version                      )
  128.          call EMS_Item_Line_Unique( 'write_msg', 'header', ' * Origin: ', ' * Origin: ' || msg_orig || ' (' || area_addr || ')' )
  129.  
  130.       end
  131.  
  132.       do k=1 to file.0
  133.  
  134.          call EMS_Item_File_Read( 'write_msg', 'text', file.k, 'APPEND' )
  135.  
  136.       end
  137.  
  138.       call EMS_Item_Write( 'write_msg' )
  139.       call EMS_Item_Free(  'write_msg' )
  140.  
  141.    end
  142.  
  143. end
  144.  
  145. ExitScript:
  146.  
  147. call EMS_FreeScriptData()
  148. exit 0
  149.  
  150.  
  151. error:
  152. syntax:
  153.  
  154. error_text = EMS_LastError()
  155.  
  156. if error_text = '' then error_text = rc ErrorText( rc )
  157.  
  158. say '| ***BREAK: error at' sigl error_text
  159.  
  160. call EMS_FreeScriptData()
  161. exit rc
  162.  
  163.  
  164. FindMailArea: procedure
  165.  
  166.    call EMS_Areas( 'a' )
  167.  
  168.    do i=1 to a.0
  169.  
  170.       if upper( EMS_Area_Type( a.i ) ) = 'MAIL' then return a.i
  171.  
  172.    end
  173.  
  174.    return ''
  175.