f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#ifndef IMAP_URLAUTH_FETCH_H
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define IMAP_URLAUTH_FETCH_H
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
b22a040754a7011cfbb4f5cca02fb525a496e73fStephan Boschstruct imap_url;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschstruct imap_urlauth_context;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschstruct imap_urlauth_fetch;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschenum imap_urlauth_fetch_flags {
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch /* Indicates that this is an extended request */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch IMAP_URLAUTH_FETCH_FLAG_EXTENDED = 0x01,
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch /* Fetch body part unmodified */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch IMAP_URLAUTH_FETCH_FLAG_BODY = 0x02,
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch /* Fetch body part as binary, i.e. without content encoding */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch IMAP_URLAUTH_FETCH_FLAG_BINARY = 0x04,
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch /* Fetch IMAP bodypartstructure */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch IMAP_URLAUTH_FETCH_FLAG_BODYPARTSTRUCTURE = 0x08,
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch};
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschstruct imap_urlauth_fetch_reply {
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch const char *url;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch enum imap_urlauth_fetch_flags flags;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch struct istream *input;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch uoff_t size;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch const char *bodypartstruct;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch const char *error;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool succeeded:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool binary_has_nuls:1;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch};
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch/* Callback to handle fetch reply. Returns 1 if handled completely and ready
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch for next reply, 0 if not all data was processed, and -1 for error. If a
96fbbe9c6fd04bca25770020bf94eec50888bc9bStephan Bosch callback returns 0, imap_urlauth_fetch_continue() must be called once
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch new replies may be processed. If this is the last request to yield a reply,
659f431cb56f26ec07e308db4d6c563c0eaa5300Stephan Bosch argument last is TRUE. */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschtypedef int
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschimap_urlauth_fetch_callback_t(struct imap_urlauth_fetch_reply *reply,
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch bool last, void *context);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschstruct imap_urlauth_fetch *
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschimap_urlauth_fetch_init(struct imap_urlauth_context *uctx,
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch imap_urlauth_fetch_callback_t *callback, void *context);
659f431cb56f26ec07e308db4d6c563c0eaa5300Stephan Boschvoid imap_urlauth_fetch_deinit(struct imap_urlauth_fetch **ufetch);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschint imap_urlauth_fetch_url(struct imap_urlauth_fetch *ufetch, const char *url,
96fbbe9c6fd04bca25770020bf94eec50888bc9bStephan Bosch enum imap_urlauth_fetch_flags url_flags);
b22a040754a7011cfbb4f5cca02fb525a496e73fStephan Boschint imap_urlauth_fetch_url_parsed(struct imap_urlauth_fetch *ufetch,
b22a040754a7011cfbb4f5cca02fb525a496e73fStephan Bosch const char *url, struct imap_url *imap_url,
b22a040754a7011cfbb4f5cca02fb525a496e73fStephan Bosch enum imap_urlauth_fetch_flags url_flags);
620b60321d04006b32a116824d49b88b61be7131Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschbool imap_urlauth_fetch_continue(struct imap_urlauth_fetch *ufetch);
620b60321d04006b32a116824d49b88b61be7131Stephan Boschbool imap_urlauth_fetch_is_pending(struct imap_urlauth_fetch *ufetch);
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#endif