.\" This file is part of libmail.
.\"
.\" (c) 2009 - Dimitris Mandalidis <mandas@users.sourceforge.net>
.\"
.\" libmail is free software: you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation, either version 3 of the License, or
.\" (at your option) any later version.
.\"
.\" libmail is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with libmail. If not, see <http://www.gnu.org/licenses/>.
.TH LIBMAIL_MBOX 3 "2009-03-23" "version 0.2" "libmail - A mail handling library"
.SH NAME
mbox_check - libmail's mbox supporting functions
.SH SYNOPSIS
.nf
.B #include <libmail/libmail.h>
.B #include <libmail/mbox.h>
.sp
.BI "int mbox_check(mbox_server_t *" "server" ", int *" "n_new_messages" ", int *" "n_messages" );
.fi
.SH DESCRIPTION
.B mbox_check()
takes a pointer to
.B mbox_server_t
structure which identify the mailbox location. More specifically
.I mbox_server_t
is defined as follows :
.sp
.nf
typedef struct mbox_server_t {
char file[PATH_MAX+1];
} mbox_server_t;
.fi
.sp
In
.I file
the path of the local mailbox is specified.
.B mbox_check()
checks for messages filling the
.I n_messages
and
.I n_new_messages
with the number of total and new messages respectively.
.SH "RETURN VALUE"
.B mbox_check()
returns
.B LIBMAIL_SUCCESS
on success and
.B LIBMAIL_SYSERROR
otherwise (errno defined in <errno.h> is set).
.TP
You can retrieve a short description about a specific error through libmail_strerror()
.SH "SEE ALSO"
.BR "mbox" "(5)" "libmail_strerror" "(3)"
.SH "AUTHOR"
Dimitris Mandalidis <mandas AT users DOT sourceforge DOT net>
.SH "EXAMPLES"
For convenience,
.B endpeer_t
and
.B server_t
are defined as follows:
.sp
.nf
typedef union server_t {
pop3_server_t pop3_server;
imap4_server_t imap4_server;
mbox_server_t local_mbox;
} server_t;
typedef struct endpeer_t {
time_t last_checked_on;
short protocol;
int n_messages;
int n_new_messages;
server_t server;
} endpeer_t;
.fi
.sp
However they will never be used by libmail as arguments of return values of
functions. A short example on using libmail mbox support follows:
.sp
.nf
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#include <libmail/libmail.h>
#include <libmail/mbox.h>
int check_for_messages(endpeer_t *endpeer) {
int status;
if ((status = mbox_check(&endpeer->server.local_mbox, &endpeer->n_new_messages, &endpeer->n_messages)) != 0)
return status;
endpeer->last_checked_on = time(NULL);
return 0;
}
void mbox_test(void) {
endpeer_t endpeer;
mbox_server_t mbox_server;
strcpy(mbox_server.file, "/var/mail/mandas");
endpeer.protocol = MBOX_PROTO;
endpeer.server.local_mbox = mbox_server;
if (check_for_messages(&endpeer) != 0) {
printf("ERROR");
exit(EXIT_FAILURE);
}
printf("%d total messages and %d new messages", endpeer.n_messages, endpeer.n_new_messages);
return;
}
.fi