• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

duesee / imap-codec / 18635078135

19 Oct 2025 07:30PM UTC coverage: 90.848% (-0.9%) from 91.776%
18635078135

Pull #669

github

web-flow
Merge 9e771a7bb into 6b76cfe16
Pull Request #669: feat: Implement RFC 2342 (NAMESPACE) in imap-codec

15 of 129 new or added lines in 6 files covered. (11.63%)

8 existing lines in 1 file now uncovered.

10324 of 11364 relevant lines covered (90.85%)

930.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.19
/imap-types/src/command.rs
1
//! Client Commands.
2
//!
3
//! See <https://tools.ietf.org/html/rfc3501#section-6>.
4

5
use std::borrow::Cow;
6
#[cfg(feature = "ext_condstore_qresync")]
7
use std::num::NonZeroU32;
8
#[cfg(feature = "ext_condstore_qresync")]
9
use std::num::NonZeroU64;
10

11
#[cfg(feature = "arbitrary")]
12
use arbitrary::Arbitrary;
13
use bounded_static_derive::ToStatic;
14
#[cfg(feature = "serde")]
15
use serde::{Deserialize, Serialize};
16

17
#[cfg(feature = "ext_id")]
18
use crate::core::{IString, NString};
19
#[cfg(feature = "ext_metadata")]
20
use crate::extensions::metadata::{Entry, EntryValue, GetMetadataOption};
21
use crate::{
22
    auth::AuthMechanism,
23
    command::error::{AppendError, CopyError, ListError, LoginError, RenameError},
24
    core::{AString, Charset, Literal, Tag, Vec1},
25
    datetime::DateTime,
26
    extensions::{
27
        binary::LiteralOrLiteral8, compress::CompressionAlgorithm, enable::CapabilityEnable,
28
        quota::QuotaSet, sort::SortCriterion, thread::ThreadingAlgorithm,
29
    },
30
    fetch::MacroOrMessageDataItemNames,
31
    flag::{Flag, StoreResponse, StoreType},
32
    mailbox::{ListMailbox, Mailbox},
33
    search::SearchKey,
34
    secret::Secret,
35
    sequence::SequenceSet,
36
    status::StatusDataItemName,
37
};
38

39
/// Command.
40
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
41
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
42
#[derive(Debug, Clone, PartialEq, Eq, Hash, ToStatic)]
43
pub struct Command<'a> {
44
    /// Tag.
45
    pub tag: Tag<'a>,
46
    /// Body, e.g., CAPABILITY, LOGIN, SELECT, etc.
47
    pub body: CommandBody<'a>,
48
}
49

50
impl<'a> Command<'a> {
51
    /// Create a new command.
52
    pub fn new<T>(tag: T, body: CommandBody<'a>) -> Result<Self, T::Error>
178✔
53
    where
178✔
54
        T: TryInto<Tag<'a>>,
178✔
55
    {
56
        Ok(Self {
57
            tag: tag.try_into()?,
178✔
58
            body,
160✔
59
        })
60
    }
178✔
61

62
    /// Get the command name.
63
    pub fn name(&self) -> &'static str {
×
64
        self.body.name()
×
65
    }
×
66
}
67

68
/// Command body.
69
///
70
/// This enum is used to encode all the different commands.
71
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
72
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
73
#[derive(Debug, Clone, PartialEq, Eq, Hash, ToStatic)]
74
pub enum CommandBody<'a> {
75
    // ----- Any State (see https://tools.ietf.org/html/rfc3501#section-6.1) -----
76
    /// ### 6.1.1.  CAPABILITY Command
77
    ///
78
    /// * Arguments:  none
79
    /// * Responses:  REQUIRED untagged response: CAPABILITY
80
    /// * Result:
81
    ///   * OK - capability completed
82
    ///   * BAD - command unknown or arguments invalid
83
    ///
84
    /// The CAPABILITY command requests a listing of capabilities that the
85
    /// server supports.  The server MUST send a single untagged
86
    /// CAPABILITY response with "IMAP4rev1" as one of the listed
87
    /// capabilities before the (tagged) OK response.
88
    ///
89
    /// A capability name which begins with "AUTH=" indicates that the
90
    /// server supports that particular authentication mechanism.  All
91
    /// such names are, by definition, part of this specification.  For
92
    /// example, the authorization capability for an experimental
93
    /// "blurdybloop" authenticator would be "AUTH=XBLURDYBLOOP" and not
94
    /// "XAUTH=BLURDYBLOOP" or "XAUTH=XBLURDYBLOOP".
95
    ///
96
    /// Other capability names refer to extensions, revisions, or
97
    /// amendments to this specification.  See the documentation of the
98
    /// CAPABILITY response for additional information.  No capabilities,
99
    /// beyond the base IMAP4rev1 set defined in this specification, are
100
    /// enabled without explicit client action to invoke the capability.
101
    ///
102
    /// Client and server implementations MUST implement the STARTTLS,
103
    /// LOGINDISABLED, and AUTH=PLAIN (described in [IMAP-TLS])
104
    /// capabilities.  See the Security Considerations section for
105
    /// important information.
106
    ///
107
    /// See the section entitled "Client Commands -
108
    /// Experimental/Expansion" for information about the form of site or
109
    /// implementation-specific capabilities.
110
    Capability,
111

112
    /// ### 6.1.2.  NOOP Command
113
    ///
114
    /// * Arguments:  none
115
    /// * Responses:  no specific responses for this command (but see below)
116
    /// * Result:
117
    ///   * OK - noop completed
118
    ///   * BAD - command unknown or arguments invalid
119
    ///
120
    /// The NOOP command always succeeds.  It does nothing.
121
    ///
122
    /// Since any command can return a status update as untagged data, the
123
    /// NOOP command can be used as a periodic poll for new messages or
124
    /// message status updates during a period of inactivity (this is the
125
    /// preferred method to do this).  The NOOP command can also be used
126
    /// to reset any inactivity autologout timer on the server.
127
    Noop,
128

129
    /// ### 6.1.3.  LOGOUT Command
130
    ///
131
    /// * Arguments:  none
132
    /// * Responses:  REQUIRED untagged response: BYE
133
    /// * Result:
134
    ///   * OK - logout completed
135
    ///   * BAD - command unknown or arguments invalid
136
    ///
137
    /// The LOGOUT command informs the server that the client is done with
138
    /// the connection.  The server MUST send a BYE untagged response
139
    /// before the (tagged) OK response, and then close the network
140
    /// connection.
141
    Logout,
142

143
    // ----- Not Authenticated State (https://tools.ietf.org/html/rfc3501#section-6.2) -----
144
    /// ### 6.2.1.  STARTTLS Command
145
    ///
146
    /// * Arguments:  none
147
    /// * Responses:  no specific response for this command
148
    /// * Result:
149
    ///   * OK - starttls completed, begin TLS negotiation
150
    ///   * BAD - command unknown or arguments invalid
151
    ///
152
    /// A \[TLS\] negotiation begins immediately after the CRLF at the end
153
    /// of the tagged OK response from the server.  Once a client issues a
154
    /// STARTTLS command, it MUST NOT issue further commands until a
155
    /// server response is seen and the \[TLS\] negotiation is complete.
156
    ///
157
    /// The server remains in the non-authenticated state, even if client
158
    /// credentials are supplied during the \[TLS\] negotiation.  This does
159
    /// not preclude an authentication mechanism such as EXTERNAL (defined
160
    /// in \[SASL\]) from using client identity determined by the \[TLS\]
161
    /// negotiation.
162
    ///
163
    /// Once \[TLS\] has been started, the client MUST discard cached
164
    /// information about server capabilities and SHOULD re-issue the
165
    /// CAPABILITY command.  This is necessary to protect against man-in-
166
    /// the-middle attacks which alter the capabilities list prior to
167
    /// STARTTLS.  The server MAY advertise different capabilities after
168
    /// STARTTLS.
169
    ///
170
    /// <div class="warning">
171
    /// This must only be used when the server advertised support for it sending the STARTTLS capability.
172
    ///
173
    /// Try to avoid STARTTLS using implicit TLS on port 993.
174
    /// </div>
175
    #[cfg(feature = "starttls")]
176
    #[cfg_attr(docsrs, doc(cfg(feature = "starttls")))]
177
    StartTLS,
178

179
    /// ### 6.2.2.  AUTHENTICATE Command
180
    ///
181
    /// * Arguments:  authentication mechanism name
182
    /// * Responses:  continuation data can be requested
183
    /// * Result:
184
    ///   * OK - authenticate completed, now in authenticated state
185
    ///   * NO - authenticate failure: unsupported authentication  mechanism, credentials rejected
186
    ///   * BAD - command unknown or arguments invalid, authentication exchange cancelled
187
    ///
188
    /// The AUTHENTICATE command indicates a \[SASL\] authentication
189
    /// mechanism to the server.  If the server supports the requested
190
    /// authentication mechanism, it performs an authentication protocol
191
    /// exchange to authenticate and identify the client.  It MAY also
192
    /// negotiate an OPTIONAL security layer for subsequent protocol
193
    /// interactions.  If the requested authentication mechanism is not
194
    /// supported, the server SHOULD reject the AUTHENTICATE command by
195
    /// sending a tagged NO response.
196
    ///
197
    /// The AUTHENTICATE command does not support the optional "initial
198
    /// response" feature of \[SASL\].  Section 5.1 of \[SASL\] specifies how
199
    /// to handle an authentication mechanism which uses an initial
200
    /// response.
201
    ///
202
    /// The service name specified by this protocol's profile of \[SASL\] is
203
    /// "imap".
204
    ///
205
    /// The authentication protocol exchange consists of a series of
206
    /// server challenges and client responses that are specific to the
207
    /// authentication mechanism.  A server challenge consists of a
208
    /// command continuation request response with the "+" token followed
209
    /// by a BASE64 encoded string.  The client response consists of a
210
    /// single line consisting of a BASE64 encoded string.  If the client
211
    /// wishes to cancel an authentication exchange, it issues a line
212
    /// consisting of a single "*".  If the server receives such a
213
    /// response, it MUST reject the AUTHENTICATE command by sending a
214
    /// tagged BAD response.
215
    ///
216
    /// If a security layer is negotiated through the \[SASL\]
217
    /// authentication exchange, it takes effect immediately following the
218
    /// CRLF that concludes the authentication exchange for the client,
219
    /// and the CRLF of the tagged OK response for the server.
220
    ///
221
    /// While client and server implementations MUST implement the
222
    /// AUTHENTICATE command itself, it is not required to implement any
223
    /// authentication mechanisms other than the PLAIN mechanism described
224
    /// in [IMAP-TLS].  Also, an authentication mechanism is not required
225
    /// to support any security layers.
226
    ///
227
    ///   Note: a server implementation MUST implement a
228
    ///   configuration in which it does NOT permit any plaintext
229
    ///   password mechanisms, unless either the STARTTLS command
230
    ///   has been negotiated or some other mechanism that
231
    ///   protects the session from password snooping has been
232
    ///   provided.  Server sites SHOULD NOT use any configuration
233
    ///   which permits a plaintext password mechanism without
234
    ///   such a protection mechanism against password snooping.
235
    ///   Client and server implementations SHOULD implement
236
    ///   additional \[SASL\] mechanisms that do not use plaintext
237
    ///   passwords, such the GSSAPI mechanism described in \[SASL\]
238
    ///   and/or the [DIGEST-MD5] mechanism.
239
    ///
240
    /// Servers and clients can support multiple authentication
241
    /// mechanisms.  The server SHOULD list its supported authentication
242
    /// mechanisms in the response to the CAPABILITY command so that the
243
    /// client knows which authentication mechanisms to use.
244
    ///
245
    /// A server MAY include a CAPABILITY response code in the tagged OK
246
    /// response of a successful AUTHENTICATE command in order to send
247
    /// capabilities automatically.  It is unnecessary for a client to
248
    /// send a separate CAPABILITY command if it recognizes these
249
    /// automatic capabilities.  This should only be done if a security
250
    /// layer was not negotiated by the AUTHENTICATE command, because the
251
    /// tagged OK response as part of an AUTHENTICATE command is not
252
    /// protected by encryption/integrity checking.  \[SASL\] requires the
253
    /// client to re-issue a CAPABILITY command in this case.
254
    ///
255
    /// If an AUTHENTICATE command fails with a NO response, the client
256
    /// MAY try another authentication mechanism by issuing another
257
    /// AUTHENTICATE command.  It MAY also attempt to authenticate by
258
    /// using the LOGIN command (see section 6.2.3 for more detail).  In
259
    /// other words, the client MAY request authentication types in
260
    /// decreasing order of preference, with the LOGIN command as a last
261
    /// resort.
262
    ///
263
    /// The authorization identity passed from the client to the server
264
    /// during the authentication exchange is interpreted by the server as
265
    /// the user name whose privileges the client is requesting.
266
    Authenticate {
267
        /// Authentication mechanism.
268
        mechanism: AuthMechanism<'a>,
269
        /// Initial response (if any).
270
        ///
271
        /// This type holds the raw binary data, i.e., a `Vec<u8>`, *not* the BASE64 string.
272
        ///
273
        /// <div class="warning">
274
        /// This extension must only be used when the server advertised support for it sending the SASL-IR capability.
275
        /// </div>
276
        initial_response: Option<Secret<Cow<'a, [u8]>>>,
277
    },
278

279
    /// ### 6.2.3.  LOGIN Command
280
    ///
281
    /// * Arguments:
282
    ///   * user name
283
    ///   * password
284
    /// * Responses:  no specific responses for this command
285
    /// * Result:
286
    ///   * OK - login completed, now in authenticated state
287
    ///   * NO - login failure: user name or password rejected
288
    ///   * BAD - command unknown or arguments invalid
289
    ///
290
    /// The LOGIN command identifies the client to the server and carries
291
    /// the plaintext password authenticating this user.
292
    ///
293
    /// A server MAY include a CAPABILITY response code in the tagged OK
294
    /// response to a successful LOGIN command in order to send
295
    /// capabilities automatically.  It is unnecessary for a client to
296
    /// send a separate CAPABILITY command if it recognizes these
297
    /// automatic capabilities.
298
    ///
299
    ///   Note: Use of the LOGIN command over an insecure network
300
    ///   (such as the Internet) is a security risk, because anyone
301
    ///   monitoring network traffic can obtain plaintext passwords.
302
    ///   The LOGIN command SHOULD NOT be used except as a last
303
    ///   resort, and it is recommended that client implementations
304
    ///   have a means to disable any automatic use of the LOGIN
305
    ///   command.
306
    ///
307
    ///   Unless either the STARTTLS command has been negotiated or
308
    ///   some other mechanism that protects the session from
309
    ///   password snooping has been provided, a server
310
    ///   implementation MUST implement a configuration in which it
311
    ///   advertises the LOGINDISABLED capability and does NOT permit
312
    ///   the LOGIN command.  Server sites SHOULD NOT use any
313
    ///   configuration which permits the LOGIN command without such
314
    ///   a protection mechanism against password snooping.  A client
315
    ///   implementation MUST NOT send a LOGIN command if the
316
    ///   LOGINDISABLED capability is advertised.
317
    Login {
318
        /// Username.
319
        username: AString<'a>,
320
        /// Password.
321
        password: Secret<AString<'a>>,
322
    },
323

324
    // ----- Authenticated State (https://tools.ietf.org/html/rfc3501#section-6.3) -----
325
    /// ### 6.3.1.  SELECT Command
326
    ///
327
    /// * Arguments:  mailbox name
328
    /// * Responses:
329
    ///   * REQUIRED untagged responses: FLAGS, EXISTS, RECENT
330
    ///   * REQUIRED OK untagged responses: UNSEEN, PERMANENTFLAGS, UIDNEXT, UIDVALIDITY
331
    /// * Result:
332
    ///   * OK - select completed, now in selected state
333
    ///   * NO - select failure, now in authenticated state: no such mailbox, can't access mailbox
334
    ///   * BAD - command unknown or arguments invalid
335
    ///
336
    /// The SELECT command selects a mailbox so that messages in the
337
    /// mailbox can be accessed.  Before returning an OK to the client,
338
    /// the server MUST send the following untagged data to the client.
339
    /// Note that earlier versions of this protocol only required the
340
    /// FLAGS, EXISTS, and RECENT untagged data; consequently, client
341
    /// implementations SHOULD implement default behavior for missing data
342
    /// as discussed with the individual item.
343
    ///
344
    ///   FLAGS       Defined flags in the mailbox.  See the description
345
    ///               of the FLAGS response for more detail.
346
    ///
347
    ///   \<n\> EXISTS  The number of messages in the mailbox.  See the
348
    ///               description of the EXISTS response for more detail.
349
    ///
350
    ///   \<n\> RECENT  The number of messages with the \Recent flag set.
351
    ///               See the description of the RECENT response for more
352
    ///               detail.
353
    ///
354
    ///   OK [UNSEEN \<n\>]
355
    ///               The message sequence number of the first unseen
356
    ///               message in the mailbox.  If this is missing, the
357
    ///               client can not make any assumptions about the first
358
    ///               unseen message in the mailbox, and needs to issue a
359
    ///               SEARCH command if it wants to find it.
360
    ///
361
    ///   OK [PERMANENTFLAGS (\<list of flags\>)]
362
    ///               A list of message flags that the client can change
363
    ///               permanently.  If this is missing, the client should
364
    ///               assume that all flags can be changed permanently.
365
    ///
366
    ///   OK [UIDNEXT \<n\>]
367
    ///               The next unique identifier value.  Refer to section
368
    ///               2.3.1.1 for more information.  If this is missing,
369
    ///               the client can not make any assumptions about the
370
    ///               next unique identifier value.
371
    ///
372
    ///   OK [UIDVALIDITY \<n\>]
373
    ///               The unique identifier validity value.  Refer to
374
    ///               section 2.3.1.1 for more information.  If this is
375
    ///               missing, the server does not support unique
376
    ///               identifiers.
377
    ///
378
    /// Only one mailbox can be selected at a time in a connection;
379
    /// simultaneous access to multiple mailboxes requires multiple
380
    /// connections.  The SELECT command automatically deselects any
381
    /// currently selected mailbox before attempting the new selection.
382
    /// Consequently, if a mailbox is selected and a SELECT command that
383
    /// fails is attempted, no mailbox is selected.
384
    ///
385
    /// If the client is permitted to modify the mailbox, the server
386
    /// SHOULD prefix the text of the tagged OK response with the
387
    /// "[READ-WRITE]" response code.
388
    ///
389
    /// If the client is not permitted to modify the mailbox but is
390
    /// permitted read access, the mailbox is selected as read-only, and
391
    /// the server MUST prefix the text of the tagged OK response to
392
    /// SELECT with the "[READ-ONLY]" response code.  Read-only access
393
    /// through SELECT differs from the EXAMINE command in that certain
394
    /// read-only mailboxes MAY permit the change of permanent state on a
395
    /// per-user (as opposed to global) basis.  Netnews messages marked in
396
    /// a server-based .newsrc file are an example of such per-user
397
    /// permanent state that can be modified with read-only mailboxes.
398
    Select {
399
        /// Mailbox.
400
        mailbox: Mailbox<'a>,
401
        #[cfg(feature = "ext_condstore_qresync")]
402
        parameters: Vec<SelectParameter>,
403
    },
404

405
    /// Unselect a mailbox.
406
    ///
407
    /// This should bring the client back to the AUTHENTICATED state.
408
    ///
409
    /// <div class="warning">
410
    /// This extension must only be used when the server advertised support for it sending the UNSELECT capability.
411
    /// </div>
412
    Unselect,
413

414
    /// 6.3.2.  EXAMINE Command
415
    ///
416
    /// Arguments:  mailbox name
417
    /// Responses:  REQUIRED untagged responses: FLAGS, EXISTS, RECENT
418
    ///             REQUIRED OK untagged responses:  UNSEEN,  PERMANENTFLAGS,
419
    ///             UIDNEXT, UIDVALIDITY
420
    /// Result:     OK - examine completed, now in selected state
421
    ///             NO - examine failure, now in authenticated state: no
422
    ///                  such mailbox, can't access mailbox
423
    ///             BAD - command unknown or arguments invalid
424
    ///
425
    /// The EXAMINE command is identical to SELECT and returns the same
426
    /// output; however, the selected mailbox is identified as read-only.
427
    /// No changes to the permanent state of the mailbox, including
428
    /// per-user state, are permitted; in particular, EXAMINE MUST NOT
429
    /// cause messages to lose the \Recent flag.
430
    ///
431
    /// The text of the tagged OK response to the EXAMINE command MUST
432
    /// begin with the "[READ-ONLY]" response code.
433
    Examine {
434
        /// Mailbox.
435
        mailbox: Mailbox<'a>,
436
        #[cfg(feature = "ext_condstore_qresync")]
437
        parameters: Vec<SelectParameter>,
438
    },
439

440
    /// ### 6.3.3.  CREATE Command
441
    ///
442
    /// * Arguments:  mailbox name
443
    /// * Responses:  no specific responses for this command
444
    /// * Result:
445
    ///   * OK - create completed
446
    ///   * NO - create failure: can't create mailbox with that name
447
    ///   * BAD - command unknown or arguments invalid
448
    ///
449
    /// The CREATE command creates a mailbox with the given name.  An OK
450
    /// response is returned only if a new mailbox with that name has been
451
    /// created.  It is an error to attempt to create INBOX or a mailbox
452
    /// with a name that refers to an extant mailbox.  Any error in
453
    /// creation will return a tagged NO response.
454
    ///
455
    /// If the mailbox name is suffixed with the server's hierarchy
456
    /// separator character (as returned from the server by a LIST
457
    /// command), this is a declaration that the client intends to create
458
    /// mailbox names under this name in the hierarchy.  Server
459
    /// implementations that do not require this declaration MUST ignore
460
    /// the declaration.  In any case, the name created is without the
461
    /// trailing hierarchy delimiter.
462
    ///
463
    /// If the server's hierarchy separator character appears elsewhere in
464
    /// the name, the server SHOULD create any superior hierarchical names
465
    /// that are needed for the CREATE command to be successfully
466
    /// completed.  In other words, an attempt to create "foo/bar/zap" on
467
    /// a server in which "/" is the hierarchy separator character SHOULD
468
    /// create foo/ and foo/bar/ if they do not already exist.
469
    ///
470
    /// If a new mailbox is created with the same name as a mailbox which
471
    /// was deleted, its unique identifiers MUST be greater than any
472
    /// unique identifiers used in the previous incarnation of the mailbox
473
    /// UNLESS the new incarnation has a different unique identifier
474
    /// validity value.  See the description of the UID command for more
475
    /// detail.
476
    ///
477
    ///   Note: The interpretation of this example depends on whether
478
    ///   "/" was returned as the hierarchy separator from LIST.  If
479
    ///   "/" is the hierarchy separator, a new level of hierarchy
480
    ///   named "owatagusiam" with a member called "blurdybloop" is
481
    ///   created.  Otherwise, two mailboxes at the same hierarchy
482
    ///   level are created.
483
    Create {
484
        /// Mailbox.
485
        mailbox: Mailbox<'a>,
486
    },
487

488
    /// 6.3.4.  DELETE Command
489
    ///
490
    /// Arguments:  mailbox name
491
    /// Responses:  no specific responses for this command
492
    /// Result:     OK - delete completed
493
    ///             NO - delete failure: can't delete mailbox with that name
494
    ///             BAD - command unknown or arguments invalid
495
    ///
496
    /// The DELETE command permanently removes the mailbox with the given
497
    /// name.  A tagged OK response is returned only if the mailbox has
498
    /// been deleted.  It is an error to attempt to delete INBOX or a
499
    /// mailbox name that does not exist.
500
    ///
501
    /// The DELETE command MUST NOT remove inferior hierarchical names.
502
    /// For example, if a mailbox "foo" has an inferior "foo.bar"
503
    /// (assuming "." is the hierarchy delimiter character), removing
504
    /// "foo" MUST NOT remove "foo.bar".  It is an error to attempt to
505
    /// delete a name that has inferior hierarchical names and also has
506
    /// the \Noselect mailbox name attribute (see the description of the
507
    /// LIST response for more details).
508
    ///
509
    /// It is permitted to delete a name that has inferior hierarchical
510
    /// names and does not have the \Noselect mailbox name attribute.  In
511
    /// this case, all messages in that mailbox are removed, and the name
512
    /// will acquire the \Noselect mailbox name attribute.
513
    ///
514
    /// The value of the highest-used unique identifier of the deleted
515
    /// mailbox MUST be preserved so that a new mailbox created with the
516
    /// same name will not reuse the identifiers of the former
517
    /// incarnation, UNLESS the new incarnation has a different unique
518
    /// identifier validity value.  See the description of the UID command
519
    /// for more detail.
520
    Delete {
521
        /// Mailbox.
522
        mailbox: Mailbox<'a>,
523
    },
524

525
    /// 6.3.5.  RENAME Command
526
    ///
527
    /// Arguments:  existing mailbox name
528
    ///             new mailbox name
529
    /// Responses:  no specific responses for this command
530
    /// Result:     OK - rename completed
531
    ///             NO - rename failure: can't rename mailbox with that name,
532
    ///                  can't rename to mailbox with that name
533
    ///             BAD - command unknown or arguments invalid
534
    ///
535
    /// The RENAME command changes the name of a mailbox.  A tagged OK
536
    /// response is returned only if the mailbox has been renamed.  It is
537
    /// an error to attempt to rename from a mailbox name that does not
538
    /// exist or to a mailbox name that already exists.  Any error in
539
    /// renaming will return a tagged NO response.
540
    ///
541
    /// If the name has inferior hierarchical names, then the inferior
542
    /// hierarchical names MUST also be renamed.  For example, a rename of
543
    /// "foo" to "zap" will rename "foo/bar" (assuming "/" is the
544
    /// hierarchy delimiter character) to "zap/bar".
545
    ///
546
    /// If the server's hierarchy separator character appears in the name,
547
    /// the server SHOULD create any superior hierarchical names that are
548
    /// needed for the RENAME command to complete successfully.  In other
549
    /// words, an attempt to rename "foo/bar/zap" to baz/rag/zowie on a
550
    /// server in which "/" is the hierarchy separator character SHOULD
551
    /// create baz/ and baz/rag/ if they do not already exist.
552
    ///
553
    /// The value of the highest-used unique identifier of the old mailbox
554
    /// name MUST be preserved so that a new mailbox created with the same
555
    /// name will not reuse the identifiers of the former incarnation,
556
    /// UNLESS the new incarnation has a different unique identifier
557
    /// validity value.  See the description of the UID command for more
558
    /// detail.
559
    ///
560
    /// Renaming INBOX is permitted, and has special behavior.  It moves
561
    /// all messages in INBOX to a new mailbox with the given name,
562
    /// leaving INBOX empty.  If the server implementation supports
563
    /// inferior hierarchical names of INBOX, these are unaffected by a
564
    /// rename of INBOX.
565
    Rename {
566
        /// Current name.
567
        from: Mailbox<'a>,
568
        /// New name.
569
        to: Mailbox<'a>,
570
    },
571

572
    /// ### 6.3.6.  SUBSCRIBE Command
573
    ///
574
    /// * Arguments:  mailbox
575
    /// * Responses:  no specific responses for this command
576
    /// * Result:
577
    ///   * OK - subscribe completed
578
    ///   * NO - subscribe failure: can't subscribe to that name
579
    ///   * BAD - command unknown or arguments invalid
580
    ///
581
    /// The SUBSCRIBE command adds the specified mailbox name to the
582
    /// server's set of "active" or "subscribed" mailboxes as returned by
583
    /// the LSUB command.  This command returns a tagged OK response only
584
    /// if the subscription is successful.
585
    ///
586
    /// A server MAY validate the mailbox argument to SUBSCRIBE to verify
587
    /// that it exists.  However, it MUST NOT unilaterally remove an
588
    /// existing mailbox name from the subscription list even if a mailbox
589
    /// by that name no longer exists.
590
    ///
591
    ///   Note: This requirement is because a server site can
592
    ///   choose to routinely remove a mailbox with a well-known
593
    ///   name (e.g., "system-alerts") after its contents expire,
594
    ///   with the intention of recreating it when new contents
595
    ///   are appropriate.
596
    Subscribe {
597
        /// Mailbox.
598
        mailbox: Mailbox<'a>,
599
    },
600

601
    /// 6.3.7.  UNSUBSCRIBE Command
602
    ///
603
    /// Arguments:  mailbox name
604
    /// Responses:  no specific responses for this command
605
    /// Result:     OK - unsubscribe completed
606
    ///             NO - unsubscribe failure: can't unsubscribe that name
607
    ///             BAD - command unknown or arguments invalid
608
    ///
609
    /// The UNSUBSCRIBE command removes the specified mailbox name from
610
    /// the server's set of "active" or "subscribed" mailboxes as returned
611
    /// by the LSUB command.  This command returns a tagged OK response
612
    /// only if the unsubscription is successful.
613
    Unsubscribe {
614
        /// Mailbox.
615
        mailbox: Mailbox<'a>,
616
    },
617

618
    /// ### 6.3.8.  LIST Command
619
    ///
620
    /// * Arguments:
621
    ///   * reference name
622
    ///   * mailbox name with possible wildcards
623
    /// * Responses:  untagged responses: LIST
624
    /// * Result:
625
    ///   * OK - list completed
626
    ///   * NO - list failure: can't list that reference or name
627
    ///   * BAD - command unknown or arguments invalid
628
    ///
629
    /// The LIST command returns a subset of names from the complete set
630
    /// of all names available to the client.  Zero or more untagged LIST
631
    /// replies are returned, containing the name attributes, hierarchy
632
    /// delimiter, and name; see the description of the LIST reply for
633
    /// more detail.
634
    ///
635
    /// The LIST command SHOULD return its data quickly, without undue
636
    /// delay.  For example, it SHOULD NOT go to excess trouble to
637
    /// calculate the \Marked or \Unmarked status or perform other
638
    /// processing; if each name requires 1 second of processing, then a
639
    /// list of 1200 names would take 20 minutes!
640
    ///
641
    /// An empty ("" string) reference name argument indicates that the
642
    /// mailbox name is interpreted as by SELECT.  The returned mailbox
643
    /// names MUST match the supplied mailbox name pattern.  A non-empty
644
    /// reference name argument is the name of a mailbox or a level of
645
    /// mailbox hierarchy, and indicates the context in which the mailbox
646
    /// name is interpreted.
647
    ///
648
    /// An empty ("" string) mailbox name argument is a special request to
649
    /// return the hierarchy delimiter and the root name of the name given
650
    /// in the reference.  The value returned as the root MAY be the empty
651
    /// string if the reference is non-rooted or is an empty string.  In
652
    /// all cases, a hierarchy delimiter (or NIL if there is no hierarchy)
653
    /// is returned.  This permits a client to get the hierarchy delimiter
654
    /// (or find out that the mailbox names are flat) even when no
655
    /// mailboxes by that name currently exist.
656
    ///
657
    /// The reference and mailbox name arguments are interpreted into a
658
    /// canonical form that represents an unambiguous left-to-right
659
    /// hierarchy.  The returned mailbox names will be in the interpreted
660
    /// form.
661
    ///
662
    ///   Note: The interpretation of the reference argument is
663
    ///   implementation-defined.  It depends upon whether the
664
    ///   server implementation has a concept of the "current
665
    ///   working directory" and leading "break out characters",
666
    ///   which override the current working directory.
667
    ///
668
    ///   For example, on a server which exports a UNIX or NT
669
    ///   filesystem, the reference argument contains the current
670
    ///   working directory, and the mailbox name argument would
671
    ///   contain the name as interpreted in the current working
672
    ///   directory.
673
    ///
674
    /// If a server implementation has no concept of break out
675
    /// characters, the canonical form is normally the reference
676
    /// name appended with the mailbox name.  Note that if the
677
    /// server implements the namespace convention (section
678
    /// 5.1.2), "#" is a break out character and must be treated
679
    /// as such.
680
    ///
681
    /// If the reference argument is not a level of mailbox
682
    /// hierarchy (that is, it is a \NoInferiors name), and/or
683
    /// the reference argument does not end with the hierarchy
684
    /// delimiter, it is implementation-dependent how this is
685
    /// interpreted.  For example, a reference of "foo/bar" and
686
    /// mailbox name of "rag/baz" could be interpreted as
687
    /// "foo/bar/rag/baz", "foo/barrag/baz", or "foo/rag/baz".
688
    /// A client SHOULD NOT use such a reference argument except
689
    /// at the explicit request of the user.  A hierarchical
690
    /// browser MUST NOT make any assumptions about server
691
    /// interpretation of the reference unless the reference is
692
    /// a level of mailbox hierarchy AND ends with the hierarchy
693
    /// delimiter.
694
    ///
695
    /// Any part of the reference argument that is included in the
696
    /// interpreted form SHOULD prefix the interpreted form.  It SHOULD
697
    /// also be in the same form as the reference name argument.  This
698
    /// rule permits the client to determine if the returned mailbox name
699
    /// is in the context of the reference argument, or if something about
700
    /// the mailbox argument overrode the reference argument.  Without
701
    /// this rule, the client would have to have knowledge of the server's
702
    /// naming semantics including what characters are "breakouts" that
703
    /// override a naming context.
704
    ///
705
    ///   For example, here are some examples of how references
706
    ///   and mailbox names might be interpreted on a UNIX-based
707
    ///   server:
708
    ///
709
    /// ```text
710
    /// Reference     Mailbox Name  Interpretation
711
    /// ------------  ------------  --------------
712
    /// ~smith/Mail/  foo.*         ~smith/Mail/foo.*
713
    /// archive/      %             archive/%
714
    /// #news.        comp.mail.*   #news.comp.mail.*
715
    /// ~smith/Mail/  /usr/doc/foo  /usr/doc/foo
716
    /// archive/      ~fred/Mail/*  ~fred/Mail/*
717
    /// ```
718
    ///
719
    ///   The first three examples demonstrate interpretations in
720
    ///   the context of the reference argument.  Note that
721
    ///   "~smith/Mail" SHOULD NOT be transformed into something
722
    ///   like "/u2/users/smith/Mail", or it would be impossible
723
    ///   for the client to determine that the interpretation was
724
    ///   in the context of the reference.
725
    ///
726
    /// The character "*" is a wildcard, and matches zero or more
727
    /// characters at this position.  The character "%" is similar to "*",
728
    /// but it does not match a hierarchy delimiter.  If the "%" wildcard
729
    /// is the last character of a mailbox name argument, matching levels
730
    /// of hierarchy are also returned.  If these levels of hierarchy are
731
    /// not also selectable mailboxes, they are returned with the
732
    /// \Noselect mailbox name attribute (see the description of the LIST
733
    /// response for more details).
734
    ///
735
    /// Server implementations are permitted to "hide" otherwise
736
    /// accessible mailboxes from the wildcard characters, by preventing
737
    /// certain characters or names from matching a wildcard in certain
738
    /// situations.  For example, a UNIX-based server might restrict the
739
    /// interpretation of "*" so that an initial "/" character does not
740
    /// match.
741
    ///
742
    /// The special name INBOX is included in the output from LIST, if
743
    /// INBOX is supported by this server for this user and if the
744
    /// uppercase string "INBOX" matches the interpreted reference and
745
    /// mailbox name arguments with wildcards as described above.  The
746
    /// criteria for omitting INBOX is whether SELECT INBOX will return
747
    /// failure; it is not relevant whether the user's real INBOX resides
748
    /// on this or some other server.
749
    List {
750
        /// Reference.
751
        reference: Mailbox<'a>,
752
        /// Mailbox (wildcard).
753
        mailbox_wildcard: ListMailbox<'a>,
754
    },
755

756
    /// ### 6.3.9.  LSUB Command
757
    ///
758
    /// * Arguments:
759
    ///   * reference name
760
    ///   * mailbox name with possible wildcards
761
    /// * Responses:  untagged responses: LSUB
762
    /// * Result:
763
    ///   * OK - lsub completed
764
    ///   * NO - lsub failure: can't list that reference or name
765
    ///   * BAD - command unknown or arguments invalid
766
    ///
767
    /// The LSUB command returns a subset of names from the set of names
768
    /// that the user has declared as being "active" or "subscribed".
769
    /// Zero or more untagged LSUB replies are returned.  The arguments to
770
    /// LSUB are in the same form as those for LIST.
771
    ///
772
    /// The returned untagged LSUB response MAY contain different mailbox
773
    /// flags from a LIST untagged response.  If this should happen, the
774
    /// flags in the untagged LIST are considered more authoritative.
775
    ///
776
    /// A special situation occurs when using LSUB with the % wildcard.
777
    /// Consider what happens if "foo/bar" (with a hierarchy delimiter of
778
    /// "/") is subscribed but "foo" is not.  A "%" wildcard to LSUB must
779
    /// return foo, not foo/bar, in the LSUB response, and it MUST be
780
    /// flagged with the \Noselect attribute.
781
    ///
782
    /// The server MUST NOT unilaterally remove an existing mailbox name
783
    /// from the subscription list even if a mailbox by that name no
784
    /// longer exists.
785
    Lsub {
786
        /// Reference.
787
        reference: Mailbox<'a>,
788
        /// Mailbox (wildcard).
789
        mailbox_wildcard: ListMailbox<'a>,
790
    },
791

792
    /// ### 6.3.10. STATUS Command
793
    ///
794
    /// * Arguments:
795
    ///   * mailbox name
796
    ///   * status data item names
797
    /// * Responses:  untagged responses: STATUS
798
    /// * Result:
799
    ///   * OK - status completed
800
    ///   * NO - status failure: no status for that name
801
    ///   * BAD - command unknown or arguments invalid
802
    ///
803
    /// The STATUS command requests the status of the indicated mailbox.
804
    /// It does not change the currently selected mailbox, nor does it
805
    /// affect the state of any messages in the queried mailbox (in
806
    /// particular, STATUS MUST NOT cause messages to lose the \Recent
807
    /// flag).
808
    ///
809
    /// The STATUS command provides an alternative to opening a second
810
    /// IMAP4rev1 connection and doing an EXAMINE command on a mailbox to
811
    /// query that mailbox's status without deselecting the current
812
    /// mailbox in the first IMAP4rev1 connection.
813
    ///
814
    /// Unlike the LIST command, the STATUS command is not guaranteed to
815
    /// be fast in its response.  Under certain circumstances, it can be
816
    /// quite slow.  In some implementations, the server is obliged to
817
    /// open the mailbox read-only internally to obtain certain status
818
    /// information.  Also unlike the LIST command, the STATUS command
819
    /// does not accept wildcards.
820
    ///
821
    ///   Note: The STATUS command is intended to access the
822
    ///   status of mailboxes other than the currently selected
823
    ///   mailbox.  Because the STATUS command can cause the
824
    ///   mailbox to be opened internally, and because this
825
    ///   information is available by other means on the selected
826
    ///   mailbox, the STATUS command SHOULD NOT be used on the
827
    ///   currently selected mailbox.
828
    ///
829
    ///   The STATUS command MUST NOT be used as a "check for new
830
    ///   messages in the selected mailbox" operation (refer to
831
    ///   sections 7, 7.3.1, and 7.3.2 for more information about
832
    ///   the proper method for new message checking).
833
    ///
834
    ///   Because the STATUS command is not guaranteed to be fast
835
    ///   in its results, clients SHOULD NOT expect to be able to
836
    ///   issue many consecutive STATUS commands and obtain
837
    ///   reasonable performance.
838
    Status {
839
        /// Mailbox.
840
        mailbox: Mailbox<'a>,
841
        /// Status data items.
842
        item_names: Cow<'a, [StatusDataItemName]>,
843
    },
844

845
    /// 6.3.11. APPEND Command
846
    ///
847
    /// Arguments:  mailbox name
848
    ///             OPTIONAL flag parenthesized list
849
    ///             OPTIONAL date/time string
850
    ///             message literal
851
    /// Responses:  no specific responses for this command
852
    /// Result:     OK - append completed
853
    ///             NO - append error: can't append to that mailbox, error
854
    ///                  in flags or date/time or message text
855
    ///             BAD - command unknown or arguments invalid
856
    ///
857
    /// The APPEND command appends the literal argument as a new message
858
    /// to the end of the specified destination mailbox.  This argument
859
    /// SHOULD be in the format of an [RFC-2822] message.  8-bit
860
    /// characters are permitted in the message.  A server implementation
861
    /// that is unable to preserve 8-bit data properly MUST be able to
862
    /// reversibly convert 8-bit APPEND data to 7-bit using a [MIME-IMB]
863
    /// content transfer encoding.
864
    ///
865
    ///   Note: There MAY be exceptions, e.g., draft messages, in
866
    ///   which required [RFC-2822] header lines are omitted in
867
    ///   the message literal argument to APPEND.  The full
868
    ///   implications of doing so MUST be understood and
869
    ///   carefully weighed.
870
    ///
871
    /// If a flag parenthesized list is specified, the flags SHOULD be set
872
    /// in the resulting message; otherwise, the flag list of the
873
    /// resulting message is set to empty by default.  In either case, the
874
    /// Recent flag is also set.
875
    ///
876
    /// If a date-time is specified, the internal date SHOULD be set in
877
    /// the resulting message; otherwise, the internal date of the
878
    /// resulting message is set to the current date and time by default.
879
    ///
880
    /// If the append is unsuccessful for any reason, the mailbox MUST be
881
    /// restored to its state before the APPEND attempt; no partial
882
    /// appending is permitted.
883
    ///
884
    /// If the destination mailbox does not exist, a server MUST return an
885
    /// error, and MUST NOT automatically create the mailbox.  Unless it
886
    /// is certain that the destination mailbox can not be created, the
887
    /// server MUST send the response code "\[TRYCREATE\]" as the prefix of
888
    /// the text of the tagged NO response.  This gives a hint to the
889
    /// client that it can attempt a CREATE command and retry the APPEND
890
    /// if the CREATE is successful.
891
    ///
892
    /// If the mailbox is currently selected, the normal new message
893
    /// actions SHOULD occur.  Specifically, the server SHOULD notify the
894
    /// client immediately via an untagged EXISTS response.  If the server
895
    /// does not do so, the client MAY issue a NOOP command (or failing
896
    /// that, a CHECK command) after one or more APPEND commands.
897
    ///
898
    ///   Note: The APPEND command is not used for message delivery,
899
    ///   because it does not provide a mechanism to transfer \[SMTP\]
900
    ///   envelope information.
901
    Append {
902
        /// Mailbox.
903
        mailbox: Mailbox<'a>,
904
        /// Flags.
905
        flags: Vec<Flag<'a>>,
906
        /// Datetime.
907
        date: Option<DateTime>,
908
        /// Message to append.
909
        ///
910
        /// <div class="warning">
911
        /// Use [`LiteralOrLiteral8::Literal8`] only when the server advertised [`Capability::Binary`](crate::response::Capability::Binary).
912
        /// </div>
913
        message: LiteralOrLiteral8<'a>,
914
    },
915

916
    // ----- Selected State (https://tools.ietf.org/html/rfc3501#section-6.4) -----
917
    /// ### 6.4.1.  CHECK Command
918
    ///
919
    /// * Arguments:  none
920
    /// * Responses:  no specific responses for this command
921
    /// * Result:
922
    ///   * OK - check completed
923
    ///   * BAD - command unknown or arguments invalid
924
    ///
925
    /// The CHECK command requests a checkpoint of the currently selected
926
    /// mailbox.  A checkpoint refers to any implementation-dependent
927
    /// housekeeping associated with the mailbox (e.g., resolving the
928
    /// server's in-memory state of the mailbox with the state on its
929
    /// disk) that is not normally executed as part of each command.  A
930
    /// checkpoint MAY take a non-instantaneous amount of real time to
931
    /// complete.  If a server implementation has no such housekeeping
932
    /// considerations, CHECK is equivalent to NOOP.
933
    ///
934
    /// There is no guarantee that an EXISTS untagged response will happen
935
    /// as a result of CHECK.  NOOP, not CHECK, SHOULD be used for new
936
    /// message polling.
937
    Check,
938

939
    /// ### 6.4.2.  CLOSE Command
940
    ///
941
    /// * Arguments: none
942
    /// * Responses: no specific responses for this command
943
    /// * Result:
944
    ///   * OK - close completed, now in authenticated state
945
    ///   * BAD - command unknown or arguments invalid
946
    ///
947
    /// The CLOSE command permanently removes all messages that have the
948
    /// \Deleted flag set from the currently selected mailbox, and returns
949
    /// to the authenticated state from the selected state.  No untagged
950
    /// EXPUNGE responses are sent.
951
    ///
952
    /// No messages are removed, and no error is given, if the mailbox is
953
    /// selected by an EXAMINE command or is otherwise selected read-only.
954
    ///
955
    /// Even if a mailbox is selected, a SELECT, EXAMINE, or LOGOUT
956
    /// command MAY be issued without previously issuing a CLOSE command.
957
    /// The SELECT, EXAMINE, and LOGOUT commands implicitly close the
958
    /// currently selected mailbox without doing an expunge.  However,
959
    /// when many messages are deleted, a CLOSE-LOGOUT or CLOSE-SELECT
960
    /// sequence is considerably faster than an EXPUNGE-LOGOUT or
961
    /// EXPUNGE-SELECT because no untagged EXPUNGE responses (which the
962
    /// client would probably ignore) are sent.
963
    Close,
964

965
    /// 6.4.3.  EXPUNGE Command
966
    ///
967
    /// Arguments: none
968
    /// Responses: untagged responses: EXPUNGE
969
    /// Result:    OK - expunge completed
970
    ///            NO - expunge failure: can't expunge (e.g., permission denied)
971
    ///            BAD - command unknown or arguments invalid
972
    ///
973
    /// The EXPUNGE command permanently removes all messages that have the
974
    /// \Deleted flag set from the currently selected mailbox.  Before
975
    /// returning an OK to the client, an untagged EXPUNGE response is
976
    /// sent for each message that is removed.
977
    Expunge,
978

979
    /// 2.1.  UID EXPUNGE Command (RFC 4315)
980
    ///
981
    /// Arguments: sequence set
982
    /// Data:      untagged responses: EXPUNGE
983
    /// Result:    OK - expunge completed
984
    ///            NO - expunge failure (e.g., permission denied)
985
    ///            BAD - command unknown or arguments invalid
986
    ///
987
    /// The UID EXPUNGE command permanently removes all messages that both
988
    /// have the \Deleted flag set and have a UID that is included in the
989
    /// specified sequence set from the currently selected mailbox.  If a
990
    /// message either does not have the \Deleted flag set or has a UID
991
    /// that is not included in the specified sequence set, it is not
992
    /// affected.
993
    ///
994
    /// This command is particularly useful for disconnected use clients.
995
    /// By using UID EXPUNGE instead of EXPUNGE when resynchronizing with
996
    /// the server, the client can ensure that it does not inadvertantly
997
    /// remove any messages that have been marked as \Deleted by other
998
    /// clients between the time that the client was last connected and
999
    /// the time the client resynchronizes.
1000
    ///
1001
    /// If the server does not support the UIDPLUS capability, the client
1002
    /// should fall back to using the STORE command to temporarily remove
1003
    /// the \Deleted flag from messages it does not want to remove, then
1004
    /// issuing the EXPUNGE command.  Finally, the client should use the
1005
    /// STORE command to restore the \Deleted flag on the messages in
1006
    /// which it was temporarily removed.
1007
    ///
1008
    /// Alternatively, the client may fall back to using just the EXPUNGE
1009
    /// command, risking the unintended removal of some messages.
1010
    ExpungeUid { sequence_set: SequenceSet },
1011

1012
    /// ### 6.4.4.  SEARCH Command
1013
    ///
1014
    /// * Arguments:
1015
    ///   * OPTIONAL \[CHARSET\] specification
1016
    ///   * searching criteria (one or more)
1017
    /// * Responses:  REQUIRED untagged response: SEARCH
1018
    /// * Result:
1019
    ///   * OK - search completed
1020
    ///   * NO - search error: can't search that \[CHARSET\] or criteria
1021
    ///   * BAD - command unknown or arguments invalid
1022
    ///
1023
    /// The SEARCH command searches the mailbox for messages that match
1024
    /// the given searching criteria.  Searching criteria consist of one
1025
    /// or more search keys.  The untagged SEARCH response from the server
1026
    /// contains a listing of message sequence numbers corresponding to
1027
    /// those messages that match the searching criteria.
1028
    ///
1029
    /// When multiple keys are specified, the result is the intersection
1030
    /// (AND function) of all the messages that match those keys.  For
1031
    /// example, the criteria DELETED FROM "SMITH" SINCE 1-Feb-1994 refers
1032
    /// to all deleted messages from Smith that were placed in the mailbox
1033
    /// since February 1, 1994.  A search key can also be a parenthesized
1034
    /// list of one or more search keys (e.g., for use with the OR and NOT
1035
    /// keys).
1036
    ///
1037
    /// Server implementations MAY exclude [MIME-IMB] body parts with
1038
    /// terminal content media types other than TEXT and MESSAGE from
1039
    /// consideration in SEARCH matching.
1040
    ///
1041
    /// The OPTIONAL \[CHARSET\] specification consists of the word
1042
    /// "CHARSET" followed by a registered \[CHARSET\].  It indicates the
1043
    /// \[CHARSET\] of the strings that appear in the search criteria.
1044
    /// [MIME-IMB] content transfer encodings, and [MIME-HDRS] strings in
1045
    /// [RFC-2822]/[MIME-IMB] headers, MUST be decoded before comparing
1046
    /// text in a \[CHARSET\] other than US-ASCII.  US-ASCII MUST be
1047
    /// supported; other \[CHARSET\]s MAY be supported.
1048
    ///
1049
    /// If the server does not support the specified \[CHARSET\], it MUST
1050
    /// return a tagged NO response (not a BAD).  This response SHOULD
1051
    /// contain the BADCHARSET response code, which MAY list the
1052
    /// \[CHARSET\]s supported by the server.
1053
    ///
1054
    /// In all search keys that use strings, a message matches the key if
1055
    /// the string is a substring of the field.  The matching is
1056
    /// case-insensitive.
1057
    ///
1058
    /// See [SearchKey] enum.
1059
    ///
1060
    /// Note: Since this document is restricted to 7-bit ASCII
1061
    /// text, it is not possible to show actual UTF-8 data.  The
1062
    /// "XXXXXX" is a placeholder for what would be 6 octets of
1063
    /// 8-bit data in an actual transaction.
1064
    Search {
1065
        /// Charset.
1066
        charset: Option<Charset<'a>>,
1067
        /// Criteria.
1068
        criteria: Vec1<SearchKey<'a>>,
1069
        /// Use UID variant.
1070
        uid: bool,
1071
    },
1072

1073
    /// SORT command.
1074
    ///
1075
    /// The SORT command is a variant of SEARCH with sorting semantics for the results.
1076
    ///
1077
    /// Data:
1078
    /// * untagged responses: SORT
1079
    ///
1080
    /// Result:
1081
    /// * OK - sort completed
1082
    /// * NO - sort error: can't sort that charset or criteria
1083
    /// * BAD - command unknown or arguments invalid
1084
    ///
1085
    /// <div class="warning">
1086
    /// This extension must only be used when the server advertised support for it sending the SORT capability.
1087
    /// </div>
1088
    Sort {
1089
        /// Sort criteria.
1090
        sort_criteria: Vec1<SortCriterion>,
1091
        /// Charset.
1092
        charset: Charset<'a>,
1093
        /// Search criteria.
1094
        search_criteria: Vec1<SearchKey<'a>>,
1095
        /// Use UID variant.
1096
        uid: bool,
1097
    },
1098

1099
    /// THREAD command.
1100
    ///
1101
    /// The THREAD command is a variant of SEARCH with threading semantics for the results.
1102
    ///
1103
    /// Data:
1104
    /// * untagged responses: THREAD
1105
    ///
1106
    /// Result:
1107
    /// * OK - thread completed
1108
    /// * NO - thread error: can't thread that charset or criteria
1109
    /// * BAD - command unknown or arguments invalid
1110
    ///
1111
    /// <div class="warning">
1112
    /// This extension must only be used when the server advertised support for it sending the THREAD capability.
1113
    /// </div>
1114
    Thread {
1115
        /// Threading algorithm.
1116
        algorithm: ThreadingAlgorithm<'a>,
1117
        /// Charset.
1118
        charset: Charset<'a>,
1119
        /// Search criteria.
1120
        search_criteria: Vec1<SearchKey<'a>>,
1121
        /// Use UID variant.
1122
        uid: bool,
1123
    },
1124

1125
    /// ### 6.4.5.  FETCH Command
1126
    ///
1127
    /// * Arguments:
1128
    ///   * sequence set
1129
    ///   * message data item names or macro
1130
    /// * Responses:  untagged responses: FETCH
1131
    /// * Result:
1132
    ///   * OK - fetch completed
1133
    ///   * NO - fetch error: can't fetch that data
1134
    ///   * BAD - command unknown or arguments invalid
1135
    ///
1136
    /// The FETCH command retrieves data associated with a message in the
1137
    /// mailbox.  The data items to be fetched can be either a single atom
1138
    /// or a parenthesized list.
1139
    ///
1140
    /// Most data items, identified in the formal syntax under the
1141
    /// msg-att-static rule, are static and MUST NOT change for any
1142
    /// particular message.  Other data items, identified in the formal
1143
    /// syntax under the msg-att-dynamic rule, MAY change, either as a
1144
    /// result of a STORE command or due to external events.
1145
    ///
1146
    ///   For example, if a client receives an ENVELOPE for a
1147
    ///   message when it already knows the envelope, it can
1148
    ///   safely ignore the newly transmitted envelope.
1149
    Fetch {
1150
        /// Set of messages.
1151
        sequence_set: SequenceSet,
1152
        /// Message data items (or a macro).
1153
        macro_or_item_names: MacroOrMessageDataItemNames<'a>,
1154
        /// Use UID variant.
1155
        uid: bool,
1156
        #[cfg(feature = "ext_condstore_qresync")]
1157
        modifiers: Vec<FetchModifier>,
1158
    },
1159

1160
    /// ### 6.4.6.  STORE Command
1161
    ///
1162
    /// * Arguments:
1163
    ///   * sequence set
1164
    ///   * message data item name
1165
    ///   * value for message data item
1166
    /// * Responses:  untagged responses: FETCH
1167
    /// * Result:
1168
    ///   * OK - store completed
1169
    ///   * NO - store error: can't store that data
1170
    ///   * BAD - command unknown or arguments invalid
1171
    ///
1172
    /// The STORE command alters data associated with a message in the
1173
    /// mailbox.  Normally, STORE will return the updated value of the
1174
    /// data with an untagged FETCH response.  A suffix of ".SILENT" in
1175
    /// the data item name prevents the untagged FETCH, and the server
1176
    /// SHOULD assume that the client has determined the updated value
1177
    /// itself or does not care about the updated value.
1178
    ///
1179
    ///   Note: Regardless of whether or not the ".SILENT" suffix
1180
    ///   was used, the server SHOULD send an untagged FETCH
1181
    ///   response if a change to a message's flags from an
1182
    ///   external source is observed.  The intent is that the
1183
    ///   status of the flags is determinate without a race
1184
    ///   condition.
1185
    ///
1186
    /// The currently defined data items that can be stored are:
1187
    ///
1188
    /// FLAGS \<flag list\>
1189
    ///    Replace the flags for the message (other than \Recent) with the
1190
    ///    argument.  The new value of the flags is returned as if a FETCH
1191
    ///    of those flags was done.
1192
    ///
1193
    /// FLAGS.SILENT \<flag list\>
1194
    ///    Equivalent to FLAGS, but without returning a new value.
1195
    ///
1196
    /// +FLAGS \<flag list\>
1197
    ///    Add the argument to the flags for the message.  The new value
1198
    ///    of the flags is returned as if a FETCH of those flags was done.
1199
    ///
1200
    /// +FLAGS.SILENT \<flag list\>
1201
    ///    Equivalent to +FLAGS, but without returning a new value.
1202
    ///
1203
    /// -FLAGS \<flag list\>
1204
    ///    Remove the argument from the flags for the message.  The new
1205
    ///    value of the flags is returned as if a FETCH of those flags was
1206
    ///    done.
1207
    ///
1208
    /// -FLAGS.SILENT \<flag list\>
1209
    ///    Equivalent to -FLAGS, but without returning a new value.
1210
    Store {
1211
        /// Set of messages.
1212
        sequence_set: SequenceSet,
1213
        /// Kind of storage, i.e., replace, add, or remove.
1214
        kind: StoreType,
1215
        /// Kind of response, i.e., answer or silent.
1216
        response: StoreResponse,
1217
        /// Flags.
1218
        flags: Vec<Flag<'a>>, // FIXME(misuse): must not accept "\*" or "\Recent"
1219
        /// Use UID variant.
1220
        uid: bool,
1221
        /// --- Modifiers ---
1222
        #[cfg(feature = "ext_condstore_qresync")]
1223
        modifiers: Vec<StoreModifier>,
1224
    },
1225

1226
    /// 6.4.7.  COPY Command
1227
    ///
1228
    /// Arguments:  sequence set
1229
    ///             mailbox name
1230
    /// Responses:  no specific responses for this command
1231
    /// Result:     OK - copy completed
1232
    ///             NO - copy error: can't copy those messages or to that
1233
    ///                  name
1234
    ///             BAD - command unknown or arguments invalid
1235
    ///
1236
    /// The COPY command copies the specified message(s) to the end of the
1237
    /// specified destination mailbox.  The flags and internal date of the
1238
    /// message(s) SHOULD be preserved, and the Recent flag SHOULD be set,
1239
    /// in the copy.
1240
    ///
1241
    /// If the destination mailbox does not exist, a server SHOULD return
1242
    /// an error.  It SHOULD NOT automatically create the mailbox.  Unless
1243
    /// it is certain that the destination mailbox can not be created, the
1244
    /// server MUST send the response code "\[TRYCREATE\]" as the prefix of
1245
    /// the text of the tagged NO response.  This gives a hint to the
1246
    /// client that it can attempt a CREATE command and retry the COPY if
1247
    /// the CREATE is successful.
1248
    ///
1249
    /// If the COPY command is unsuccessful for any reason, server
1250
    /// implementations MUST restore the destination mailbox to its state
1251
    /// before the COPY attempt.
1252
    Copy {
1253
        /// Set of messages.
1254
        sequence_set: SequenceSet,
1255
        /// Destination mailbox.
1256
        mailbox: Mailbox<'a>,
1257
        /// Use UID variant.
1258
        uid: bool,
1259
    },
1260

1261
    // The UID mechanism was inlined into copy, fetch, store, and search.
1262
    // as an additional parameter.
1263
    //
1264
    // ### 6.4.8.  UID Command
1265
    //
1266
    // * Arguments:
1267
    //   * command name
1268
    //   * command arguments
1269
    // * Responses:  untagged responses: FETCH, SEARCH
1270
    // * Result:
1271
    //   * OK - UID command completed
1272
    //   * NO - UID command error
1273
    //   * BAD - command unknown or arguments invalid
1274
    //
1275
    // The UID command has two forms.  In the first form, it takes as its
1276
    // arguments a COPY, FETCH, or STORE command with arguments
1277
    // appropriate for the associated command.  However, the numbers in
1278
    // the sequence set argument are unique identifiers instead of
1279
    // message sequence numbers.  Sequence set ranges are permitted, but
1280
    // there is no guarantee that unique identifiers will be contiguous.
1281
    //
1282
    // A non-existent unique identifier is ignored without any error
1283
    // message generated.  Thus, it is possible for a UID FETCH command
1284
    // to return an OK without any data or a UID COPY or UID STORE to
1285
    // return an OK without performing any operations.
1286
    //
1287
    // In the second form, the UID command takes a SEARCH command with
1288
    // SEARCH command arguments.  The interpretation of the arguments is
1289
    // the same as with SEARCH; however, the numbers returned in a SEARCH
1290
    // response for a UID SEARCH command are unique identifiers instead
1291
    // of message sequence numbers.  For example, the command UID SEARCH
1292
    // 1:100 UID 443:557 returns the unique identifiers corresponding to
1293
    // the intersection of two sequence sets, the message sequence number
1294
    // range 1:100 and the UID range 443:557.
1295
    //
1296
    //   Note: in the above example, the UID range 443:557
1297
    //   appears.  The same comment about a non-existent unique
1298
    //   identifier being ignored without any error message also
1299
    //   applies here.  Hence, even if neither UID 443 or 557
1300
    //   exist, this range is valid and would include an existing
1301
    //   UID 495.
1302
    //
1303
    //   Also note that a UID range of 559:* always includes the
1304
    //   UID of the last message in the mailbox, even if 559 is
1305
    //   higher than any assigned UID value.  This is because the
1306
    //   contents of a range are independent of the order of the
1307
    //   range endpoints.  Thus, any UID range with * as one of
1308
    //   the endpoints indicates at least one message (the
1309
    //   message with the highest numbered UID), unless the
1310
    //   mailbox is empty.
1311
    //
1312
    //   The number after the "*" in an untagged FETCH response is always a
1313
    //   message sequence number, not a unique identifier, even for a UID
1314
    //   command response.  However, server implementations MUST implicitly
1315
    //   include the UID message data item as part of any FETCH response
1316
    //   caused by a UID command, regardless of whether a UID was specified
1317
    //   as a message data item to the FETCH.
1318
    //
1319
    //   Note: The rule about including the UID message data item as part
1320
    //   of a FETCH response primarily applies to the UID FETCH and UID
1321
    //   STORE commands, including a UID FETCH command that does not
1322
    //   include UID as a message data item.  Although it is unlikely that
1323
    //   the other UID commands will cause an untagged FETCH, this rule
1324
    //   applies to these commands as well.
1325

1326
    // ----- Experimental/Expansion (https://tools.ietf.org/html/rfc3501#section-6.5) -----
1327

1328
    // ### 6.5.1.  X<atom> Command
1329
    //
1330
    // * Arguments:  implementation defined
1331
    // * Responses:  implementation defined
1332
    // * Result:
1333
    //   * OK - command completed
1334
    //   * NO - failure
1335
    //   * BAD - command unknown or arguments invalid
1336
    //
1337
    // Any command prefixed with an X is an experimental command.
1338
    // Commands which are not part of this specification, a standard or
1339
    // standards-track revision of this specification, or an
1340
    // IESG-approved experimental protocol, MUST use the X prefix.
1341
    //
1342
    // Any added untagged responses issued by an experimental command
1343
    // MUST also be prefixed with an X.  Server implementations MUST NOT
1344
    // send any such untagged responses, unless the client requested it
1345
    // by issuing the associated experimental command.
1346
    //X,
1347
    /// IDLE command.
1348
    ///
1349
    /// <div class="warning">
1350
    /// This extension must only be used when the server advertised support for it sending the IDLE capability.
1351
    /// </div>
1352
    Idle,
1353

1354
    /// ENABLE command.
1355
    ///
1356
    /// <div class="warning">
1357
    /// This extension must only be used when the server advertised support for it sending the ENABLE capability.
1358
    /// </div>
1359
    Enable {
1360
        /// Capabilities to enable.
1361
        capabilities: Vec1<CapabilityEnable<'a>>,
1362
    },
1363

1364
    /// COMPRESS command.
1365
    ///
1366
    /// <div class="warning">
1367
    /// This extension must only be used when the server advertised support for it sending the COMPRESS capability.
1368
    /// </div>
1369
    Compress {
1370
        /// Compression algorithm.
1371
        algorithm: CompressionAlgorithm,
1372
    },
1373

1374
    /// Takes the name of a quota root and returns the quota root's resource usage and limits in an untagged QUOTA response.
1375
    ///
1376
    /// Arguments:
1377
    /// * quota root
1378
    ///
1379
    /// Responses:
1380
    /// * REQUIRED untagged responses: QUOTA
1381
    ///
1382
    /// Result:
1383
    /// * OK - getquota completed
1384
    /// * NO - getquota error: no such quota root, permission denied
1385
    /// * BAD - command unknown or arguments invalid
1386
    ///
1387
    /// # Example (IMAP)
1388
    ///
1389
    /// ```imap
1390
    /// S: * CAPABILITY [...] QUOTA QUOTA=RES-STORAGE [...]
1391
    /// [...]
1392
    /// C: G0001 GETQUOTA "!partition/sda4"
1393
    /// S: * QUOTA "!partition/sda4" (STORAGE 104 10923847)
1394
    /// S: G0001 OK Getquota complete
1395
    /// ```
1396
    ///
1397
    /// <div class="warning">
1398
    /// This extension must only be used when the server advertised support for it sending the QUOTA* capability.
1399
    /// </div>
1400
    GetQuota {
1401
        /// Name of quota root.
1402
        root: AString<'a>,
1403
    },
1404

1405
    /// Takes a mailbox name and returns the list of quota roots for the mailbox in an untagged QUOTAROOT response.
1406
    /// For each listed quota root, it also returns the quota root's resource usage and limits in an untagged QUOTA response.
1407
    ///
1408
    /// Arguments:
1409
    /// * mailbox name
1410
    ///
1411
    /// Responses:
1412
    /// * REQUIRED untagged responses: QUOTAROOT, QUOTA
1413
    ///
1414
    /// Result:
1415
    /// * OK - getquotaroot completed
1416
    /// * NO - getquotaroot error: permission denied
1417
    /// * BAD - command unknown or arguments invalid
1418
    ///
1419
    /// Note that the mailbox name parameter doesn't have to reference an existing mailbox.
1420
    /// This can be handy in order to determine which quota root would apply to a mailbox when it gets created
1421
    ///
1422
    /// # Example (IMAP)
1423
    ///
1424
    /// ```imap
1425
    /// S: * CAPABILITY [...] QUOTA QUOTA=RES-STORAGE QUOTA=RES-MESSAGE
1426
    /// [...]
1427
    /// C: G0002 GETQUOTAROOT INBOX
1428
    /// S: * QUOTAROOT INBOX "#user/alice" "!partition/sda4"
1429
    /// S: * QUOTA "#user/alice" (MESSAGE 42 1000)
1430
    /// S: * QUOTA "!partition/sda4" (STORAGE 104 10923847)
1431
    /// S: G0002 OK Getquotaroot complete
1432
    /// ```
1433
    ///
1434
    /// <div class="warning">
1435
    /// This extension must only be used when the server advertised support for it sending the QUOTA* capability.
1436
    /// </div>
1437
    GetQuotaRoot {
1438
        /// Name of mailbox.
1439
        mailbox: Mailbox<'a>,
1440
    },
1441

1442
    /// Changes the mailbox quota root resource limits to the specified limits.
1443
    ///
1444
    /// Arguments:
1445
    /// * quota root list of resource limits
1446
    ///
1447
    /// Responses:
1448
    /// * untagged responses: QUOTA
1449
    ///
1450
    /// Result:
1451
    ///
1452
    /// * OK - setquota completed
1453
    /// * NO - setquota error: can't set that data
1454
    /// * BAD - command unknown or arguments invalid
1455
    ///
1456
    /// Note: requires the server to advertise the "QUOTASET" capability.
1457
    ///
1458
    /// # Example (IMAP)
1459
    ///
1460
    /// ```imap
1461
    /// S: * CAPABILITY [...] QUOTA QUOTASET QUOTA=RES-STORAGE QUOTA=RES-
1462
    /// MESSAGE [...]
1463
    /// [...]
1464
    /// C: S0000 GETQUOTA "#user/alice"
1465
    /// S: * QUOTA "#user/alice" (STORAGE 54 111 MESSAGE 42 1000)
1466
    /// S: S0000 OK Getquota completed
1467
    /// C: S0001 SETQUOTA "#user/alice" (STORAGE 510)
1468
    /// S: * QUOTA "#user/alice" (STORAGE 58 512)
1469
    /// // The server has rounded the STORAGE quota limit requested to
1470
    /// the nearest 512 blocks of 1024 octets; otherwise, another client
1471
    /// has performed a near-simultaneous SETQUOTA using a limit of 512.
1472
    /// S: S0001 OK Rounded quota
1473
    /// C: S0002 SETQUOTA "!partition/sda4" (STORAGE 99999999)
1474
    /// S: * QUOTA "!partition/sda4" (STORAGE 104 10923847)
1475
    /// // The server has not changed the quota, since this is a
1476
    /// filesystem limit, and it cannot be changed. The QUOTA
1477
    /// response here is entirely optional.
1478
    /// S: S0002 NO Cannot change system limit
1479
    /// ```
1480
    ///
1481
    /// <div class="warning">
1482
    /// This extension must only be used when the server advertised support for it sending the QUOTA* capability.
1483
    /// </div>
1484
    SetQuota {
1485
        /// Name of quota root.
1486
        root: AString<'a>,
1487
        /// List of resource limits.
1488
        quotas: Vec<QuotaSet<'a>>,
1489
    },
1490

1491
    /// MOVE command.
1492
    ///
1493
    /// <div class="warning">
1494
    /// This extension must only be used when the server advertised support for it sending the MOVE capability.
1495
    /// </div>
1496
    Move {
1497
        /// Set of messages.
1498
        sequence_set: SequenceSet,
1499
        /// Destination mailbox.
1500
        mailbox: Mailbox<'a>,
1501
        /// Use UID variant.
1502
        uid: bool,
1503
    },
1504

1505
    #[cfg(feature = "ext_id")]
1506
    /// ID command.
1507
    ///
1508
    /// <div class="warning">
1509
    /// This extension must only be used when the server advertised support for it sending the ID capability.
1510
    /// </div>
1511
    Id {
1512
        /// Parameters.
1513
        parameters: Option<Vec<(IString<'a>, NString<'a>)>>,
1514
    },
1515

1516
    #[cfg(feature = "ext_metadata")]
1517
    /// Set annotation(s).
1518
    ///
1519
    /// <div class="warning">
1520
    /// This extension must only be used when the server advertised support for it sending the METADATA* capability.
1521
    /// </div>
1522
    SetMetadata {
1523
        mailbox: Mailbox<'a>,
1524
        entry_values: Vec1<EntryValue<'a>>,
1525
    },
1526

1527
    #[cfg(feature = "ext_metadata")]
1528
    /// Retrieve server or mailbox annotation(s).
1529
    ///
1530
    /// <div class="warning">
1531
    /// This extension must only be used when the server advertised support for it sending the METADATA* capability.
1532
    /// </div>
1533
    GetMetadata {
1534
        options: Vec<GetMetadataOption>,
1535
        mailbox: Mailbox<'a>,
1536
        entries: Vec1<Entry<'a>>,
1537
    },
1538

1539
    #[cfg(feature = "ext_namespace")]
1540
    /// Retrieve the namespaces available to the client.
1541
    ///
1542
    /// <div class="warning">
1543
    /// This extension must only be used when the server advertised support for it sending the NAMESPACE capability.
1544
    /// </div>
1545
    Namespace,
1546
}
1547

1548
impl<'a> CommandBody<'a> {
1549
    /// Prepend a tag to finalize the command body to a command.
1550
    pub fn tag<T>(self, tag: T) -> Result<Command<'a>, T::Error>
120✔
1551
    where
120✔
1552
        T: TryInto<Tag<'a>>,
120✔
1553
    {
1554
        Ok(Command {
1555
            tag: tag.try_into()?,
120✔
1556
            body: self,
120✔
1557
        })
1558
    }
120✔
1559

1560
    // ----- Constructors -----
1561

1562
    /// Construct an AUTHENTICATE command.
1563
    pub fn authenticate(mechanism: AuthMechanism<'a>) -> Self {
30✔
1564
        CommandBody::Authenticate {
30✔
1565
            mechanism,
30✔
1566
            initial_response: None,
30✔
1567
        }
30✔
1568
    }
30✔
1569

1570
    /// Construct an AUTHENTICATE command (with an initial response, SASL-IR).
1571
    ///
1572
    /// Note: Use this only when the server advertised the `SASL-IR` capability.
1573
    ///
1574
    /// <div class="warning">
1575
    /// This extension must only be used when the server advertised support for it sending the SASL-IR capability.
1576
    /// </div>
1577
    pub fn authenticate_with_ir<I>(mechanism: AuthMechanism<'a>, initial_response: I) -> Self
8✔
1578
    where
8✔
1579
        I: Into<Cow<'a, [u8]>>,
8✔
1580
    {
1581
        CommandBody::Authenticate {
8✔
1582
            mechanism,
8✔
1583
            initial_response: Some(Secret::new(initial_response.into())),
8✔
1584
        }
8✔
1585
    }
8✔
1586

1587
    /// Construct a LOGIN command.
1588
    pub fn login<U, P>(username: U, password: P) -> Result<Self, LoginError<U::Error, P::Error>>
50✔
1589
    where
50✔
1590
        U: TryInto<AString<'a>>,
50✔
1591
        P: TryInto<AString<'a>>,
50✔
1592
    {
1593
        Ok(CommandBody::Login {
1594
            username: username.try_into().map_err(LoginError::Username)?,
50✔
1595
            password: Secret::new(password.try_into().map_err(LoginError::Password)?),
44✔
1596
        })
1597
    }
50✔
1598

1599
    /// Construct a SELECT command.
1600
    pub fn select<M>(mailbox: M) -> Result<Self, M::Error>
14✔
1601
    where
14✔
1602
        M: TryInto<Mailbox<'a>>,
14✔
1603
    {
1604
        Ok(CommandBody::Select {
1605
            mailbox: mailbox.try_into()?,
14✔
1606
            #[cfg(feature = "ext_condstore_qresync")]
1607
            parameters: Vec::default(),
14✔
1608
        })
1609
    }
14✔
1610

1611
    /// Construct an EXAMINE command.
1612
    pub fn examine<M>(mailbox: M) -> Result<Self, M::Error>
12✔
1613
    where
12✔
1614
        M: TryInto<Mailbox<'a>>,
12✔
1615
    {
1616
        Ok(CommandBody::Examine {
1617
            mailbox: mailbox.try_into()?,
12✔
1618
            #[cfg(feature = "ext_condstore_qresync")]
1619
            parameters: Vec::default(),
12✔
1620
        })
1621
    }
12✔
1622

1623
    /// Construct a CREATE command.
1624
    pub fn create<M>(mailbox: M) -> Result<Self, M::Error>
2✔
1625
    where
2✔
1626
        M: TryInto<Mailbox<'a>>,
2✔
1627
    {
1628
        Ok(CommandBody::Create {
1629
            mailbox: mailbox.try_into()?,
2✔
1630
        })
1631
    }
2✔
1632

1633
    /// Construct a DELETE command.
1634
    pub fn delete<M>(mailbox: M) -> Result<Self, M::Error>
2✔
1635
    where
2✔
1636
        M: TryInto<Mailbox<'a>>,
2✔
1637
    {
1638
        Ok(CommandBody::Delete {
1639
            mailbox: mailbox.try_into()?,
2✔
1640
        })
1641
    }
2✔
1642

1643
    /// Construct a RENAME command.
1644
    pub fn rename<F, T>(mailbox: F, new_mailbox: T) -> Result<Self, RenameError<F::Error, T::Error>>
2✔
1645
    where
2✔
1646
        F: TryInto<Mailbox<'a>>,
2✔
1647
        T: TryInto<Mailbox<'a>>,
2✔
1648
    {
1649
        Ok(CommandBody::Rename {
1650
            from: mailbox.try_into().map_err(RenameError::From)?,
2✔
1651
            to: new_mailbox.try_into().map_err(RenameError::To)?,
2✔
1652
        })
1653
    }
2✔
1654

1655
    /// Construct a SUBSCRIBE command.
1656
    pub fn subscribe<M>(mailbox: M) -> Result<Self, M::Error>
2✔
1657
    where
2✔
1658
        M: TryInto<Mailbox<'a>>,
2✔
1659
    {
1660
        Ok(CommandBody::Subscribe {
1661
            mailbox: mailbox.try_into()?,
2✔
1662
        })
1663
    }
2✔
1664

1665
    /// Construct an UNSUBSCRIBE command.
1666
    pub fn unsubscribe<M>(mailbox: M) -> Result<Self, M::Error>
2✔
1667
    where
2✔
1668
        M: TryInto<Mailbox<'a>>,
2✔
1669
    {
1670
        Ok(CommandBody::Unsubscribe {
1671
            mailbox: mailbox.try_into()?,
2✔
1672
        })
1673
    }
2✔
1674

1675
    /// Construct a LIST command.
1676
    pub fn list<A, B>(
6✔
1677
        reference: A,
6✔
1678
        mailbox_wildcard: B,
6✔
1679
    ) -> Result<Self, ListError<A::Error, B::Error>>
6✔
1680
    where
6✔
1681
        A: TryInto<Mailbox<'a>>,
6✔
1682
        B: TryInto<ListMailbox<'a>>,
6✔
1683
    {
1684
        Ok(CommandBody::List {
1685
            reference: reference.try_into().map_err(ListError::Reference)?,
6✔
1686
            mailbox_wildcard: mailbox_wildcard.try_into().map_err(ListError::Mailbox)?,
6✔
1687
        })
1688
    }
6✔
1689

1690
    /// Construct a LSUB command.
1691
    pub fn lsub<A, B>(
4✔
1692
        reference: A,
4✔
1693
        mailbox_wildcard: B,
4✔
1694
    ) -> Result<Self, ListError<A::Error, B::Error>>
4✔
1695
    where
4✔
1696
        A: TryInto<Mailbox<'a>>,
4✔
1697
        B: TryInto<ListMailbox<'a>>,
4✔
1698
    {
1699
        Ok(CommandBody::Lsub {
1700
            reference: reference.try_into().map_err(ListError::Reference)?,
4✔
1701
            mailbox_wildcard: mailbox_wildcard.try_into().map_err(ListError::Mailbox)?,
4✔
1702
        })
1703
    }
4✔
1704

1705
    /// Construct a STATUS command.
1706
    pub fn status<M, I>(mailbox: M, item_names: I) -> Result<Self, M::Error>
4✔
1707
    where
4✔
1708
        M: TryInto<Mailbox<'a>>,
4✔
1709
        I: Into<Cow<'a, [StatusDataItemName]>>,
4✔
1710
    {
1711
        let mailbox = mailbox.try_into()?;
4✔
1712

1713
        Ok(CommandBody::Status {
4✔
1714
            mailbox,
4✔
1715
            item_names: item_names.into(),
4✔
1716
        })
4✔
1717
    }
4✔
1718

1719
    /// Construct an APPEND command.
1720
    pub fn append<M, D>(
4✔
1721
        mailbox: M,
4✔
1722
        flags: Vec<Flag<'a>>,
4✔
1723
        date: Option<DateTime>,
4✔
1724
        message: D,
4✔
1725
    ) -> Result<Self, AppendError<M::Error, D::Error>>
4✔
1726
    where
4✔
1727
        M: TryInto<Mailbox<'a>>,
4✔
1728
        D: TryInto<Literal<'a>>,
4✔
1729
    {
1730
        Ok(CommandBody::Append {
1731
            mailbox: mailbox.try_into().map_err(AppendError::Mailbox)?,
4✔
1732
            flags,
4✔
1733
            date,
4✔
1734
            message: LiteralOrLiteral8::Literal(message.try_into().map_err(AppendError::Data)?),
4✔
1735
        })
1736
    }
4✔
1737

1738
    /// Construct a SEARCH command.
1739
    pub fn search(charset: Option<Charset<'a>>, criteria: Vec1<SearchKey<'a>>, uid: bool) -> Self {
14✔
1740
        CommandBody::Search {
14✔
1741
            charset,
14✔
1742
            criteria,
14✔
1743
            uid,
14✔
1744
        }
14✔
1745
    }
14✔
1746

1747
    /// Construct a FETCH command.
1748
    pub fn fetch<S, I>(sequence_set: S, macro_or_item_names: I, uid: bool) -> Result<Self, S::Error>
8✔
1749
    where
8✔
1750
        S: TryInto<SequenceSet>,
8✔
1751
        I: Into<MacroOrMessageDataItemNames<'a>>,
8✔
1752
    {
1753
        let sequence_set = sequence_set.try_into()?;
8✔
1754

1755
        Ok(CommandBody::Fetch {
8✔
1756
            sequence_set,
8✔
1757
            macro_or_item_names: macro_or_item_names.into(),
8✔
1758
            uid,
8✔
1759
            #[cfg(feature = "ext_condstore_qresync")]
8✔
1760
            modifiers: Vec::default(),
8✔
1761
        })
8✔
1762
    }
8✔
1763

1764
    /// Construct a STORE command.
1765
    pub fn store<S>(
6✔
1766
        sequence_set: S,
6✔
1767
        kind: StoreType,
6✔
1768
        response: StoreResponse,
6✔
1769
        flags: Vec<Flag<'a>>,
6✔
1770
        uid: bool,
6✔
1771
    ) -> Result<Self, S::Error>
6✔
1772
    where
6✔
1773
        S: TryInto<SequenceSet>,
6✔
1774
    {
1775
        let sequence_set = sequence_set.try_into()?;
6✔
1776

1777
        Ok(CommandBody::Store {
6✔
1778
            sequence_set,
6✔
1779
            kind,
6✔
1780
            response,
6✔
1781
            flags,
6✔
1782
            uid,
6✔
1783
            #[cfg(feature = "ext_condstore_qresync")]
6✔
1784
            modifiers: Vec::default(),
6✔
1785
        })
6✔
1786
    }
6✔
1787

1788
    /// Construct a COPY command.
1789
    pub fn copy<S, M>(
4✔
1790
        sequence_set: S,
4✔
1791
        mailbox: M,
4✔
1792
        uid: bool,
4✔
1793
    ) -> Result<Self, CopyError<S::Error, M::Error>>
4✔
1794
    where
4✔
1795
        S: TryInto<SequenceSet>,
4✔
1796
        M: TryInto<Mailbox<'a>>,
4✔
1797
    {
1798
        Ok(CommandBody::Copy {
1799
            sequence_set: sequence_set.try_into().map_err(CopyError::Sequence)?,
4✔
1800
            mailbox: mailbox.try_into().map_err(CopyError::Mailbox)?,
4✔
1801
            uid,
4✔
1802
        })
1803
    }
4✔
1804

1805
    /// Get the name of the command.
1806
    pub fn name(&self) -> &'static str {
66✔
1807
        match self {
66✔
1808
            Self::Capability => "CAPABILITY",
2✔
1809
            Self::Noop => "NOOP",
2✔
1810
            Self::Logout => "LOGOUT",
2✔
1811
            #[cfg(feature = "starttls")]
1812
            Self::StartTLS => "STARTTLS",
2✔
1813
            Self::Authenticate { .. } => "AUTHENTICATE",
2✔
1814
            Self::Login { .. } => "LOGIN",
2✔
1815
            Self::Select { .. } => "SELECT",
2✔
1816
            Self::Sort { .. } => "SORT",
×
1817
            Self::Thread { .. } => "THREAD",
×
1818
            Self::Unselect => "UNSELECT",
2✔
1819
            Self::Examine { .. } => "EXAMINE",
2✔
1820
            Self::Create { .. } => "CREATE",
2✔
1821
            Self::Delete { .. } => "DELETE",
2✔
1822
            Self::Rename { .. } => "RENAME",
2✔
1823
            Self::Subscribe { .. } => "SUBSCRIBE",
2✔
1824
            Self::Unsubscribe { .. } => "UNSUBSCRIBE",
2✔
1825
            Self::List { .. } => "LIST",
2✔
1826
            Self::Lsub { .. } => "LSUB",
2✔
1827
            Self::Status { .. } => "STATUS",
2✔
1828
            Self::Append { .. } => "APPEND",
4✔
1829
            Self::Check => "CHECK",
2✔
1830
            Self::Close => "CLOSE",
2✔
1831
            Self::Expunge => "EXPUNGE",
2✔
1832
            Self::ExpungeUid { .. } => "EXPUNGE",
×
1833
            Self::Search { .. } => "SEARCH",
2✔
1834
            Self::Fetch { .. } => "FETCH",
2✔
1835
            Self::Store { .. } => "STORE",
2✔
1836
            Self::Copy { .. } => "COPY",
2✔
1837
            Self::Idle => "IDLE",
2✔
1838
            Self::Enable { .. } => "ENABLE",
2✔
1839
            Self::Compress { .. } => "COMPRESS",
2✔
1840
            Self::GetQuota { .. } => "GETQUOTA",
2✔
1841
            Self::GetQuotaRoot { .. } => "GETQUOTAROOT",
2✔
1842
            Self::SetQuota { .. } => "SETQUOTA",
2✔
1843
            Self::Move { .. } => "MOVE",
2✔
1844
            #[cfg(feature = "ext_id")]
1845
            Self::Id { .. } => "ID",
×
1846
            #[cfg(feature = "ext_metadata")]
1847
            Self::SetMetadata { .. } => "SETMETADATA",
×
1848
            #[cfg(feature = "ext_metadata")]
1849
            Self::GetMetadata { .. } => "GETMETADATA",
×
1850
            #[cfg(feature = "ext_namespace")]
NEW
1851
            Self::Namespace => "NAMESPACE",
×
1852
        }
1853
    }
66✔
1854
}
1855

1856
#[cfg(feature = "ext_condstore_qresync")]
1857
#[cfg_attr(docsrs, doc(cfg("ext_condstore_qresync")))]
1858
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
1859
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1860
#[derive(Debug, Clone, PartialEq, Eq, Hash, ToStatic)]
1861
pub enum SelectParameter {
1862
    CondStore,
1863
    QResync {
1864
        uid_validity: NonZeroU32,
1865
        mod_sequence_value: NonZeroU64,
1866
        known_uids: Option<SequenceSet>, // TODO(misuse): "*" is not allowed.
1867
        seq_match_data: Option<(SequenceSet, SequenceSet)>, // TODO(misuse): ensure both have the same length?
1868
    },
1869
}
1870

1871
#[cfg(feature = "ext_condstore_qresync")]
1872
#[cfg_attr(docsrs, doc(cfg("ext_condstore_qresync")))]
1873
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
1874
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1875
#[derive(Debug, Clone, PartialEq, Eq, Hash, ToStatic)]
1876
pub enum FetchModifier {
1877
    ChangedSince(NonZeroU64),
1878
    Vanished,
1879
}
1880

1881
#[cfg(feature = "ext_condstore_qresync")]
1882
#[cfg_attr(docsrs, doc(cfg("ext_condstore_qresync")))]
1883
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
1884
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1885
#[derive(Debug, Clone, PartialEq, Eq, Hash, ToStatic)]
1886
pub enum StoreModifier {
1887
    UnchangedSince(u64),
1888
}
1889

1890
/// Error-related types.
1891
pub mod error {
1892
    use thiserror::Error;
1893

1894
    #[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
1895
    pub enum LoginError<U, P> {
1896
        #[error("Invalid username: {0}")]
1897
        Username(U),
1898
        #[error("Invalid password: {0}")]
1899
        Password(P),
1900
    }
1901

1902
    #[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
1903
    pub enum RenameError<F, T> {
1904
        #[error("Invalid (from) mailbox: {0}")]
1905
        From(F),
1906
        #[error("Invalid (to) mailbox: {0}")]
1907
        To(T),
1908
    }
1909

1910
    #[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
1911
    pub enum ListError<R, M> {
1912
        #[error("Invalid reference: {0}")]
1913
        Reference(R),
1914
        #[error("Invalid mailbox: {0}")]
1915
        Mailbox(M),
1916
    }
1917

1918
    #[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
1919
    pub enum AppendError<M, D> {
1920
        #[error("Invalid mailbox: {0}")]
1921
        Mailbox(M),
1922
        #[error("Invalid data: {0}")]
1923
        Data(D),
1924
    }
1925

1926
    #[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
1927
    pub enum CopyError<S, M> {
1928
        #[error("Invalid sequence: {0}")]
1929
        Sequence(S),
1930
        #[error("Invalid mailbox: {0}")]
1931
        Mailbox(M),
1932
    }
1933
}
1934

1935
#[cfg(test)]
1936
mod tests {
1937
    use chrono::DateTime as ChronoDateTime;
1938

1939
    use super::*;
1940
    #[cfg(feature = "ext_utf8")]
1941
    use crate::extensions::{enable::CapabilityEnable, utf8::Utf8Kind};
1942
    use crate::{
1943
        auth::AuthMechanism,
1944
        core::{AString, Charset, IString, Literal, LiteralMode, Vec1},
1945
        datetime::DateTime,
1946
        extensions::{binary::Literal8, compress::CompressionAlgorithm},
1947
        fetch::{Macro, MacroOrMessageDataItemNames, MessageDataItemName, Part, Section},
1948
        flag::{Flag, StoreType},
1949
        mailbox::{ListMailbox, Mailbox},
1950
        search::SearchKey,
1951
        secret::Secret,
1952
        sequence::{SeqOrUid, Sequence, SequenceSet},
1953
        status::StatusDataItemName,
1954
    };
1955

1956
    #[test]
1957
    fn test_conversion_command_body() {
2✔
1958
        let cmds = vec![
2✔
1959
            CommandBody::Capability,
2✔
1960
            CommandBody::Noop,
2✔
1961
            CommandBody::Logout,
2✔
1962
            #[cfg(feature = "starttls")]
1963
            CommandBody::StartTLS,
2✔
1964
            CommandBody::authenticate(AuthMechanism::Plain),
2✔
1965
            CommandBody::authenticate(AuthMechanism::Login),
2✔
1966
            CommandBody::authenticate_with_ir(AuthMechanism::Plain, b"XXXXXXXX".as_ref()),
2✔
1967
            CommandBody::authenticate_with_ir(AuthMechanism::Login, b"YYYYYYYY".as_ref()),
2✔
1968
            CommandBody::login("alice", "I_am_an_atom").unwrap(),
2✔
1969
            CommandBody::login("alice", "I am \\ \"quoted\"").unwrap(),
2✔
1970
            CommandBody::login("alice", "I am a literal²").unwrap(),
2✔
1971
            CommandBody::login(
2✔
1972
                AString::Atom("alice".try_into().unwrap()),
2✔
1973
                AString::String(crate::core::IString::Literal(
2✔
1974
                    vec![0xff, 0xff, 0xff].try_into().unwrap(),
2✔
1975
                )),
2✔
1976
            )
1977
            .unwrap(),
2✔
1978
            CommandBody::select("inbox").unwrap(),
2✔
1979
            CommandBody::select("atom").unwrap(),
2✔
1980
            CommandBody::select("C:\\").unwrap(),
2✔
1981
            CommandBody::select("²").unwrap(),
2✔
1982
            CommandBody::select("Trash").unwrap(),
2✔
1983
            CommandBody::examine("inbox").unwrap(),
2✔
1984
            CommandBody::examine("atom").unwrap(),
2✔
1985
            CommandBody::examine("C:\\").unwrap(),
2✔
1986
            CommandBody::examine("²").unwrap(),
2✔
1987
            CommandBody::examine("Trash").unwrap(),
2✔
1988
            CommandBody::create("inBoX").unwrap(),
2✔
1989
            CommandBody::delete("inBOX").unwrap(),
2✔
1990
            CommandBody::rename("iNBoS", "INboX").unwrap(),
2✔
1991
            CommandBody::subscribe("inbox").unwrap(),
2✔
1992
            CommandBody::unsubscribe("INBOX").unwrap(),
2✔
1993
            CommandBody::list("iNbOx", "test").unwrap(),
2✔
1994
            CommandBody::list("inbox", ListMailbox::Token("test".try_into().unwrap())).unwrap(),
2✔
1995
            CommandBody::lsub(
2✔
1996
                "inbox",
1997
                ListMailbox::String(IString::Quoted("\x7f".try_into().unwrap())),
2✔
1998
            )
1999
            .unwrap(),
2✔
2000
            CommandBody::list("inBoX", ListMailbox::Token("test".try_into().unwrap())).unwrap(),
2✔
2001
            CommandBody::lsub(
2✔
2002
                "INBOX",
2003
                ListMailbox::String(IString::Quoted("\x7f".try_into().unwrap())),
2✔
2004
            )
2005
            .unwrap(),
2✔
2006
            CommandBody::status("inbox", vec![StatusDataItemName::Messages]).unwrap(),
2✔
2007
            CommandBody::append(
2✔
2008
                "inbox",
2009
                vec![],
2✔
2010
                Some(
2✔
2011
                    DateTime::try_from(
2✔
2012
                        ChronoDateTime::parse_from_rfc2822("Tue, 1 Jul 2003 10:52:37 +0200")
2✔
2013
                            .unwrap(),
2✔
2014
                    )
2✔
2015
                    .unwrap(),
2✔
2016
                ),
2✔
2017
                vec![0xff, 0xff, 0xff],
2✔
2018
            )
2019
            .unwrap(),
2✔
2020
            CommandBody::append(
2✔
2021
                "inbox",
2022
                vec![Flag::Keyword("test".try_into().unwrap())],
2✔
2023
                Some(
2✔
2024
                    DateTime::try_from(
2✔
2025
                        ChronoDateTime::parse_from_rfc2822("Tue, 1 Jul 2003 10:52:37 +0200")
2✔
2026
                            .unwrap(),
2✔
2027
                    )
2✔
2028
                    .unwrap(),
2✔
2029
                ),
2✔
2030
                vec![0xff, 0xff, 0xff],
2✔
2031
            )
2032
            .unwrap(),
2✔
2033
            CommandBody::Check,
2✔
2034
            CommandBody::Close,
2✔
2035
            CommandBody::Expunge,
2✔
2036
            CommandBody::search(
2✔
2037
                None,
2✔
2038
                Vec1::from(SearchKey::And(
2✔
2039
                    vec![SearchKey::All, SearchKey::New, SearchKey::Unseen]
2✔
2040
                        .try_into()
2✔
2041
                        .unwrap(),
2✔
2042
                )),
2✔
2043
                false,
2044
            ),
2045
            CommandBody::search(
2✔
2046
                None,
2✔
2047
                Vec1::from(SearchKey::And(
2✔
2048
                    vec![SearchKey::All, SearchKey::New, SearchKey::Unseen]
2✔
2049
                        .try_into()
2✔
2050
                        .unwrap(),
2✔
2051
                )),
2✔
2052
                true,
2053
            ),
2054
            CommandBody::search(
2✔
2055
                None,
2✔
2056
                Vec1::from(SearchKey::And(
2✔
2057
                    vec![SearchKey::SequenceSet(SequenceSet(
2✔
2058
                        vec![Sequence::Single(SeqOrUid::Value(42.try_into().unwrap()))]
2✔
2059
                            .try_into()
2✔
2060
                            .unwrap(),
2✔
2061
                    ))]
2✔
2062
                    .try_into()
2✔
2063
                    .unwrap(),
2✔
2064
                )),
2✔
2065
                true,
2066
            ),
2067
            CommandBody::search(
2✔
2068
                None,
2✔
2069
                Vec1::from(SearchKey::SequenceSet("42".try_into().unwrap())),
2✔
2070
                true,
2071
            ),
2072
            CommandBody::search(
2✔
2073
                None,
2✔
2074
                Vec1::from(SearchKey::SequenceSet("*".try_into().unwrap())),
2✔
2075
                true,
2076
            ),
2077
            CommandBody::search(
2✔
2078
                None,
2✔
2079
                Vec1::from(SearchKey::Or(
2✔
2080
                    Box::new(SearchKey::Draft),
2✔
2081
                    Box::new(SearchKey::All),
2✔
2082
                )),
2✔
2083
                true,
2084
            ),
2085
            CommandBody::search(
2✔
2086
                Some(Charset::try_from("UTF-8").unwrap()),
2✔
2087
                Vec1::from(SearchKey::Or(
2✔
2088
                    Box::new(SearchKey::Draft),
2✔
2089
                    Box::new(SearchKey::All),
2✔
2090
                )),
2✔
2091
                true,
2092
            ),
2093
            CommandBody::fetch(
2✔
2094
                "1",
2095
                vec![MessageDataItemName::BodyExt {
2✔
2096
                    partial: None,
2✔
2097
                    section: Some(Section::Part(Part(
2✔
2098
                        vec![1.try_into().unwrap(), 1.try_into().unwrap()]
2✔
2099
                            .try_into()
2✔
2100
                            .unwrap(),
2✔
2101
                    ))),
2✔
2102
                    peek: true,
2✔
2103
                }],
2✔
2104
                false,
2105
            )
2106
            .unwrap(),
2✔
2107
            CommandBody::fetch("1:*,2,3", Macro::Full, true).unwrap(),
2✔
2108
            CommandBody::store(
2✔
2109
                "1,2:*",
2110
                StoreType::Remove,
2✔
2111
                StoreResponse::Answer,
2✔
2112
                vec![Flag::Seen, Flag::Draft],
2✔
2113
                false,
2114
            )
2115
            .unwrap(),
2✔
2116
            CommandBody::store(
2✔
2117
                "1:5",
2118
                StoreType::Add,
2✔
2119
                StoreResponse::Answer,
2✔
2120
                vec![Flag::Keyword("TEST".try_into().unwrap())],
2✔
2121
                true,
2122
            )
2123
            .unwrap(),
2✔
2124
            CommandBody::copy("1", "inbox", false).unwrap(),
2✔
2125
            CommandBody::copy("1337", "archive", true).unwrap(),
2✔
2126
        ];
2127

2128
        for (no, cmd_body) in cmds.into_iter().enumerate() {
102✔
2129
            println!("Test: {no}, {cmd_body:?}");
102✔
2130

102✔
2131
            let _ = cmd_body.tag(format!("A{no}")).unwrap();
102✔
2132
        }
102✔
2133
    }
2✔
2134

2135
    #[test]
2136
    fn test_command_body_name() {
2✔
2137
        let tests = [
2✔
2138
            (CommandBody::Capability, "CAPABILITY"),
2✔
2139
            (CommandBody::Noop, "NOOP"),
2✔
2140
            (CommandBody::Logout, "LOGOUT"),
2✔
2141
            #[cfg(feature = "starttls")]
2✔
2142
            (CommandBody::StartTLS, "STARTTLS"),
2✔
2143
            (
2✔
2144
                CommandBody::Authenticate {
2✔
2145
                    mechanism: AuthMechanism::Plain,
2✔
2146
                    initial_response: None,
2✔
2147
                },
2✔
2148
                "AUTHENTICATE",
2✔
2149
            ),
2✔
2150
            (
2✔
2151
                CommandBody::Login {
2✔
2152
                    username: AString::try_from("user").unwrap(),
2✔
2153
                    password: Secret::new(AString::try_from("pass").unwrap()),
2✔
2154
                },
2✔
2155
                "LOGIN",
2✔
2156
            ),
2✔
2157
            (
2✔
2158
                CommandBody::Select {
2✔
2159
                    mailbox: Mailbox::Inbox,
2✔
2160
                    #[cfg(feature = "ext_condstore_qresync")]
2✔
2161
                    parameters: Vec::default(),
2✔
2162
                },
2✔
2163
                "SELECT",
2✔
2164
            ),
2✔
2165
            (CommandBody::Unselect, "UNSELECT"),
2✔
2166
            (
2✔
2167
                CommandBody::Examine {
2✔
2168
                    mailbox: Mailbox::Inbox,
2✔
2169
                    #[cfg(feature = "ext_condstore_qresync")]
2✔
2170
                    parameters: Vec::default(),
2✔
2171
                },
2✔
2172
                "EXAMINE",
2✔
2173
            ),
2✔
2174
            (
2✔
2175
                CommandBody::Create {
2✔
2176
                    mailbox: Mailbox::Inbox,
2✔
2177
                },
2✔
2178
                "CREATE",
2✔
2179
            ),
2✔
2180
            (
2✔
2181
                CommandBody::Delete {
2✔
2182
                    mailbox: Mailbox::Inbox,
2✔
2183
                },
2✔
2184
                "DELETE",
2✔
2185
            ),
2✔
2186
            (
2✔
2187
                CommandBody::Rename {
2✔
2188
                    from: Mailbox::Inbox,
2✔
2189
                    to: Mailbox::Inbox,
2✔
2190
                },
2✔
2191
                "RENAME",
2✔
2192
            ),
2✔
2193
            (
2✔
2194
                CommandBody::Subscribe {
2✔
2195
                    mailbox: Mailbox::Inbox,
2✔
2196
                },
2✔
2197
                "SUBSCRIBE",
2✔
2198
            ),
2✔
2199
            (
2✔
2200
                CommandBody::Unsubscribe {
2✔
2201
                    mailbox: Mailbox::Inbox,
2✔
2202
                },
2✔
2203
                "UNSUBSCRIBE",
2✔
2204
            ),
2✔
2205
            (
2✔
2206
                CommandBody::List {
2✔
2207
                    reference: Mailbox::Inbox,
2✔
2208
                    mailbox_wildcard: ListMailbox::try_from("").unwrap(),
2✔
2209
                },
2✔
2210
                "LIST",
2✔
2211
            ),
2✔
2212
            (
2✔
2213
                CommandBody::Lsub {
2✔
2214
                    reference: Mailbox::Inbox,
2✔
2215
                    mailbox_wildcard: ListMailbox::try_from("").unwrap(),
2✔
2216
                },
2✔
2217
                "LSUB",
2✔
2218
            ),
2✔
2219
            (
2✔
2220
                CommandBody::Status {
2✔
2221
                    mailbox: Mailbox::Inbox,
2✔
2222
                    item_names: vec![].into(),
2✔
2223
                },
2✔
2224
                "STATUS",
2✔
2225
            ),
2✔
2226
            (
2✔
2227
                CommandBody::Append {
2✔
2228
                    mailbox: Mailbox::Inbox,
2✔
2229
                    flags: vec![],
2✔
2230
                    date: None,
2✔
2231
                    message: LiteralOrLiteral8::Literal(Literal::try_from("").unwrap()),
2✔
2232
                },
2✔
2233
                "APPEND",
2✔
2234
            ),
2✔
2235
            (
2✔
2236
                CommandBody::Append {
2✔
2237
                    mailbox: Mailbox::Inbox,
2✔
2238
                    flags: vec![],
2✔
2239
                    date: None,
2✔
2240
                    message: LiteralOrLiteral8::Literal8(Literal8 {
2✔
2241
                        data: b"Hello\x00World\x00".as_ref().into(),
2✔
2242
                        mode: LiteralMode::NonSync,
2✔
2243
                    }),
2✔
2244
                },
2✔
2245
                "APPEND",
2✔
2246
            ),
2✔
2247
            (CommandBody::Check, "CHECK"),
2✔
2248
            (CommandBody::Close, "CLOSE"),
2✔
2249
            (CommandBody::Expunge, "EXPUNGE"),
2✔
2250
            (
2✔
2251
                CommandBody::Search {
2✔
2252
                    charset: None,
2✔
2253
                    criteria: Vec1::from(SearchKey::Recent),
2✔
2254
                    uid: true,
2✔
2255
                },
2✔
2256
                "SEARCH",
2✔
2257
            ),
2✔
2258
            (
2✔
2259
                CommandBody::Fetch {
2✔
2260
                    sequence_set: SequenceSet::try_from(1u32).unwrap(),
2✔
2261
                    macro_or_item_names: MacroOrMessageDataItemNames::Macro(Macro::Full),
2✔
2262
                    uid: true,
2✔
2263
                    #[cfg(feature = "ext_condstore_qresync")]
2✔
2264
                    modifiers: Vec::default(),
2✔
2265
                },
2✔
2266
                "FETCH",
2✔
2267
            ),
2✔
2268
            (
2✔
2269
                CommandBody::Store {
2✔
2270
                    sequence_set: SequenceSet::try_from(1).unwrap(),
2✔
2271
                    flags: vec![],
2✔
2272
                    response: StoreResponse::Silent,
2✔
2273
                    kind: StoreType::Add,
2✔
2274
                    uid: true,
2✔
2275
                    #[cfg(feature = "ext_condstore_qresync")]
2✔
2276
                    modifiers: Vec::default(),
2✔
2277
                },
2✔
2278
                "STORE",
2✔
2279
            ),
2✔
2280
            (
2✔
2281
                CommandBody::Copy {
2✔
2282
                    sequence_set: SequenceSet::try_from(1).unwrap(),
2✔
2283
                    mailbox: Mailbox::Inbox,
2✔
2284
                    uid: true,
2✔
2285
                },
2✔
2286
                "COPY",
2✔
2287
            ),
2✔
2288
            (CommandBody::Idle, "IDLE"),
2✔
2289
            #[cfg(feature = "ext_utf8")]
2✔
2290
            (
2✔
2291
                CommandBody::Enable {
2✔
2292
                    capabilities: Vec1::from(CapabilityEnable::Utf8(Utf8Kind::Only)),
2✔
2293
                },
2✔
2294
                "ENABLE",
2✔
2295
            ),
2✔
2296
            (
2✔
2297
                CommandBody::Compress {
2✔
2298
                    algorithm: CompressionAlgorithm::Deflate,
2✔
2299
                },
2✔
2300
                "COMPRESS",
2✔
2301
            ),
2✔
2302
            (
2✔
2303
                CommandBody::GetQuota {
2✔
2304
                    root: AString::try_from("root").unwrap(),
2✔
2305
                },
2✔
2306
                "GETQUOTA",
2✔
2307
            ),
2✔
2308
            (
2✔
2309
                CommandBody::GetQuotaRoot {
2✔
2310
                    mailbox: Mailbox::Inbox,
2✔
2311
                },
2✔
2312
                "GETQUOTAROOT",
2✔
2313
            ),
2✔
2314
            (
2✔
2315
                CommandBody::SetQuota {
2✔
2316
                    root: AString::try_from("root").unwrap(),
2✔
2317
                    quotas: vec![],
2✔
2318
                },
2✔
2319
                "SETQUOTA",
2✔
2320
            ),
2✔
2321
            (
2✔
2322
                CommandBody::Move {
2✔
2323
                    sequence_set: SequenceSet::try_from(1).unwrap(),
2✔
2324
                    mailbox: Mailbox::Inbox,
2✔
2325
                    uid: true,
2✔
2326
                },
2✔
2327
                "MOVE",
2✔
2328
            ),
2✔
2329
        ];
2✔
2330

2331
        for (test, expected) in tests {
68✔
2332
            assert_eq!(test.name(), expected);
66✔
2333
        }
2334
    }
2✔
2335
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc