imap-fetch.c revision a5a0a25a2aa6c85e1bbf0f281d515b45018e190e
5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic void fetch_uid(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_flags(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch imap_write_flags(flags->flags, flags->custom_flags,
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_internaldate(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_printfa(ctx->str, "INTERNALDATE \"%s\" ", imap_to_datetime(time));
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_rfc822_size(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_printfa(ctx->str, "RFC822.SIZE %"PRIuUOFF_T" ", size);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_body(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch body = mail->get_special(mail, MAIL_FETCH_IMAP_BODY);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_bodystructure(struct imap_fetch_context *ctx,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch bodystructure = mail->get_special(mail, MAIL_FETCH_IMAP_BODYSTRUCTURE);
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen str_printfa(ctx->str, "BODYSTRUCTURE (%s) ", bodystructure);
56d1345c43bbd28c36b7faa85e4163bd9e874290Timo Sirainenstatic int fetch_envelope(struct imap_fetch_context *ctx, struct mail *mail)
35e962a9186b4e9b2001628c1d7b55c24b33ce84Timo Sirainen envelope = mail->get_special(mail, MAIL_FETCH_IMAP_ENVELOPE);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_printfa(ctx->str, "ENVELOPE (%s) ", envelope);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_send_rfc822(struct imap_fetch_context *ctx, struct mail *mail)
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen const char *str;
70505f4839520ac67895992621c97d2480c22e7fTimo Sirainen stream = mail->get_stream(mail, &hdr_size, &body_size);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str = t_strdup_printf(" RFC822 {%"PRIuUOFF_T"}\r\n",
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return message_send(ctx->output, stream, &body_size,
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_send_rfc822_header(struct imap_fetch_context *ctx,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *str;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch stream = mail->get_stream(mail, &hdr_size, NULL);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str = t_strdup_printf(" RFC822.HEADER {%"PRIuUOFF_T"}\r\n",
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return message_send(ctx->output, stream, &hdr_size, 0, (uoff_t)-1) >= 0;
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_send_rfc822_text(struct imap_fetch_context *ctx,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *str;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch stream = mail->get_stream(mail, &hdr_size, &body_size);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str = t_strdup_printf(" RFC822.TEXT {%"PRIuUOFF_T"}\r\n",
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch i_stream_seek(stream, hdr_size.physical_size);
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch return message_send(ctx->output, stream, &body_size,
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int fetch_mail(struct imap_fetch_context *ctx, struct mail *mail)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch str_printfa(ctx->str, "* %u FETCH (", mail->seq);
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen /* write the data into temp string */
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen if ((ctx->fetch_data & MAIL_FETCH_FLAGS) || mail->seen_updated)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ctx->fetch_data & MAIL_FETCH_RECEIVED_DATE)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ctx->fetch_data & MAIL_FETCH_IMAP_BODYSTRUCTURE)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ctx->fetch_data & MAIL_FETCH_IMAP_ENVELOPE)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* send the data written into temp string */
17cd0e0963f2fb0e66d49703e8cd0bda1b842468Timo Sirainen if (o_stream_send(ctx->output, str_data(ctx->str), len) < 0)
ba1c847d0af4afe4787ed470d0c818e948e184e2Timo Sirainen /* large data */
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen if (ctx->imap_data & IMAP_FETCH_RFC822_HEADER)
35e962a9186b4e9b2001628c1d7b55c24b33ce84Timo Sirainen for (body = ctx->bodies; body != NULL; body = body->next) {
35e962a9186b4e9b2001628c1d7b55c24b33ce84Timo Sirainen if (!imap_fetch_body_section(ctx, body, mail))
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen if (o_stream_send(ctx->output, ")\r\n", 3) < 0)
return !failed;