Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] clean this up a bit?

From: tofo:695online at: 17-Feb-2003 16:43

hey guys, waaay back in rebol/zine issue one, there was (is) a pop-to-mbox filter. I use a slightly modified version of this thing all the time. There are, however, a couple of problems with it. 1. Its kinda slow... 2. It does not retrieve all of my mail "in one shot." I have to run the script several times to get everything (I don't _think_ I'm losing any). anyhow, I was hoping that some more capable eyes than mine could look over the script, and suggest improvements... Here's the script: ; ;--begin script ; rebol [ Title: "Filter to Mailbox Files" File: %popfilter.r ] ;--- Settings ---------------------------------------- me1: "blap" pass1: "blap" server1: "blap" me2: "blap" pass2: "blap" server2: "blap" change-dir %/path/to/mail-dir/ spam-box: %spambox days: [Mon Tue Wed Thu Fri Sat Sun] months: [Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec] pad: [#"0" ""] spc: #" " when: now filters: [ [%frogs.mbox From [[kermit--rebol--com][toady--rebol--net]]] [%alert.mbox Subject ["Oh no!" "Yikes!" "Hey!" "Woops!"]] [%tests.mbox Subject ["test" "foobar"]] [ %lists.mbox From [ [rebol-list--rebol--com][ally-list--rebol--com] [command-list--rebol--com] ] ] [%main.mbox To [[me--example--com]]] ] ;--- Make the filter rules make-rule: func [list [block!] /local rule] [ rule: copy [] foreach item list [ repend rule [item '|] ] head remove back tail rule ] foreach filter filters [ change/only at filter 3 make-rule filter/3 ] ;--- Funcs do-filter: func [ mail [object!] "Imported email object" filter [block!] "One of our filters" /local field ] [ if any [ not field: in mail filter/2 not field: get field ] [return false] if parse field reduce [filter/3 'to 'end] [filter/1] ;-- Results in false otherwise ] save-to-mbox: func [ file [file!] "MBox format file" mail [object!] "Import-email object" mesg [string!] "Raw email message" ] [ write/append file rejoin [ "From " mail/from spc pick days when/weekday spc pick months when/month spc pick pad when/day < 10 when/day spc pick pad when/time < 10:00 when/time spc when/year newline mesg newline ] print file ] process-mail: does [ forall pop [ mail: import-email mesg: first pop prin [index? pop mail/from tab mail/subject "->"] if not foreach filter filters [ if target: do-filter mail filter [ save-to-mbox target mail mesg break/return true ] ] [save-to-mbox spam-box mail mesg] either remove-mail [remove pop] [inbox: next pop] ] ] ;--- and go ... pop1: does [ pop: open to-url rejoin ["pop://" me1 ":" pass1 "@" server1] process-mail close pop ] pop2: does [ pop: open to-url rejoin ["pop://" me2 ":" pass2 "@" server3] process-mail close pop ] pop1 pop2 quit ; ;--end script ; -- signature to baby: "doobywoobybooboo" -tom