/* ** $VER: AminetRate.rexx 1.5 (12.12.2001) ** Copyright ©1999-2001 by Olivier Fabre . ** ** A big thank you to Robin Evans for his ARexxGuide ! ** ** Requires RexxDOSSupport.library (Copyright (C) 1994-1997 by hartmut Goebel). ** ** Vote for Aminet files made easy. ** ** v1.5 (12.12.2001) ** · Fixed MOVEREADME bug [Michael Taylor]. ** v1.4 (04.12.2001): ** · Improved SMTP client. Added "HELO" message in the SMTP dialog (the ** domain is based on the email address). [thanks to Michael Taylor] ** · Improved a little bit the documentation. ** v1.3 (14.09.2001): ** · Handles "http://" and "ftp://" so that this script can be integrated ** as a link context menu in a web browser (AWeb). ** · Localised (French and English for now). ** · Now remembers the mark given to a file in the archive. ** · Minor improvements and/or bug additions since I didn't check ** everything ;) ** · Added examples of usage. ** v1.02 (21.05.2000): ** · When voting a second time for a file, removes the older entry from ** the marks archive. ** · Does not open a window with "0" after sending the mail anymore. ** · Encloses mail addresses between "<" and ">" when sending the mail. ** ** Template: FILE/M,MARK/K/N,MAIL/S,DELFILE/S,DELREADME/S,MOVEFILE/S,MOVEREADME/S ** ** FILE/M ** Either a readme or an Aminet file (eg #?.lha). Might start with ** "http://" or "ftp://". AminetRate will try to find the Aminet directory ** with these methods: ** - look in the readme for a "Type:" line (if the file is local) ** - look if the file is in an Aminet-like directory (eg DOWNLOAD:comm/misc) ** (- if online, have a look on Aminet) ->TODO ? ** - ask the user :-) ** ** You can rate several files at the same time. If you do not provide a ** MARK value, then you will be asked a mark for each file; otherwise they ** will all get the same mark. ** ** MARK/K/N ** How much you rate this file, from 0 to 10. If not given, and a FILE is ** given, you will be asked to select a mark in a requester. ** ** MAIL/S ** Tells AminetRate to send a mail with all the votes stored so far. ** This needs the "TCP:" stuff (works at least with Miami 3). ** ** DELFILE/S, DELREADME/S ** Tells AminetRate to delete the file/readme once the mark is stored. ** ** MOVEFILE/S, MOVEREADME/S ** Tells AminetRate to move the file/readme into another directory once ** the mark is stored. ** ** ** EXAMPLES: ** ** AminetRate.rexx dev/c/vbcc.lha MARK=10 ** or AminetRate.rexx dev/c/vbcc.readme MARK=10 ** gives a 10/10 to dev/c/vbcc.lha. ** ** AminetRate.rexx vbcc.lha MARK=10 ** Same, but might ask you to type the directory if it can't be found ** in the associated readme or from the file directory. ** ** AminetRate.rexx ftp://us.aminet.net/pub/aminet/dev/c/vbcc.lha ** opens a requester to ask your mark for vbcc. ** ** AminetRate.rexx dev/c/vbcc.lha dev/c/CLib37x.readme MARK=9 ** gives 9/10 to VBCC and CLib37x. ** ** SPat AminetRate.rexx #?.readme ** to rate all the Aminet files of the directory. ** ** AminetRate.rexx MAIL ** sends a mail with all your votes to the Aminet server. ** ** ** Please edit the following lines to suit your taste... */ replyto = "@" /* Your mail address */ mailserver = "smtp" /* Your mail server */ movereadmedir = "DOWNLOAD:Store" /* Where to move readme files */ movefiledir = "DOWNLOAD:Store" /* Where to move files */ marksfile = "DOWNLOAD:AminetMarks" /* Where to store the marks */ marksarchivefile = "DOWNLOAD:AminetMarksArchive" /* Where to store the name of files you've already voted for */ language = "english" /* "english" or "français" */ logging = "no" /* Log SMTP dialog into T:AminetRate.smtp.log or not. If "AminetRate MAIL" doesn't work, send me the log. */ /* The following shouldn't need to be changed, but you can... */ aminetserver = "aminet-server" "@" "wuarchive.wustl.edu" /* Where to send your votes */ aminetdirs = "/biz/comm/demo/dev/disk/docs/game/gfx/hard/misc/mods/mus/pix/text/util/" /* List of all Aminet directories */ maxaminetsubdirlength = 5 /* for sub-dirs check */ aminetdirsdir = "T:AminetRate" /* Temporary directory */ arv = "AminetRate" /* Name of the environment variable used for getting return values from shell commands */ /* Language catalog */ /* English first, replaced by another language if applicable */ cat.norexxdoss = "RexxDOSSupport.library is missing." cat.errarg = "Error parsing arguments." cat.twodirs = "Two different Aminet directories were found ! Choose the good one..." cat.fromloc = "from local dir" cat.fromread = "from readme" cat.typedir = "Please type the Aminet directory of" cat.selectmark = "Please select a mark for" cat.cancel = "Cancel" cat.by = "by" cat.already = "You already voted for" cat.on = "on" cat.anyway = "Vote anyway" cat.cnxfail = "Connection to the mail server failed." cat.abortmail = "Aborting mail transfer." cat.errmarks = "Error opening" marksfile "for reading." cat.smtperr = "SMTP error" cat.mailsent = "Mail sent !" cat.nothing = "Nothing to send." IF language = "français" THEN DO cat.norexxdoss = "RexxDOSSupport.library manquante." cat.errarg = "Erreur lors de l'analyse des arguments." cat.twodirs = "Deux répertoires Aminet différents ont été trouvés ! Choisissez le bon..." cat.fromloc = "rép. local" cat.fromread = "readme" cat.typedir = "Tapez le nom du répertoire Aminet de" cat.selectmark = "Choisissez une note pour" cat.cancel = "Annuler" cat.by = "par" cat.already = "Vous avez déjà voté pour" cat.on = "le" cat.anyway = "Voter quand même" cat.cnxfail = "La connexion au serveur de courrier a échoué." cat.abortmail = "Transfert de courrier annulé." cat.errmarks = "Erreur à l'ouverture de" marksfile "en lecture." cat.smtperr = "Erreur SMTP" cat.mailsent = "Mail envoyé !" cat.nothing = "Rien à envoyer." END /********************************/ /* Do not change anything below */ /********************************/ wintitle = "AminetRate 1.5 ©1999-2001 by Olivier Fabre" IF ~SHOW( 'L', "rexxdossupport.library" ) THEN DO IF ~ADDLIB( "rexxdossupport.library", 0, -30, 2 ) THEN DO Error( cat.norexxdoss, 20 ) END END PARSE ARG args template = "FILE/M,MARK/K/N,MAIL/S,DELFILE/S,DELREADME/S,MOVEFILE/S,MOVEREADME/S" IF ~ReadArgs( args, template ) THEN DO Error( cat.errarg, 20 ) END IF file.count=0 & ~mail THEN DO SHELL COMMAND "Which >ENV:"arv" AminetRate.rexx" IF LENGTH( GetVar(arv) )<=1 THEN SHELL COMMAND "Which >ENV:"arv" AminetRate" IF OPEN( f, GetVar(arv), "R" ) THEN DO DO WHILE ~EOF( f ) l = READLN( f ) IF FIND( l, "Please edit" )>0 THEN DO SAY "*" || "/" EXIT END SAY l END END DeleteVar(arv) END /* Process each given file */ /* ----------------------- */ IF file.count>0 THEN DO IF ~EXISTS( aminetdirsdir ) THEN DO MakeDir( aminetdirsdir ) END DO f=0 FOR file.count /* Find path, file and readme names */ /* -------------------------------- */ /* First check if name starts with http:// or ftp:// */ distantFile = 0 IF LEFT( file.f, 7 ) = "http://" | LEFT( file.f, 6 ) = "ftp://" THEN DO distantFile = 1 file.f = SUBSTR( file.f, 7 ) END totalpath = AbsolutePath( file.f ) path = PathPart( totalpath ) IF LENGTH( path )=0 THEN DO path = PathPart( file.f ) END thisfile = FilePart( file.f ) IF RIGHT( thisfile, 7 ) = ".readme" THEN DO thisfile = LEFT( thisfile, LENGTH( thisfile )-6 ) /*SHELL COMMAND "List >ENV:"arv AddPart( path, thisfile )"#? LFORMAT=%f%s"*/ thisfile = thisfile"lha" END thisreadme = LEFT( thisfile, LASTPOS( ".", thisfile ) )"readme" /* Find type according to the local directory */ /* ------------------------------------------ */ dir = "" subdir = "" IF path ~= "" THEN DO slashpos = LASTPOS( "/", path ) IF slashpos>2 THEN DO subdir = SUBSTR( path, slashpos+1 ) IF LENGTH( subdir ) <= maxaminetsubdirlength THEN DO cutpath = LEFT( path, slashpos-1 ) slashpos = LASTPOS( "/", cutpath ) IF slashpos=0 THEN slashpos = LASTPOS( ":", cutpath ) dir = SUBSTR( cutpath, slashpos+1 ) IF POS( "/"dir"/", aminetdirs )=0 THEN DO dir = "" /* acts as a flag */ END END /* IF LENGTH( subdir ) <= maxaminetsubdirlength */ END /* IF slashpos>0 */ END /* IF path~="" */ IF dir = "" THEN subdir = "" /* Find type according to the "Type:" line in the readme */ /* ----------------------------------------------------- */ IF ~distantFile & OPEN( readmef, AddPart( path, thisreadme ), "R" ) THEN DO DO WHILE ~EOF( readmef ) line = COMPRESS( READLN( readmef ) ) IF UPPER( LEFT( line, 5 ) )="TYPE:" THEN DO slashpos = POS( "/", line ) IF slashpos > 6 THEN DO newdir = SUBSTR( line, 6, slashpos-6 ) newsubdir = SUBSTR( line, slashpos+1 ) IF dir ~= "" THEN DO IF newdir ~= dir | newsubdir ~= subdir THEN DO SHELL COMMAND 'RequestChoice >ENV:'arv' "'wintitle'" "'cat.twodirs'" "'dir'/'subdir' ('cat.fromloc')" "'newdir'/'newsubdir' ('cat.fromread')"' IF GetVar( arv )=0 THEN DO dir = newdir subdir = newsubdir END DeleteVar( arv ) END END /* IF dir ~= "" */ ELSE DO dir = newdir subdir = newsubdir END /* IF dir = "" */ END /* IF slashpos > 6 */ BREAK END /* IF "TYPE:" */ END /* WHILE ~EOF( readmef ) */ CLOSE( readmef ) END /* IF ~distantFile & OPEN( readmef ) */ /* Ask for type if not found */ /* ------------------------- */ IF dir = "" THEN DO SHELL COMMAND 'RequestFile >ENV:'arv '"'aminetdirsdir'" TITLE="'cat.typedir thisfile'"' dir = GetVar( arv ) IF LENGTH( dir ) > LENGTH( aminetdirsdir )+6 THEN DO dir = SUBSTR( dir, LENGTH( aminetdirsdir )+3 ) dir = LEFT( dir, LENGTH( dir )-1 ) DeleteVar( arv ) IF RIGHT( dir, 1 ) = "/" THEN dir = LEFT( dir, LENGTH( dir )-1 ) slashpos = LASTPOS( "/", dir ) IF slashpos > 2 THEN DO subdir = SUBSTR( dir, slashpos+1 ) IF LENGTH( subdir ) <= maxaminetsubdirlength THEN DO cutdir = LEFT( dir, slashpos-1 ) slashpos = LASTPOS( "/", cutdir ) IF slashpos = 0 THEN slashpos = LASTPOS( ":", cutdir ) dir = SUBSTR( cutdir, slashpos+1 ) IF POS( "/"dir"/", aminetdirs ) = 0 THEN DO dir = "" END END /* IF subdir length */ END /* IF slashpos > 2 */ END /* IF LENGTH( dir )... */ END /* IF dir = "" */ IF dir = "" THEN subdir = "" /* Ask the mark & add it to the mail file */ /* -------------------------------------- */ dir = dir"/"subdir IF dir = "/" THEN Error( "Aborting", 0 ) ELSE DO aminetfile = dir"/"thisfile flag = 1 IF EXISTS( marksarchivefile ) THEN DO SHELL COMMAND "Search >ENV:"arv marksarchivefile aminetfile "NONUM" IF GetVar( arv ) ~= "" THEN DO SHELL COMMAND 'RequestChoice >ENV:'arv '"'wintitle'" "'cat.already GetVar( arv )'" "'cat.anyway'" "'cat.cancel'"' flag = GetVar( arv ) END END IF flag THEN DO IF mark = "MARK" THEN mark = AskMark( aminetfile ) IF mark >= 0 & mark <= 10 THEN DO SHELL COMMAND "Echo >>"marksfile "rate" aminetfile mark /* Removes any older entry in the marks archive file */ /* ------------------------------------------------- */ SHELL COMMAND "Copy" marksarchivefile marksarchivefile".tmp QUIET" IF OPEN( maf2, marksarchivefile".tmp", "R" ) THEN DO IF OPEN( maf, marksarchivefile, "W" ) THEN DO DO WHILE ~EOF( maf2 ) line = READLN( maf2 ) IF line ~= "" & POS( aminetfile, line ) ~= 1 THEN WRITELN( maf, line ) END CLOSE( maf ) END CLOSE( maf2 ) END SHELL COMMAND "Delete" marksarchivefile".tmp QUIET" SHELL COMMAND "Echo >>"marksarchivefile aminetfile cat.on "`Date` ("mark"/10)" /* Moves & | delete files if asked by the user */ /* ------------------------------------------- */ IF ~distantFile THEN DO IF movefile THEN DO IF ~EXISTS( movefiledir ) THEN MakeDir( movefiledir ) Rename( AddPart( path, thisfile ), AddPart( movefiledir, thisfile ) ) END ELSE IF delfile THEN DO Delete( AddPart( path, thisfile ) ) END IF movereadme THEN DO IF ~EXISTS( movereadmedir ) THEN MakeDir( movereadmedir ) Rename( AddPart( path, thisreadme ), AddPart( movereadmedir, thisreadme ) ) END ELSE IF delreadme THEN DO Delete( AddPart( path, thisreadme ) ) END END /* IF ~distantFile */ END /* IF mark >= 0 & mark <= 10 */ END /* IF flag */ END /* IF dir ~= "/" */ END /* DO f=0 FOR file.count */ END /* IF file.count > 0 */ /* Send the mail */ /* ------------- */ IF mail & EXISTS( marksfile ) THEN DO IF ~OPEN( smtp, "TCP:"mailserver"/smtp", "W" ) THEN DO Error( cat.cnxfail cat.abortmail, 10 ) END IF logging="yes" THEN IF ~OPEN( log, "T:AminetRate.smtp.log", "W" ) THEN DO Error( "Opening of T:AminetRate.smtp.log failed.", 10 ) END IF ~OPEN( mf, marksfile, "R" ) THEN DO Error( cat.errmarks cat.abortmail, 10 ) END l = ReadSMTP() IF LEFT( l, 3 ) ~= "220" THEN Error( cat.smtperr ":" l, 10 ) WriteSMTP( "HELO" SUBSTR( replyto, LASTPOS("@",replyto)+1 ) ) l = ReadSMTP() IF LEFT( l, 3 ) ~= "250" THEN Error( cat.smtperr ":" l, 10 ) WriteSMTP( "MAIL FROM:" "<"replyto">" ) l = ReadSMTP() IF LEFT( l, 3 ) ~= "250" THEN Error( cat.smtperr ":" l, 10 ) WriteSMTP( "RCPT TO:" "<"aminetserver">" ) l = ReadSMTP() IF LEFT( l, 3 ) ~= "250" & LEFT( l, 3 ) ~= "251" THEN Error( cat.smtperr ":" l, 10 ) WriteSMTP( "DATA" ) l = ReadSMTP() IF LEFT( l, 3 ) ~= "354" THEN Error( cat.smtperr ":" l, 10 ) WriteSMTP( "To:" aminetserver ) WriteSMTP( "" ) DO WHILE ~EOF( mf ) l = READLN( mf ) WriteSMTP( l ) END WriteSMTP( "." ) l = ReadSMTP() IF LEFT( l, 3 ) ~= "250" THEN Error( cat.smtperr ":" l, 10 ) WriteSMTP( "quit" ) ReadSMTP() /* 221 for succes... should I care ? */ IF logging="yes" THEN CLOSE( log ) CLOSE( smtp ) CLOSE( mf ) Delete( marksfile ) Error( cat.mailsent, 0 ) END IF mail & ~EXISTS( marksfile ) THEN Error( cat.nothing, 0 ) EXIT /* Fonctions */ /* --------- */ AskMark: PROCEDURE EXPOSE wintitle cat. PARSE ARG file SHELL COMMAND 'RequestChoice >ENV:'arv' "'wintitle'" "'cat.selectmark file'" 0 1 2 3 4 5 6 7 8 9 10 "'cat.cancel'"' askmark = GetVar( arv ) DeleteVar( arv ) RETURN askmark-1 Error: PROCEDURE EXPOSE wintitle PARSE ARG texte,code SHELL COMMAND 'RequestChoice >NIL: "' wintitle '" "'texte'" "Ok"' EXIT code ReadSMTP: PROCEDURE EXPOSE smtp log logging DO UNTIL SUBSTR( l, 4, 1 ) ~= "-" l = READLN( smtp ) IF logging="yes" THEN WRITELN( log, l ) END RETURN l WriteSMTP: PROCEDURE EXPOSE smtp log logging PARSE ARG l WRITELN( smtp, l ) IF logging="yes" THEN WRITELN( log, l ) RETURN 0