58857608 |
<html>
<head>
<title>Allegro CL imap interface</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
</head>
<body>
<h1 align="center">Allegro CL imap interface</h1>
<p align="left">copyright (c) 1999 Franz Inc.</p>
<p align="left"> </p>
<p align="left"><strong>imap</strong> is a client-server protocol for processing
electronic mail boxes. <strong>imap </strong>is the successor to the <strong>pop</strong>
protocol. It is not an upward compatible successor.</p>
<p align="left">This document and interface is based on the Imap4rev1 protocol described
in rfc2060. Where this document is describing the actions of the imap commands
it should be considered a secondary source of information about those command and rfc2060
should be considered the primary source.</p>
<p align="left">The advantages of <strong>imap</strong> over <strong>pop</strong> are:</p>
<ol>
<li><p align="left"><strong>imap </strong>can work with multiple mailboxes (<strong>pop </strong>works
with a single mailbox)</p>
</li>
<li><p align="left">With <strong>imap</strong> you're encouraged to leave mail in mailboxes
on the server machine, thus it can be read from any machine on the network.
With <strong>pop</strong> you're encouraged to download the mail to the client machine's
disk, and it thus becomes inaccessible to all other client machines.</p>
</li>
<li><p align="left"><strong>imap</strong> parses the headers of messages thus allowing
easier analysis of mail messages by the client program.</p>
</li>
<li><p align="left"><strong>imap</strong> supports searching messages for data and sorting
by date.</p>
</li>
<li><p align="left"><strong>imap </strong>supports annotating messages with flags, thus
making subsequent searching easier.</p>
</li>
</ol>
<p align="left"> </p>
<h1 align="left">Mailboxes</h1>
<p align="left">Mailboxes are repositories for messages. Mailboxes are named
by Lisp strings. The mailbox "inbox" always exists and it is the mailbox
in which new messages are stored. New mailboxes can be created.
They can have simple names, like "foo" or they can have
hierarchical names (like "clients/california/widgetco"). After
connecting to an imap server you can determine what string of characters you must use
between simple names to create a hierarchical name (in this example "/" was the
separator character). </p>
<p align="left">Each mailbox has an associated unique number called its <strong>uidvalidity</strong>.
This number won't change as long as only <strong>imap</strong> is the
only program used to manipulate the mailbox. In fact if you see that the
number has changed then that means that some other program has done something to the
mailbox that destroyed the information that <strong>imap</strong> had been keeping about
the mailbox. In particular you can't now retrieve messages by their
unique ids that you had used before.</p>
<h1 align="left">Messages</h1>
<p align="left">Messages in a mailbox can be denoted in one of two ways: message
sequence number or unique id. </p>
<p align="left">The <em>message sequence number</em> is the normal way. The messages
in a mailbox are numbered from 1 to N where N is the number of messages in the mailbox.
There are never any gaps in the sequence numbers. If you tell <strong>imap</strong>
to delete messages 3,4 and 5 then it will return a value telling you the it has deleted
messages 3,3 and 3. This is because when you deleted message 3, message 4 became the
new message 3 just before it was deleted and then message 5 became message 3 just before
it was deleted.</p>
<p align="left">A <em>unique id </em>of a message is a number associated with a message
that is unique only within a mailbox. As long as the uidvalidity value of a
mailbox doesn't change, the unique ids used in deleted messages will never be reused for
new messages. </p>
<h1 align="left">Flags</h1>
<p align="left">A flag is a symbol denoting that a message or mailbox has a certain
property. We use keywords in Lisp to denote flags. There are two
kinds of flags - System and User flags. System flags begin with the backslash
character, which is an unfortunate design decision since that means that in Lisp we
have to remember to use two backslashes (e.g. <strong>:\\deleted</strong>).
A subset of the flags can be stored permanently in the mailbox with the
messages. When a connection is made to an <strong>imap</strong> server it will
return the list of flags and permanent flags (and these are stored in the mailbox object
returned for access by the program). If the list of permanent flags includes <strong>:\\*</strong>
then the program can create its own flag names (not beginning with a backslash) and can
store them permanently in messages.</p>
<p align="left">Some of the important system flags are:</p>
<ul>
<li><p align="left"><strong>:\\seen</strong> - this means that the message has been read
(a <strong>fetch-letter</strong> has been done that includes the content of the
message, not just its headers)</p>
</li>
<li><p align="left"><strong>:\\deleted </strong>- the message will be deleted the next time
an <strong>expunge-mailbox</strong> or <strong>close-mailbox</strong> is done.</p>
</li>
<li><p align="left"><strong>:\\recent </strong>- this is the first session to have been
notified about this message being present in the mailbox.</p>
</li>
</ul>
<p align="left"> </p>
<h1 align="left">Connecting to the server</h1>
<p align="left"> </p>
<p align="left"><font face="Courier New">(<strong>make-imap-connection host &key user
password port timeout)</strong></font></p>
<p align="left">This creates a connection to the <strong>imap</strong> server on machine <strong>host</strong>
and logs in as <strong>user </strong>with password <strong>password. </strong>The
<strong>port</strong> argument defaults to143, which is the port on which the <strong>imap</strong>
server normally listens. The <strong>timeout</strong> argument defaults
to 30 (seconds) and this value is used to limit the amount of time this imap interface
code will wait for a response from the server before giving up. In
certain circumstances the server may get so busy that you see timeout errors signaled in
this code. In that case you should specify a larger timeout when connecting. </p>
<p align="left">The <strong>make-imap-connection</strong> function returns a <strong>mailbox</strong>
object which is then passed to other functions in this interface. From this
one connection you can access all of the mailboxes owned by <strong>user</strong>.</p>
<p align="left">After the connection is established a mailbox is <strong>not</strong>
selected. In this state attempting to execute message access functions may
result in cryptic error messages from the <strong>imap</strong> server that won't tell you
what you need to know -- that a mailbox is not selected. Therefore be sure to
select a mailbox using <strong>select-mailbox</strong> shortly after connecting.</p>
<p align="left"> </p>
<p align="left"> </p>
<p align="left"><strong><font face="Courier New">(close-imap-connection mailbox)</font></strong></p>
<p align="left">This sends a <strong>logout</strong> command to the <strong>imap</strong>
server and then closes the socket that's communicating with the <strong>imap</strong>
server. <strong>mailbox </strong>is the object returned by <strong>make-imap-connection.</strong>
This does <em>not</em> close the currently select mailbox before logging out,
thus messages marked to be deleted in the currently selected mailbox will <em>not</em> be
removed from the mailbox. Use <strong>close-mailbox</strong> or <strong>expunge-mailbox</strong>
before calling this <strong>close-imap-connection</strong> to ensure that messages to be
deleted are deleted.</p>
<p align="left"> </p>
<p align="left"> </p>
<h1 align="left">Mailbox manipulation</h1>
<p align="left">These functions work on mailboxes as a whole. The <strong>mailbox</strong>
argument to the functions is is the object returned by <strong>make-imap-connection.
</strong>If a return value isn't specified for a function then the return value
isn't important - if something goes wrong an error will be signaled.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(select-mailbox mailbox name)</strong></font></p>
<p align="left">makes the mailbox named by the string <strong>name</strong> be the current
mailbox and store statistics about that mailbox in the <strong>mailbox</strong> object
where they can be retrieved by the accessors described below. The
selected mailbox is the source for all message manipulation functions.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(create-mailbox mailbox name)</strong></font></p>
<p align="left">creates a new mailbox with the given <strong>name</strong>. It
is an error if the mailbox already exists. If you want to create a mailbox in a
hierarchy then you should be sure that it uses the correct hierarchy separator character
string (see <strong>mailbox-separator)</strong>. You do <strong>not</strong>
have to create intermediate levels of the hierarchy yourself -- just provide the
complete name and the <strong>imap</strong> server will create all necessary levels.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(delete-mailbox mailbox name)</strong></font></p>
<p align="left">deletes the mailbox with the given name.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(rename-mailbox mailbox old-name
new-name)</strong></font></p>
<p align="left">changes the name of mailbox <strong>old-name</strong> to <strong>new-name</strong>.
It's an error if <strong>new-name</strong> already exists. There's a special
behavior if <strong>old-name</strong> is "inbox". In this case all of the
messages in "inbox" are moved to <strong>new-name </strong>mailbox, but the
"inbox" mailbox continues to exist. Note: The <strong>imap </strong>server
supplied with Linux does <strong>not</strong> support this special behavior of renaming
"inbox".</p>
<p align="left"> </p>
<p align="left"><strong><font face="Courier New">(mailbox-list mailbox &key reference
pattern)</font></strong></p>
<p align="left">returns a list of items describing the mailboxes that match the arguments.
The <strong>reference</strong> is the root of the hierarchy to
scan. By default is is the empty string (from which all mailboxes are reachable).
The <strong>pattern </strong>is a string matched against all mailbox
names reachable from <strong>reference. </strong>There are two special characters allowed
in the <strong>pattern: </strong>Asterisk (*) matches all characters including
hierarchy delimiters. Percent (%) matches all characters but not the hierarchy
delimiter. Thus</p>
<p align="center"><font face="Courier New">(mailbox-list mailbox :pattern "*")</font></p>
<p align="left">returns a list of all mailboxes at all depths in the hierarchy.
</p>
<p align="left">The value returned is a list of lists, but we've created the <strong>mailbox-list
</strong>struct definition in order to make accessing the parts of the inner lists
easier. The accessors for that structure are:</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(mailbox-list-flags mailbox-list) </strong></font></p>
<p align="left">returns the flags describing this entry. The most important
flag to check is <strong>:\\noselect</strong> as this specifies that this is not a mailbox
but instead just a directory in the hierarchy of mailboxes. The flag <strong>:\\noinferiors</strong>
specifies that you can't create a hierarchical mailbox name with this as a prefix.
This flag is often associated with the special mailbox "inbox".</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(mailbox-list-separator mailbox-list)</strong></font></p>
<p align="left">returns a string containing the characters used to separate names in a
hierarchical name.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(mailbox-list-name mailbox-list)</strong></font></p>
<p align="left">returns the name of the mailbox or directory (see mailbox-list-flags to
determine which it is).</p>
<p align="left"> </p>
<h1 align="left">Message manipulation</h1>
<p align="left">These functions work with the messages in the currently selected mailbox.
The <strong>mailbox</strong> argument is the object returned by <strong>make-imap-connection.</strong>
The <strong>messages</strong> argument is either a number (denoting a single
message), or is the list <strong>(:seq N M) </strong>denoting messages <strong>N</strong>
through <strong>M, </strong>or is a list of numbers and <strong>:seq </strong>forms
denoting the messages specified in the list.</p>
<p align="left"> </p>
<p align="left">(<font face="Courier New"><strong>alter-flags mailbox messages &key
flags add-flags remove-flags silent uid)</strong></font></p>
<p>changes the flags of the messages in the specified way. Exactly one of <strong>flags,
add-flags</strong>, and <strong>remove-flags</strong> must be specified. <strong>flags</strong>
specifies the complete set of flags to be stores in the <strong>messages</strong> and the
other two add or remove flags. If <strong>uid</strong> is true then <strong>messages</strong>
will be interpreted as unique ids rather than message sequence numbers.
Normally <strong>alter-flags</strong> returns a data structure
that describes the state of the flags after the alternation has been done. This data
structure can be examined with the <strong>fetch-field</strong> function.
If <strong>silent</strong> is true then this data structure won't be created
thus saving some time and space.</p>
<p>Removing a message from a mailbox is done by adding the <strong>:\\deleted</strong>
flag to the message and then either calling <strong>close-mailbox </strong>or <strong>expunge-mailbox.</strong></p>
<p> </p>
<p><font face="Courier New"><strong>(close-mailbox mailbox)</strong></font></p>
<p>permanently removes all messages flagged as <strong>:\\deleted</strong> from the
currently selected mailbox and then un-selects the currently selected mailbox. After
this command has finished there is no currently selected mailbox.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(delete-letter mailbox messages &key
expunge uid</strong></font>)</p>
<p align="left">Mark the <strong>messages</strong> for deletion and then remove them
permanently (using <strong>expunge-mailbox</strong>) if <strong>expunge</strong> is true.
<strong>expunge </strong>defaults to true. If <strong>uid</strong>
is true then the message numbers are unique ids instead of messages sequence numbers.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(expunge-mailbox mailbox)</strong></font></p>
<p align="left">permanently removes all messages flagged as <strong>:\\deleted</strong>
from the currently selected mailbox. The currently selected mailbox stays
selected.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(fetch-field message part info &key
uid)</strong></font></p>
<p align="left">is used to extract the desired information from the value returned by <strong>fetch-letter</strong>.
With <strong>fetch-letter</strong> you can retrieve a variety of
information about one or more messages and <strong>fetch-field</strong> can search though
that information and return a particular piece of information about a particular
letter. <strong>message</strong> is the message number (it's assumed to be a
message sequence number unless <strong>uid </strong>is true, in which case it's a unique
id). <strong>part </strong>is the type of information desired. It is a
string just as used in the call to <strong>fetch-letter</strong>.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(fetch-letter mailbox messages parts
&key uid)</strong></font></p>
<p align="left">retrieves the specified <strong>parts</strong> of the specified <strong>messages.
</strong>If <strong>uid</strong> is true then the <strong>messages</strong>
are considered to be unique ids rather than message sequence numbers.
The description of what can be specified for <strong>parts </strong>is
quite complex and has been moved to the section below "Fetching a Letter".</p>
<p align="left">The return value from this function is a structure that can be examined
with <strong>fetch-field</strong>.</p>
<p align="left">When the result returned includes an envelope value the following
functions can be used to extract the parts of the envelope:</p>
<ul>
<li><p align="left"><font face="Courier New"><strong>envelope-date</strong></font></p>
</li>
<li><p align="left"><font face="Courier New"><strong>envelope-subject</strong></font></p>
</li>
<li><p align="left"><font face="Courier New"><strong>envelope-from</strong></font></p>
</li>
<li><p align="left"><font face="Courier New"><strong>envelope-sender</strong></font></p>
</li>
<li><p align="left"><font face="Courier New"><strong>envelope-reply-to</strong></font></p>
</li>
<li><p align="left"><font face="Courier New"><strong>envelope-to</strong></font></p>
</li>
<li><p align="left"><font face="Courier New"><strong>envelope-cc</strong></font></p>
</li>
<li><p align="left"><font face="Courier New"><strong>envelope-bcc</strong></font></p>
</li>
<li><p align="left"><font face="Courier New"><strong>envelope-in-reply-to</strong></font></p>
</li>
<li><p align="left"><font face="Courier New"><strong>envelope-message-id</strong></font></p>
</li>
</ul>
<p align="left"> </p>
<p align="left"> </p>
<p align="left"><strong><font face="Courier New">(noop mailbox)</font></strong></p>
<p align="left">does nothing but remind the <strong>imap</strong> server that this
client is still active, thus resetting the timers used in the server that will
automatically shut down this connection after a period of inactivity. Like all
other commands if messages have been added to the currently selected mailbox, the server
will return the new message count as a response to the <strong>noop</strong> command, and
this can be check using <strong>mailbox-message-count</strong>. </p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(search-mailbox search-expression
&key uid)</strong></font></p>
<p align="left">return a list of messages in the mailbox that satisfy the<strong>
search-expression. </strong>If <strong>uid</strong> is true then unique ids
will be returned instead of message sequence numbers. See the section
"Searching for messages" for details on the <strong>search-expression</strong>.</p>
<p align="left"> </p>
<h1 align="left">Mailbox Accessors</h1>
<p align="left">The mailbox object contains information about the <strong>imap </strong>server
it's connected to as well as the currently selected mailbox. This information
can potentially be updated each time a request is made to the <strong>imap </strong>server.
The following functions access values from the mailbox object. </p>
<p align="left"><font face="Courier New"><strong>(mailbox-flags mailbox)</strong></font></p>
<p align="left">returns a complete list of flags used in all the messages in this mailbox.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(mailbox-permanent-flags mailbox)</strong></font></p>
<p align="left">returns a list of flags that can be stored permanently in a message.
If the flag <strong>:\\*</strong> is present then it means that the client can
create its own flags.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(mailbox-message-count mailbox)</strong></font></p>
<p align="left">returns the number of messages in the currently selected mailbox</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(mailbox-recent-messages mailbox)</strong></font></p>
<p align="left">returns the number of messages have just arrived in the mailbox.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(mailbox-separator mailbox)</strong></font></p>
<p align="left">returns the hierarchy separator string for this <strong>imap </strong>server.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(mailbox-uidnext mailbox)</strong></font></p>
<p align="left">returns the value predicated to be the unique id assigned to the
next message.</p>
<p align="left"> </p>
<p align="left"><font face="Courier New"><strong>(mailbox-uidvalidty mailbox)</strong></font></p>
<p align="left">returns the uidvalidity value for the currently selected mailbox.</p>
<p align="left"> </p>
<p align="left"> </p>
<h1 align="left">Fetching a Letter</h1>
<p align="left">When using <strong>fetch-letter</strong> to access letters, you must
specify the parts of the messages in which you're interested. There are a wide
variety of specifiers, some redundant and overlapping, described in the imap specification
in rfe2060. We'll describe the most common ones here. The specification
is always a string but it may be specify more than one thing by the use of parentheses in
the string, e.g. "(flags envelope)". </p>
<p align="left">The most common specifiers are:</p>
<ul>
<li><p align="left"><strong>body[]</strong> - this returns the full message: headers and
body.</p>
</li>
<li><p align="left"><strong>body[text]</strong> - this returns just the the text of the body
of the message, not the header.</p>
</li>
<li><p align="left"><strong>body</strong> - this returns a list describing the structure of
the message.</p>
</li>
<li><p align="left"><strong>envelope</strong> - this parses the header and returns a list of
information in it. We've defined a set of accessors <strong>(</strong>like<strong>
envelope-xxx</strong>) that allow you to retrieve the envelope information easily.</p>
</li>
<li><p align="left"><strong>flags</strong> - return a list of the flags in the message</p>
</li>
<li><p align="left"><strong>uid</strong> - the unique identifier of the message</p>
</li>
</ul>
<p align="left"> </p>
<p align="left">The result of a <strong>fetch-letter</strong> is a data structure
containing all of the requested information. The <strong>fetch-field</strong>
function is then used to extract the particular information for the particular message.</p>
<p align="left"> </p>
<h1 align="left">Searching for Messages</h1>
<p align="left">.The <strong>imap</strong> server is able to search for messages matching
a search expression. A search-expression is a predicate or one of
these forms:</p>
<ul>
<li><p align="left">(<strong>and</strong> search-expression ...)</p>
</li>
<li><p align="left">(<strong>or</strong> search-expression ...)</p>
</li>
<li><p align="left">(<strong>not</strong> search-expression)</p>
</li>
</ul>
<p align="left">A predicate is </p>
<ul>
<li><p align="left">a number in which case the predicate is true if and only if we're are
considering this message</p>
</li>
<li><p align="left">a <strong>(:seq N M)</strong> expression that is true if we're
considering messages N through M.</p>
</li>
<li><p align="left"><strong>:all</strong> - this predicate is always true</p>
</li>
<li><p align="left"><strong>:answered</strong> - true if the message has the <strong>:\\answered</strong>
flag</p>
</li>
<li><p align="left"><strong>(:bcc "string") </strong>- true if the envelope
structure's bcc field contains this "string".</p>
</li>
<li><p align="left"><strong>(:before date)</strong> - true if the messages internal date is
before this date. The date can either be a string in the rfc822 form (e.g.
"7-Mar-1999") or a lisp universal time.</p>
</li>
<li><p align="left"><strong>(:body "string") </strong>- true if the body of the
message contains "string"</p>
</li>
<li><p align="left"><strong>(:cc "string")</strong> - true if the envelope
structure's cc field contains this "string".</p>
</li>
<li><p align="left"><strong>:deleted</strong> - true if the <strong>:\\deleted</strong> flag
is set for this message</p>
</li>
<li><p align="left"><strong>:draft</strong> - true if the <strong>:\\draft </strong>flag is
set for this message</p>
</li>
<li><p align="left"><strong>:flagged </strong>- true if the <strong>:\\flagged</strong> flag
is set for this message</p>
</li>
<li><p align="left"><strong>(:from "string")</strong> - true if the envelope
structure's from field contains this "string".</p>
</li>
<li><p align="left"><strong>(:header "field" "string")</strong> - true
if the message contains a header named "field" and its value contains
"string".</p>
</li>
<li><p align="left"><strong>(:keyword flag)</strong> - true if the specified flag is set for
this message</p>
</li>
<li><p align="left"><strong>(:larger N)</strong> - true if the rfc822 size of the message is
larger than N.</p>
</li>
<li><p align="left"><strong>:new </strong>- true if the message has the <strong>:\\recent</strong>
flag set but not the <strong>:\\seen </strong>flag.</p>
</li>
<li><p align="left"><strong>:seen </strong>- true if the message has the <strong>:\\seen </strong>flag
set.</p>
</li>
<li><p align="left"><strong>(:sentbefore date)</strong> - true if the message's Date header
is earlier than the given date. See the description of :before for the format of
dates.</p>
</li>
<li><p align="left"><strong>(:senton date)</strong> - true if the message's Date header is
within the specified date.</p>
</li>
<li><p align="left"><strong>(:sentsince date) </strong>- true if the message's Date header
is within or since the given date.</p>
</li>
<li><p align="left"><strong>(:smaller N)</strong> - true if the rfc822 size of the message
is smaller than N</p>
</li>
<li><p align="left"><strong>(:subject "string") </strong>- true if the Subject
header line of the message contains "string"</p>
</li>
<li><p align="left"><strong>(:text "string") </strong>- true if the message's
header or body contains the specified "string"</p>
</li>
<li><p align="left"><strong>(:to "string")</strong> - true if the envelope
structure's to field contains this "string".</p>
</li>
<li><p align="left"><strong>(:uid message-set)</strong> - true if the message is one of the
message denoted by the message set, where the message set describes messages by unique id.</p>
</li>
<li><p align="left"><strong>:unanswered</strong> - true if the message does not have the <strong>:\\answered</strong>
flag set</p>
</li>
<li><p align="left"><strong>:undeleted</strong> - true if the message does not have the <strong>:\\deleted</strong>
flag set</p>
</li>
<li><p align="left"><strong>:undraft </strong>- true if the message does not have the <strong>:\\draft
</strong>flag set.</p>
</li>
<li><p align="left"><strong>:unflagged </strong>- true if the message does not have the <strong>:\\flagged</strong>
flag set.</p>
</li>
<li><p align="left"><strong>(:unkeyword flag)</strong> - true if the message does not have
the specified flag set.</p>
</li>
<li><p align="left"><strong>:unseen </strong>- true if the message does not have the <strong>:\\seen
</strong>flag set.</p>
</li>
</ul>
<p align="left"> </p>
<h1 align="left">Examples</h1>
<p align="left">We show an example of using this interface</p>
<p align="left"> </p>
<p align="left"><strong>Connect to the imap server on the machine holding the email:</strong></p>
<div align="left">
<pre>user(2): (setq mb (mb:make-imap-connection "mailmachine.franz.com"
:user "myacct"
:password "mypasswd"))
#<mailbox::imap-mailbox @ #x2064ca4a></pre>
</div>
<p align="left"> </p>
<p align="left"><strong>Select the inbox, that's where the incoming mail arrives:</strong></p>
<div align="left">
<pre>
user(3): (mb:select-mailbox mb "inbox")
t</pre>
</div>
<p align="left"> </p>
<p align="left"><strong>Check how many messages are in the mailbox:</strong></p>
<div align="left">
<pre>
user(4): (mb:mailbox-message-count mb)
7</pre>
</div>
<p align="left"><strong>There are seven messages at the moment. Fetch the
whole 4th message</strong></p>
<div align="left">
<pre>
user(5): (setq body (mb:fetch-letter mb 4 "body[]"))
((4
("BODY[]" "Return-Path: <jkfmail@tiger.franz.com>
Received: from tiger.franz.com (jkf@tiger [192.132.95.103])
by tiger.franz.com (8.8.7/8.8.7) with SMTP id LAA20261
for <jkfmail@tiger.franz.com>; Mon, 13 Sep 1999 11:36:26 -0700
Date: Mon, 13 Sep 1999 11:36:26 -0700
From: jkf mail tester <jkfmail@tiger.franz.com>
Message-Id: <199909131836.LAA20261@tiger.franz.com>
message number 5
")))</pre>
</div>
<p align="left"><strong>The value was returned inside a data structure designed to hold
information about one or more messages. In order to extract the particular
information we want we use fetch-field:</strong></p>
<div align="left">
<pre>
user(6): (mb:fetch-field 4 "body[]" body)
"Return-Path: <jkfmail@tiger.franz.com>
Received: from tiger.franz.com (jkf@tiger [192.132.95.103])
by tiger.franz.com (8.8.7/8.8.7) with SMTP id LAA20261
for <jkfmail@tiger.franz.com>; Mon, 13 Sep 1999 11:36:26 -0700
Date: Mon, 13 Sep 1999 11:36:26 -0700
From: jkf mail tester <jkfmail@tiger.franz.com>
Message-Id: <199909131836.LAA20261@tiger.franz.com>
message number 5
"</pre>
</div>
<p align="left"><strong>We use the search function to find all the messages containing the
word blitzfig. It turns out there is only one. We then extract the contents of
that message.</strong></p>
<div align="left">
<pre>
user(7): (mb:search-mailbox mb '(:text "blitzfig"))
(7)
user(8): (mb:fetch-field 7 "body[]" (mb:fetch-letter mb 7 "body[]"))
"Return-Path: <jkf@verada.com>
Received: from main.verada.com (main.verada.com [208.164.216.3])
by tiger.franz.com (8.8.7/8.8.7) with ESMTP id NAA20541
for <jkfmail@tiger.franz.com>; Mon, 13 Sep 1999 13:37:24 -0700
Received: from main.verada.com (IDENT:jkf@localhost [127.0.0.1])
by main.verada.com (8.9.3/8.9.3) with ESMTP id NAA06121
for <jkfmail@tiger.franz.com>; Mon, 13 Sep 1999 13:36:54 -0700
Message-Id: <199909132036.NAA06121@main.verada.com>
To: jkfmail@tiger.franz.com
Subject: s test
Date: Mon, 13 Sep 1999 13:36:54 -0700
From: jkf <jkf@verada.com>
secret word: blitzfig
ok?
"</pre>
</div>
<p align="left"><strong>We've been using message sequence numbers up to now.
The are the simplest to use but if you're concerned with keeping track of
messages when deletions are being done then using unique id's is useful. Here
we do the above search example using uids:</strong></p>
<div align="left">
<pre>
user(9): (mb:search-mailbox mb '(:text "blitzfig") :uid t)
(68)
user(10): (mb:fetch-field 68 "body[]" (mb:fetch-letter mb 68 "body[]" :uid t) :uid t)
"Return-Path: <jkf@verada.com>
Received: from main.verada.com (main.verada.com [208.164.216.3])
by tiger.franz.com (8.8.7/8.8.7) with ESMTP id NAA20541
for <jkfmail@tiger.franz.com>; Mon, 13 Sep 1999 13:37:24 -0700
Received: from main.verada.com (IDENT:jkf@localhost [127.0.0.1])
by main.verada.com (8.9.3/8.9.3) with ESMTP id NAA06121
for <jkfmail@tiger.franz.com>; Mon, 13 Sep 1999 13:36:54 -0700
Message-Id: <199909132036.NAA06121@main.verada.com>
To: jkfmail@tiger.franz.com
Subject: s test
Date: Mon, 13 Sep 1999 13:36:54 -0700
From: jkf <jkf@verada.com>
secret word: blitzfig
ok?
"</pre>
</div>
<p align="left"><strong>We'll delete that letter with the secret word and then note that
we have only six messages in the mailbox.</strong></p>
<div align="left">
<pre>
user(11): (mb:delete-letter mb 68 :uid t)
(7)
user(12): (mb:mailbox-message-count mb)
6</pre>
</div>
<p align="left"><strong>Now we assume that a bit of time has passed and we want to see if
any new messages have been delivered into the mailbox. In order to find out we
have to send a command to the imap server since it will only notify us of new messages
when it responds to a command. Since we have nothing to ask the imap server to
do we issue the noop command, which does nothing on the server.</strong></p>
<div align="left">
<pre>
user(13): (mb:noop mb)
nil
user(14): (mb:mailbox-message-count mb)
7</pre>
</div>
<p align="left"><strong>The server told us that there are now 7 messages in the inbox, one
more than before. Next we create a new mailbox, copy the messages from the inbox to
the new mailbox and then delete them from the inbox. Note how we use the :seq form
to specify a sequence of messages.</strong></p>
<div align="left">
<pre>
user(15): (mb:create-mailbox mb "tempbox")
t
user(18): (let ((count (mb:mailbox-message-count mb)))
(mb:copy-to-mailbox mb `(:seq 1 ,count) "tempbox")
(mb:delete-letter mb `(:seq 1 ,count)))
(1 1 1 1 1 1 1)
user(19): (mb:mailbox-message-count mb)
0</pre>
</div>
<p align="left"><strong>When we're done there are 0 messages in the currently selected
mailbox, which is inbox. We now select the maibox we just created and see that the
messages are there.</strong></p>
<div align="left">
<pre>
user(22): (mb:select-mailbox mb "tempbox")
t
user(23): (mb:mailbox-message-count mb)
7</pre>
</div>
<p align="left"><strong>Finally we shut down the connection. Note that imap
servers will automatically shut down a connection that's been idle for too long (usually
around 10 minutes). When that happens, the next time the client tries to use an imap
function to access the mailbox an error will occur. There is nothing that can
be done to revive the connection however it is important to call close-imap-connection on
the lisp side in order to free up the resources still in use for the now dead connection.</strong></p>
<div align="left">
<pre>
user(24): (mb:close-imap-connection mb)
t
</pre>
</div>
<p align="left"> </p>
<p> </p>
</body>
</html>
|