{"record":{"id":"bb34c8cf0135c704","repo":"jstedfast/MailKit","slug":"the-messagenew-event-cannot-have-any-parameters-for-mailbox","errorCode":null,"errorMessage":"The MessageNew event cannot have any parameters for mailbox filters other than SELECTED and SELECTED-DELAYED.","messagePattern":"The MessageNew event cannot have any parameters for mailbox filters other than SELECTED and SELECTED-DELAYED\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapEventGroup.cs","lineNumber":725,"sourceCode":"\t\t\t/// </summary>\n\t\t\t/// <remarks>\n\t\t\t/// Formats the IMAP NOTIFY command for this particular IMAP mailbox filter.\n\t\t\t/// </remarks>\n\t\t\t/// <param name=\"engine\">The IMAP engine.</param>\n\t\t\t/// <param name=\"command\">The IMAP command builder.</param>\n\t\t\t/// <param name=\"args\">The IMAP command argument builder.</param>\n\t\t\t/// <param name=\"isSelectedFilter\"><see langword=\"true\" /> if the event is being registered for a\n\t\t\t/// <see cref=\"ImapMailboxFilter.Selected\"/> or <see cref=\"ImapMailboxFilter.SelectedDelayed\"/>\n\t\t\t/// mailbox filter.</param>\n\t\t\tinternal override void Format (ImapEngine engine, StringBuilder command, IList<object> args, bool isSelectedFilter)\n\t\t\t{\n\t\t\t\tcommand.Append (Name);\n\n\t\t\t\tif (ImapFolder.IsEmptyFetchRequest (request))\n\t\t\t\t\treturn;\n\n\t\t\t\tif (!isSelectedFilter)\n\t\t\t\t\tthrow new InvalidOperationException (\"The MessageNew event cannot have any parameters for mailbox filters other than SELECTED and SELECTED-DELAYED.\");\n\n\t\t\t\tcommand.Append (' ');\n\t\t\t\tcommand.Append (ImapFolder.FormatSummaryItems (engine, request, out _, isNotify: true));\n\t\t\t}\n\t\t}\n\t}\n}\n","sourceCodeStart":707,"sourceCodeEnd":733,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapEventGroup.cs#L707-L733","documentation":"The MessageNew event can carry a fetch request (summary items) only when the event group's mailbox filter is SELECTED or SELECTED-DELAYED; for other filters (Personal, Subscribed, mailboxes list) RFC 5465 forbids parameters on MessageNew. Format() throws InvalidOperationException if a request is attached and isSelectedFilter is false.","triggerScenarios":"Creating an ImapEventGroup with MailboxFilter = Personal (or Subscribed/Mailboxes) and setting the MessageNew event's request items (e.g. via new ImapEvent.MessageNew(summaryItems)), then issuing NOTIFY.","commonSituations":"Copy-pasting a SELECTED-group MessageNew configuration into a Personal group; wanting preview/summary data for new messages across all personal folders, which NOTIFY does not allow.","solutions":["Remove the parameters so MessageNew is parameterless for non-SELECTED filters (new ImapEvent.MessageNew() or ImapEvent.MessageNew as appropriate)","Use MailboxFilter.Selected/SelectedDelayed if you genuinely need MessageNew with summary items and only care about the currently selected mailbox","Fetch full summaries yourself in the notification handler after receiving the event"],"exampleFix":"// before\nvar group = new ImapEventGroup(ImapMailboxFilter.Personal) {\n    Events = { new ImapEvent.MessageNew(MessageSummaryItems.UniqueId | MessageSummaryItems.Envelope) }\n};\n\n// after\nvar group = new ImapEventGroup(ImapMailboxFilter.Personal) {\n    Events = { ImapEvent.MessageNew, ImapEvent.MessageExpunge }\n};","handlingStrategy":"validation","validationCode":"bool MessageNewParamsAllowed(ImapEventGroup g) =>\n    g.MailboxFilter is ImapMailboxFilter.Selected or ImapMailboxFilter.SelectedDelayed\n    || g.Events.All(e => e is not ImapEvent.MessageNew mn || ImapFolder.IsEmptyFetchRequest(mn.Request));","typeGuard":"null","tryCatchPattern":"try {\n    client.Notify(groups);\n} catch (InvalidOperationException ex) when (ex.Message.Contains(\"MessageNew event cannot have any parameters\")) {\n    // rebuild with parameterless MessageNew for non-selected filters\n}","preventionTips":["Only attach summary-item requests to MessageNew in SELECTED/SELECTED-DELAYED groups","Check the filter type before configuring MessageNew parameters","Handle new-message data needs by fetching in the event handler instead"],"tags":["imap","notify","rfc5465","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}