imap-fetch.c revision a5a0a25a2aa6c85e1bbf0f281d515b45018e190e
5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "common.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "istream.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "ostream.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "str.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "message-send.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "message-size.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "imap-date.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "commands.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "imap-fetch.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include <unistd.h>
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic void fetch_uid(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_printfa(ctx->str, "UID %u ", mail->uid);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_flags(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const struct mail_full_flags *flags;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch flags = mail->get_flags(mail);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (flags == NULL)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_printfa(ctx->str, "FLAGS (%s) ",
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch imap_write_flags(flags->flags, flags->custom_flags,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch flags->custom_flags_count));
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return TRUE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_internaldate(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch time_t time;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch time = mail->get_received_date(mail);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (time == (time_t)-1)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_printfa(ctx->str, "INTERNALDATE \"%s\" ", imap_to_datetime(time));
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return TRUE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_rfc822_size(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch uoff_t size;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch size = mail->get_size(mail);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (size == (uoff_t)-1)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_printfa(ctx->str, "RFC822.SIZE %"PRIuUOFF_T" ", size);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return TRUE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_body(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *body;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch body = mail->get_special(mail, MAIL_FETCH_IMAP_BODY);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (body == NULL)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_printfa(ctx->str, "BODY (%s) ", body);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return TRUE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_bodystructure(struct imap_fetch_context *ctx,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *bodystructure;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch bodystructure = mail->get_special(mail, MAIL_FETCH_IMAP_BODYSTRUCTURE);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (bodystructure == NULL)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return FALSE;
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen str_printfa(ctx->str, "BODYSTRUCTURE (%s) ", bodystructure);
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen return TRUE;
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
56d1345c43bbd28c36b7faa85e4163bd9e874290Timo Sirainenstatic int fetch_envelope(struct imap_fetch_context *ctx, struct mail *mail)
30d917bcd48d70af0371baf27571cc198d621a62Timo Sirainen{
9d0aee99a8c80d71137aa9b8c216cc203bec7a9aTimo Sirainen const char *envelope;
9d0aee99a8c80d71137aa9b8c216cc203bec7a9aTimo Sirainen
35e962a9186b4e9b2001628c1d7b55c24b33ce84Timo Sirainen envelope = mail->get_special(mail, MAIL_FETCH_IMAP_ENVELOPE);
35e962a9186b4e9b2001628c1d7b55c24b33ce84Timo Sirainen if (envelope == NULL)
35e962a9186b4e9b2001628c1d7b55c24b33ce84Timo Sirainen return FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_printfa(ctx->str, "ENVELOPE (%s) ", envelope);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return TRUE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_send_rfc822(struct imap_fetch_context *ctx, struct mail *mail)
ad03049781fc14807248007d524be4daf06c3ee2Stephan Bosch{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct message_size hdr_size, body_size;
feba5e502b2131c9a1c766b7ef9ff041dbf71d1dStephan Bosch struct istream *stream;
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen const char *str;
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen
70505f4839520ac67895992621c97d2480c22e7fTimo Sirainen stream = mail->get_stream(mail, &hdr_size, &body_size);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (stream == NULL)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch message_size_add(&body_size, &hdr_size);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str = t_strdup_printf(" RFC822 {%"PRIuUOFF_T"}\r\n",
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch body_size.virtual_size);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ctx->first) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str++; ctx->first = FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch }
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (o_stream_send_str(ctx->output, str) < 0)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return message_send(ctx->output, stream, &body_size,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch 0, (uoff_t)-1) >= 0;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_send_rfc822_header(struct imap_fetch_context *ctx,
9dc01e0d10a61cab14867b26bf0d2d1dcf8ad978Timo Sirainen struct mail *mail)
9dc01e0d10a61cab14867b26bf0d2d1dcf8ad978Timo Sirainen{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct message_size hdr_size;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct istream *stream;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *str;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch stream = mail->get_stream(mail, &hdr_size, NULL);
aacf2a69acc59e9382578d6f4e030788abc79706Timo Sirainen if (stream == NULL)
aacf2a69acc59e9382578d6f4e030788abc79706Timo Sirainen return FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str = t_strdup_printf(" RFC822.HEADER {%"PRIuUOFF_T"}\r\n",
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch hdr_size.virtual_size);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ctx->first) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str++; ctx->first = FALSE;
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen }
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen if (o_stream_send_str(ctx->output, str) < 0)
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen return FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return message_send(ctx->output, stream, &hdr_size, 0, (uoff_t)-1) >= 0;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_send_rfc822_text(struct imap_fetch_context *ctx,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
636d0f43138468f8efe685a681326b123f660e49Timo Sirainen struct message_size hdr_size, body_size;
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch struct istream *stream;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *str;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch stream = mail->get_stream(mail, &hdr_size, &body_size);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (stream == NULL)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str = t_strdup_printf(" RFC822.TEXT {%"PRIuUOFF_T"}\r\n",
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch body_size.virtual_size);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ctx->first) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str++; ctx->first = FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch }
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (o_stream_send_str(ctx->output, str) < 0)
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch return FALSE;
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch i_stream_seek(stream, hdr_size.physical_size);
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch return message_send(ctx->output, stream, &body_size,
636d0f43138468f8efe685a681326b123f660e49Timo Sirainen 0, (uoff_t)-1) >= 0;
636d0f43138468f8efe685a681326b123f660e49Timo Sirainen}
636d0f43138468f8efe685a681326b123f660e49Timo Sirainen
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_mail(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct imap_fetch_body_data *body;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch size_t len, orig_len;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch int failed, data_written;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_truncate(ctx->str, 0);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_printfa(ctx->str, "* %u FETCH (", mail->seq);
fb1be3de0159d6a10e916ad992e2bc53be64c6d5Timo Sirainen orig_len = str_len(ctx->str);
fb1be3de0159d6a10e916ad992e2bc53be64c6d5Timo Sirainen
fb1be3de0159d6a10e916ad992e2bc53be64c6d5Timo Sirainen failed = TRUE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch data_written = FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch do {
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen /* write the data into temp string */
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen if (ctx->imap_data & IMAP_FETCH_UID)
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen fetch_uid(ctx, mail);
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen if ((ctx->fetch_data & MAIL_FETCH_FLAGS) || mail->seen_updated)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch fetch_flags(ctx, mail);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ctx->fetch_data & MAIL_FETCH_RECEIVED_DATE)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch fetch_internaldate(ctx, mail);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ctx->fetch_data & MAIL_FETCH_SIZE)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch fetch_rfc822_size(ctx, mail);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ctx->fetch_data & MAIL_FETCH_IMAP_BODY)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch fetch_body(ctx, mail);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ctx->fetch_data & MAIL_FETCH_IMAP_BODYSTRUCTURE)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch fetch_bodystructure(ctx, mail);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ctx->fetch_data & MAIL_FETCH_IMAP_ENVELOPE)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch fetch_envelope(ctx, mail);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* send the data written into temp string */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch len = str_len(ctx->str);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx->first = len == orig_len;
17cd0e0963f2fb0e66d49703e8cd0bda1b842468Timo Sirainen
17cd0e0963f2fb0e66d49703e8cd0bda1b842468Timo Sirainen if (!ctx->first)
17cd0e0963f2fb0e66d49703e8cd0bda1b842468Timo Sirainen str_truncate(ctx->str, --len);
17cd0e0963f2fb0e66d49703e8cd0bda1b842468Timo Sirainen if (o_stream_send(ctx->output, str_data(ctx->str), len) < 0)
17cd0e0963f2fb0e66d49703e8cd0bda1b842468Timo Sirainen break;
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen data_written = TRUE;
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen
ba1c847d0af4afe4787ed470d0c818e948e184e2Timo Sirainen /* large data */
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen if (ctx->imap_data & IMAP_FETCH_RFC822)
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen if (!fetch_send_rfc822(ctx, mail))
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen break;
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen if (ctx->imap_data & IMAP_FETCH_RFC822_HEADER)
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen if (!fetch_send_rfc822_header(ctx, mail))
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen break;
56d1345c43bbd28c36b7faa85e4163bd9e874290Timo Sirainen if (ctx->imap_data & IMAP_FETCH_RFC822_TEXT)
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen if (!fetch_send_rfc822_text(ctx, mail))
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen break;
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen
35e962a9186b4e9b2001628c1d7b55c24b33ce84Timo Sirainen for (body = ctx->bodies; body != NULL; body = body->next) {
35e962a9186b4e9b2001628c1d7b55c24b33ce84Timo Sirainen if (!imap_fetch_body_section(ctx, body, mail))
35e962a9186b4e9b2001628c1d7b55c24b33ce84Timo Sirainen break;
d47b9f1bd7274c7b2d9049c2e1718d1cf89cc572Timo Sirainen }
d47b9f1bd7274c7b2d9049c2e1718d1cf89cc572Timo Sirainen
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen failed = FALSE;
ba1c847d0af4afe4787ed470d0c818e948e184e2Timo Sirainen } while (0);
ba1c847d0af4afe4787ed470d0c818e948e184e2Timo Sirainen
ba1c847d0af4afe4787ed470d0c818e948e184e2Timo Sirainen if (data_written) {
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen if (o_stream_send(ctx->output, ")\r\n", 3) < 0)
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen failed = TRUE;
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen }
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen
return !failed;
}
int imap_fetch(struct client *client,
enum mail_fetch_field fetch_data,
enum imap_fetch_field imap_data,
struct imap_fetch_body_data *bodies,
const char *messageset, int uidset)
{
struct imap_fetch_context ctx;
struct mail *mail;
int all_found, update_seen = FALSE;
if (!client->mailbox->readonly) {
/* If we have any BODY[..] sections, \Seen flag is added for
all messages */
struct imap_fetch_body_data *body;
for (body = bodies; body != NULL; body = body->next) {
if (!body->peek) {
update_seen = TRUE;
break;
}
}
if (imap_data & (IMAP_FETCH_RFC822|IMAP_FETCH_RFC822_TEXT))
update_seen = TRUE;
}
memset(&ctx, 0, sizeof(ctx));
ctx.fetch_data = fetch_data;
ctx.imap_data = imap_data;
ctx.bodies = bodies;
ctx.output = client->output;
ctx.select_counter = client->select_counter;
ctx.str = t_str_new(8192);
ctx.fetch_ctx = client->mailbox->
fetch_init(client->mailbox, fetch_data, &update_seen,
messageset, uidset);
if (ctx.fetch_ctx == NULL)
return -1;
while ((mail = client->mailbox->fetch_next(ctx.fetch_ctx)) != NULL) {
if (!fetch_mail(&ctx, mail)) {
ctx.failed = TRUE;
break;
}
}
if (!client->mailbox->fetch_deinit(ctx.fetch_ctx, &all_found))
return -1;
return ctx.failed ? -1 : all_found;
}