]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: Introduce cmd_notify_parse_event_list() function.
authorsergey.kitov <sergey.kitov@open-xchange.com>
Thu, 8 Jun 2023 10:56:52 +0000 (13:56 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 8 Jun 2023 17:33:21 +0000 (17:33 +0000)
src/imap/cmd-notify.c

index 3e680bf4d068a31b9a93175c99a9ac13a2b2d5de..2822459155f046ca8aebd5063458884a7956eb2f 100644 (file)
@@ -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;
 }