POP-3 command TOP not supported, what to do?
[1/4] from: martin_rommel:mac at: 4-Feb-2001 23:02
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). This is important if you have some big email sitting in your mailbox
and only want to know the header without downloading the whole thing.
Why doesn't the import-email function just have a modifier to allow only
downloading the header without the content of the message.
I tried to write to the open port without success (I just started using
rebol last week, but already set up a very helpful little script).
When telnetting into a POP-3 server it is trivial, just type "TOP 1 0" and
you get the header of the first message (with 0 lines of the content).
How to do that in rebol? Has anybody ever tried that?
Any help is appreciated!
Cheers, Martin
[2/4] from: gjones05:mail:orion at: 6-Feb-2001 6:29
Hi, Martin,
Here was my quick hack that version that I brewed up yesterday, but I
hesitated to send it after seeing Kevin's resubmission of Jeff's more
definitive solution. Today, I'm thinking what the heck, it works, I'll send
it anyway.
i-buf: make string! 1002
pop-port: open pop://USER:[PASS--pop--server--dom]
write-io pop-port "TOP 1 0" 1000
read-io pop-port i-buf 1000
write-io pop-port "QUIT" 1000
print i-buf
If you wish to see more feedback messages while tinkering, be sure to turn
on tracing with:
trace/net on
Just my 2 cents, which is worth 2 cents *before* inflation :-)
--Scott
[3/4] from: deryk:iitowns at: 6-Feb-2001 23:03
GS Jones wrote:
> Hi, Martin,
> Here was my quick hack that version that I brewed up yesterday, but I
<<quoted lines omitted: 32>>
> > How to do that in rebol? Has anybody ever tried that?
> > Any help is appreciated!
(aimed at Martin)
RFC1939 also states that TOP is an optional command and need not be
implemented at all (Section 7). On the other side of the fence, a
properly written client (protocol API in this instance) can easily check
the results of an attempt at using the command, if successful, great,
otherwise, a fallback to a normal scan listing could be performed.
Regards,
Deryk
[4/4] 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
<<quoted lines omitted: 3>>
> Why doesn't the import-email function just have a modifier to allow only
> downloading the header without the content of the message.
<clip>
> 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
]
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted