17 |
*/ |
*/ |
18 |
int test(void) |
int test(void) |
19 |
{ |
{ |
20 |
imap_noop(); |
return server_response(imap_noop()); |
|
return server_response("NOOP"); |
|
21 |
} |
} |
22 |
#endif |
#endif |
23 |
|
|
24 |
|
|
25 |
/* |
/* |
26 |
* Login to server. |
* Check server's capabilities. |
27 |
*/ |
*/ |
28 |
int login(char *user, char *pass) |
int check_capabilities(void) |
29 |
{ |
{ |
30 |
imap_login(user, pass); |
return capability_response(imap_capability()); |
|
|
|
|
log_info(LOG_USERNAME, user); |
|
|
|
|
|
return server_response("LOGIN"); |
|
31 |
} |
} |
32 |
|
|
33 |
|
|
34 |
/* |
/* |
35 |
* Open mailbox in read-only mode. |
* Login to server. |
36 |
*/ |
*/ |
37 |
int examine_mailbox(char *mbox) |
int login(char *user, char *pass) |
38 |
{ |
{ |
39 |
int r; |
log_info(LOG_USERNAME, user); |
|
|
|
|
imap_examine(mbox); |
|
|
r = server_response("EXAMINE"); |
|
|
|
|
|
if (!r) |
|
|
mailbox_status(mbox); |
|
40 |
|
|
41 |
return r; |
return server_response(imap_login(user, pass)); |
42 |
} |
} |
43 |
|
|
|
|
|
44 |
/* |
/* |
45 |
* Open mailbox in read-write mode. |
* Open mailbox in read-write mode. |
46 |
*/ |
*/ |
48 |
{ |
{ |
49 |
int r; |
int r; |
50 |
|
|
51 |
imap_select(mbox); |
if (mailbox_status(mbox) == -2) |
52 |
r = server_response("SELECT"); |
return -2; /* No messages exist. No filters need to |
|
|
|
|
if (!r) |
|
|
if (mailbox_status(mbox) == -2) |
|
|
return -2; /* No messages exist. No filters need to |
|
53 |
be applied. */ |
be applied. */ |
54 |
|
|
55 |
|
r = select_response(imap_select(mbox)); |
56 |
|
|
57 |
log_info(LOG_MAILBOX, mbox); |
log_info(LOG_MAILBOX, mbox); |
58 |
|
|
59 |
return r; |
return r; |
67 |
{ |
{ |
68 |
int r = 0; |
int r = 0; |
69 |
|
|
70 |
if (!(options & OPTION_DETAILS_QUITE)) { |
if (!(options & OPTION_DETAILS_QUIET)) { |
71 |
imap_status(mbox, "MESSAGES RECENT UNSEEN"); |
r = status_response(imap_status(mbox, "MESSAGES RECENT UNSEEN")); |
|
r = status_response(); |
|
72 |
info("in mailbox %s.\n", mbox); |
info("in mailbox %s.\n", mbox); |
73 |
} |
} |
74 |
return r; |
return r; |
79 |
*/ |
*/ |
80 |
int close_mailbox(void) |
int close_mailbox(void) |
81 |
{ |
{ |
82 |
imap_close(); |
return server_response(imap_close()); |
|
return server_response("CLOSE"); |
|
83 |
} |
} |
84 |
|
|
85 |
|
|
88 |
*/ |
*/ |
89 |
int logout(void) |
int logout(void) |
90 |
{ |
{ |
91 |
imap_logout(); |
return server_response(imap_logout()); |
|
return server_response("LOGOUT"); |
|
92 |
} |
} |
93 |
|
|
94 |
|
|
95 |
/* |
/* |
96 |
* Match and apply filters assigned to a mailbox. |
* Match and apply filters assigned to a mailbox. |
97 |
*/ |
*/ |
98 |
int apply_filters(filter_t ** filters, char *mbox) |
int apply_filters(filter_t ** filters) |
99 |
{ |
{ |
100 |
int i; |
int i; |
101 |
char mesgs[SEARCH_MESSAGES_BUF]; |
char mesgs[SEARCH_MESSAGES_BUF]; |
110 |
log_info(LOG_FILTER, filters[i]->key); |
log_info(LOG_FILTER, filters[i]->key); |
111 |
|
|
112 |
apply_action(mesgs, &(filters[i]->action.type), |
apply_action(mesgs, &(filters[i]->action.type), |
113 |
filters[i]->action.destmbox, filters[i]->action.args); |
filters[i]->action.destmbox, filters[i]->action.args); |
114 |
} |
} |
115 |
|
|
116 |
return 0; |
return 0; |
132 |
search = generate_filter_and(filter->masks, filter->masknum, |
search = generate_filter_and(filter->masks, filter->masknum, |
133 |
filter->masklen); |
filter->masklen); |
134 |
|
|
135 |
imap_search(search); |
search_response(imap_search(search), mesgs); |
|
search_response(mesgs); |
|
136 |
|
|
137 |
free(search); |
free(search); |
138 |
|
|
191 |
* masks are AND-ed. |
* masks are AND-ed. |
192 |
*/ |
*/ |
193 |
char *generate_filter_and(mask_t * mask, unsigned int masknum, |
char *generate_filter_and(mask_t * mask, unsigned int masknum, |
194 |
unsigned int masklen) |
unsigned int masklen) |
195 |
{ |
{ |
196 |
const unsigned int searchbuf = masklen + masknum * 6 + 8; |
const unsigned int searchbuf = masklen + masknum * 6 + 8; |
197 |
int len = 0; |
int len = 0; |
203 |
search[0] = 0; |
search[0] = 0; |
204 |
|
|
205 |
tmp = mask; |
tmp = mask; |
206 |
while ((tmp = tmp->next)) { |
if (!tmp) { |
207 |
|
strncat(search, "ALL ", searchbuf - len - 1); |
208 |
|
len += 4; |
209 |
|
} else |
210 |
|
while ((tmp = tmp->next)) { |
211 |
if (tmp->type != MASK_TYPE_OR) { |
if (tmp->type != MASK_TYPE_OR) { |
212 |
strncat(search, "ALL ", searchbuf - len - 1); |
strncat(search, "ALL ", searchbuf - len - 1); |
213 |
len += 4; |
len += 4; |
250 |
search[++len] = 0; |
search[++len] = 0; |
251 |
} |
} |
252 |
} |
} |
253 |
|
|
254 |
search[len - 1] = 0; |
search[len - 1] = 0; |
255 |
|
|
256 |
return search; |
return search; |
262 |
* masks are OR-ed |
* masks are OR-ed |
263 |
*/ |
*/ |
264 |
char *generate_filter_or(mask_t * mask, unsigned int masknum, |
char *generate_filter_or(mask_t * mask, unsigned int masknum, |
265 |
unsigned int masklen) |
unsigned int masklen) |
266 |
{ |
{ |
267 |
const unsigned int searchbuf = masklen + masknum * 6 + 8; |
const unsigned int searchbuf = masklen + masknum * 6 + 8; |
268 |
int len = 0; |
int len = 0; |
315 |
} |
} |
316 |
|
|
317 |
search[len - 1] = 0; |
search[len - 1] = 0; |
318 |
|
|
319 |
free(mfifo); |
free(mfifo); |
320 |
|
|
321 |
return search; |
return search; |
326 |
* Apply the appropriate action. |
* Apply the appropriate action. |
327 |
*/ |
*/ |
328 |
int apply_action(char *mesgs, unsigned int *type, char *destmbox, |
int apply_action(char *mesgs, unsigned int *type, char *destmbox, |
329 |
char *args) |
char *args) |
330 |
{ |
{ |
331 |
unsigned int cnt; |
unsigned int cnt; |
332 |
|
|
382 |
*occur = ' '; |
*occur = ' '; |
383 |
} |
} |
384 |
while ((tok = strsep(&m, delim))) { |
while ((tok = strsep(&m, delim))) { |
385 |
if (*args) { |
if (*args) |
386 |
imap_fetch(0, tok, acp); |
fetch_response(imap_fetch(tok, acp, 0)); |
387 |
fetch_response(); |
|
388 |
} |
server_response(imap_store(tok, "\\Deleted")); |
|
imap_store(tok, "\\Deleted"); |
|
|
server_response("STORE"); |
|
389 |
} |
} |
390 |
|
|
391 |
free(mcp); |
free(mcp); |
392 |
|
|
393 |
if (*args) |
if (*args) |
394 |
free(acp); |
free(acp); |
395 |
|
|
414 |
*occur = ' '; |
*occur = ' '; |
415 |
} |
} |
416 |
while ((tok = strsep(&m, delim))) { |
while ((tok = strsep(&m, delim))) { |
417 |
if (*args) { |
if (*args) |
418 |
imap_fetch(1, tok, acp); |
fetch_response(imap_fetch(tok, acp, 0)); |
419 |
fetch_response(); |
|
420 |
} |
if (copy_response(imap_copy(tok, destmbox)) == RESPONSE_TRYCREATE) |
421 |
imap_copy(tok, destmbox); |
if (!server_response(imap_create(destmbox))) |
422 |
if (copy_response() == 1) { |
copy_response(imap_copy(tok, destmbox)); |
|
imap_create(destmbox); |
|
|
if (!server_response("CREATE")) { |
|
|
imap_copy(tok, destmbox); |
|
|
copy_response(); |
|
|
} |
|
|
} |
|
423 |
} |
} |
424 |
|
|
425 |
free(mcp); |
free(mcp); |
438 |
{ |
{ |
439 |
action_copy(mesgs, destmbox, args); |
action_copy(mesgs, destmbox, args); |
440 |
action_delete(mesgs, "\0"); |
action_delete(mesgs, "\0"); |
441 |
imap_expunge(); |
server_response(imap_expunge()); |
|
server_response("EXPUNGE"); |
|
442 |
|
|
443 |
return 0; |
return 0; |
444 |
} |
} |
461 |
while ((occur = strchr(acp, ','))) |
while ((occur = strchr(acp, ','))) |
462 |
*occur = ' '; |
*occur = ' '; |
463 |
|
|
464 |
while ((tok = strsep(&m, delim))) { |
while ((tok = strsep(&m, delim))) |
465 |
imap_fetch(1, tok, acp); |
fetch_response(imap_fetch(tok, acp, 1)); |
|
fetch_response(); |
|
|
} |
|
466 |
|
|
467 |
free(mcp); |
free(mcp); |
468 |
free(acp); |
free(acp); |
485 |
|
|
486 |
cp = xstrdup(mesgs); |
cp = xstrdup(mesgs); |
487 |
|
|
488 |
start = (unsigned int) strtoul(cp, &tail, 0); |
start = (unsigned int) strtoul(cp, &tail, 10); |
489 |
cnt++; |
cnt++; |
490 |
end = start; |
end = start; |
491 |
|
|
492 |
do { |
do { |
493 |
if (tail) { |
if (tail) { |
494 |
tmp = (unsigned int) strtoul(tail, &tail, 0); |
tmp = (unsigned int) strtoul(tail, &tail, 10); |
495 |
if (tmp) |
if (tmp) |
496 |
cnt++; |
cnt++; |
497 |
} |
} |