[REBOL] Re: How do you check for new emails?
From: gchiu:compkarori at: 4-Oct-2002 10:54
>I basically want my phone to notify me through a text
>message if I get a
>new email in my inbox.
>
>Is there a flag in each email that lets you see if it's
>been "read"? I
Mail clients use the UIDL command to retrieve the unique
message id to see if they have read the message or not.
Rebol's POP protocol doesn't do this.
But you can fudge it.
Jeff @ Rebol wrote a modified POP protocol that allows you
to send the TOP command. This means that you can grab all
the headers ( including subject, from, and message id )
when you open up the mailbox without having to read the
message bodies. You can then parse out the message ids,
and then only retrieve the subject/from details as you
need. You will need to track the message ids though.
Here's his post again ( it's hard to find on Escribe )
Jeff (jeff from 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
]
--
Graham Chiu