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

[REBOL] Re: POP-3 command TOP not supported, what to do?

From: kevin:sunshinecable at: 5-Feb-2001 17:02

On Sun, 4 Feb 2001, Martin Rommel wrote:
> Hello list, > the implementation of the POP-3 protocol in Rebol seems not to support the > command TOP which is used to retrieve only the header of an email from the > server (and possibly a specified number of lines of the message, see RFC > 1939). <clip> > Why doesn't the import-email function just have a modifier to allow only > downloading the header without the content of the message.
> How to do that in rebol? Has anybody ever tried that? > Any help is appreciated!
Hi Martin, This was discussed ages ago (summer of '99) between Allen K, Bo, and myself. When it was brought up again last year, I summarized the earlier conclusions and tossed the challenge to Jeff at REBOL who had a couple of free minutes that afternoon and whipped up a solution. This change has not yet been included into REBOL's stock POP3 protocol, but IMHO it should be. I originally suggested a refinement for 'read. Here's what Jeff came up with... It works very well. Hope it helps you. Cheers, Kev [insert original message...] Jeff ([jeff--rebol--com]) wrote: Well, that's pretty simple. It would be a little more difficult to have a different refinement for read with pop-- but pop can pretty easily be modified to return the top info, or store the info similarly to the way we had the LIST command do it. Perhaps the URL could be a little different: x: open pop://user:[pass--server]/summary Will cause x/locals to get a field that contains the TOP info. Of course, its up to you to parse the TOP info afterwards. So... change the number in top-check block to how ever many lines of context you want. Here you go: ------------------------------------------------------- REBOL [ Title: "A slightly modified version of pop" ] make Root-Protocol [ {Communicate with POP. This protocol is block oriented not string oriented.} port-flags: system/standard/port-flags/pass-thru open-check: [ ; port is bound to confirm frame none "+OK" ["USER" port/user] "+OK" ["PASS" port/pass] "+OK" ] close-check: ["QUIT" "+OK"] write-check: [none "+OK"] stat-check: ["STAT" "+OK"] list-check: ["LIST" "+OK"] top-check: [reform ["TOP" num 10] "+OK"] open: func [port /total/tblock/summary][ open-proto port port/state/tail: second total: load net-utils/confirm port/sub-port stat-check port/locals: make object! [ total-size: third total net-utils/confirm port/sub-port list-check sizes: load read-til-dot port make string! 100 summary: either port/target = "summary" [ tblock: system/words/copy [] repeat num port/state/tail [ net-utils/confirm port/sub-port reduce bind top-check 'num append tblock read-til-dot port make string! 100 ] tblock ][none] msg-nums: make block! port/state/tail repeat n port/state/tail [append msg-nums n] ; lookaside index ] port/state/index: 0 ; a zero based index ] read-til-dot: func [port buf][ while [(line: system/words/pick port/sub-port 1) <> "."] [ insert tail buf line insert tail buf newline ] buf ] read-message: func [ "Read a message from the POP server" port n [integer!] /local buf line ][ insert port/sub-port reform [ "RETR" system/words/pick port/locals/msg-nums port/state/index + n] net-utils/confirm port/sub-port write-check read-til-dot port buf: make string! 1024 ; guess at size ] pick: func [ "Read the Nth message from the POP port" port ][ read-message port 1 ] copy: func [ "Copy a set of messages into a block" port /local msgs n ][ msgs: make block! port/state/num repeat n port/state/num [ append msgs read-message port n ] msgs ] remove: func [ "Remove the current message" port ][ while [ port/state/num > 0 ][ insert port/sub-port reform [ "DELE" system/words/pick port/locals/msg-nums port/state/index + 1] net-utils/confirm port/sub-port write-check system/words/remove at port/locals/msg-nums port/state/index + 1 port/state/tail: port/state/tail - 1 port/state/num: port/state/num - 1 ] port ] net-utils/net-install POP self 110 ]