#include <stdio.h>
#include <errno.h>
#include <newmail.h>
int query = NM_QUERY_NCUR|NM_QUERY_NNEW;
char *b2s(int b) {
if (b < 0) return "fail";
if (b > 0) return "yes";
return "no";
}
void cb(const char *spool, void*user) {
struct nm_spool* s = NULL;
struct nm_info i;
struct nm_status st;
if (!(s = nm_open(spool))) {
fprintf(stderr, "nm_open(\"%s\"): %s\n", spool, nm_strerror(nm_errno, errno, nm_explanation));
goto finish;
}
if (nm_info(s, &i) < 0) {
fprintf(stderr, "nm_info(\"%s\"): %s\n", spool, nm_strerror(nm_errno, errno, nm_explanation));
goto finish;
}
printf("\n%s:\n\tName: %s\n\tType: %s\n\tText: %s\n\tFlags: ", i.path, i.name, i.type, i.text);
if (i.flags & NM_FLAG_SYNCHRONOUS) printf("SYNCHRONOUS ");
if (i.flags & NM_FLAG_ASYNCHRONOUS) printf("ASYNCHRONOUS ");
printf("\n");
if (nm_query(s, query, &st) < 0) {
fprintf(stderr, "nm_check(\"%s\"): %s\n", spool, nm_strerror(nm_errno, errno, nm_explanation));
goto finish;
}
if (query & NM_QUERY_NCUR)
printf("\tCurrent: %i\n", st.cur);
else if (query & NM_QUERY_CUR)
printf("\tCurrent: %s\n", b2s(st.cur));
if (query & NM_QUERY_NNEW)
printf("\tNew: %i\n", st.new);
else if (query & NM_QUERY_NEW)
printf("\tNew: %s\n", b2s(st.new));
finish:
if (s)
nm_close(s);
}
int main(int argc, char *argv[]) {
if (nm_list(cb, NULL) < 0)
nm_perror("nm_list()");
return 0;
}