imap-fetch.h revision 88ea893b45d3ed8d68000921db9156c03cbe1b00
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen#ifndef __IMAP_FETCH_H
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen#define __IMAP_FETCH_H
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
47e0598840ecffa364ebed523e06939e22738f06Timo Sirainenstruct imap_fetch_context;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen/* Returns 1 = ok, 0 = client output buffer full, call again, -1 = error.
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen mail = NULL for deinit. */
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainentypedef int imap_fetch_handler_t(struct imap_fetch_context *ctx,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen struct mail *mail, void *context);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenstruct imap_fetch_handler {
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen const char *name;
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen /* Returns FALSE if arg is invalid. */
1d738cce754bc64bbc66d3355ebdaf3f6eac55f1Timo Sirainen int (*init)(struct imap_fetch_context *ctx, const char *name,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen struct imap_arg **args);
bdd7a96c363346f7c38f389791be1487ca08775bTimo Sirainen};
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainenstruct imap_fetch_context_handler {
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainen imap_fetch_handler_t *handler;
63e2edd14ae7b1dc4a08e2e659501dbf519462f9Timo Sirainen void *context;
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen int buffered;
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen};
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainenstruct imap_fetch_context {
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen struct client *client;
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen struct client_command_context *cmd;
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen struct mailbox *box;
029cfcdce65b284d5230adf1c920a5f526b03b5cTimo Sirainen
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen struct mailbox_transaction_context *trans;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen struct mail_search_context *search_ctx;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen struct mail *mail;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen enum mail_fetch_field fetch_data;
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen buffer_t *all_headers_buf;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen struct mailbox_header_lookup_ctx *all_headers_ctx;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen array_t ARRAY_DEFINE(handlers, struct imap_fetch_context_handler);
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen unsigned int buffered_handlers_count;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen struct mail *cur_mail;
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen unsigned int cur_handler;
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen uoff_t cur_size, cur_offset;
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen string_t *cur_str;
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen struct istream *cur_input;
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen int skip_cr;
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen int (*cont_handler)(struct imap_fetch_context *ctx);
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen unsigned int select_counter;
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen unsigned int flags_have_handler:1;
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen unsigned int flags_update_seen:1;
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen unsigned int flags_show_only_seen_changes:1;
e925f007930955f10fa8728509a44f7a53d2b13eTimo Sirainen unsigned int update_partial:1;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen unsigned int cur_have_eoh:1;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen unsigned int cur_append_eoh:1;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen unsigned int first:1;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen unsigned int line_finished:1;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen unsigned int partial_fetch:1;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen unsigned int failed:1;
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainen};
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenvoid imap_fetch_handlers_register(const struct imap_fetch_handler *handlers,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen size_t count);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenvoid imap_fetch_add_handler(struct imap_fetch_context *ctx, int buffered,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen imap_fetch_handler_t *handler, void *context);
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenstruct imap_fetch_context *imap_fetch_init(struct client_command_context *cmd);
90c23747727c85f80e4e8eed7968f0edbeac7ac5Timo Sirainenint imap_fetch_deinit(struct imap_fetch_context *ctx);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenint imap_fetch_init_handler(struct imap_fetch_context *ctx, const char *name,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen struct imap_arg **args);
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainen
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainenvoid imap_fetch_begin(struct imap_fetch_context *ctx,
b397665e90fa0fc7c6a9156fdd6cf28b571e8e39Timo Sirainen struct mail_search_arg *search_arg);
b397665e90fa0fc7c6a9156fdd6cf28b571e8e39Timo Sirainenint imap_fetch(struct imap_fetch_context *ctx);
b397665e90fa0fc7c6a9156fdd6cf28b571e8e39Timo Sirainen
b397665e90fa0fc7c6a9156fdd6cf28b571e8e39Timo Sirainenint fetch_body_section_init(struct imap_fetch_context *ctx, const char *name,
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainen struct imap_arg **args);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainenint fetch_rfc822_init(struct imap_fetch_context *ctx, const char *name,
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen struct imap_arg **args);
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen#endif
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainen