146 |
|
|
147 |
apply_action(mesgs, &(filters[i]->action.type), |
apply_action(mesgs, &(filters[i]->action.type), |
148 |
filters[i]->action.raccount, filters[i]->action.destmbox, |
filters[i]->action.raccount, filters[i]->action.destmbox, |
149 |
filters[i]->action.args); |
&filters[i]->action.msgflags, filters[i]->action.args); |
150 |
|
|
151 |
xfree(mesgs); |
xfree(mesgs); |
152 |
} |
} |
364 |
* Apply the appropriate action. |
* Apply the appropriate action. |
365 |
*/ |
*/ |
366 |
int apply_action(char *mesgs, unsigned int *type, account_t * raccount, |
int apply_action(char *mesgs, unsigned int *type, account_t * raccount, |
367 |
char *destmbox, char *args) |
char *destmbox, unsigned int *msgflags, char *args) |
368 |
{ |
{ |
369 |
unsigned int cnt; |
unsigned int cnt; |
370 |
|
|
403 |
plural(cnt), destmbox, raccount->key); |
plural(cnt), destmbox, raccount->key); |
404 |
action_rmove(mesgs, raccount, destmbox, args); |
action_rmove(mesgs, raccount, destmbox, args); |
405 |
break; |
break; |
406 |
|
case FILTER_ACTION_FLAG_REPLACE: |
407 |
|
case FILTER_ACTION_FLAG_ADD: |
408 |
|
case FILTER_ACTION_FLAG_REMOVE: |
409 |
|
info("%d message%s flagged.\n", cnt, plural(cnt)); |
410 |
|
action_flag(mesgs, type, msgflags, args); |
411 |
|
break; |
412 |
case FILTER_ACTION_LIST: |
case FILTER_ACTION_LIST: |
413 |
info("%d message%s listed.\n", cnt, plural(cnt)); |
info("%d message%s listed.\n", cnt, plural(cnt)); |
414 |
action_list(mesgs, args); |
action_list(mesgs, args); |
427 |
*/ |
*/ |
428 |
int action_delete(char *mesgs, char *args) |
int action_delete(char *mesgs, char *args) |
429 |
{ |
{ |
430 |
char *tok, *mcp, *m, *cm; |
char *tok, *m, *mcp; |
431 |
|
|
432 |
action_list(mesgs, args); |
action_list(mesgs, args); |
433 |
|
|
434 |
cm = convert_messages(mesgs); |
m = mcp = convert_messages(mesgs); |
|
|
|
|
m = mcp = xstrdup(cm); |
|
435 |
|
|
436 |
while ((tok = strsep(&m, " "))) |
while ((tok = strsep(&m, " "))) |
437 |
server_response(&sockpri, imap_store(&sockpri, tok, "\\Deleted")); |
server_response(&sockpri, imap_store(&sockpri, tok, |
438 |
|
STORE_FLAG_ADD, "\\Deleted")); |
439 |
|
|
440 |
if (options & OPTION_EXPUNGE) |
if (options & OPTION_EXPUNGE) |
441 |
server_response(&sockpri, imap_expunge(&sockpri)); |
server_response(&sockpri, imap_expunge(&sockpri)); |
442 |
|
|
|
xfree(cm); |
|
443 |
xfree(mcp); |
xfree(mcp); |
444 |
|
|
445 |
return 0; |
return 0; |
452 |
int action_copy(char *mesgs, char *destmbox, char *args) |
int action_copy(char *mesgs, char *destmbox, char *args) |
453 |
{ |
{ |
454 |
int r = 0; |
int r = 0; |
455 |
char *tok = NULL, *mcp, *m, *cm; |
char *tok = NULL, *mcp, *m; |
456 |
|
|
457 |
action_list(mesgs, args); |
action_list(mesgs, args); |
458 |
|
|
459 |
cm = convert_messages(mesgs); |
m = mcp = convert_messages(mesgs); |
|
|
|
|
m = mcp = xstrdup(cm); |
|
460 |
|
|
461 |
while ((tok = strsep(&m, " "))) { |
while ((tok = strsep(&m, " "))) { |
462 |
if ((r = copy_response(&sockpri, |
if ((r = copy_response(&sockpri, |
468 |
} |
} |
469 |
} |
} |
470 |
|
|
|
xfree(cm); |
|
471 |
xfree(mcp); |
xfree(mcp); |
472 |
|
|
473 |
return r; |
return r; |
590 |
|
|
591 |
|
|
592 |
/* |
/* |
593 |
|
* |
594 |
|
*/ |
595 |
|
int action_flag(char *mesgs, unsigned int *type, unsigned int *msgflags, |
596 |
|
char *args) |
597 |
|
{ |
598 |
|
unsigned int t; |
599 |
|
char s[STORE_FLAGS_BUF]; |
600 |
|
char *tok, *m, *mcp; |
601 |
|
|
602 |
|
*s = 0; |
603 |
|
|
604 |
|
switch (*type) { |
605 |
|
case FILTER_ACTION_FLAG_REPLACE: |
606 |
|
t = STORE_FLAG_REPLACE; |
607 |
|
break; |
608 |
|
case FILTER_ACTION_FLAG_ADD: |
609 |
|
t = STORE_FLAG_ADD; |
610 |
|
break; |
611 |
|
case FILTER_ACTION_FLAG_REMOVE: |
612 |
|
t = STORE_FLAG_REMOVE; |
613 |
|
break; |
614 |
|
} |
615 |
|
|
616 |
|
if ((*msgflags != MESSAGE_FLAG_NONE)) { |
617 |
|
if ((*msgflags & MESSAGE_FLAG_SEEN)) |
618 |
|
strncat(s, "\\Seen ", STORE_FLAGS_BUF - strlen(s) - 1); |
619 |
|
if ((*msgflags & MESSAGE_FLAG_ANSWERED)) |
620 |
|
strncat(s, "\\Answered ", STORE_FLAGS_BUF - strlen(s) - 1); |
621 |
|
if ((*msgflags & MESSAGE_FLAG_FLAGGED)) |
622 |
|
strncat(s, "\\Flagged ", STORE_FLAGS_BUF - strlen(s) - 1); |
623 |
|
if ((*msgflags & MESSAGE_FLAG_DELETED)) |
624 |
|
strncat(s, "\\Deleted ", STORE_FLAGS_BUF - strlen(s) - 1); |
625 |
|
if ((*msgflags & MESSAGE_FLAG_DRAFT)) |
626 |
|
strncat(s, "\\Draft", STORE_FLAGS_BUF - strlen(s) - 1); |
627 |
|
if ((s[strlen(s) - 1] == ' ')) |
628 |
|
s[strlen(s) - 1] = 0; |
629 |
|
} |
630 |
|
action_list(mesgs, args); |
631 |
|
|
632 |
|
m = mcp = convert_messages(mesgs); |
633 |
|
|
634 |
|
while ((tok = strsep(&m, " "))) |
635 |
|
server_response(&sockpri, imap_store(&sockpri, tok, t, s)); |
636 |
|
|
637 |
|
if (options & OPTION_EXPUNGE) |
638 |
|
server_response(&sockpri, imap_expunge(&sockpri)); |
639 |
|
|
640 |
|
xfree(mcp); |
641 |
|
|
642 |
|
return 0; |
643 |
|
} |
644 |
|
|
645 |
|
/* |
646 |
* List user selected headers of messages. |
* List user selected headers of messages. |
647 |
*/ |
*/ |
648 |
int action_list(char *mesgs, char *args) |
int action_list(char *mesgs, char *args) |