The mail daemon currently supports only one POP account, so this function will always return 1. You shouldn't assume there will only be one POP account, though, as this will probably change in the future.
status_t check_for_mail(int32* incoming_count = NULL);
Sends and retrieves mail. More specifically, this function asks the
mail daemon to retrieve incoming messages from the POP server and send any
queued outgoing messages to the SMTP server. The number of POP messages
that were retrieved are stored in the variable pointed to by
incoming_count
. If you specify
NULL
for
incoming_count
,
check_for_mail()
won't return the number of
messages retrieved. You should specify NULL
unless
you really want to know how many messages were retrieved, since requesting
this information could potentially slow down the retrieval
process.
If all is well in the mail world, this function returns
B_OK
; otherwise, it returns a highly useful result
code.
Return Code | Description |
---|---|
| Mail was sent and retrieved without incident. |
| The mail daemon isn't running. |
| The POP server doesn't recognize the user name. |
| The POP server doesn't recognize the password. |
| The POP or SMTP server can't be found. |
| The connection to the POP or SMTP server failed. |
int32 count_pop_accounts();
Returns the number of POP accounts that have been configured.
The mail daemon currently supports only one POP account, so this function will always return 1. You shouldn't assume there will only be one POP account, though, as this will probably change in the future.
ssize_t decode_base64(char* out,
char* in,
off_t length,
bool replace_cr = false);
Decodes the base-64 data pointed to by
in
, which is length
bytes long, and writes the decoded output into the buffer pointed to by
out
. If replace_cr
is
true
, carriage return characters in the output are
converted into newlines, otherwise the data is returned in its original,
unaltered, form.
You would typically specify replace_cr
as true
if you're decoding an ASCII text document,
and as false
if decoding a binary file.
This function returns the size of the output data that's been
stored in the out
buffer.
You must be certain, in advance, that the output buffer is large enough to hold the decoded data, or this function will do bad things.
ssize_t encode_base64(char* out,
char* in,
off_t length);
Encodes the data pointed to by in
,
which is length
bytes long, and writes
the base-64 encoded output into the buffer pointed to by
out
.
This function returns the size of the output data that's been stored in
the out
buffer.
You must be certain, in advance, that the output buffer is large enough to hold the encoded data, or this function will do bad things.
status_t forward_mail(entry_ref* message_ref,
const char* recipients,
bool now = true);
Forwards the mail message specified by
message_ref
to the list of users given by
recipients
. The list of user names specified in
recipients
must be separated by commas and/or
whitespace, and must be null-terminated.
If the now
parameter is
true
, the messages will be sent immediately; if
false
, the message will be queued up to be sent
the next time check_for_mail()
is called, or the next time the mail daemon performs an automatic
mail check.
Return Code | Description |
---|---|
| The message was forwarded without error. |
| No valid recipients were specified. |
Other Errors | Errors returned by
|
status_t get_mail_notification(mail_notification* notification_settings);
status_t set_mail_notification(mail_notification* notification_settings,
bool save = true);
get_mail_notification()
fills the specified
mail_notification structure
with information describing how the user is currently being notified of
received e-mail. There are two possible notification signals: the mail
alert panel and the system beep. The mail_notification
structure looks like this:
typedef struct { boolalert
; boolbeep
; } mail_notification;
get_mail_notification()
always returns
B_OK
. If the current settings can't be checked
(for example, if the user has never configured mail),
alert
will be returned as the default value of
false
, and beep
will be
true
.
set_mail_notification()
accepts a pointer
to a mail_notification structure and configures the system
to report incoming mail using the methods specified therein. If the
save
argument is true
,
the change is set as the new default and will be remembered when the
computer is shut down. If false
, the change is
temporary.
Return Code | Description |
---|---|
| The notification was successfully set or retrieved. |
| The mail daemon didn't respond to the request. |
status_t get_pop_account(mail_pop_account* account_info,
int32 index = 0);
status_t set_pop_account(mail_pop_account* account_info,
int32 index = 0);
Get and set the specified POP account's information. The mail_pop_account structure is defined as follows:
typedef struct { charpop_name
[B_MAX_USER_NAME_LENGTH
]; charpop_password
[B_MAX_USER_NAME_LENGTH
]; charpop_host
[B_MAX_HOST_NAME_LENGTH
]; charreal_name
[128]; charreply_to
[128]; int32days
; int32interval
; int32begin_time
; int32end_time
; } mail_pop_account;
The pop_name
, pop_password
,
and pop_host
fields in the mail_pop_account
structure represent the username, password, and POP server host of the
e-mail user. The real_name
is the user's
real name, and reply_to
is the
e-mail address to which replies should be sent.
The days
field can contain any of the following flags to specify which
days of the week the mail daemon should automatically check mail for the
described account:
Constant | Description |
---|---|
| Don't automatically check the account's mail. |
| Check the mail only on weekdays. |
| Check the mail every day. |
| Check continuously every day. |
The interval
specifies how many seconds apart each e-mail retrieval
should be, and the begin_time
and end_time
specify the time of day (in
seconds) that automatic retrieval should begin and end. If begin_time
and
end_time
are the same, the daemon checks mail round-the-clock.
Eventually these functions will support multiple POP accounts; at this
time, the Mail Kit only supports one POP account, so you must use an
index
of 0. Any other index
will result in a B_BAD_INDEX
error.
get_pop_account()
fills the specified
mail_pop_account structure with the
information on the POP account, and
set_pop_account()
takes the
information in the buffer and saves it as the new default.
Return Code | Description |
---|---|
| The notification was successfully set or retrieved. |
| An |
| The mail daemon didn't reply to the request. |
status_t get_smtp_host(char* smtp_host);
status_t set_smtp_host(char* smtp_host,
bool save = true);
get_smtp_host()
returns in the buffer
pointed to by smtp_host
the name of the SMTP
host as currently configured. The buffer should be at lest
B_MAX_HOST_NAME_LENGTH
bytes long.
set_smtp_host()
sets the SMTP host through
which mail will be sent in the future to the specified host. If
save
is true
, the new
setting becomes the default and will persist through a reboot of the
computer; otherwise, the change is only temporary.
Return Code | Description |
---|---|
| The notification was successfully set or retrieved. |
| The mail daemon didn't respond to the request. |