18 |
|
|
19 |
|
|
20 |
extern account_t *accounts; |
extern account_t *accounts; |
21 |
extern int options; |
extern unsigned int options; |
22 |
|
|
23 |
int sock; |
int sock; |
24 |
|
|
75 |
|
|
76 |
|
|
77 |
/* |
/* |
78 |
* Reads (if any) data the server sent. |
* Reads data the server sent. |
79 |
*/ |
*/ |
80 |
int get_response(char *buf) |
int recv_response(char *buf) |
81 |
{ |
{ |
82 |
int flags; |
int flags; |
83 |
fd_set rfds; |
fd_set rfds; |
115 |
|
|
116 |
|
|
117 |
/* |
/* |
118 |
* Clears stream from any data server sent without processing them. |
* Clears stream from any data server sent. |
119 |
*/ |
*/ |
120 |
int clear_stream(void) |
int clear_stream(void) |
121 |
{ |
{ |
|
int r; |
|
|
unsigned int orig; |
|
122 |
char buf[RESPONSE_BUF]; |
char buf[RESPONSE_BUF]; |
123 |
|
|
124 |
orig = options; /* Needed so response won't be analyzed. */ |
return recv_response(buf); |
|
options &= OPT_DETAILS_CLEAR; |
|
|
|
|
|
r = get_response(buf); |
|
|
|
|
|
options = orig; |
|
|
|
|
|
return r; |
|
125 |
} |
} |
126 |
|
|
127 |
|
|
128 |
/* |
/* |
129 |
* Processes the data that server sent due to IMAP SELSECT client request. |
* Processes the data that server sent due to IMAP STATUS client request. |
130 |
*/ |
*/ |
131 |
int status_response(void) |
int status_response(void) |
132 |
{ |
{ |
133 |
int r, s; |
int r, s; |
134 |
char buf[RESPONSE_BUF]; |
char buf[RESPONSE_BUF]; |
135 |
char exists[STATUS_BUF], recent[STATUS_BUF], unseen[STATUS_BUF]; |
char exist[STATUS_BUF], recent[STATUS_BUF], unseen[STATUS_BUF]; |
136 |
regex_t creg; |
regex_t creg; |
137 |
regmatch_t match[4]; |
regmatch_t match[4]; |
138 |
const char *reg = |
const char *reg = |
139 |
"\\* STATUS INBOX \\(MESSAGES ([[:digit:]]+) RECENT ([[:digit:]]+) UNSEEN ([[:digit:]]+)\\)"; |
"\\* STATUS INBOX \\(MESSAGES ([[:digit:]]+) RECENT ([[:digit:]]+) UNSEEN ([[:digit:]]+)\\)"; |
140 |
|
|
141 |
exists[0] = recent[0] = unseen[0] = 0; |
exist[0] = recent[0] = unseen[0] = 0; |
142 |
|
|
143 |
r = get_response(buf); |
r = recv_response(buf); |
144 |
|
|
145 |
regcomp(&creg, reg, REG_EXTENDED); |
regcomp(&creg, reg, REG_EXTENDED); |
146 |
|
|
147 |
if (!regexec(&creg, buf, 4, match, 0)) { |
if (!regexec(&creg, buf, 4, match, 0)) { |
148 |
s = min(match[1].rm_eo - match[1].rm_so, STATUS_BUF - 1); |
s = min(match[1].rm_eo - match[1].rm_so, STATUS_BUF - 1); |
149 |
strncpy(exists, buf + match[1].rm_so, s); |
strncpy(exist, buf + match[1].rm_so, s); |
150 |
exists[s] = 0; |
exist[s] = 0; |
151 |
|
|
152 |
s = min(match[2].rm_eo - match[2].rm_so, STATUS_BUF - 1); |
s = min(match[2].rm_eo - match[2].rm_so, STATUS_BUF - 1); |
153 |
strncpy(recent, buf + match[2].rm_so, s); |
strncpy(recent, buf + match[2].rm_so, s); |
157 |
strncpy(unseen, buf + match[3].rm_so, s); |
strncpy(unseen, buf + match[3].rm_so, s); |
158 |
unseen[s] = 0; |
unseen[s] = 0; |
159 |
|
|
160 |
info("%s messages exist, %s recent, %s unseen.\n", exists, recent, |
info("%s messages exist, %s recent, %s unseen.\n", exist, recent, |
161 |
unseen); |
unseen); |
162 |
} |
} |
163 |
|
|
178 |
|
|
179 |
len = strlen(res); |
len = strlen(res); |
180 |
|
|
181 |
r = get_response(buf); |
r = recv_response(buf); |
182 |
|
|
183 |
regcomp(&creg, reg, REG_EXTENDED); |
regcomp(&creg, reg, REG_EXTENDED); |
184 |
|
|
206 |
"Subject: [[:print:]]*" |
"Subject: [[:print:]]*" |
207 |
}; |
}; |
208 |
|
|
209 |
r = get_response(buf); |
r = recv_response(buf); |
210 |
|
|
211 |
for (i = 0; i < 3; i++) { |
for (i = 0; i < 3; i++) { |
212 |
regcomp(&creg[i], reg[i], REG_EXTENDED); |
regcomp(&creg[i], reg[i], REG_EXTENDED); |
234 |
int s; |
int s; |
235 |
regex_t creg; |
regex_t creg; |
236 |
regmatch_t match[2]; |
regmatch_t match[2]; |
237 |
const char *reg = "[[:xdigit:]]{4,4} ([[:print:]]*)"; |
const char *reg = "[[:xdigit:]]{4,4} ((OK|NO|BAD) [[:print:]]*)"; |
238 |
char res[RESULTS_BUF]; |
char res[RESULTS_BUF]; |
239 |
|
|
240 |
regcomp(&creg, reg, REG_EXTENDED); |
regcomp(&creg, reg, REG_EXTENDED); |