static int cmd_show_messages(struct backup *backup, const struct cyrbu_cmd_options *options) { struct backup_message *message = NULL; struct backup_mailbox_list *mailboxes = NULL; struct backup_mailbox *mailbox; struct message_guid want_guid; int i; for (i = 0; i < strarray_size(options->argv); i++) { if (!message_guid_decode(&want_guid, strarray_nth(options->argv, i))) continue; message = backup_get_message(backup, &want_guid); if (!message) continue; fprintf(stdout, "guid:\t%s\n", message_guid_encode(message->guid)); mailboxes = backup_get_mailboxes_by_message(backup, message, 0); if (mailboxes) { fprintf(stdout, "mailboxes:\n"); for (mailbox = mailboxes->head; mailbox; mailbox = mailbox->next) { fprintf(stdout, "\t%s\t%s\n", mailbox->uniqueid, mailbox->mboxname); } backup_mailbox_list_empty(mailboxes); free(mailboxes); } fprintf(stdout, "headers:\n"); backup_read_message_data(backup, message, show_message_headers, stdout); fprintf(stdout, "\n"); backup_message_free(&message); } return 0; }
static int restore_add_object(const char *object_name, const struct restore_options *options, struct backup *backup, struct backup_mailbox_list *mailbox_list, struct sync_folder_list *reserve_folder_list, struct sync_reserve_list *reserve_list) { struct backup_mailbox *mailbox = NULL; struct backup_message *message = NULL; struct message_guid tmp_guid; size_t len; int r; /* try to work out what we're restoring */ len = strlen(object_name); if (len == 24 && strspn(object_name, HEX_DIGITS) == len) { /* looks like a non-libuuid uniqueid */ mailbox = backup_get_mailbox_by_uniqueid(backup, object_name, BACKUP_MAILBOX_ALL_RECORDS); } else if (len == 36 && strspn(object_name, "-" HEX_DIGITS) == len) { /* looks like a libuuid uniqueid */ mailbox = backup_get_mailbox_by_uniqueid(backup, object_name, BACKUP_MAILBOX_ALL_RECORDS); } else if (message_guid_decode(&tmp_guid, object_name)) { /* looks like it's a message guid */ message = backup_get_message(backup, &tmp_guid); } else if (strchr(object_name, '.')) { /* has a dot, might be an mboxname */ mbname_t *mbname = mbname_from_intname(object_name); mailbox = backup_get_mailbox_by_name(backup, mbname, BACKUP_MAILBOX_ALL_RECORDS); mbname_free(&mbname); } else { /* not sure what it is, guess mboxname? */ mbname_t *mbname = mbname_from_intname(object_name); mailbox = backup_get_mailbox_by_name(backup, mbname, BACKUP_MAILBOX_ALL_RECORDS); mbname_free(&mbname); } /* add it to the restore lists */ if (mailbox) { r = restore_add_mailbox(mailbox, options, mailbox_list, reserve_folder_list, reserve_list); if (!r && options->do_submailboxes) { char prefix[MAX_MAILBOX_NAME + 1]; int len; len = snprintf(prefix, sizeof(prefix), "%s.", mailbox->mboxname); /* can only be submailboxes if parent's name is short enough... */ if (len < MAX_MAILBOX_NAME) { struct submailbox_rock rock = { prefix, strlen(prefix), options, mailbox_list, reserve_folder_list, reserve_list, }; r = backup_mailbox_foreach(backup, 0, BACKUP_MAILBOX_ALL_RECORDS, submailbox_cb, &rock); } } backup_mailbox_free(&mailbox); } else if (message) { struct backup_mailbox_list *mailboxes = NULL; if (!options->override_mboxname) mailboxes = backup_get_mailboxes_by_message(backup, message, BACKUP_MAILBOX_MATCH_RECORDS); r = restore_add_message(message, mailboxes, options, mailbox_list, reserve_folder_list, reserve_list); if (mailboxes) { backup_mailbox_list_empty(mailboxes); free(mailboxes); } backup_message_free(&message); } else { r = IMAP_MAILBOX_NONEXISTENT; } return r; }