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

[REBOL] Re: Deleting Email. Review this Script?

From: Izkata::Comcast::net at: 12-Aug-2006 1:21

I didn't take too close a look at it (and don't really have something to test it on at the moment), but take a close look at the "mailbox: next mailbox ; next message" line, and how series look in general:
>> while [not tail? S][
[ A: first S [ if #"3" = first S [remove S] [ B: first S [ S: next S [ print rejoin [A {, } B {, } first S] [ ] 1, 1, 2 2, 2, 3 3, 4, 5 5, 5, 6 6, 6, 7 7, 7, 8 8, 8, 9 9, 9, 0 ** Script Error: Out of range or past end ** Where: rejoin ** Near: first S See how it skipped weirdly when it hit the character being checked for? When your script finds something to be remove, it immediately removes it - which automatically means "first mailbox" has already advanced to the next one, making the "mailbox: next mailbox" line skip the email that goes after the removed one. It doesn't look like it because of the way yours skips backwards to remove it, but it does. I would suggest cleaning up the function's code like this: main: func[ /local mailbox deleted msg recipient ][ deleted: 0 print "Connecting ......" mailbox: open url print rejoin [(length? mailbox) " messages found."] while [not tail? mailbox][ msg: import-email first mailbox ; imports the email message recipient: to-string msg/to ; sets the recipient ('TO:') value in the message either recipient = email-address [ ;You only have one condition, so 'all []' is not needed print "<font color=^"blue^">------- KEEPING ----------------------" print rejoin[ "From: " msg/from newline "Subject: " msg/subject </font>] mailbox: next mailbox ; next message ;You're keeping it, so advance to the next message ][ print "<font color=^"red^">------- DELETING ----------------------" print rejoin[ "From: " msg/from newline "Subject: " msg/subject </font>] remove mailbox ;remove current message ;You're deleting it and advancing to the next message with this here. deleted: deleted + 1 print rejoin["deleting number " deleted] ] ] print rejoin[deleted " message(s) were deleted"] ]