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