1 |
#include "config.h" |
2 |
#include "imapfilter.h" |
3 |
|
4 |
|
5 |
extern conn_t connpri, connaux; |
6 |
extern unsigned int options; |
7 |
|
8 |
|
9 |
/* |
10 |
* Test/ping server. |
11 |
*/ |
12 |
int |
13 |
test(conn_t * conn) |
14 |
{ |
15 |
return server_response(conn, imap_noop(conn)); |
16 |
} |
17 |
|
18 |
|
19 |
/* |
20 |
* Check server's capabilities. |
21 |
*/ |
22 |
int |
23 |
check_capabilities(conn_t * conn) |
24 |
{ |
25 |
conn->caps = CAPABILITY_NONE; |
26 |
|
27 |
return capability_response(conn, imap_capability(conn)); |
28 |
} |
29 |
|
30 |
|
31 |
/* |
32 |
* Get namespace of mail server's mailboxes. |
33 |
*/ |
34 |
int |
35 |
check_namespace(conn_t * conn) |
36 |
{ |
37 |
conn->nsp.prefix[0] = conn->nsp.delim = '\0'; |
38 |
|
39 |
if (!(options & OPTION_NAMESPACE) || |
40 |
!(conn->caps & CAPABILITY_NAMESPACE)) |
41 |
return 0; |
42 |
else |
43 |
return namespace_response(conn, imap_namespace(conn)); |
44 |
} |
45 |
|
46 |
|
47 |
#ifdef SSL_TLS |
48 |
/* |
49 |
* Begin TLS negotiation (STARTTLS). |
50 |
*/ |
51 |
int |
52 |
negotiate_tls(conn_t * conn) |
53 |
{ |
54 |
int r; |
55 |
|
56 |
r = server_response(conn, imap_starttls(conn)); |
57 |
init_secure_connection(conn, SSL_TLS_V1); |
58 |
|
59 |
return r; |
60 |
} |
61 |
#endif |
62 |
|
63 |
|
64 |
/* |
65 |
* Login to server. |
66 |
*/ |
67 |
int |
68 |
login(conn_t * conn, char *user, char *pass) |
69 |
{ |
70 |
return server_response(conn, imap_login(conn, user, pass)); |
71 |
} |
72 |
|
73 |
|
74 |
|
75 |
/* |
76 |
* Check if a mailbox exists. |
77 |
*/ |
78 |
int |
79 |
check_mailbox(conn_t * conn, char *mbox) |
80 |
{ |
81 |
return server_response(conn, imap_status(conn, mbox, "MESSAGES")); |
82 |
} |
83 |
|
84 |
|
85 |
/* |
86 |
* Open mailbox in read-write mode. |
87 |
*/ |
88 |
int |
89 |
select_mailbox(conn_t * conn, char *mbox) |
90 |
{ |
91 |
int r; |
92 |
|
93 |
if (mailbox_status(conn, mbox) == -2) |
94 |
return -2; /* No messages exist. No filters need to be |
95 |
* applied. */ |
96 |
|
97 |
r = select_response(conn, imap_select(conn, |
98 |
apply_namespace(mbox, conn->nsp.prefix, conn->nsp.delim))); |
99 |
|
100 |
log_info(LOG_MAILBOX, mbox); |
101 |
|
102 |
return r; |
103 |
} |
104 |
|
105 |
|
106 |
/* |
107 |
* Get mailbox's status. |
108 |
*/ |
109 |
int |
110 |
mailbox_status(conn_t * conn, char *mbox) |
111 |
{ |
112 |
return status_response(conn, imap_status(conn, |
113 |
apply_namespace(mbox, conn->nsp.prefix, conn->nsp.delim), |
114 |
"MESSAGES RECENT UNSEEN"), mbox); |
115 |
} |
116 |
|
117 |
|
118 |
/* |
119 |
* Close examined/selected mailbox. |
120 |
*/ |
121 |
int |
122 |
close_mailbox(conn_t * conn) |
123 |
{ |
124 |
return server_response(conn, imap_close(conn)); |
125 |
} |
126 |
|
127 |
|
128 |
/* |
129 |
* Logout from server. |
130 |
*/ |
131 |
int |
132 |
logout(conn_t * conn) |
133 |
{ |
134 |
return logout_response(conn, imap_logout(conn)); |
135 |
} |