cmd-status.c revision 28a74c3bd54dc4b503262ebfaaeef9ce27944841
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen/* Returns status items, or -1 if error */
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainenstatic MailboxStatusItems get_status_items(Client *client, ImapArgList *list)
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen /* list may contain only atoms */
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen client_send_command_error(client, "Status list "
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen "contains non-atoms.");
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainenstatic int mailbox_name_equals(const char *box1, const char *box2)
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen return strcasecmp(box1, "INBOX") == 0 && strcasecmp(box2, "INBOX") == 0;
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainenstatic int get_mailbox_status(Client *client, const char *mailbox,
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen MailboxStatusItems items, MailboxStatus *status)
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen mailbox_name_equals(client->mailbox->name, mailbox)) {
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen /* this mailbox is selected */
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen /* open the mailbox */
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen box = client->storage->open_mailbox(client->storage,
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen failed = !box->get_status(box, items, status);
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen /* <mailbox> <status items> */
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen if (mailbox == NULL || args[1].type != IMAP_ARG_LIST) {
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen client_send_command_error(client, "Status items must be list.");
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen /* get the items client wants */
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen items = get_status_items(client, args[1].data.list);
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen /* get status */
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen if (!get_mailbox_status(client, mailbox, items, &status)) {
cc935aff970ed6c24d136cc560c7e705a49d536cTimo Sirainen t_string_printfa(str, "* STATUS %s (", mailbox);
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen t_string_printfa(str, "MESSAGES %u ", status.messages);
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen t_string_printfa(str, "RECENT %u ", status.recent);
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen t_string_printfa(str, "UIDNEXT %u ", status.uidnext);
d6a7cb184cc882a90aa3d9312082e0029f354ff6Timo Sirainen t_string_printfa(str, "UIDVALIDITY %u ", status.uidvalidity);
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen t_string_printfa(str, "UNSEEN %u ", status.unseen);
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen client_send_tagline(client, "OK Status completed.");