From: sergey.kitov Date: Thu, 8 Jun 2023 10:56:52 +0000 (+0300) Subject: imap: Introduce cmd_notify_parse_event_list() function. X-Git-Tag: 2.4.0~2709 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=336f20cf6ef922a952c3609687b4aa3c71f4a6a3;p=thirdparty%2Fdovecot%2Fcore.git imap: Introduce cmd_notify_parse_event_list() function. --- diff --git a/src/imap/cmd-notify.c b/src/imap/cmd-notify.c index 3e680bf4d0..2822459155 100644 --- a/src/imap/cmd-notify.c +++ b/src/imap/cmd-notify.c @@ -48,63 +48,75 @@ cmd_notify_parse_fetch(struct imap_notify_context *ctx, &ctx->fetch_ctx, &ctx->error); } -static int -cmd_notify_set_selected(struct imap_notify_context *ctx, - const struct imap_arg *events) +static bool +cmd_notify_parse_event_list(struct imap_notify_context *ctx, + const struct imap_arg *list, + enum imap_notify_event *mask_r) { #define EV_NEW_OR_EXPUNGE \ (IMAP_NOTIFY_EVENT_MESSAGE_NEW | IMAP_NOTIFY_EVENT_MESSAGE_EXPUNGE) - const struct imap_arg *list, *fetch_att_list; - const char *str; + const struct imap_arg *fetch_att_list; enum imap_notify_event event; - if (imap_arg_get_atom(events, &str) && - strcasecmp(str, "NONE") == 0) { - /* no events for selected mailbox. this is also the default - when NOTIFY command doesn't specify it explicitly */ - if (events[1].type != IMAP_ARG_EOL) - return -1; /* no extra parameters */ - return 0; - } - - if (!imap_arg_get_list(events, &list)) - return -1; - if (events[1].type != IMAP_ARG_EOL) - return -1; /* no extra parameters */ - if (list->type == IMAP_ARG_EOL) - return -1; /* at least one event */ - + *mask_r = 0; for (; list->type != IMAP_ARG_EOL; list++) { if (cmd_notify_parse_event(list, &event) < 0) - return -1; - ctx->selected_events |= event; + return FALSE; + *mask_r |= event; ctx->global_used_events |= event; if (event == IMAP_NOTIFY_EVENT_MESSAGE_NEW && imap_arg_get_list(&list[1], &fetch_att_list)) { /* MessageNew: list of fetch-att */ if (cmd_notify_parse_fetch(ctx, fetch_att_list) < 0) - return -1; + return FALSE; list++; } } /* if MessageNew or MessageExpunge is specified, both of them must */ - if ((ctx->selected_events & EV_NEW_OR_EXPUNGE) != 0 && - (ctx->selected_events & EV_NEW_OR_EXPUNGE) != EV_NEW_OR_EXPUNGE) { + if ((*mask_r & EV_NEW_OR_EXPUNGE) != 0 && + (*mask_r & EV_NEW_OR_EXPUNGE) != EV_NEW_OR_EXPUNGE) { ctx->error = "MessageNew and MessageExpunge must be together"; - return -1; + return FALSE; } /* if FlagChange or AnnotationChange is specified, MessageNew and MessageExpunge must also be specified */ - if ((ctx->selected_events & + if ((*mask_r & (IMAP_NOTIFY_EVENT_FLAG_CHANGE | IMAP_NOTIFY_EVENT_ANNOTATION_CHANGE)) != 0 && - (ctx->selected_events & IMAP_NOTIFY_EVENT_MESSAGE_EXPUNGE) == 0) { + (*mask_r & IMAP_NOTIFY_EVENT_MESSAGE_EXPUNGE) == 0) { ctx->error = "FlagChange requires MessageNew and MessageExpunge"; - return -1; + return FALSE; } + return TRUE; +} + +static int +cmd_notify_set_selected(struct imap_notify_context *ctx, + const struct imap_arg *events) +{ + const struct imap_arg *list; + const char *str; + + if (imap_arg_get_atom(events, &str) && + strcasecmp(str, "NONE") == 0) { + /* no events for selected mailbox. this is also the default + when NOTIFY command doesn't specify it explicitly */ + if (events[1].type != IMAP_ARG_EOL) + return -1; /* no extra parameters */ + return 0; + } + + if (!imap_arg_get_list(events, &list)) + return -1; + if (events[1].type != IMAP_ARG_EOL) + return -1; /* no extra parameters */ + if (list->type == IMAP_ARG_EOL) + return -1; /* at least one event */ + if (!cmd_notify_parse_event_list(ctx, list, &ctx->selected_events)) + return -1; return 0; }