home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / internet / yamtools20 / yamtools20english / ytprint.rexx < prev    next >
OS/2 REXX Batch file  |  1997-08-08  |  43KB  |  1,267 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*                              YTPrint                                       */
  4. /*                 Copyright ©1997 by Dick Whiting                            */
  5. /*                                                                            */
  6. /*----------------------------------------------------------------------------*/
  7. /*    This version requires MuiRexx 3.0 use Yamtools 1.7 with MuiRexx 2.2     */
  8. /*----------------------------------------------------------------------------*/
  9. /* This script requires YAMTOOLS for it to work. If you don't have YAMTOOLS   */
  10. /* you can get it on Aminet in directory comm/mail. This script allows you    */
  11. /* to Print a Yam mail with textstyling (bold, underline, italic) as it       */
  12. /* appears from within Yam (color changed to bold). It also allows for        */
  13. /* saving to disk with/without converting the styling to ANSI codes.          */
  14. /*----------------------------------------------------------------------------*/
  15. /* To use this select a mail and decide how much you want printed, saved, or  */
  16. /* viewed and whether to STYLE or not. There is also an option to print/save  */
  17. /* each section of the mail as a separate page/file.                          */
  18. /*----------------------------------------------------------------------------*/
  19. /*                                                                            */
  20. /* Standard Disclaimer: I wrote it, it works for me, I don't guarantee        */
  21. /* that it will do anything productive for anyone else, etc. etc. ;-)         */
  22. /*                                                                            */
  23. /*HOWEVER, if you DO find a use for it: I homeschool my kids and they         */
  24. /*would love a postcard from where EVER you live.                             */
  25. /*                                                                            */
  26. /*Instant GEOGRAPHY lesson;)                                                  */
  27. /*                                                                            */
  28. /*                                                                            */
  29. /*POSTCARDS:    Dick Whiting                                                  */
  30. /*              28590 S. Beavercreek Rd.                                      */
  31. /*              Mulino, Oregon 97042                                          */
  32. /*              USA                                                           */
  33. /*                                                                            */
  34. /*----------------------------------------------------------------------------*/
  35. /*                                                                            */
  36. /*               Address Bug Reports or Comments to:                          */
  37. /*                Dick Whiting <dwhiting@europa.com>                          */
  38. /*                           21 June 1997                                     */
  39. /*                                                                            */
  40. /******************************************************************************/
  41. /*
  42. $VER: 1.0 Copyright ©1997 by Dick Whiting
  43. $AUTHOR: Dick Whiting
  44. $DESCRIPTION: Print a mail file with styling     
  45. */
  46.  
  47. options results
  48. options failat 21
  49.  
  50. parse arg mainparm subparm
  51.  
  52. /**************************************************************************/
  53. /*                         Initialize Variables                           */
  54. /**************************************************************************/
  55. Call MUIvars                                /* go define vars for MUI use */
  56. Call YTvars                                 /* various values used in YT  */
  57. Call Helpvars                               /* pointers into HELP guide   */
  58. Call Localize                               /* vars for localizing strings*/
  59. Call Builtvars                              /* built using previous values*/
  60.  
  61. Address YAMTOOLS
  62.  
  63. Call CheckYam
  64.  
  65. Select
  66.    when mainparm='' then do
  67.       Call CheckDup
  68.       Call GetYamInfo
  69.       Call ReadMail
  70.       Call BuildWindow
  71.       Call IdMail
  72.    end
  73.    when mainparm='READ' then do
  74.       Call ViewPrint  
  75.    end
  76.    when mainparm='VIEW' then do
  77.       Call ViewPrint
  78.    end
  79.    when mainparm='PRINT' then do
  80.       Call ViewPrint
  81.    end
  82.    when mainparm='DISK' then do
  83.       Call ViewPrint
  84.    end
  85.    when mainparm='UNMIME' then do
  86.       Call GetYamInfo
  87.       method ID YTPRM MUIM_List_Clear
  88.       method ID YTPRH MUIM_List_Clear
  89.       method ID YTPRT MUIM_List_Clear
  90.       method ID YTPRR MUIM_List_Clear
  91.       Call UnMime
  92.       Call ReadMail
  93.       Call IdMail
  94.    end
  95.    when mainparm='QUIT' then do
  96.       'window ID YTPRW close'
  97.    end
  98.    otherwise do
  99.       errmsg=_text._badparm
  100.       Call ErrorMsg
  101.    end
  102. end 
  103.  
  104. j=0
  105. k=j
  106. do i=1 to selected.0
  107.    list ID YTPRM ATTRS MUIA_List_Entries
  108.    mcnt=result
  109.    do j=k to mcnt-1
  110.       list ID YTPRM POS j
  111.       xsubparm=result
  112.       if xsubparm=selected.i then do
  113.          reselptr=1+reselect.0
  114.          reselect.0=reselptr
  115.          reselect.reselptr=j
  116.          k=j
  117.          leave j
  118.       end
  119.    end
  120. end
  121. do j=1 to reselect.0
  122.    method ID YTPRM MUIM_List_Select reselect.j MUIV_List_Select_On
  123. end
  124.  
  125. exit
  126.  
  127. /**************************************************************************/
  128. /*                        Read the mail file into array                   */
  129. /**************************************************************************/
  130. ReadMail:     
  131.  
  132.    maillist.=''
  133.    maillist.0=0
  134.    i=0
  135.  
  136.    if open('IN',mfile,'R') then do
  137.       do while ~eof('IN')
  138.          linein=readln('IN')
  139.          if ~eof('IN') then do
  140.             i=i+1
  141.             linein=translate(linein,' ',tab)
  142.             maillist.i=linein
  143.          end
  144.       end
  145.       maillist.0=i
  146.       foo=close('IN')
  147.       window ID YTINF close
  148.    end
  149.    else do
  150.       errmsg=_text._badmail
  151.       Call ErrorMsg
  152.       exit     
  153.    end
  154.  
  155. Return
  156.  
  157. /**************************************************************************/
  158. /*                 Loop thru the mail identifying parts                   */
  159. /**************************************************************************/
  160. IdMail:     
  161.  
  162.    infotext=_text._prepmail
  163.    infobuttons=''
  164.    showbusy=TRUE
  165.    Call InfoWindow
  166.  
  167.     header.=' '
  168.  
  169.    parts.0=0
  170.    parts.=''
  171.  
  172.    i=0
  173.    header=TRUE
  174.    multipart=FALSE
  175.    quoted=FALSE
  176.    bfound=FALSE   
  177.    parttype='H'
  178.    boundary=''
  179.    partname='text/plain'
  180.    content='text/plain'
  181.    encoding=''
  182.    partnum=0
  183.    headnum=1
  184.  
  185.    list ID YTPRT ATTRS MUIA_List_Quiet TRUE 
  186.    list ID YTPRM ATTRS MUIA_List_Quiet TRUE 
  187.  
  188.    do i=1 to maillist.0
  189.       if header then do
  190.          if maillist.i~='' then do
  191.                 select
  192.                  when upper(word(maillist.i,1))='FROM:' then header.1=maillist.i
  193.                  when upper(word(maillist.i,1))='TO:'   then header.2=maillist.i
  194.                  when upper(word(maillist.i,1))='DATE:' then header.3=maillist.i
  195.                  when upper(word(maillist.i,1))='SUBJECT:' then header.4=maillist.i
  196.                  when upper(word(maillist.i,1))='CONTENT-TYPE:' then do
  197.                   if pos('BOUNDARY=',upper(maillist.i))>0 then do
  198.                      parse var maillist.i junk '=' boundary
  199.                      boundary=strip(boundary,'B','"')
  200.                      if boundary~='' then do 
  201.                         boundary='--'||boundary
  202.                         endbound=boundary||'--'
  203.                         multipart=TRUE
  204.                      end
  205.                   end
  206.                   else do
  207.                      content=word(maillist.i,2)
  208.                      content=strip(content,'T',';')
  209.                      parse var maillist.i junk'name='partname';'rest
  210.                      partname=strip(partname,'B','"')
  211.                   end
  212.                end
  213.                  when upper(word(maillist.i,1))='CONTENT-TRANSFER-ENCODING:' then do
  214.                   encoding=word(maillist.i,2)
  215.                   if upper(encoding)='QUOTED-PRINTABLE' then do 
  216.                      quoted=TRUE
  217.                   end
  218.                end
  219.                     otherwise nop
  220.                 end
  221.             call LoadParts
  222.          end           
  223.          else do  /* start of section after a header */
  224.             partnum=partnum+1
  225.             if multipart & ~bfound then parttype='L' 
  226.                                    else parttype='B'
  227.             call LoadParts
  228.             headnum=headnum+1
  229.             header=FALSE
  230.          end
  231.       end   
  232.       else do
  233.          if ~multipart then do
  234.             call LoadParts
  235.          end
  236.          else do  /* need to handle multipart */
  237.             select
  238.                when ~bfound & maillist.i~=boundary then do
  239.                   call LoadParts
  240.                end
  241.                when ~bfound & maillist.i=boundary then do
  242.                   parttype='X'
  243.                   call LoadParts
  244.                   bfound=TRUE
  245.                   partcnt=partcnt+1
  246.                   j=i+1
  247.                   if maillist.j='' then do /* line after boundary null */
  248.                      parttype='B'       /*!changed from T */
  249.                      headnum=headnum+1  /* inserted       */
  250.                   end
  251.                   else do /* line after boundary NOT null */
  252.                      parttype='H'
  253.                      header=TRUE
  254.                   end
  255.                end
  256.                when bfound & maillist.i=endbound then do
  257.                   parttype='X'
  258.                   call LoadParts
  259.                   partcnt=partcnt+1
  260.                   parttype='T' 
  261.                end
  262.                when bfound & maillist.i~=boundary then do
  263.                   call LoadParts
  264.                end
  265.                when bfound & maillist.i=boundary then do
  266.                   parttype='X'
  267.                   call LoadParts
  268.                   bfound=TRUE
  269.                   j=i+1
  270.                   if maillist.j='' then do /* line after boundary null */
  271.                      parttype='B' 
  272.                      headnum=headnum+1
  273.                      partcnt=partcnt+1
  274.                   end
  275.                   else do /* line after boundary NOT null */
  276.                      parttype='H'
  277.                      header=TRUE
  278.                   end
  279.                end
  280.                otherwise do
  281.                   say 'found otherwise in IdMail'
  282.                end
  283.             end   
  284.          end 
  285.       end
  286.    end
  287.  
  288.     do j=1 to 4
  289.        list ID YTPRT INSERT POS MUIV_List_Insert_Bottom STRING '='header.j
  290.     end
  291.  
  292.    parttype=parts.1
  293.    partcnt=parts.1.1
  294.    sectcnt=1
  295.  
  296.    do i=2 to maillist.0
  297.       if parts.i=parttype & parts.i.1=partcnt then do
  298.          sectcnt=sectcnt+1
  299.       end          
  300.       else do
  301.          Call ReportParts
  302.          parttype=parts.i
  303.          partcnt=parts.i.1
  304.          sectcnt=1
  305.       end
  306.    end
  307.  
  308.    i=maillist.0
  309.    Call ReportParts
  310.  
  311.    list ID YTPRT ATTRS MUIA_List_Quiet FALSE 
  312.    list ID YTPRM ATTRS MUIA_List_Quiet FALSE 
  313.  
  314.    list ID YTPRM ATTRS MUIA_List_Entries
  315.    mcnt=result
  316.  
  317.    do i=0 to mcnt-1
  318.       list ID YTPRM POS i
  319.       subparm=result
  320.       parse var subparm parttype ',' xpartcnt ',' rest
  321.       if substr(parttype,3)='Body' then leave i
  322.    end
  323.  
  324.    if i>0 then do
  325.       firsttime=TRUE
  326.       method ID YTPRM MUIM_List_Select i MUIV_List_Select_On
  327.       mainparm='VIEW'
  328.       Call ViewPrint
  329.    end
  330.  
  331.    if quoted then do
  332.       errmsg=_text._prtquoted
  333.       Call ErrorMsg
  334.       exit
  335.    end
  336.  
  337. Return
  338.  
  339. /**************************************************************************/
  340. /*             Build array with type information for each line            */
  341. /**************************************************************************/
  342. LoadParts:
  343.  
  344.    if parttype='H' then partcnt=headnum
  345.                    else partcnt=partcnt
  346.  
  347.    linein=parttype||','||partcnt||','||partname||','||content||','||encoding||',='||maillist.i
  348.    list ID YTPRH INSERT POS MUIV_List_Insert_Bottom, 
  349.         ATTRS MUIA_List_Format """,,,,,""",
  350.         STRING linein
  351.    parts.i=parttype
  352.    parts.i.1=partcnt
  353.    parts.i.1.1=partname
  354.    parts.i.1.1.1=content
  355.    parts.i.1.1.1.1=encoding
  356.  
  357. Return
  358.  
  359. /**************************************************************************/
  360. /*             Display one line per portion of Mail File                  */
  361. /*             !!! need to figure out what is encodet how in multipart    */
  362. /**************************************************************************/
  363. ReportParts:
  364.  
  365.    if parttype~='B' then do
  366.       partname=''
  367.       content=''
  368.       encoding=''
  369.    end
  370.    else do
  371.       partname=parts.i.1.1
  372.       content=parts.i.1.1.1
  373.       encoding=parts.i.1.1.1.1
  374.    end
  375.  
  376.    select
  377.       when parttype='H' then parttype='Header'
  378.       when parttype='L' then parttype='Leader'
  379.       when parttype='X' then parttype='Boundary'
  380.       when parttype='B' then parttype=bo||'Body'
  381.       when parttype='T' then parttype='Trailer'
  382.       otherwise parttype='Unknown'
  383.    end
  384.  
  385.    linein=parttype||','||partcnt||','||sectcnt||','||partname||','||content||','||encoding
  386.    list ID YTPRM INSERT POS MUIV_List_Insert_Bottom,  
  387.         ATTRS MUIA_List_Format """P=\033l BAR,P=\033r BAR,P=\033r BAR,P=\033l BAR,BAR,""", 
  388.         STRING linein
  389.  
  390. Return
  391.  
  392. /**************************************************************************/
  393. /*                    Display portion of mail in list                     */
  394. /**************************************************************************/
  395. DisplayMail:
  396.  
  397.    parse var subparm parttype ',' xpartcnt ',' rest
  398.  
  399.    list ID YTPRM ATTRS MUIA_List_Entries
  400.    mcnt=result
  401.  
  402.    do i=0 to mcnt-1
  403.       list ID YTPRM POS i
  404.       xsubparm=result
  405.       if xsubparm=subparm then do
  406.          selected.0=1
  407.          selected.1=subparm
  408.          leave i
  409.       end
  410.    end
  411.  
  412.    parttype=substr(parttype,2)
  413.    if c2d(substr(parttype,1,1))=27 then do
  414.       parttype=substr(parttype,3)
  415.    end
  416.    select
  417.       when parttype='Header'   then xparttype='H'
  418.       when parttype='Leader'   then xparttype='L'
  419.       when parttype='Boundary' then xparttype='X'
  420.       when parttype='Body'     then xparttype='B'
  421.       when parttype='Trailer'  then xparttype='T'
  422.       otherwise do
  423.          errmsg=_text._badparttype
  424.          Call ErrorMsg
  425.          exit
  426.       end
  427.    end
  428.  
  429.    list ID YTPRH ATTRS MUIA_List_Entries
  430.    mcnt=result
  431.  
  432.    list ID YTPRR ATTRS MUIA_List_Quiet TRUE  
  433.    method ID YTPRR MUIM_List_Clear
  434.  
  435.    found=FALSE
  436.    do i=0 to mcnt-1
  437.       list ID YTPRH POS i
  438.       linein=result
  439.       parse var linein parttype ',' partcnt ',' partname ',' content ',' encoding ',' maillist
  440.       if xparttype=parttype & xpartcnt=partcnt then do
  441.          found=TRUE
  442.          list ID YTPRR INSERT POS MUIV_List_Insert_Bottom,
  443.          STRING '='maillist
  444.       end
  445.       else do
  446.          if found then leave
  447.       end
  448.    end 
  449.    list ID YTPRR ATTRS MUIA_List_Quiet FALSE
  450.  
  451. Return
  452.  
  453. /**************************************************************************/
  454. /*             Main Logic Loop for viewing and printing                   */
  455. /**************************************************************************/
  456. ViewPrint:
  457.  
  458.    if ~firsttime then do
  459.       infotext=_text._prepmail
  460.       infobuttons=''
  461.       showbusy=TRUE
  462.       Call InfoWindow 
  463.    end
  464.  
  465.    cycle  ID YTPR4
  466.    styled=result
  467.    if styled=_label._ytpr4a then styled=TRUE
  468.                             else styled=FALSE
  469.  
  470.    cycle  ID YTPR5
  471.    multijob=result
  472.    if multijob=_label._ytpr5b then multijob=TRUE
  473.                               else multijob=FALSE
  474.  
  475.    cycle  ID YTPR7
  476.    coloropt=result
  477.  
  478.    if coloropt=_label._ytpr7a then coloropt=FALSE
  479.                               else coloropt=TRUE
  480.  
  481.    Call StyleVals
  482.  
  483.    select
  484.       when mainparm='VIEW' then do
  485.          list ID YTPRR ATTRS MUIA_List_Quiet TRUE 
  486.          method ID YTPRR MUIM_List_Clear
  487.          Call DoViewPrint
  488.          list ID YTPRR ATTRS MUIA_List_Quiet FALSE
  489.       end
  490.       when mainparm='PRINT' then do
  491.          if open('OUT','PRT:','W') then do
  492.             Call DoViewPrint
  493.             foo=close('OUT')
  494.          end  /* good open on PRT: */
  495.          else do
  496.             errmsg=_text._noprinter
  497.             Call ErrorMsg
  498.             exit
  499.          end
  500.       end
  501.       otherwise do /* better be SAVE to DISK */
  502.          Call GetFileName
  503.          Call DoViewPrint
  504.       end
  505.    end
  506.  
  507.    window ID YTINF close
  508.  
  509. Return
  510.  
  511. /**************************************************************************/
  512. /*              Handle looping thru selected mail parts                   */
  513. /**************************************************************************/
  514. DoViewPrint:
  515.      
  516.    list ID YTPRM ATTRS MUIA_List_Entries
  517.    mcnt=result
  518.  
  519.    list ID YTPRH ATTRS MUIA_List_Entries
  520.    hcnt=result
  521.  
  522.    do i=0 to mcnt-1
  523.       list ID YTPRM
  524.       subparm=result
  525.       if subparm='' then leave i
  526.       selptr=1+selected.0
  527.       selected.0=selptr
  528.       selected.selptr=subparm
  529.       parse var subparm parttype ',' xpartcnt ',' rest
  530.  
  531.       if c2d(substr(parttype,1,1))=27 then do
  532.          parttype=substr(parttype,3)
  533.       end
  534.  
  535.       select
  536.          when parttype='Header'   then xparttype='H'
  537.          when parttype='Leader'   then xparttype='L'
  538.          when parttype='Boundary' then xparttype='X'
  539.          when parttype='Body'     then xparttype='B'
  540.          when parttype='Trailer'  then xparttype='T'
  541.          otherwise do
  542.             errmsg=_text._badparttype
  543.             Call ErrorMsg
  544.             exit
  545.          end
  546.       end
  547.  
  548.       found=FALSE
  549.  
  550.       if mainparm='PRINT' & multijob & i>0 then do 
  551.          foo=writeln('OUT',FF)
  552.       end
  553.       if mainparm='DISK' & multijob & i>0 then do 
  554.          foo=close('OUT')
  555.          Call GetFileName
  556.       end
  557.  
  558.       if i=0 then do
  559.          if coloropt & styled & mainparm='PRINT' then do
  560.             foo=writech('OUT',qoff)          /* force to normal text      */ 
  561.          end
  562.          if xparttype~='H' | xpartcnt~=1 then do
  563.             Call DoHeader
  564.          end
  565.       end
  566.  
  567.       do j=0 to hcnt-1
  568.          list ID YTPRH POS j
  569.          linein=result
  570.          parse var linein parttype ',' partcnt ',' partname ',' content ',' encoding ',' maillist
  571.          if xparttype=parttype & xpartcnt=partcnt then do
  572.             found=TRUE
  573.             if styled then do
  574.                Call StyleIt
  575.             end
  576.             if mainparm='VIEW' then do
  577.                maillist=translate(maillist,' ',',')
  578.                if maillist='' then maillist=no
  579.                list ID YTPRR INSERT POS MUIV_List_Insert_Bottom,
  580.                STRING maillist
  581.             end
  582.             else do  /* Print OR Save it */
  583.                foo=writeln('OUT',maillist)
  584.             end
  585.          end
  586.          else do
  587.             if found then leave j
  588.          end 
  589.       end  
  590.    end
  591.  
  592.    if i=0 then do
  593.       errmsg=_text._nosect
  594.       Call ErrorMsg
  595.       exit
  596.    end
  597.  
  598. Return
  599.  
  600. /**************************************************************************/
  601. /*                   Handle type of header to include                     */
  602. /**************************************************************************/
  603. DoHeader:
  604.  
  605.    cycle  ID YTPR6
  606.    headopt=result
  607.  
  608.    select
  609.       when mainparm='VIEW' then nop          /* no headers on VIEW option */
  610.       when headopt=_label._ytpr6c then nop   /* set to NONE for header    */
  611.       when headopt=_label._ytpr6b then do    /* set to FULL for header    */
  612.          do j=0 to hcnt-1                    /* loop thru file            */
  613.             list ID YTPRH POS j
  614.             linein=result
  615.             parse var linein parttype ',' partcnt ',' partname ',' content ',' encoding ',' maillist
  616.             if parttype='H' & partcnt=1 then do
  617.                foo=writeln('OUT',maillist)  
  618.             end
  619.             else leave j
  620.          end
  621.       end
  622.       otherwise do                           /* set to SHORT for header   */
  623.          do j=0 to 3
  624.             list ID YTPRT POS j
  625.             headline=result
  626.             foo=writeln('OUT',headline)
  627.          end
  628.       end
  629.    end
  630.  
  631. Return
  632.  
  633. /**************************************************************************/
  634. /*                        Get Filename for SAVES                          */
  635. /**************************************************************************/
  636. GetFileName:
  637.  
  638.    getvar YTPRINTDIR 
  639.    ytprintfile=result   
  640.  
  641.    select
  642.       when lastpos('/',ytprintfile)>0 then do
  643.          savfile=substr(ytprintfile,lastpos('/',ytprintfile)+1)
  644.          savdir=substr(ytprintfile,1,lastpos('/',ytprintfile)-1)
  645.       end
  646.       when lastpos(':',ytprintfile)>0 then do
  647.          savfile=substr(ytprintfile,lastpos(':',ytprintfile)+1)
  648.          savdir=substr(ytprintfile,1,lastpos(':',ytprintfile))
  649.       end
  650.       otherwise do
  651.          savfile=''
  652.          savdir="""T:"""
  653.       end
  654.    end
  655.  
  656.    aslrequest ID YTPRW TITLE _title._asl,
  657.               ATTRS ASLFR_InitialDrawer savdir ASLFR_InitialFile savfile 
  658.    if rc = 0 then do
  659.       ytprintfile=result
  660.       setvar YTPRINTDIR ytprintfile
  661.       if ~open('OUT',ytprintfile,'W') then do
  662.          errmsg=_text._badsavefile
  663.          Call ErrorMsg
  664.          exit
  665.       end
  666.    end
  667.    else do
  668.       window ID YTINF close
  669.       exit
  670.    end
  671.  
  672. Return
  673.  
  674. /**************************************************************************/
  675. /*                        Set Styling code values                         */
  676. /*                                                                        */
  677. /**************************************************************************/
  678. StyleVals:
  679.  
  680.    stylelist='#_*/'
  681.    goodpre1=' [({\"&+'
  682.    goodpre2="'"
  683.    badpost1=' /_:;.,#+\|?=([{&%$§"!'
  684.    goodpost1=" +&'\n})]-.:,;!?"  
  685.  
  686.    select
  687.       when mainparm='VIEW' then do    /* show with MUI formatted styling  */
  688.          SansiBold=bo
  689.          EansiBold=no
  690.          SansiItal=it
  691.          EansiItal=no
  692.          SansiUlin=ul  
  693.          EansiUlin=no
  694.          SansiColr=co
  695.          EansiColr=cx
  696.          QuoteColr=hl
  697.          qattr=QuoteColr
  698.          qoff=EansiColr
  699.       end
  700.       when coloropt & mainparm='DISK' then do  /* save as COLORED styling */
  701.          csi='1B5B'x
  702.          SansiBold=csi||'1m'
  703.          EansiBold=csi||'22m'
  704.          SansiItal=csi||'3m'
  705.          EansiItal=csi||'23m'
  706.          SansiUlin=csi||'4m'
  707.          EansiUlin=csi||'24m'
  708.          SansiColr=csi||'33;40m'
  709.          EansiColr=csi||'31;40m'
  710.          QuoteColr=csi||'37;40m'
  711.          qattr=QuoteColr
  712.          qoff=EansiColr
  713.       end
  714.       when coloropt & mainparm='PRINT' then do /* print as COLORED styling */
  715.          csi='1B5B'x
  716.          SansiBold=csi||'1m'
  717.          EansiBold=csi||'22m'
  718.          SansiItal=csi||'3m'
  719.          EansiItal=csi||'23m'
  720.          SansiUlin=csi||'4m'
  721.          EansiUlin=csi||'24m'
  722.          SansiColr=csi||'36;47m'
  723.          EansiColr=csi||'30;47m'
  724.          QuoteColr=csi||'31;47m'
  725.          qattr=QuoteColr
  726.          qoff=EansiColr
  727.       end
  728.       otherwise do                    /* print or save as B/W styling     */
  729.          csi='1B5B'x
  730.          SansiBold=csi||'1m'
  731.          EansiBold=csi||'22m'
  732.          SansiItal=csi||'3m'
  733.          EansiItal=csi||'23m'
  734.          SansiUlin=csi||'4m'
  735.          EansiUlin=csi||'24m'
  736.          SansiColr=csi||'1m'
  737.          EansiColr=csi||'22m'
  738.          QuoteColr=SansiColr
  739.          qattr=QuoteColr
  740.          qoff=EansiColr
  741.       end
  742.    end
  743.  
  744. Return
  745.  
  746. /**************************************************************************/
  747. /*                        Convert styling to ANSI                         */
  748. /*                                                                        */
  749. /* Logic: Locate FIRST style character that fits rules.                   */
  750. /*        Locate FIRST same  character after it.                          */
  751. /*        If valid then replace those with ANSI codes.                    */
  752. /*           Save that portion and loop for possible others.              */
  753. /*        If NOT valid then loop looking for a new FIRST possibility.     */
  754. /*                                                                        */
  755. /* This appears to match the logic in Yam1.3.4 which probably will change */
  756. /* in Yam2.x Right now it seems that the next matching style character    */
  757. /* MUST be a valid ending one OR the starting one is invalid as a start.  */
  758. /*                                                                        */
  759. /**************************************************************************/
  760. StyleIt:     
  761.  
  762.    qattr=QuoteColr
  763.    qline=TRUE
  764.    testword=word(maillist,1)
  765.    if pos('>',testword)=0 then do 
  766.       qline=FALSE
  767.       qattr=qoff
  768.    end
  769.  
  770. /******************* better logic for quoted lines **********
  771.    qline=TRUE
  772.    testword=word(maillist,1)
  773.    if length(testword)>0 then do 
  774.       tchar0=substr(testword,length(testword),1)
  775.       if tchar0~='>' & substr(testword,1,1)~='>' then do 
  776.          qline=FALSE
  777.          qattr=qoff
  778.       end
  779.    end
  780.    else do
  781.       qline=FALSE
  782.       qattr=qoff
  783.    end
  784. ********************************************************/
  785.  
  786.    mailtest=maillist
  787.    mailcopy=''
  788.  
  789.    spos=verify(mailtest,stylelist,'MATCH')
  790.  
  791.    do while spos>0
  792.       schar=substr(mailtest,spos,1)
  793.  
  794.       /* test if character BEFORE style character is a valid one */ 
  795.       if spos>1 then do        
  796.          tchar1=substr(mailtest,spos-1,1)
  797.          if verify(goodpre1,tchar1,'MATCH')=0 & tchar1~=goodpre2 then do
  798.             Call TrimIt
  799.             iterate         
  800.          end
  801.       end
  802.  
  803.       /* Character BEFORE style character IS valid - test one after it */
  804.       if spos<length(mailtest) then do
  805.          tchar2=substr(mailtest,spos+1,1)
  806.          if verify(badpost1,tchar2,'MATCH')>0 then do
  807.             Call TrimIt
  808.             iterate         
  809.          end
  810.       end
  811.       else do   /* all done - style char was last char in string */
  812.          mailcopy=mailcopy||mailtest
  813.          spos=0
  814.       end
  815.  
  816.       /* NOW locate the NEXT matching character if one                 */
  817.       epos=pos(schar,substr(mailtest,spos+1))
  818.  
  819.       /* if epos is not last character then check if following char val*/
  820.       if epos>0 then do
  821.           epos=spos+epos                         /* real position      */
  822.           if epos<length(mailtest) then do
  823.             tchar3=substr(mailtest,epos+1,1)  
  824.             if verify(goodpost1,tchar3,'MATCH')=0 then do
  825.                Call TrimIt
  826.                iterate         
  827.             end
  828.          end
  829.       end
  830.       else do  /* no matching end character */
  831.          Call TrimIt 
  832.          iterate         
  833.       end
  834.  
  835.       /* OK, have a valid START and END styling character                 */ 
  836.       if spos>1 then do 
  837.          temp1=substr(mailtest,1,spos-1)
  838.       end
  839.       else do 
  840.          temp1='' 
  841.       end
  842.  
  843.       temp2=substr(mailtest,spos+1,epos-spos-1)
  844.  
  845.       if epos<length(mailtest) then do 
  846.          temp3=substr(mailtest,epos+1)
  847.       end
  848.       else temp3=''  
  849.       
  850.       select
  851.          when schar='*' then temp2=SansiBold||temp2||EansiBold
  852.          when schar='#' then do 
  853.             if qline & mainparm='PRINT' then do 
  854.                temp2=EansiColr||temp2||EansiColr
  855.             end
  856.             else do
  857.                temp2=SansiColr||temp2||EansiColr
  858.             end 
  859.          end
  860.          when schar='_' then temp2=SansiUlin||temp2||EansiUlin
  861.          when schar='/' then temp2=SansiItal||temp2||EansiItal
  862.          otherwise nop
  863.       end
  864.       mailcopy=mailcopy||temp1||temp2
  865.       mailtest=qattr||temp3
  866.       spos=verify(mailtest,stylelist,'MATCH')
  867.    end 
  868.  
  869.    maillist=qattr||mailcopy||mailtest
  870.  
  871. Return
  872.  
  873. /**************************************************************************/
  874. /*                        Save the mail file back                         */
  875. /**************************************************************************/
  876. TrimIt:
  877.  
  878.    mailcopy=mailcopy||substr(mailtest,1,spos)
  879.    mailtest=substr(mailtest,spos+1)
  880.    if length(mailtest)>0 then do
  881.       spos=verify(mailtest,stylelist,'MATCH')
  882.    end
  883.    else do
  884.       spos=0
  885.    end
  886.  
  887. Return
  888.  
  889. /**************************************************************************/
  890. /*              Make sure YAM  and YAMTOOLS are running. Show YAM.        */
  891. /**************************************************************************/
  892. CheckYAM:
  893.  
  894.    if ~show('p','YAMTOOLS') then do
  895.       errmsg=_text._noyt
  896.       say errmsg
  897.       exit
  898.    end
  899.  
  900.    if ~show('p','YAM') then do
  901.       errmsg=_text._noyam
  902.       Call ErrorMsg
  903.       exit
  904.    end
  905.  
  906.    Address YAM 'show'                       /* uniconify YAM's screen     */  
  907.  
  908.     Address YAM 'info SCREEN'                /* get YAM's screen           */
  909.     screen=result
  910.     if screen='' then screen='Workbench'
  911.  
  912. Return
  913.  
  914. /**************************************************************************/
  915. /*              Make sure there isn't one running already.                */
  916. /**************************************************************************/
  917. CheckDup:
  918.  
  919.    list ID YTPRM ATTRS MUIA_List_Entries
  920.    if result~='RESULT' then do
  921.       errmsg=_text._secondrun
  922.       Call ErrorMsg
  923.       exit
  924.    end
  925.  
  926. Return
  927. /******************************************************************************/
  928. /*  Get information from YAM config file                                      */
  929. /******************************************************************************/
  930. GetYamInfo:
  931.  
  932.    Address YAM 'getmailinfo file'           /* find which mail to rewrap  */
  933.    mfile=result
  934.    
  935.    if mfile='' | mfile='RESULT' then do     /* no mail selected           */
  936.       errmsg=_text._nomail
  937.       Call ErrorMsg
  938.       exit
  939.    end
  940.  
  941. Return
  942.  
  943. /******************************************************************************/
  944. /*  Display ERROR message and EXIT.                                           */
  945. /******************************************************************************/
  946. ErrorMsg:
  947.  
  948.    window ID YTINF CLOSE
  949.  
  950.    request ID ERRM GADGETS  _text._ok errmsg
  951.  
  952.    exit
  953.  
  954. Return
  955.  
  956. /******************************************************************************/
  957. /*  Display the mail in a list window.                                        */
  958. /******************************************************************************/
  959. BuildWindow:
  960.  
  961.    if exists(UnMime.rexx) then ghostunmime=FALSE
  962.                           else ghostunmime=TRUE
  963.  
  964.    window ID YTPRW TITLE _title._main,        
  965.           COMMAND '"YTPrint.rexx QUIT"',
  966.           ATTRS MUIA_Window_PublicScreen screen
  967.  
  968.         group
  969.          group 
  970.                text ID YTPRF HELP help.YTPRF NODE node.YTPRF LABEL mfile
  971.             list ID YTPRH INSERT ATTRS MUIA_ShowMe FALSE 
  972.          endgroup
  973.          group HORIZ ATTRS MUIA_VertWeight 100
  974.             group 
  975.                list ID YTPRT HELP help.YTPRT NODE node.YTPRT INSERT,
  976.                     ATTRS MUIA_VertWeight 70 
  977.                list ID YTPRM HELP help.YTPRM NODE node.YTPRM INSERT,
  978.                     COMMAND '"YTPrint.rexx VIEW %s"',
  979.                     TITLE _title._ytprm,
  980.                      ATTRS MUIA_Listview_MultiSelect MUIV_Listview_MultiSelect_Shifted
  981.             endgroup
  982.             group HORIZ ATTRS MUIA_HorizWeight 20
  983.                group
  984.                   cycle  ID YTPR4 HELP help.YTPR4 NODE node.YTPR4,
  985.                          LABELS _label._ytpr4
  986.                   cycle  ID YTPR5 HELP help.YTPR5 NODE node.YTPR5,
  987.                          LABELS _label._ytpr5
  988.                   cycle  ID YTPR6 HELP help.YTPR6 NODE node.YTPR6,
  989.                          LABELS _label._ytpr6
  990.                   cycle  ID YTPR7 HELP help.YTPR7 NODE node.YTPR7,
  991.                          LABELS _label._ytpr7
  992.                   space 
  993.                endgroup
  994.                group
  995.                   button ID YTPR0 COMMAND '"YTPrint.rexx VIEW"',
  996.                                 HELP help.YTPR0 NODE node.YTPR0, 
  997.                                  LABEL _label._YTPR0
  998.                   button ID YTPR1 COMMAND '"YTPrint.rexx PRINT"',
  999.                                 HELP help.YTPR1 NODE node.YTPR1, 
  1000.                                  LABEL _label._YTPR1
  1001.                   button ID YTPR2 COMMAND '"YTPrint.rexx DISK"',  
  1002.                               HELP help.YTPR2 NODE node.YTPR2,               
  1003.                          LABEL _label._YTPR2                            
  1004.                   button ID YTPR3 COMMAND '"YTPrint.rexx UNMIME"',  
  1005.                               HELP help.YTPR3 NODE node.YTPR3,               
  1006.                          ATTRS MUIA_Disabled ghostunmime,
  1007.                          LABEL _label._YTPR3                            
  1008.                   space
  1009.                   button ID YTPRQ COMMAND '"YTPrint.rexx QUIT"',
  1010.                                 HELP help.YTPRQ NODE node.YTPRQ, 
  1011.                                  LABEL _label._YTPRQ
  1012.                endgroup
  1013.             endgroup
  1014.          endgroup
  1015.          group ATTRS MUIA_VertWeight 150
  1016.             list ID YTPRR HELP help.YTPRR NODE node.YTPRR INSERT
  1017.          endgroup
  1018.         endgroup
  1019.  
  1020.    endwindow
  1021.  
  1022. Return
  1023.  
  1024. /******************************************************************************/
  1025. /*  Simple information/error message window.                                  */
  1026. /******************************************************************************/
  1027. InfoWindow:
  1028.  
  1029.    window ID YTINF TITLE _title._info ATTRS MUIA_Window_PublicScreen screen,
  1030.           MUIA_Window_DepthGadget FALSE
  1031.  
  1032.       group 
  1033.          group 
  1034.             text ID STEXT HELP help.STEXT  NODE node.STEXT LABEL infotext
  1035.          endgroup
  1036.          if showbusy then do
  1037.             group
  1038.                object CLASS '"Busy.mcc"' ATTRS MUIA_VertWeight 25
  1039.             endgroup
  1040.          end
  1041.          if infobuttons ~='' then do
  1042.             group HORIZ
  1043.                group 
  1044.                   space HORIZ 
  1045.                endgroup
  1046.                group 
  1047.                   radio ID SQUIT HELP help.SQUIT  NODE node.SQUIT LABELS infobuttons
  1048.                endgroup
  1049.                group 
  1050.                   space HORIZ 
  1051.                endgroup
  1052.             endgroup
  1053.          end
  1054.          else do
  1055.             group 
  1056.                space HORIZ 100
  1057.             endgroup
  1058.          end
  1059.       endgroup
  1060.    endwindow
  1061.  
  1062. Return
  1063.  
  1064. /******************************************************************************/
  1065. /*                      MUIREXX TAGS & VARIABLES                              */
  1066. /******************************************************************************/
  1067. Muivars:
  1068.  
  1069. /*
  1070. MUIA_CycleChain =           0x80421ce7
  1071. MUIA_String_Accept =        0x8042e3e1
  1072. MUIA_Window_ActiveObject =  0x80427925
  1073. MUIA_Window_ActiveObject =  0x80427925
  1074. MUIA_String_AdvanceOnCR =   0x804226de
  1075. MUIA_Window_SizeGadget  =   0x8042e33d
  1076. MUIM_List_Jump =            0x8042baab
  1077. MUIV_List_Insert_Active = -1
  1078. MUIV_List_Remove_First =  0
  1079. MUIV_Window_ActiveObject_Next = -1
  1080. */
  1081.  
  1082. MUIA_Disabled =             0x80423661
  1083. MUIA_HorizWeight =          0x80426db9
  1084. MUIA_List_Active =          0x8042391c 
  1085. MUIA_List_Format =          0x80423c0a 
  1086. MUIA_List_Entries =         0x80421654 
  1087. MUIA_Listview_MultiSelect = 0x80427e08
  1088. MUIA_List_Quiet =           0x8042d8c7
  1089. MUIA_List_Visible =         0x8042191f
  1090. MUIA_Selected =             0x8042654b
  1091. MUIA_ShowMe =               0x80429ba8
  1092. MUIA_VertWeight =           0x804298d0 
  1093. MUIA_Weight =               0x80421d1f 
  1094. MUIA_Window_DepthGadget  =  0x80421923
  1095. MUIA_Window_PublicScreen =  0x804278e4
  1096.  
  1097. ASLFR_InitialFile =         0x80080008
  1098. ASLFR_InitialDrawer =       0x80080009
  1099.  
  1100. MUIM_List_Clear =           0x8042ad89
  1101. MUIM_List_Select =          0x804252d8 
  1102.  
  1103. TRUE=1
  1104. FALSE=0
  1105.  
  1106. MUIV_List_Insert_Bottom = -3
  1107. MUIV_List_Select_Off = 0
  1108. MUIV_List_Select_On = 1
  1109. MUIV_Listview_MultiSelect_Shifted = 2
  1110.  
  1111. Return
  1112.  
  1113. /**************************************************************************/
  1114. /*           Various values used throughout the various routines          */
  1115. /**************************************************************************/
  1116. YTvars:
  1117.  
  1118. missing='.'
  1119. comma=','
  1120. tab='09'x                                   /* tab character              */
  1121. firsttime=FALSE
  1122. selected.0=0
  1123. reselect.0=0
  1124.  
  1125. FF='0C'x                                    /* print control FORM FEED    */
  1126. bo='\033b'                                  /* print control BOLD         */
  1127. bc='\033b\033c'                             /* print control BOLD CENTER  */
  1128. it='\033i'                                  /* print control ITALIC       */
  1129. ul='\033u'                                  /* print control UNDERLINED   */
  1130. co='\0335'                                  /* print control COLORED pen5 */
  1131. cx='\0332'                                  /* print control FOREGROUND   */
  1132. hl='\0338'                                  /* print control HIGHLIGHT    */
  1133. nc='\033n\033c'                             /* print control NORM CENTER  */
  1134. no='\033n'                                  /* print control NORM         */
  1135. nl='\n'                                     /* print control 1 NEW LINE   */
  1136. nl2='\n\n'                                  /* print control 2 NEW LINES  */
  1137. ct='\033c'                                  /* print control CENTER       */
  1138. lf='\033l'                                  /* print control LEFT ALIGN   */
  1139. rt='\033r'                                  /* print control RIGHT ALIGN  */
  1140.  
  1141. Return
  1142.  
  1143. /**************************************************************************/
  1144. /*    Messages, text, etc. constructed using previously defined values    */
  1145. /**************************************************************************/
  1146. Builtvars:
  1147.  
  1148. _title._ytprm='"'||bc||_col._ytprm1||comma||bo||_col._ytprm2||comma||bo||_col._ytprm3||comma||bc||_col._ytprm4||comma||bo||_col._ytprm5||comma||bo||_col._ytprm6||'"'
  1149. _label._ytpr4=_label._ytpr4a||comma||_label._ytpr4b
  1150. _label._ytpr5=_label._ytpr5a||comma||_label._ytpr5b
  1151. _label._ytpr6=_label._ytpr6a||comma||_label._ytpr6b||comma||_label._ytpr6c
  1152. _label._ytpr7=_label._ytpr7a||comma||_label._ytpr7b
  1153.  
  1154. Return
  1155.  
  1156. /**************************************************************************/
  1157. /*               Pointers into the YamTools.guide documentation           */
  1158. /**************************************************************************/
  1159. Helpvars:
  1160.  
  1161. node.SQUIT='7.3.'
  1162. node.STEXT='7.3.'
  1163. node.YTPRF='7.3.'
  1164. node.YTPRT='7.3.'
  1165. node.YTPRM='7.3.'
  1166. node.YTPRR='7.3.'
  1167. node.YTPR0='7.3.'
  1168. node.YTPR1='7.3.'
  1169. node.YTPR2='7.3.'
  1170. node.YTPR3='7.3.'
  1171. node.YTPR4='7.3.'
  1172. node.YTPR5='7.3.'
  1173. node.YTPR6='7.3.'
  1174. node.YTPR7='7.3.'
  1175. node.YTPRQ='7.3.'
  1176.  
  1177. Return
  1178.  
  1179. /**************************************************************************/
  1180. /*       Mui Gadgets, text, msgs, etc. used in YamTools                   */
  1181. /**************************************************************************/
  1182. Localize:
  1183.  
  1184. /*********************************/
  1185. /* Miscellaneous info strings    */
  1186. /*********************************/
  1187. _title._main="""YTPrint v1.0"""            /* main screen title          */
  1188. _title._info="""YTPrint Info"""            /* default title on infomsg   */
  1189. _title._asl="""Select File"""              /* title for ASL requester    */ 
  1190.  
  1191. _text._ok="Ok"                              /* various OK buttons         */
  1192. _text._cancel="Cancel"                      /* LABEL for CANCEL button    */
  1193.  
  1194. _label._ytpr0="View"                        /* label for VIEW button      */
  1195. _label._ytpr1="Print"                       /* label for Print button     */
  1196. _label._ytpr2="Disk"                        /* label for DISK button      */
  1197. _label._ytpr3="UnMime"                      /* label for UNMIME button    */
  1198. _label._ytpr4a="Styled"                     /* convert to ANSI text style */ 
  1199. _label._ytpr4b="Normal"                     /* leave text as is           */
  1200. _label._ytpr5a="Single"                     /* process as single file     */
  1201. _label._ytpr5b="Multiple"                   /* treat each section separate*/
  1202.  
  1203. _label._ytpr6a="Short"                      /* type of header to include  */
  1204. _label._ytpr6b="Full"                       /* type of header to include  */
  1205. _label._ytpr6c="None"                       /* type of header to include  */
  1206.  
  1207. _label._ytpr7a="B/W"                        /* format for black and white */
  1208. _label._ytpr7b="Color"                      /* format for color printing  */
  1209.  
  1210. _label._ytprq="Quit"                        /* label for QUIT  button     */
  1211.  
  1212. _col._ytprm1="Type"                         /* heading for ytprm column 1 */
  1213. _col._ytprm2="N"                            /* heading for ytprm column 2 */
  1214. _col._ytprm3="Lines"                        /* heading for ytprm column 3 */
  1215. _col._ytprm4="Name"                         /* heading for ytprm column 1 */
  1216. _col._ytprm5="Content"                      /* heading for ytprm column 2 */
  1217. _col._ytprm6="Encoding"                     /* heading for ytprm column 3 */
  1218.  
  1219. _text._savemail="Saving Mail File..."        /* saving mailfile message   */
  1220. _text._prepmail="Preparing Mail..." /* preparing mail message   */
  1221. _text._noprinter="Unable to open PRT:\nIs the Printer on?"
  1222.  
  1223. /*********************************/
  1224. /* Various error conditions      */
  1225. /*********************************/
  1226.  
  1227. _text._noyam="You need YAM running to use YAMTOOLS"    /* yam not running */
  1228. _text._noyt="You need YAMTOOLS running to use YTPrint" /* no yamtools  */
  1229. _text._secondrun="You ALREADY have a YTPrint started"  /* second run   */
  1230. _text._nomail="You need to select a mail file to use YTPrint"
  1231. _text._nosect="You need to select mail section(s) to View/Print/Save"
  1232. _text._badmail="Cannot open the mail file"
  1233. _text._badparm="Unrecognized parms passed to YTPrint:"
  1234. _text._prtquoted="Warning! Parts of this message are in Quoted-Printable format\nYou may wish to UnMime before printing"
  1235. _text._badparttype="Found unknown part type in mail"
  1236. _text._badsavefile="Unable to open output file"
  1237.  
  1238. /**************************************************************************/
  1239. /*           Help Messages to display with MUI bubble facility.           */
  1240. /*                                                                        */
  1241. /* Format is simple: help.ID where ID is the id specified on the MUI      */
  1242. /* object statement.                                                      */
  1243. /* Similar approach for accessing the .guide information using the NODE   */
  1244. /* option on the object statement.                                        */
  1245. /*                                                                        */
  1246. /**************************************************************************/
  1247.  
  1248. help.SQUIT=""""""
  1249. help.STEXT=""""""
  1250. help.YTPRF="""Yam mail file"""
  1251. help.YTPRT="""Short Header of mail file"""
  1252. help.YTPRM="""Information about each mail section\nDouble-click to Read section\nMulti-select to View/Print/Save"""
  1253. help.YTPRR="""Area for Reading/Viewing mail sections"""
  1254. help.YTPR0="""View selected section(s) in read area"""
  1255. help.YTPR1="""Print selected section(s)\nEnsure printer is ON"""
  1256. help.YTPR2="""Save selected section(s) to disk"""
  1257. help.YTPR3="""Convert mail to 8bit encoding using UnMime.rexx if available"""
  1258. help.YTPR4="""Leave as plain text\nConvert to ANSI text styling"""
  1259. help.YTPR5="""Process selected section(s) as single file\nProcess each section separate"""
  1260. help.YTPR6="""Type of header to include in Printing/Saving to disk\nIf the Header is not selected"""
  1261. help.YTPR7="""Styled for Black and White or for COLOR\non PRINT or save to DISK"""
  1262. help.YTPRQ="""Quit"""
  1263.  
  1264. Return
  1265.  
  1266.  
  1267.