6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch#ifndef IMAP_URL_H
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch#define IMAP_URL_H
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
66134fbce11778241ca9f8458ee2a0488a05bde0Stephan Bosch#include "uri-util.h"
66134fbce11778241ca9f8458ee2a0488a05bde0Stephan Bosch
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Boschstruct imap_url {
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* server */
66134fbce11778241ca9f8458ee2a0488a05bde0Stephan Bosch struct uri_host host;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch in_port_t port;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* user */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const char *userid;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const char *auth_type;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* mailbox */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const char *mailbox;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch uint32_t uidvalidity; /* 0 if not set */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* message part */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch uint32_t uid;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const char *section;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch uoff_t partial_offset;
4d955db590c3d76a631dfc5d37bcdf578a43e55aStephan Bosch uoff_t partial_size; /* 0 if not set */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* message list (uid == 0) */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const char *search_program;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* urlauth */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const char *uauth_rumpurl;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const char *uauth_access_application;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const char *uauth_access_user;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const char *uauth_mechanism;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const unsigned char *uauth_token;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch size_t uauth_token_size;
4d955db590c3d76a631dfc5d37bcdf578a43e55aStephan Bosch time_t uauth_expire; /* (time_t)-1 if not set */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool have_partial:1;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch};
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch/*
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch * IMAP URL parsing
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Boschenum imap_url_parse_flags {
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* Scheme part 'imap:' is already parsed externally. This implies that
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch this is an absolute IMAP URL. */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch IMAP_URL_PARSE_SCHEME_EXTERNAL = 0x01,
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* Require relative URL (omitting _both_ scheme and authority), e.g.
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /MAILBOX/;UID=uid or even ;UID=uid. This flag means that an absolute
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch URL makes no sense in this context. Relative URLs are allowed once a
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch base URL is provided to the parser. */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch IMAP_URL_PARSE_REQUIRE_RELATIVE = 0x02,
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* Allow URLAUTH URL */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch IMAP_URL_PARSE_ALLOW_URLAUTH = 0x04
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch};
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
639bb36b12b9f9bb54c8bb1be50eac623622f8a0Timo Sirainen/* Parses full IMAP URL. The returned URL is allocated from data stack. */
dc78180b54a05d5736d0e0e444cba0332265eb62Phil Carmodyint imap_url_parse(const char *url, const struct imap_url *base,
639bb36b12b9f9bb54c8bb1be50eac623622f8a0Timo Sirainen enum imap_url_parse_flags flags,
639bb36b12b9f9bb54c8bb1be50eac623622f8a0Timo Sirainen struct imap_url **url_r, const char **error_r);
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch/*
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch * IMAP URL construction
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
4d955db590c3d76a631dfc5d37bcdf578a43e55aStephan Boschconst char *imap_url_create(const struct imap_url *url);
4d955db590c3d76a631dfc5d37bcdf578a43e55aStephan Bosch
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Boschconst char *imap_url_add_urlauth(const char *rumpurl, const char *mechanism,
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const unsigned char *token, size_t token_len);
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch#endif