Go to the first, previous, next, last section, table of contents.
/* Prefix pop3_ is reserved */
#include <mailutils/pop3.h>
The purpose of the Post Office Protocol Version 3 (POP3) is to permit a client to download a maildrop from a remote server. It does not provide complex or extensive operation on the maildrop. When the client successfully authenticates, the server acquires an exclusive access lock on the mailbox and holds it the entire duration of the session. After the authentication, the session enters transaction state and the client may issues commands to access messages in the mailbox.
When the command Quit is issue the session enters the update state. The servers removes all messages marked deleted, releases the exclusive lock and closes the TCP connection.
An opaque structure pop3_t is use as a handle for the session, it is
allocated and initialized by calling pop3_create ()
. All Functions will
wait for a reply from the POP3 server before returning. The duration of
the wait can be set by calling pop3_set_timeout ()
, the default
is 10 minutes(1). Once a successful
connection is established with pop3_connect ()
, two builtins
authentications are provided pop3_apop ()
or
pop3_user ()
/pop3_pass ()
. The pop3_stat ()
and
pop3_list ()
functions can be use to get the number and size of
messages. Downloading of messages is done via a stream provided by
pop3_retr ()
or pop3_top ()
(2).
The stream_t
should be destroyed to indicate to the library that the
action is finished. POP3 only provide a single channel for operation, it
means only one operation can be done at a time, all the functions will return
MU_ERROR_OPERATION_IN_PROGRESS if call during another operation. The
functions pop3_list_all ()
, pop3_uidl_all ()
and
pop3_capa ()
return iterators pop3_list_current ()
,
pop3_uidl_current ()
are provided as cover function to format the
string return by iterator_current ()
, iterator_destroy ()
must
be call to release any resources.
In a multithreaded application, only one thread should access pop3_t handles.
Allocate and initialize a pop3 handle.
MU_ERROR_NO_MEMORY
MU_ERROR_INVALID_PARAMETER
When a POP3 session is finished, the structure must be free ()
'ed to
reclaim memory.
A connection is established by calling pop3d_open ()
, the previous
connection is close first. If non-blocking the function should be recalled
until the return value is not MU_ERROR_TRY_AGAIN or MU_ERROR_IN_PROGRESS.
MU_ERROR_NO_MEMORY
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_IN_PROGRESS
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
MU_ERROR_TIMEOUT
MU_ERROR_NO_LOCK
The type of stream use to contact as server will be set to carrier in the pop3_t handle. Any previous carrier stream in the handle, will be close and release.
MU_ERROR_INVALID_PARAMETER
Return the pop3_t carrier. If none was set, a new tcp stream will be created.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_NO_MEMORY
Apop offers an alternative to User/Pass authentication. For intermittent
use of POP3, like checking for new mail, it is the preferred the
authentication. It reduces the risk of password capture. The user
and the shared secret are pass to pop3_apop ()
, the MD5 digest
is calculated by applying the times tamp given by the server in the greeting
followed by the secret.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
The Capa command is send to the sever and the list of capabilities is
return in an iterator. iterator_current ()
gives an allocated
string that should be free ()
'ed.
Caution: The iterator must be destroy after use, it will discard
any remaining responses from CAPA and clear the way for new operations.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
#include <stdio.h> #include <stdlib.h> #include <mailutils/pop3.h> void print_capabilities (pop3_t pop3) { iterator_t iterator; status = pop3_capa (pop3, &iterator); if (status == 0) { for (iterator_first (iterator); !iterator_is_done (iterator); iterator_next (iterator)) { char *capa; if (iterator_current (iterator, &capa) == 0) {; printf ("CAPA: %s\n", capa); free (capa); } } pop3_capa_destroy (&iterator); } else printf ("NONE\n"); }
Sends a Dele to the servers who will mark the msgno for deletion. The msgno may not refer to a message already marked deleted. If successful any future reference to msgno in other operations will be an error, unless unmarked by RSET.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Sends a List for a specific msgno and returns the size.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Sends A List with no argument to the server. The iterator must be
destroy after use, it will discard any remaining response from LIST and
clear the way for new operations. A cover function pop3_list_current ()
around to scan properly the string return by the iterator_current ()
.
#include <stdio.h> #include <stdlib.h> #include <mailutils/pop3.h> void print_list (pop3_t pop3) { iterator_t iterator; status = pop3_list_all (pop3, &iterator); if (status == 0) { for (iterator_first (iterator); !iterator_is_done (iterator); iterator_next (iterator)) { unsigned int msgno, size; if (pop3_list_current (iterator, &msgno, &size) == 0) { printf ("LIST: %d %d\n", msgno, size); } } iterator (&iterator); } else printf ("NONE\n"); }
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Cover functions around iterator_current ()
from an iterator created
by pop3_list_all ()
to format the result.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Sends a NOOP, useful to reset the timeout on the server.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Sends the PASS, to authenticate after the USER command.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Enter the UPDATE state. The server will delete all messages marked deleted before closing the connection.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
If successful a stream_t
is created to allow downloading of the
message, byte-stuff lines or handle internally, CRLFs are converted to LF.
All other operations will fail until the stream is destroyed by the caller.
#include <stdio.h> #include <mailutils/pop3.h> int print_message (pop3_t pop3, unsigned int msgno) { stream_t stream; int status = pop3_retr (pop3, msgno, &stream); if (status == 0) { size_t n = 0; char buf[128]; while ((stream_readline (stream, buf, sizeof buf, &n) == 0) && n) printf ("%s", buf); stream_release (stream); } return status; }
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Sends a RSET to unmark the messages marked as deleted.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
The number of messages in the mailbox and the size of the mailbox in octets. Caution: The size is in RFC822 where line termination is CRLF, messages marked as deleted are not counted in either total.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
If successful a stream
is created to allow downloading of the header,
byte-stuff lines or handle internally, CRLFs are converted to LF. All other
operations will failed until the stream is destroyed by the caller.
#include <stdio.h> #include <mailutils/pop3.h> int print_top (pop3_t pop3, unsigned int msgno, unsigned int lines) { stream_t stream; int status = pop3_top (pop3, msgno, lines, &stream); if (status == 0) { size_t n = 0; char buf[128]; while ((stream_readline (stream, buf, sizeof buf, &n) == 0) && n) printf ("%s", buf); stream_release (stream); } return status; }
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
The Uniq Identifier is return in uidl, the string must be
free ()
'ed, by the caller.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
An iterator
object is return to iterate through the response and
must be destroyed by the caller.
#include <stdio.h> #include <stdlib.h> #include <mailutils/pop3.h> void print_uidl (pop3_t pop3) { iterator_t iterator; status = pop3_uidl_all (pop3, &iterator); if (status == 0) { for (iterator_first (iterator); !iterator_is_done (iterator); iterator_next (iterator)) { unsigned int msgno; char *uidl; if (pop3_uidl_current (iterator, &msgno, &uidl) == 0) { printf ("LIST: %d %s\n", msgno, uidl); free (uidl); } } iterator (&iterator); } else printf ("NONE\n"); }
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Cover functions around iterator_current ()
from an iterator created
by pop3_uidl_all ()
to format the result. The variable uidl
should be free ()
'ed.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Sends the User command.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Copy in the internal buffer of pop3_t
the string, pop3_send ()
should be called later to flush the string to the POP3 server.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Cover function for pop3_writeline ()
and pop3_send ()
.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Flushes out the strings written by pop3_writeline ()
in the internal
buffer to the channel.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
The last response from the last command is save and can be examine after a failure or success.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_IO
MU_ERROR_TIMEOUT
MU_ERROR_TRY_AGAIN
MU_ERROR_OPERATION_DENIED
Set the timeout time for I/O on the carrier. The default is 10 minutes. The timeout is given in milliseconds.
Get the timeout time for I/O on the carrier. The timeout is given in milliseconds.
/* Prefix imap4_ is reserved */
#include <mailutils/imap4.h>
Internet Message Access Protocol - Version (4rev1). Not implemented.
/* Prefix mbox_ is reserved */
#include <mailutils/mbox.h>
The most common mailbox format on UNIX platform is mbox. Mbox file is messages separated by the special format string.
From SP envelope-sender SP date [SP moreinfo]
"From "
envelope-sender
date
asctime ()
moreinfo
A mbox_t is created, initialized and destroyed by mbox_create ()
and mbox_destroy ()
. When opening, mbox_open ()
will do a quick
check to see if the format is a valid format or an empty file. The scanning
of the mailbox is done by mbox_scan ()
.
The function, mbox_scan ()
, takes callback functions called during the
scanning to provide information. The scanning will cache some of the headers
fields for speed. Closing the mailbox, mbox_close ()
will free
any resources like, headers cache, locks etc ... All the messages with
attributes marked deleted will only be removed on mbox_expunge ()
.
If only the attributes need to be save but the messages not removed, this
can be done by mbox_save_attributes ()
. New messages are added with
mbox_append ()
. Attributes are saved in the Status: header
field, Read is 'R', Seen is 'O', Deleted is 'd' and Reply is 'r'.
Allocate and initialize a mbox handle.
MU_ERROR_NO_MEMORY
MU_ERROR_INVALID_PARAMETER
When a POP3 session is finished, the structure must be free ()
'ed to
reclaim memory.
Another type of stream can be provided to work on, the carrier is set in the mbox_t handle. Any previous carrier stream in the handle, will be close and release. Since the parsing code maintain only the offsets off the message the carrier stream must be seekable.
MU_ERROR_INVALID_PARAMETER
Return the mbox_t carrier. If none was set, a new file stream will be created.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_NO_MEMORY
Open carrier stream with filename and flags. The stream will be quickly examine to see if it is a mbox format.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_NO_MEMORY
MU_ERROR_NO_ENTRY
MU_ERROR_NO_ACCESS
MU_ERROR_NOT_SUPPORTED
Close the carrier stream and resources particular to the mailbox.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_NO_MEMORY
Return the uidnext, if the mbox_t was not scan mbox_scan ()
is called first.
MU_ERROR_INVALID_PARAMETER
same as mbox_scan ()
Return the uidvalidity, if the mbox_t was not scan mbox_scan ()
is called first.
MU_ERROR_INVALID_PARAMETER
same as mbox_scan ()
Return an attribute to indicate the status of message number msgno.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_NO_MEMORY
Return an allocated string in sep containing the value "From " separating
each message in Unix mbox format. The string should be free ()
ed by
the caller.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_NO_MEMORY
The variable sep should contain a valid "From " separator that will be use when the expunging.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_NO_MEMORY
Return a stream to read the header of message msgno. The stream should be destroy after usage.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_NO_MEMORY
Use stream when expunging for message msgno.
MU_ERROR_INVALID_PARAMETER
Return the size of message msgno.
MU_ERROR_INVALID_PARAMETER
Return the number of lines of message msgno.
MU_ERROR_INVALID_PARAMETER
Return a stream to read the body of message msgno. The stream should be destroy after usage.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_NO_MEMORY
Use stream when expunging for message msgno.
MU_ERROR_INVALID_PARAMETER
Return the size of message msgno.
MU_ERROR_INVALID_PARAMETER
Return the number of lines of message msgno.
MU_ERROR_INVALID_PARAMETER
Return the size of mailbox.
MU_ERROR_INVALID_PARAMETER
Save the changes to the messages back to the mailbox, but do not remove messages mark for deletion in the process.
MU_ERROR_INVALID_PARAMETER
Mark msgno for deletion.
MU_ERROR_INVALID_PARAMETER
Unmark msgno if it was marked for deletion.
MU_ERROR_INVALID_PARAMETER
Save the changes to the mailbox and in the process remove all messages marked for deletion.
MU_ERROR_INVALID_PARAMETER
Append to the mailbox an rfc822 message represented by stream. The variable sep should contain a valid "From " separator or NULL to get the default.
MU_ERROR_INVALID_PARAMETER
Append to the mailbox an rfc822 message represented by a header, hstream, and a body, bstream. The variable sep should contain a valid "From " separator or NULL to get the default.
MU_ERROR_INVALID_PARAMETER
Start scanning the mailbox for new messages. The variable start can be
a message number starting point. The result of the scanning will be in
count. The scanning will trigger the mbox_newmsg_cb()
callback
for each new message and mbox_progress_cb ()
at different interval
to notify progression. The return values of the those callback should be
0 is different then 0 the scanning will be stop an the function returns
MU_ERROR_INTERRUPTED.
MU_ERROR_INVALID_PARAMETER
MU_ERROR_INTERRUPTED
MU_ERROR_NO_MEMORY
Set the callback function for progress. The variable arg will be pass back in the callback as the second argument.
MU_ERROR_INVALID_PARAMETER
Set the callback function for new messages. The variable arg will be pass back in the callback as the second argument.
MU_ERROR_INVALID_PARAMETER
/* Prefix mh_ is reserved */
#include <mailutils/mh.h>
Mail Handler mailbox format. Not implemented.
/* Prefix maildir_ is reserved */
#include <mailutils/maildir.h>
QMail mailbox format. Not implemented.
/* Prefix smtp_ is reserved */
#include <mailutils/smtp.h>
Simple Mail Transfer Protocol. Not implemented.
/* Prefix sendmail_ is reserved */
#include <mailutils/sendmail.h>
Spawning Sendmail daemon to deliver mail. Not implemented.
/* Prefix nntp_ is reserved */
#include <mailutils/nntp.h>
Network News Transfer Protocol. Not implemented.
/* Prefix parse822_ is reserved */
#include <mailutils/parse822.h>
Internet Message Format, see Address node for the discussion.
Go to the first, previous, next, last section, table of contents.