1 #ifndef __IMAPLL_H__
2 #define __IMAPLL_H__
3 
4 #ifdef USE_OPENSSL
5 #include <openssl/ssl.h>
6 #endif
7 #include <poll.h>
8 
9 enum imap_ll_tltype {
10 	TLTYPE_UNTAGGED = 1,
11 	TLTYPE_TAGGED = 2,
12 	TLTYPE_LIST = 3,
13 	TLTYPE_SQLIST = 4,
14 	TLTYPE_ATOM = 5,
15 	TLTYPE_STRING = 6,
16 	TLTYPE_CONTINUATION = 7,
17 	/* the following only for imap_ll_build */
18 	TLTYPE_END = 100,
19 	TLTYPE_POP = 101,
20 	TLTYPE_SUB = 102
21 };
22 
23 struct imap_ll_tokenlist {
24 	enum imap_ll_tltype type;
25 	char *leaf;
26 	size_t leaflen;
27 	struct imap_ll_tokenlist *parent;
28 	struct imap_ll_tokenlist *next;
29 	/* children */
30 	struct imap_ll_tokenlist *first;
31 	struct imap_ll_tokenlist *last;
32 };
33 
34 struct imap_ll *imap_ll_connect(const char *host, const char *port);
35 struct imap_ll *imap_ll_pipe_connect(const char *command);
36 void imap_ll_timeout(struct imap_ll *, int seconds);
37 struct imap_ll_tokenlist *imap_ll_waitline(struct imap_ll *);
38 void imap_ll_freeline(struct imap_ll_tokenlist *);
39 struct imap_ll_tokenlist *imap_ll_build(enum imap_ll_tltype maintype, ...);
40 void imap_ll_append(struct imap_ll_tokenlist *, struct imap_ll_tokenlist *);
41 void imap_ll_pprint(struct imap_ll_tokenlist *, int indent, FILE *);
42 struct imap_ll_tokenlist *imap_ll_command(struct imap_ll *, struct imap_ll_tokenlist *, int timeout);
43 const char *imap_ll_status(struct imap_ll_tokenlist *);
44 int imap_ll_is_trycreate(struct imap_ll_tokenlist *);
45 
46 #ifdef USE_OPENSSL
47 enum imap_ll_starttls_result {
48 	IMAP_LL_STARTTLS_FAILED_PROCEED,	/* STARTTLS failed but session still OK */
49 	IMAP_LL_STARTTLS_FAILED,	/* session must be closed */
50 	IMAP_LL_STARTTLS_FAILED_CERT,	/* certificate problem (session must be closed) */
51 	IMAP_LL_STARTTLS_SUCCESS	/* certificate problem (session must be closed) */
52 };
53 enum imap_ll_starttls_result imap_ll_starttls(struct imap_ll *, SSL_CTX *, const char *servername);
54 #endif
55 
56 void imap_ll_logout(struct imap_ll *);
57 
58 enum imap_login_result {
59 	imap_login_ok = 0,
60 	imap_login_denied = 1,
61 	imap_login_error = 2
62 };
63 
64 enum imap_login_result
65 imap_login(
66 	struct imap_ll *,
67 	const char *username, size_t username_len,
68 	const char *password, size_t password_len
69 #ifdef USE_OPENSSL
70 	, SSL_CTX *, const char *servername
71 #endif
72 );
73 
74 /* returns the uidvalidity of the opened folder if successful */
75 const char *imap_select(
76 	struct imap_ll *,
77 	const char *foldername, size_t foldername_len,
78 	int need_write,
79 	long *exists_p	/* optional, return number of messages which exist */
80 );
81 
82 #endif
83