doveadm-mail-fetch.c revision 94ba4820927b906b333e39445c1508a29387c3aa
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
55a7410569737197afb302b07b488973324b0cc5Timo Sirainenstatic struct mail_search_args *search_args_from_str(const char *str)
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen input = i_stream_create_from_data(str, strlen(str));
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen parser = imap_parser_create(input, NULL, (size_t)-1);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen ret = imap_parser_finish_line(parser, 0, 0, &args);
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen i_fatal("%s", imap_parser_get_error(parser, &fatal));
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if (mail_search_build_from_imap_args(mail_search_register_human,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenstatic const char *params_to_imap_args_string(const char *const args[])
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen const char *p;
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if (*p == '\0' ||
def516ea503a60f20d510c14d5070b7ff5bbddf4Timo Sirainenvoid cmd_fetch(struct mail_user *user, const char *const args[])
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen search_args = search_args_from_str(params_to_imap_args_string(args+1));
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen random_fill_weak(prefix_buf, sizeof(prefix_buf));
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen base64_encode(prefix_buf, sizeof(prefix_buf), prefix);
9e0959adf671330f95ba941cff238ad5cd408fe1Timo Sirainen output = o_stream_create_fd(STDOUT_FILENO, 0, FALSE);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen box = doveadm_mailbox_find_and_sync(user, mailbox);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen search_ctx = mailbox_search_init(t, search_args, NULL);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen while (mailbox_search_next(search_ctx, mail)) {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if (mail_get_stream(mail, NULL, NULL, &input) < 0) {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen i_error("Couldn't open mail uid=%u: %s", mail->uid,
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen str_printfa(prefix, "seq=%u uid=%u\n", mail->seq, mail->uid);
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen if (o_stream_send(output, str_data(prefix), str_len(prefix)) < 0)