home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / fltintch.zip / icefx.cmd < prev   
OS/2 REXX Batch file  |  1997-10-01  |  10KB  |  383 lines

  1. /* ICEFX.CMD: mr2ice filter export utility - jt Sept 1997 */
  2. /* new (mr2i 1.34) filter format; fif level 1.34 */
  3. /* new more readable FIF format */
  4.  
  5. call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  6. call SysLoadFuncs
  7. arg outfile fltfile .
  8.  
  9. proglev= 0.6
  10. fiflev="1.35nf1"
  11. indelim='01'x
  12. wid=40
  13.  
  14. say 'ICEFX level' proglev 'creating fiflevel' fiflev
  15. /* based on doc from Nick in filter.doc  */
  16. if outfile='' then do
  17.    say 'Usage is ICEFX outfile [infile]'
  18.    say ''
  19.    say 'Run this program in the directory that contains your mr2i.flt'
  20.    say 'file (even if you explicitly specify a different infile).'
  21.    say ''
  22.    say 'If infile is not present, mr2i.flt is used as input.  The'
  23.    say 'extension .fif [Filter Interchange Format] is reccommended for'
  24.    say 'outfile.  This program reads <infile> and the folder index'
  25.    say 'file (either folder.ndx or mail\folder.ndx; converts each'
  26.    say 'filter entry to interchange format and writes to <outfile>.'
  27.    say 'The folder index file entries contain both the folder'
  28.    say 'directory and the name of the folder (as read from the'
  29.    say 'folder.ndx file); interchange files identify folders by name'
  30.    say '(the raw filter file identifies them by directory name).  A'
  31.    say 'fair amount of checking is done to ensure that the filter'
  32.    say 'item is legal.'
  33.    exit 
  34.   end
  35.  
  36. fld. = ''
  37.  
  38. if outfile="MR2I.FLT" then do
  39.    say "You don't really want to clobber mr2i.flt, do you?"
  40.    say 'Usage is ICEFX OUTFILE [filterfile]'
  41.    say 'Please respecify.'
  42.    exit
  43.    end
  44.  
  45. call readndx  /* read ndx reads the folder.ndx file and sets names */
  46.               /* into fld.F003 etc. */
  47.  
  48. if fltfile = '' then filterfile='mr2i.flt'
  49.    else filterfile=fltfile
  50. signal on notready
  51. which = filterfile
  52. if lines(filterfile) = 0 then signal notready
  53. firstlin=linein(filterfile)  /* to determine indelim */
  54. call lineout(filterfile)   /* close file */
  55. which = ''
  56. xx=pos(indelim,firstlin)
  57. xx=pos(indelim,firstlin,xx+1)
  58. yy=pos('\',firstlin)
  59. yy=pos('\',firstlin,yy+1)
  60. if xx=0 then indelim='\'
  61. if (xx=0) & (yy=0) then do
  62.    say filterfile 'does not appear to be in MR2I.FLT file format'
  63.    exit
  64.    end
  65.  
  66. infile = filterfile
  67. if stream(outfile,C,QUERY EXISTS) > '' then do 
  68.    say 'output file' outfile 'exists'
  69.    say 'press enter to delete and rewrite it'
  70.    say 'enter X to quit'
  71.    say 'enter anything else to append to' outfile
  72.    pull q
  73.    select
  74.       when q='' then '@del' outfile '> NUL'
  75.       when translate(q)='X' then exit
  76.       otherwise ;
  77.       end /*select */
  78.    end /* outfile exists */
  79. /* set up search type literal descriptors */
  80. sx.0='From'
  81. sx.1='To'
  82. sx.2='Subject'
  83. sx.3='Header'
  84. sx.4='Body'
  85. sx.5='UUencoded'
  86. sx.6='MIME'
  87. sx.7='BinHex'
  88. sx.8='MsgSize'
  89. sx.9='MsgLines'
  90.  
  91. /* flag text variables */
  92. /* watch out for single letter variables! */
  93.  
  94. txf1.I='Inbound'
  95. txf1.O='Outbound'
  96. txf1.B='Both (In and Out)'
  97. txf1.S='PreSend'
  98. txf1.T='ToOutbox'
  99. txf1.F='PreFetch'
  100. txf1.D='OnDemand'
  101.  
  102. txf2.F='Freeform'
  103. txf2.R='Rexx'
  104. txf2.P='Special'
  105. txf2.S='Simple'
  106.  
  107. txf3.N='NoMatch'
  108. txf3.A='Always'
  109. txf3.M='Match'
  110.  
  111. txf13.N='No delete'
  112. txf13n.N='Get message'
  113. txf13.A='Delete AFTER other filters'
  114. txf13n.A='Get header'
  115. txf13.Y='Delete NOW'
  116. txf13n.Y='Delete header now'
  117.  
  118. txf14.M='Filter Mail only'
  119. txf14.N='Filter NEWS only'
  120. txf14.B='Filter Mail and News'
  121.  
  122. lineno=0
  123. do while lines(infile)
  124.    line = linein(infile)
  125.    lineno=lineno+1
  126.    errmsg = ''
  127.    f. = '\\\\'
  128.    ff13. = indelim
  129.    residue = line
  130.    do ii=1 to 13
  131.       parse var residue f.ii (indelim) residue 
  132.       end
  133.  
  134.    ff13.14='M'  /* in case it's not there */
  135.    do ii=1 to length(f.13)
  136.       ff13.ii = substr(f.13,ii,1)
  137.       end
  138.  
  139.    ok=checker()
  140.    if ok then call process
  141.       else do
  142.          say f.1 f.2 errmsg
  143.          end
  144.    end /* processing of line */
  145. call lineout outfile,'---------- END end_of_last_Filter  ----------'
  146. call lineout(outfile)   /* close output file */
  147. say "all done"
  148. exit
  149.  
  150. checker:
  151. /* enough fields ? */
  152. if f.13 = '\\\\' then do
  153.    errmsg='not enough fields'
  154.    return 0
  155.    end
  156. /* enabled sw; description */
  157. enabled=substr(f.1,1,1)
  158. if pos(enabled,'+-')=0 then do
  159.    errmsg = 'enabled flag must be + or -'
  160.    return 0
  161.    end
  162. /* search mode check */
  163. if ((f.3<>'')&(datatype(f.3)='CHAR'))|((f.3)>1023) then do
  164.    errmsg = 'bad search type numeric value field 3'
  165.    return 0
  166.    end
  167. /* flags check */
  168. if (length(f.13)<13) | (length(f.13)>14) then do
  169.    errmsg = 'flags field wrong length shld be 13 or 14'
  170.    return 0
  171.    end
  172. if pos(ff13.1,'IOBSTFD')=0 then do
  173.    errmsg = 'bad filter type flag 13.1'
  174.    return 0
  175.    end
  176. if pos(ff13.2,'FRPS')=0 then do
  177.    errmsg = 'bad search type flag 13.2'
  178.    return 0
  179.    end
  180. if pos(ff13.3,'NAM')=0 then do
  181.    errmsg = 'bad match type flag 13.3'
  182.    return 0
  183.    end
  184. if pos(ff13.7,'YN')=0 then do
  185.    errmsg = 'bad copy to folder flag 13.7'
  186.    return 0
  187.    end
  188. if pos(ff13.8 ,'YN')=0 then do
  189.    errmsg = 'bad autoreply flag 13.8'
  190.    return 0
  191.    end
  192. if pos(ff13.12,'YN')=0 then do
  193.    errmsg = 'bad link to Rexx flag 13.12'
  194.    return 0
  195.    end
  196. if pos(ff13.13,'YNA')=0 then do
  197.    errmsg = 'bad disposition_is_delete flag 13.13'
  198.    return 0
  199.    end
  200. if pos(ff13.14,'MNB')=0 then do
  201.    errmsg = 'bad mail/news flag 13.14'
  202.    return 0
  203.    end
  204. xx=substr(f.13,5,2) /* 13.4 smartsearch not used but default = Y */
  205. zz=substr(f.13,9,3)
  206. if (xx||zz)<>'NNNNN' then do
  207.    say 'WARNING' f.1 f.2  'unused flags 13.5-6' x 'or 9-11' z 'not all N'
  208.    end
  209. return 1
  210.  
  211. process:
  212. j=1
  213. if enabled='-' then outline = '"Not enabled"' 
  214.    else outline='"Enabled"'
  215. out.j=left(outline,wid,' ') 'f1.1 1' enabled
  216. j=j+1
  217.  
  218. outline=left('"Filter description"',wid,' ')
  219. out.j = outline 'f1.2 *' substr(f.1,2);j=j+1
  220.  
  221. outline=left('"Filter alias"',wid,' ')
  222. out.j = outline 'f2 *' f.2;j=j+1
  223.  
  224. valu=f.3
  225. sm = ''
  226. do k=9 to 0 by -1
  227.    if valu%(2**k)>0 then do
  228.       sm=sm sx.k
  229.       valu=valu-(2**k)
  230.       end
  231.    end
  232. outline = left('"Search modes::' sm '"',wid,' ')
  233. out.j = outline 'f3 #' f.3
  234. j=j+1
  235.  
  236. if ff13.2='F' then do 
  237.      outline=left('"Search expression"',wid,' ') 'f4 *'
  238.      call splitter f.4
  239.      end  /* search expression */
  240.      else do 
  241.      outline=left('"Search text"',wid,' ') 'f4 *' 
  242.      call splitter f.4
  243.      end
  244.  
  245.  
  246. if length(f.5)>0 then do
  247.    if indelim='\' then f.5=pathsep(f.5)
  248.    out.j=left('"Rexx cmd for criteria search"',wid,' ') 'f5 *' f.5
  249.    j=j+1
  250.    end
  251. if (length(f.6)>0)&(ff13.7='Y')  then do
  252.    folderdir=f.6
  253.    out.j=left('"Folder for copy ::' f.6 '"',wid,' ') 'f6 *' fld.folderdir
  254.    j=j+1
  255.    end
  256. if (length(f.7)>0)&(ff13.8='Y') then do
  257.    out.j=left('"Auto reply template"',wid,' ') 'f7 *' f.7
  258.    j=j+1
  259.    end
  260. if length(f.8)>0 then do
  261.    out.j=left('"Email notify address"',wid,' ') 'f8 *' f.8
  262.    j=j+1
  263.    end
  264. /* link to filter name; not used */
  265. /* if length(f.9)>0 then do 
  266.    if indelim='\' then f.9=pathsep(f.9)
  267.    out.j= left('"Link-to filter name"',wid,' ') 'f9 *' f.9
  268.    j=j+1
  269.    end */
  270. if (length(f.10)>0)&(ff13.12='Y')  then do
  271.    if indelim='\' then f.10=pathsep(f.10)
  272.    out.j=left('"Rexx cmd to call on match"',wid,' ') 'f10 *' f.10 ;j=j+1
  273.    end
  274. if f.11>0 then do
  275.    out.j=left('"Msg size to exceed (bytes)"',wid,' ') 'f11 #' f.11
  276.    j=j+1
  277.    end
  278. if f.12>0 then do
  279.    out.j=left('"Msg size to exceed (lines)"',wid,' ') 'f12 #' f.12
  280.    j=j+1
  281.    end
  282.  
  283. /* field 13 flags */
  284. q=ff13.1
  285. out.j=left('"Filter type::' txf1.q '"',wid,' ') 'f13.1 1' q;j=j+1
  286. q=ff13.2
  287. out.j=left('"Search type::' txf2.q '"',wid,' ') 'f13.2 1' q;j=j+1
  288. q=ff13.3
  289. out.j=left('"Match type::' txf3.q '"',wid,' ') 'f13.3 1' q;j=j+1
  290. /* 
  291. q=ff13.4 5 6
  292.    out.j=left('"Smart Search (not used)::' txf?.q '"',wid,' ') 'f13.4 1' q;j=j+1
  293.    out.j=left('"Translate (not used)::' txf?.q '"',wid,' ') 'f13.5 1' q;j=j+1
  294.    out.j=left('"Autodetach (not used)::' txf?.q '"',wid,' ') 'f13.6 1' q;j=j+1
  295. */
  296.  
  297. if ff13.7 = 'Y' then do
  298.    out.j=left('"Copy to folder"',wid,' ') 'f13.7 1' ff13.7;j=j+1
  299.    end
  300. if ff13.8 = 'Y' then do
  301.    out.j=left('"Autoreply"',wid,' ') 'f13.8 1' ff13.8;j=j+1
  302.    end
  303. /*
  304.   out.j=left('"Notify by email (not used)"',wid,' ') 'f13.9 1' ff13.9;j=j+1
  305.   out.j=left('"Notify by popup (not used)"',wid,' ') 'f13.10 1' ff13.10;j=j+1
  306.   out.j=left('"Link to filter (not used)"',wid,' ') 'f13.11 1' ff13.11;j=j+1
  307. */
  308. if ff13.12 = 'Y' then do
  309.    out.j=left('"Link to Rexx"',wid,' ') 'f13.12 1' ff13.12;j=j+1
  310.    end
  311.  
  312. q=ff13.13
  313. if ff13.14='N' then outline=left('"Disposition::' txf13n.q '"',wid,' ')
  314.     else outline=left('"Disposition::' txf13.q '"',wid,' ')
  315. out.j=outline 'f13.13 1' q;j=j+1
  316. q=ff13.14
  317. if q<>'M' then do
  318.    out.j=left('"Mail/news flag::' txf14.q '"',wid,' ') 'f13.14 1' q;j=j+1
  319.    end
  320.  
  321.  
  322. call lineout outfile,'---------- Filter' lineno ' FIF-level' fiflev '----------'
  323. do jj=1 to j -1
  324.    call lineout outfile,out.jj
  325.    end
  326. return
  327.  
  328. readndx:
  329.  
  330. infile='folders.ndx'  /* for secondary account */
  331. if lines(infile) = 0 then do
  332.    infile = 'mail\folders.ndx'  /* default account */
  333.    if lines(infile)=0 then do
  334.       say "can't find folders.ndx or mail\folders.ndx"
  335.       exit
  336.       end
  337.    end
  338. call lineout(infile)   /* close file */
  339. which = ''
  340.  
  341. do while lines(infile)
  342.    line = linein(infile)
  343.    parse var line name '' tab '' folder '' rest
  344.    fld.folder=name
  345.    end
  346. return
  347.  
  348. pathsep: procedure
  349.    parse arg inarg
  350.    z=1
  351.    do until z=0
  352.       z=pos('/',inarg)
  353.       if z>0 then inarg=left(inarg,z-1)||'\'||substr(inarg,z+1)
  354.       end
  355.    return inarg
  356.  
  357. notready:
  358. say which " file error"
  359. exit
  360.  
  361. splitter:
  362.   parse arg xpr 
  363.   if length(f.4)<(72-wid) then do
  364.          out.j=outline xpr
  365.      j=j+1
  366.      end    /* short expression */
  367.      else do    /* parse f.4 and put out multiple lines */
  368.      out.j=outline;j=j+1
  369.      do while length(xpr)>0
  370.         ll=min(length(xpr),72)
  371.         if length(xpr)>ll then do
  372.              out.j=' '||left(xpr,ll);j=j+1
  373.              xpr=substr(xpr,ll+1)
  374.          end
  375.              else do 
  376.              out.j=' '||xpr;j=j+1
  377.          xpr=''
  378.          end
  379.         end  /* spitting out pieces */
  380.      end
  381.    return
  382.      
  383.