home *** CD-ROM | disk | FTP | other *** search
- REM Octet Purge by Simon N Goodwin, December 1997.
- REM
- REM WHAT?
- REM
- REM Program to scan MIME a mail file and remove all
- REM octet-stream binary encoded data sections.
- REM
- REM REQUIREMENTS
- REM
- REM Written in HiSoft BASIC. Requires ASL library.
- REM Uses 15 point Helvetica.font if it's available.
- REM
- REM WHY?
- REM
- REM Written to keep the size of archived YAM mail
- REM manageable, on the basis that binary contents
- REM ought to be archived somewhere else already.
- REM
- REM HOW?
- REM
- REM Start from Workbench by clicking on the icon.
- REM Select a file to be scanned or CANCEL to quit.
- REM Repeat selection for each file to be purged.
- REM
- REM Input file is not modified. A new file on the
- REM same path with the suffix ".purged" is created
- REM containing the original contents except with
- REM the 'application octet-stream' data sections
- REM replaced with the text:
- REM
- REM **** Octet stream deleted from archive.
- REM
- REM KNOWN BUGS
- REM
- REM No check that the output file name is valid.
- REM No diagnostics if the input file is malformed.
- REM
- REM
- REM STATUS
- REM
- REM Freely distributable; you must include source.
- REM
- REM AUTHOR
- REM
- REM Simon N Goodwin, simon@studio.woden.com
- REM
-
- DEFINT a-z
-
- ' HiSoft ASL library and disk font initialisation
-
- REM $INCLUDE diskfont.bh
- REM $INCLUDE graphics.bh
- REM $include asl.bh
- LIBRARY OPEN "asl.library"
- LIBRARY OPEN "diskfont.library"
- LIBRARY OPEN "graphics.library"
-
- WINDOW 1," MIME Mail archive file Octet Purger ", _
- (32,16)-(608,160),1+2+4+16+256
-
- REM Use a groovier Compugraphic fo(u)nt if you wish
-
- DIM TextAttr(4)
- InitTextAttr TextAttr(),"Helvetica.font",15,0,0
- font& = OpenDiskFont (VARPTR(TextAttr(0)))
-
- IF font&
- SetFont WINDOW (8), font&
- ELSE
- PRINT " **** Preferred font not available. Using default."
- END IF
-
- pattern$="Content-Type: application/octet-stream"
- patlen=LEN(pattern$)
-
- boundary$="--BOUNDARY"
- boundlen=LEN(boundary$)
-
- ' ASL requester initialisation
-
- CONST TAG_DONE&=0,TRUE&=1,ABORT&=-1,FALSE&=0
- DIM frtags&(20)
-
- ' Main program
-
- ok=TRUE
-
- REPEAT main
-
- TAGLIST VARPTR(frtags&(0)),ASLFR_TitleText&, _
- "Select the file to be purged", _
- ASLFR_InitialFile&,"", _
- ASLFR_InitialDrawer&,"RAM:", _
- ASLFR_InitialHeight&, 130, _
- ASLFR_InitialLeftEdge&, 280, _
- ASLFR_InitialWidth&, 310, _
- TAG_DONE&
-
- fr&=AllocAslRequest&(ASL_FileRequest&,VARPTR(frtags&(0)))
- IF fr& THEN
- ok&=AslRequest&(fr&,0)
- IF ok& THEN
- file$=PEEK$(PEEKL(fr&+fr_File))
- dir$=PEEK$(PEEKL(fr&+fr_Drawer))
- IF LEN(dir$)
- suffix$=RIGHT$(dir$,1)
- IF suffix$<>"/" AND suffix$<>":" THEN dir$=dir$+"/"
- END IF
- END IF
- FreeASlRequest fr&
- ELSE
- ok&=ABORT&
- END IF
-
- IF ok&=FALSE& OR ok&=ABORT& THEN EXIT main
-
- file$=dir$+file$
-
- PRINT
-
- OPEN file$ FOR INPUT AS #3
- OPEN file$+".purged" FOR OUTPUT AS #4
-
- copying=1 : found=0
-
- REPEAT scan
- IF EOF(3) THEN EXIT scan
- INPUT #3,a$
- IF NOT copying
- copying=LEFT$(a$,boundlen)=boundary$
- END IF
- IF LEFT$(a$,patlen)=pattern$
- PRINT #4,a$
- PRINT " Purging: ";a$
- PRINT #4
- PRINT #4,"**** Octet stream deleted from archive."
- PRINT #4
- copying=0: found=found+1
- END IF
- IF copying THEN PRINT #4,a$
- END REPEAT scan
-
- CLOSE #4
- CLOSE #3
-
- PRINT
- PRINT " OK,";found;"octet stream";
- IF found<>1 THEN PRINT "s";
- PRINT " found in ";file$
- PRINT
- PRINT " Condensed version written to ";file$+".purged"
-
- END REPEAT main
-
- SYSTEM
-
- SUB InitTextAttr(T(1),FontName$,BYVAL Height,BYVAL style,BYVAL flags)
-
- POKEL VARPTR(T(0))+ta_Name,SADD(FontName$+CHR$(0))
- t(ta_YSize\2)=Height
- POKEB VARPTR(T(0))+ta_Style,style
- POKEB VARPTR(T(0))+ta_Flags,flags
-
- END SUB ' InitTextAttr
-