/* There is no explicit call to get the message count. The count is send on a "GROUP" command. The function is also use as a way to select newsgoupr by other functions. */ static int nntp_mailbox_messages_count (mu_mailbox_t mbox, size_t *pcount) { m_nntp_t m_nntp = mbox->data; f_nntp_t f_nntp = m_nntp->f_nntp; int status = 0; status = mu_folder_open (mbox->folder, mbox->flags); if (status != 0) return status; /* Are we already selected ? */ if (m_nntp == (f_nntp->selected)) { if (pcount) *pcount = m_nntp->number; return 0; } /* Put the mailbox as selected. */ f_nntp->selected = m_nntp; status = mu_nntp_group (f_nntp->nntp, m_nntp->name, &m_nntp->number, &m_nntp->low, &m_nntp->high, NULL); if (pcount) *pcount = m_nntp->number; return status; }
int ls_folders (char *fname, char *ref, char *pattern, int level) { int status; mu_folder_t folder; mu_list_t flist; size_t count; status = mu_folder_create (&folder, fname); if (status) { mu_error ("mu_folder_create failed: %s", mu_strerror (status)); return 1; } status = mu_folder_open (folder, MU_STREAM_READ); if (status) { mu_error ("mu_folder_create failed: %s", mu_strerror (status)); return 1; } status = mu_folder_enumerate (folder, ref, pattern, 0, level, &flist, enumfun, NULL); switch (status) { case 0: mu_list_count (flist, &count); printf ("Number of folders: %lu\n", (unsigned long) count); mu_list_destroy (&flist); break; case MU_ERR_NOENT: printf ("No folders matching %s %s in %s\n", ref, pattern, fname); return 0; default: mu_error ("mu_folder_list failed: %s", mu_strerror (status)); } return 0; }
/* If the connection was not up it is open by the folder since the stream socket is actually created by the folder. It is not necessary to set select the mailbox/newsgoup right away, there are maybe on going operations. But on any operation by a particular mailbox, it will be selected first. */ static int nntp_mailbox_open (mu_mailbox_t mbox, int flags) { int status = 0; m_nntp_t m_nntp = mbox->data; f_nntp_t f_nntp = m_nntp->f_nntp; mu_iterator_t iterator; /* m_nntp must have been created during mailbox initialization. */ /* assert (mbox->data); assert (m_nntp->name); */ mbox->flags = flags; /* make sure the connection is up. */ if ((status = mu_folder_open (f_nntp->folder, flags))) return status; mu_nntp_set_debug (f_nntp->nntp, mbox->debug); /* We might not have to SELECT the newsgroup, but we need to know it exists. */ status = mu_nntp_list_active (f_nntp->nntp, m_nntp->name, &iterator); if (status == 0) { for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator); mu_iterator_next (iterator)) { char *buffer = NULL; mu_iterator_current (iterator, (void **) &buffer); mu_nntp_parse_list_active (buffer, NULL, &m_nntp->high, &m_nntp->low, &m_nntp->status); } mu_iterator_destroy (&iterator); } return status; }
int main (int argc, char **argv) { int i; int rc; mu_folder_t folder; char *fname = NULL; mu_set_program_name (argv[0]); mu_registrar_record (mu_imap_record); mu_registrar_record (mu_imaps_record); if (argc == 1) { usage (); exit (0); } for (i = 1; i < argc; i++) { if (strncmp (argv[i], "debug=", 6) == 0) mu_debug_parse_spec (argv[i] + 6); else if (strncmp (argv[i], "url=", 4) == 0) fname = argv[i] + 4; else break; } if (!fname) { mu_error ("URL not specified"); exit (1); } rc = mu_folder_create (&folder, fname); if (rc) { mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_create", fname, rc); return 1; } rc = mu_folder_open (folder, MU_STREAM_READ); if (rc) { mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_open", fname, rc); return 1; } while (i < argc) { char *comargs[2]; struct command *cmd; cmd = find_command (argv[i]); if (!cmd) { mu_error ("unknown command %s\n", argv[i]); break; } i++; if (i + cmd->nargs > argc) { mu_error ("not enough arguments for %s", cmd->verb); break; } memcpy (comargs, argv + i, cmd->nargs * sizeof (comargs[0])); i += cmd->nargs; cmd->handler (folder, comargs); } mu_folder_close (folder); mu_folder_destroy (&folder); return 0; }