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

duesee / imap-codec / 12757105626

13 Jan 2025 10:16PM UTC coverage: 92.896% (-0.1%) from 93.011%
12757105626

push

github

duesee
docs: fix warning

11350 of 12218 relevant lines covered (92.9%)

904.56 hits per line

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

98.05
/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::NonZeroU64;
8

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

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

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

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

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

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

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

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

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

177
    /// ### 6.2.2.  AUTHENTICATE Command
178
    ///
179
    /// * Arguments:  authentication mechanism name
180
    /// * Responses:  continuation data can be requested
181
    /// * Result:
182
    ///   * OK - authenticate completed, now in authenticated state
183
    ///   * NO - authenticate failure: unsupported authentication
184
    ///          mechanism, credentials rejected
185
    ///   * BAD - command unknown or arguments invalid,
186
    ///           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
    },
402

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1536
impl<'a> CommandBody<'a> {
1537
    /// Prepend a tag to finalize the command body to a command.
1538
    pub fn tag<T>(self, tag: T) -> Result<Command<'a>, T::Error>
120✔
1539
    where
120✔
1540
        T: TryInto<Tag<'a>>,
120✔
1541
    {
120✔
1542
        Ok(Command {
120✔
1543
            tag: tag.try_into()?,
120✔
1544
            body: self,
120✔
1545
        })
1546
    }
120✔
1547

1548
    // ----- Constructors -----
1549

1550
    /// Construct an AUTHENTICATE command.
1551
    pub fn authenticate(mechanism: AuthMechanism<'a>) -> Self {
30✔
1552
        CommandBody::Authenticate {
30✔
1553
            mechanism,
30✔
1554
            initial_response: None,
30✔
1555
        }
30✔
1556
    }
30✔
1557

1558
    /// Construct an AUTHENTICATE command (with an initial response, SASL-IR).
1559
    ///
1560
    /// Note: Use this only when the server advertised the `SASL-IR` capability.
1561
    ///
1562
    /// <div class="warning">
1563
    /// This extension must only be used when the server advertised support for it sending the SASL-IR capability.
1564
    /// </div>
1565
    pub fn authenticate_with_ir<I>(mechanism: AuthMechanism<'a>, initial_response: I) -> Self
8✔
1566
    where
8✔
1567
        I: Into<Cow<'a, [u8]>>,
8✔
1568
    {
8✔
1569
        CommandBody::Authenticate {
8✔
1570
            mechanism,
8✔
1571
            initial_response: Some(Secret::new(initial_response.into())),
8✔
1572
        }
8✔
1573
    }
8✔
1574

1575
    /// Construct a LOGIN command.
1576
    pub fn login<U, P>(username: U, password: P) -> Result<Self, LoginError<U::Error, P::Error>>
50✔
1577
    where
50✔
1578
        U: TryInto<AString<'a>>,
50✔
1579
        P: TryInto<AString<'a>>,
50✔
1580
    {
50✔
1581
        Ok(CommandBody::Login {
50✔
1582
            username: username.try_into().map_err(LoginError::Username)?,
50✔
1583
            password: Secret::new(password.try_into().map_err(LoginError::Password)?),
44✔
1584
        })
1585
    }
50✔
1586

1587
    /// Construct a SELECT command.
1588
    pub fn select<M>(mailbox: M) -> Result<Self, M::Error>
14✔
1589
    where
14✔
1590
        M: TryInto<Mailbox<'a>>,
14✔
1591
    {
14✔
1592
        Ok(CommandBody::Select {
14✔
1593
            mailbox: mailbox.try_into()?,
14✔
1594
        })
1595
    }
14✔
1596

1597
    /// Construct an EXAMINE command.
1598
    pub fn examine<M>(mailbox: M) -> Result<Self, M::Error>
12✔
1599
    where
12✔
1600
        M: TryInto<Mailbox<'a>>,
12✔
1601
    {
12✔
1602
        Ok(CommandBody::Examine {
12✔
1603
            mailbox: mailbox.try_into()?,
12✔
1604
        })
1605
    }
12✔
1606

1607
    /// Construct a CREATE command.
1608
    pub fn create<M>(mailbox: M) -> Result<Self, M::Error>
2✔
1609
    where
2✔
1610
        M: TryInto<Mailbox<'a>>,
2✔
1611
    {
2✔
1612
        Ok(CommandBody::Create {
2✔
1613
            mailbox: mailbox.try_into()?,
2✔
1614
        })
1615
    }
2✔
1616

1617
    /// Construct a DELETE command.
1618
    pub fn delete<M>(mailbox: M) -> Result<Self, M::Error>
2✔
1619
    where
2✔
1620
        M: TryInto<Mailbox<'a>>,
2✔
1621
    {
2✔
1622
        Ok(CommandBody::Delete {
2✔
1623
            mailbox: mailbox.try_into()?,
2✔
1624
        })
1625
    }
2✔
1626

1627
    /// Construct a RENAME command.
1628
    pub fn rename<F, T>(mailbox: F, new_mailbox: T) -> Result<Self, RenameError<F::Error, T::Error>>
2✔
1629
    where
2✔
1630
        F: TryInto<Mailbox<'a>>,
2✔
1631
        T: TryInto<Mailbox<'a>>,
2✔
1632
    {
2✔
1633
        Ok(CommandBody::Rename {
2✔
1634
            from: mailbox.try_into().map_err(RenameError::From)?,
2✔
1635
            to: new_mailbox.try_into().map_err(RenameError::To)?,
2✔
1636
        })
1637
    }
2✔
1638

1639
    /// Construct a SUBSCRIBE command.
1640
    pub fn subscribe<M>(mailbox: M) -> Result<Self, M::Error>
2✔
1641
    where
2✔
1642
        M: TryInto<Mailbox<'a>>,
2✔
1643
    {
2✔
1644
        Ok(CommandBody::Subscribe {
2✔
1645
            mailbox: mailbox.try_into()?,
2✔
1646
        })
1647
    }
2✔
1648

1649
    /// Construct an UNSUBSCRIBE command.
1650
    pub fn unsubscribe<M>(mailbox: M) -> Result<Self, M::Error>
2✔
1651
    where
2✔
1652
        M: TryInto<Mailbox<'a>>,
2✔
1653
    {
2✔
1654
        Ok(CommandBody::Unsubscribe {
2✔
1655
            mailbox: mailbox.try_into()?,
2✔
1656
        })
1657
    }
2✔
1658

1659
    /// Construct a LIST command.
1660
    pub fn list<A, B>(
6✔
1661
        reference: A,
6✔
1662
        mailbox_wildcard: B,
6✔
1663
    ) -> Result<Self, ListError<A::Error, B::Error>>
6✔
1664
    where
6✔
1665
        A: TryInto<Mailbox<'a>>,
6✔
1666
        B: TryInto<ListMailbox<'a>>,
6✔
1667
    {
6✔
1668
        Ok(CommandBody::List {
6✔
1669
            reference: reference.try_into().map_err(ListError::Reference)?,
6✔
1670
            mailbox_wildcard: mailbox_wildcard.try_into().map_err(ListError::Mailbox)?,
6✔
1671
        })
1672
    }
6✔
1673

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

1689
    /// Construct a STATUS command.
1690
    pub fn status<M, I>(mailbox: M, item_names: I) -> Result<Self, M::Error>
4✔
1691
    where
4✔
1692
        M: TryInto<Mailbox<'a>>,
4✔
1693
        I: Into<Cow<'a, [StatusDataItemName]>>,
4✔
1694
    {
4✔
1695
        let mailbox = mailbox.try_into()?;
4✔
1696

1697
        Ok(CommandBody::Status {
4✔
1698
            mailbox,
4✔
1699
            item_names: item_names.into(),
4✔
1700
        })
4✔
1701
    }
4✔
1702

1703
    /// Construct an APPEND command.
1704
    pub fn append<M, D>(
4✔
1705
        mailbox: M,
4✔
1706
        flags: Vec<Flag<'a>>,
4✔
1707
        date: Option<DateTime>,
4✔
1708
        message: D,
4✔
1709
    ) -> Result<Self, AppendError<M::Error, D::Error>>
4✔
1710
    where
4✔
1711
        M: TryInto<Mailbox<'a>>,
4✔
1712
        D: TryInto<Literal<'a>>,
4✔
1713
    {
4✔
1714
        Ok(CommandBody::Append {
4✔
1715
            mailbox: mailbox.try_into().map_err(AppendError::Mailbox)?,
4✔
1716
            flags,
4✔
1717
            date,
4✔
1718
            message: LiteralOrLiteral8::Literal(message.try_into().map_err(AppendError::Data)?),
4✔
1719
        })
1720
    }
4✔
1721

1722
    /// Construct a SEARCH command.
1723
    pub fn search(charset: Option<Charset<'a>>, criteria: Vec1<SearchKey<'a>>, uid: bool) -> Self {
14✔
1724
        CommandBody::Search {
14✔
1725
            charset,
14✔
1726
            criteria,
14✔
1727
            uid,
14✔
1728
        }
14✔
1729
    }
14✔
1730

1731
    /// Construct a FETCH command.
1732
    pub fn fetch<S, I>(sequence_set: S, macro_or_item_names: I, uid: bool) -> Result<Self, S::Error>
8✔
1733
    where
8✔
1734
        S: TryInto<SequenceSet>,
8✔
1735
        I: Into<MacroOrMessageDataItemNames<'a>>,
8✔
1736
    {
8✔
1737
        let sequence_set = sequence_set.try_into()?;
8✔
1738

1739
        Ok(CommandBody::Fetch {
8✔
1740
            sequence_set,
8✔
1741
            macro_or_item_names: macro_or_item_names.into(),
8✔
1742
            uid,
8✔
1743
            #[cfg(feature = "ext_condstore_qresync")]
8✔
1744
            changed_since: None,
8✔
1745
        })
8✔
1746
    }
8✔
1747

1748
    /// Construct a STORE command.
1749
    pub fn store<S>(
6✔
1750
        sequence_set: S,
6✔
1751
        kind: StoreType,
6✔
1752
        response: StoreResponse,
6✔
1753
        flags: Vec<Flag<'a>>,
6✔
1754
        uid: bool,
6✔
1755
    ) -> Result<Self, S::Error>
6✔
1756
    where
6✔
1757
        S: TryInto<SequenceSet>,
6✔
1758
    {
6✔
1759
        let sequence_set = sequence_set.try_into()?;
6✔
1760

1761
        Ok(CommandBody::Store {
6✔
1762
            sequence_set,
6✔
1763
            kind,
6✔
1764
            response,
6✔
1765
            flags,
6✔
1766
            uid,
6✔
1767
            #[cfg(feature = "ext_condstore_qresync")]
6✔
1768
            unchanged_since: None,
6✔
1769
        })
6✔
1770
    }
6✔
1771

1772
    /// Construct a COPY command.
1773
    pub fn copy<S, M>(
4✔
1774
        sequence_set: S,
4✔
1775
        mailbox: M,
4✔
1776
        uid: bool,
4✔
1777
    ) -> Result<Self, CopyError<S::Error, M::Error>>
4✔
1778
    where
4✔
1779
        S: TryInto<SequenceSet>,
4✔
1780
        M: TryInto<Mailbox<'a>>,
4✔
1781
    {
4✔
1782
        Ok(CommandBody::Copy {
4✔
1783
            sequence_set: sequence_set.try_into().map_err(CopyError::Sequence)?,
4✔
1784
            mailbox: mailbox.try_into().map_err(CopyError::Mailbox)?,
4✔
1785
            uid,
4✔
1786
        })
1787
    }
4✔
1788

1789
    /// Get the name of the command.
1790
    pub fn name(&self) -> &'static str {
66✔
1791
        match self {
66✔
1792
            Self::Capability => "CAPABILITY",
2✔
1793
            Self::Noop => "NOOP",
2✔
1794
            Self::Logout => "LOGOUT",
2✔
1795
            #[cfg(feature = "starttls")]
1796
            Self::StartTLS => "STARTTLS",
2✔
1797
            Self::Authenticate { .. } => "AUTHENTICATE",
2✔
1798
            Self::Login { .. } => "LOGIN",
2✔
1799
            Self::Select { .. } => "SELECT",
2✔
1800
            Self::Sort { .. } => "SORT",
×
1801
            Self::Thread { .. } => "THREAD",
×
1802
            Self::Unselect => "UNSELECT",
2✔
1803
            Self::Examine { .. } => "EXAMINE",
2✔
1804
            Self::Create { .. } => "CREATE",
2✔
1805
            Self::Delete { .. } => "DELETE",
2✔
1806
            Self::Rename { .. } => "RENAME",
2✔
1807
            Self::Subscribe { .. } => "SUBSCRIBE",
2✔
1808
            Self::Unsubscribe { .. } => "UNSUBSCRIBE",
2✔
1809
            Self::List { .. } => "LIST",
2✔
1810
            Self::Lsub { .. } => "LSUB",
2✔
1811
            Self::Status { .. } => "STATUS",
2✔
1812
            Self::Append { .. } => "APPEND",
4✔
1813
            Self::Check => "CHECK",
2✔
1814
            Self::Close => "CLOSE",
2✔
1815
            Self::Expunge => "EXPUNGE",
2✔
1816
            Self::ExpungeUid { .. } => "EXPUNGE",
×
1817
            Self::Search { .. } => "SEARCH",
2✔
1818
            Self::Fetch { .. } => "FETCH",
2✔
1819
            Self::Store { .. } => "STORE",
2✔
1820
            Self::Copy { .. } => "COPY",
2✔
1821
            Self::Idle => "IDLE",
2✔
1822
            Self::Enable { .. } => "ENABLE",
2✔
1823
            Self::Compress { .. } => "COMPRESS",
2✔
1824
            Self::GetQuota { .. } => "GETQUOTA",
2✔
1825
            Self::GetQuotaRoot { .. } => "GETQUOTAROOT",
2✔
1826
            Self::SetQuota { .. } => "SETQUOTA",
2✔
1827
            Self::Move { .. } => "MOVE",
2✔
1828
            #[cfg(feature = "ext_id")]
1829
            Self::Id { .. } => "ID",
×
1830
            #[cfg(feature = "ext_metadata")]
1831
            Self::SetMetadata { .. } => "SETMETADATA",
×
1832
            #[cfg(feature = "ext_metadata")]
1833
            Self::GetMetadata { .. } => "GETMETADATA",
×
1834
        }
1835
    }
66✔
1836
}
1837

1838
/// Error-related types.
1839
pub mod error {
1840
    use thiserror::Error;
1841

1842
    #[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
1843
    pub enum LoginError<U, P> {
1844
        #[error("Invalid username: {0}")]
1845
        Username(U),
1846
        #[error("Invalid password: {0}")]
1847
        Password(P),
1848
    }
1849

1850
    #[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
1851
    pub enum RenameError<F, T> {
1852
        #[error("Invalid (from) mailbox: {0}")]
1853
        From(F),
1854
        #[error("Invalid (to) mailbox: {0}")]
1855
        To(T),
1856
    }
1857

1858
    #[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
1859
    pub enum ListError<R, M> {
1860
        #[error("Invalid reference: {0}")]
1861
        Reference(R),
1862
        #[error("Invalid mailbox: {0}")]
1863
        Mailbox(M),
1864
    }
1865

1866
    #[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
1867
    pub enum AppendError<M, D> {
1868
        #[error("Invalid mailbox: {0}")]
1869
        Mailbox(M),
1870
        #[error("Invalid data: {0}")]
1871
        Data(D),
1872
    }
1873

1874
    #[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
1875
    pub enum CopyError<S, M> {
1876
        #[error("Invalid sequence: {0}")]
1877
        Sequence(S),
1878
        #[error("Invalid mailbox: {0}")]
1879
        Mailbox(M),
1880
    }
1881
}
1882

1883
#[cfg(test)]
1884
mod tests {
1885
    use chrono::DateTime as ChronoDateTime;
1886

1887
    use super::*;
1888
    use crate::{
1889
        auth::AuthMechanism,
1890
        core::{AString, Charset, IString, Literal, LiteralMode, Vec1},
1891
        datetime::DateTime,
1892
        extensions::{
1893
            binary::Literal8,
1894
            compress::CompressionAlgorithm,
1895
            enable::{CapabilityEnable, Utf8Kind},
1896
        },
1897
        fetch::{Macro, MacroOrMessageDataItemNames, MessageDataItemName, Part, Section},
1898
        flag::{Flag, StoreType},
1899
        mailbox::{ListMailbox, Mailbox},
1900
        search::SearchKey,
1901
        secret::Secret,
1902
        sequence::{SeqOrUid, Sequence, SequenceSet},
1903
        status::StatusDataItemName,
1904
    };
1905

1906
    #[test]
1907
    fn test_conversion_command_body() {
2✔
1908
        let cmds = vec![
2✔
1909
            CommandBody::Capability,
2✔
1910
            CommandBody::Noop,
2✔
1911
            CommandBody::Logout,
2✔
1912
            #[cfg(feature = "starttls")]
2✔
1913
            CommandBody::StartTLS,
2✔
1914
            CommandBody::authenticate(AuthMechanism::Plain),
2✔
1915
            CommandBody::authenticate(AuthMechanism::Login),
2✔
1916
            CommandBody::authenticate_with_ir(AuthMechanism::Plain, b"XXXXXXXX".as_ref()),
2✔
1917
            CommandBody::authenticate_with_ir(AuthMechanism::Login, b"YYYYYYYY".as_ref()),
2✔
1918
            CommandBody::login("alice", "I_am_an_atom").unwrap(),
2✔
1919
            CommandBody::login("alice", "I am \\ \"quoted\"").unwrap(),
2✔
1920
            CommandBody::login("alice", "I am a literal²").unwrap(),
2✔
1921
            CommandBody::login(
2✔
1922
                AString::Atom("alice".try_into().unwrap()),
2✔
1923
                AString::String(crate::core::IString::Literal(
2✔
1924
                    vec![0xff, 0xff, 0xff].try_into().unwrap(),
2✔
1925
                )),
2✔
1926
            )
2✔
1927
            .unwrap(),
2✔
1928
            CommandBody::select("inbox").unwrap(),
2✔
1929
            CommandBody::select("atom").unwrap(),
2✔
1930
            CommandBody::select("C:\\").unwrap(),
2✔
1931
            CommandBody::select("²").unwrap(),
2✔
1932
            CommandBody::select("Trash").unwrap(),
2✔
1933
            CommandBody::examine("inbox").unwrap(),
2✔
1934
            CommandBody::examine("atom").unwrap(),
2✔
1935
            CommandBody::examine("C:\\").unwrap(),
2✔
1936
            CommandBody::examine("²").unwrap(),
2✔
1937
            CommandBody::examine("Trash").unwrap(),
2✔
1938
            CommandBody::create("inBoX").unwrap(),
2✔
1939
            CommandBody::delete("inBOX").unwrap(),
2✔
1940
            CommandBody::rename("iNBoS", "INboX").unwrap(),
2✔
1941
            CommandBody::subscribe("inbox").unwrap(),
2✔
1942
            CommandBody::unsubscribe("INBOX").unwrap(),
2✔
1943
            CommandBody::list("iNbOx", "test").unwrap(),
2✔
1944
            CommandBody::list("inbox", ListMailbox::Token("test".try_into().unwrap())).unwrap(),
2✔
1945
            CommandBody::lsub(
2✔
1946
                "inbox",
2✔
1947
                ListMailbox::String(IString::Quoted("\x7f".try_into().unwrap())),
2✔
1948
            )
2✔
1949
            .unwrap(),
2✔
1950
            CommandBody::list("inBoX", ListMailbox::Token("test".try_into().unwrap())).unwrap(),
2✔
1951
            CommandBody::lsub(
2✔
1952
                "INBOX",
2✔
1953
                ListMailbox::String(IString::Quoted("\x7f".try_into().unwrap())),
2✔
1954
            )
2✔
1955
            .unwrap(),
2✔
1956
            CommandBody::status("inbox", vec![StatusDataItemName::Messages]).unwrap(),
2✔
1957
            CommandBody::append(
2✔
1958
                "inbox",
2✔
1959
                vec![],
2✔
1960
                Some(
2✔
1961
                    DateTime::try_from(
2✔
1962
                        ChronoDateTime::parse_from_rfc2822("Tue, 1 Jul 2003 10:52:37 +0200")
2✔
1963
                            .unwrap(),
2✔
1964
                    )
2✔
1965
                    .unwrap(),
2✔
1966
                ),
2✔
1967
                vec![0xff, 0xff, 0xff],
2✔
1968
            )
2✔
1969
            .unwrap(),
2✔
1970
            CommandBody::append(
2✔
1971
                "inbox",
2✔
1972
                vec![Flag::Keyword("test".try_into().unwrap())],
2✔
1973
                Some(
2✔
1974
                    DateTime::try_from(
2✔
1975
                        ChronoDateTime::parse_from_rfc2822("Tue, 1 Jul 2003 10:52:37 +0200")
2✔
1976
                            .unwrap(),
2✔
1977
                    )
2✔
1978
                    .unwrap(),
2✔
1979
                ),
2✔
1980
                vec![0xff, 0xff, 0xff],
2✔
1981
            )
2✔
1982
            .unwrap(),
2✔
1983
            CommandBody::Check,
2✔
1984
            CommandBody::Close,
2✔
1985
            CommandBody::Expunge,
2✔
1986
            CommandBody::search(
2✔
1987
                None,
2✔
1988
                Vec1::from(SearchKey::And(
2✔
1989
                    vec![SearchKey::All, SearchKey::New, SearchKey::Unseen]
2✔
1990
                        .try_into()
2✔
1991
                        .unwrap(),
2✔
1992
                )),
2✔
1993
                false,
2✔
1994
            ),
2✔
1995
            CommandBody::search(
2✔
1996
                None,
2✔
1997
                Vec1::from(SearchKey::And(
2✔
1998
                    vec![SearchKey::All, SearchKey::New, SearchKey::Unseen]
2✔
1999
                        .try_into()
2✔
2000
                        .unwrap(),
2✔
2001
                )),
2✔
2002
                true,
2✔
2003
            ),
2✔
2004
            CommandBody::search(
2✔
2005
                None,
2✔
2006
                Vec1::from(SearchKey::And(
2✔
2007
                    vec![SearchKey::SequenceSet(SequenceSet(
2✔
2008
                        vec![Sequence::Single(SeqOrUid::Value(42.try_into().unwrap()))]
2✔
2009
                            .try_into()
2✔
2010
                            .unwrap(),
2✔
2011
                    ))]
2✔
2012
                    .try_into()
2✔
2013
                    .unwrap(),
2✔
2014
                )),
2✔
2015
                true,
2✔
2016
            ),
2✔
2017
            CommandBody::search(
2✔
2018
                None,
2✔
2019
                Vec1::from(SearchKey::SequenceSet("42".try_into().unwrap())),
2✔
2020
                true,
2✔
2021
            ),
2✔
2022
            CommandBody::search(
2✔
2023
                None,
2✔
2024
                Vec1::from(SearchKey::SequenceSet("*".try_into().unwrap())),
2✔
2025
                true,
2✔
2026
            ),
2✔
2027
            CommandBody::search(
2✔
2028
                None,
2✔
2029
                Vec1::from(SearchKey::Or(
2✔
2030
                    Box::new(SearchKey::Draft),
2✔
2031
                    Box::new(SearchKey::All),
2✔
2032
                )),
2✔
2033
                true,
2✔
2034
            ),
2✔
2035
            CommandBody::search(
2✔
2036
                Some(Charset::try_from("UTF-8").unwrap()),
2✔
2037
                Vec1::from(SearchKey::Or(
2✔
2038
                    Box::new(SearchKey::Draft),
2✔
2039
                    Box::new(SearchKey::All),
2✔
2040
                )),
2✔
2041
                true,
2✔
2042
            ),
2✔
2043
            CommandBody::fetch(
2✔
2044
                "1",
2✔
2045
                vec![MessageDataItemName::BodyExt {
2✔
2046
                    partial: None,
2✔
2047
                    section: Some(Section::Part(Part(
2✔
2048
                        vec![1.try_into().unwrap(), 1.try_into().unwrap()]
2✔
2049
                            .try_into()
2✔
2050
                            .unwrap(),
2✔
2051
                    ))),
2✔
2052
                    peek: true,
2✔
2053
                }],
2✔
2054
                false,
2✔
2055
            )
2✔
2056
            .unwrap(),
2✔
2057
            CommandBody::fetch("1:*,2,3", Macro::Full, true).unwrap(),
2✔
2058
            CommandBody::store(
2✔
2059
                "1,2:*",
2✔
2060
                StoreType::Remove,
2✔
2061
                StoreResponse::Answer,
2✔
2062
                vec![Flag::Seen, Flag::Draft],
2✔
2063
                false,
2✔
2064
            )
2✔
2065
            .unwrap(),
2✔
2066
            CommandBody::store(
2✔
2067
                "1:5",
2✔
2068
                StoreType::Add,
2✔
2069
                StoreResponse::Answer,
2✔
2070
                vec![Flag::Keyword("TEST".try_into().unwrap())],
2✔
2071
                true,
2✔
2072
            )
2✔
2073
            .unwrap(),
2✔
2074
            CommandBody::copy("1", "inbox", false).unwrap(),
2✔
2075
            CommandBody::copy("1337", "archive", true).unwrap(),
2✔
2076
        ];
2✔
2077

2078
        for (no, cmd_body) in cmds.into_iter().enumerate() {
102✔
2079
            println!("Test: {}, {:?}", no, cmd_body);
102✔
2080

102✔
2081
            let _ = cmd_body.tag(format!("A{}", no)).unwrap();
102✔
2082
        }
102✔
2083
    }
2✔
2084

2085
    #[test]
2086
    fn test_command_body_name() {
2✔
2087
        let tests = [
2✔
2088
            (CommandBody::Capability, "CAPABILITY"),
2✔
2089
            (CommandBody::Noop, "NOOP"),
2✔
2090
            (CommandBody::Logout, "LOGOUT"),
2✔
2091
            #[cfg(feature = "starttls")]
2✔
2092
            (CommandBody::StartTLS, "STARTTLS"),
2✔
2093
            (
2✔
2094
                CommandBody::Authenticate {
2✔
2095
                    mechanism: AuthMechanism::Plain,
2✔
2096
                    initial_response: None,
2✔
2097
                },
2✔
2098
                "AUTHENTICATE",
2✔
2099
            ),
2✔
2100
            (
2✔
2101
                CommandBody::Login {
2✔
2102
                    username: AString::try_from("user").unwrap(),
2✔
2103
                    password: Secret::new(AString::try_from("pass").unwrap()),
2✔
2104
                },
2✔
2105
                "LOGIN",
2✔
2106
            ),
2✔
2107
            (
2✔
2108
                CommandBody::Select {
2✔
2109
                    mailbox: Mailbox::Inbox,
2✔
2110
                },
2✔
2111
                "SELECT",
2✔
2112
            ),
2✔
2113
            (CommandBody::Unselect, "UNSELECT"),
2✔
2114
            (
2✔
2115
                CommandBody::Examine {
2✔
2116
                    mailbox: Mailbox::Inbox,
2✔
2117
                },
2✔
2118
                "EXAMINE",
2✔
2119
            ),
2✔
2120
            (
2✔
2121
                CommandBody::Create {
2✔
2122
                    mailbox: Mailbox::Inbox,
2✔
2123
                },
2✔
2124
                "CREATE",
2✔
2125
            ),
2✔
2126
            (
2✔
2127
                CommandBody::Delete {
2✔
2128
                    mailbox: Mailbox::Inbox,
2✔
2129
                },
2✔
2130
                "DELETE",
2✔
2131
            ),
2✔
2132
            (
2✔
2133
                CommandBody::Rename {
2✔
2134
                    from: Mailbox::Inbox,
2✔
2135
                    to: Mailbox::Inbox,
2✔
2136
                },
2✔
2137
                "RENAME",
2✔
2138
            ),
2✔
2139
            (
2✔
2140
                CommandBody::Subscribe {
2✔
2141
                    mailbox: Mailbox::Inbox,
2✔
2142
                },
2✔
2143
                "SUBSCRIBE",
2✔
2144
            ),
2✔
2145
            (
2✔
2146
                CommandBody::Unsubscribe {
2✔
2147
                    mailbox: Mailbox::Inbox,
2✔
2148
                },
2✔
2149
                "UNSUBSCRIBE",
2✔
2150
            ),
2✔
2151
            (
2✔
2152
                CommandBody::List {
2✔
2153
                    reference: Mailbox::Inbox,
2✔
2154
                    mailbox_wildcard: ListMailbox::try_from("").unwrap(),
2✔
2155
                },
2✔
2156
                "LIST",
2✔
2157
            ),
2✔
2158
            (
2✔
2159
                CommandBody::Lsub {
2✔
2160
                    reference: Mailbox::Inbox,
2✔
2161
                    mailbox_wildcard: ListMailbox::try_from("").unwrap(),
2✔
2162
                },
2✔
2163
                "LSUB",
2✔
2164
            ),
2✔
2165
            (
2✔
2166
                CommandBody::Status {
2✔
2167
                    mailbox: Mailbox::Inbox,
2✔
2168
                    item_names: vec![].into(),
2✔
2169
                },
2✔
2170
                "STATUS",
2✔
2171
            ),
2✔
2172
            (
2✔
2173
                CommandBody::Append {
2✔
2174
                    mailbox: Mailbox::Inbox,
2✔
2175
                    flags: vec![],
2✔
2176
                    date: None,
2✔
2177
                    message: LiteralOrLiteral8::Literal(Literal::try_from("").unwrap()),
2✔
2178
                },
2✔
2179
                "APPEND",
2✔
2180
            ),
2✔
2181
            (
2✔
2182
                CommandBody::Append {
2✔
2183
                    mailbox: Mailbox::Inbox,
2✔
2184
                    flags: vec![],
2✔
2185
                    date: None,
2✔
2186
                    message: LiteralOrLiteral8::Literal8(Literal8 {
2✔
2187
                        data: b"Hello\x00World\x00".as_ref().into(),
2✔
2188
                        mode: LiteralMode::NonSync,
2✔
2189
                    }),
2✔
2190
                },
2✔
2191
                "APPEND",
2✔
2192
            ),
2✔
2193
            (CommandBody::Check, "CHECK"),
2✔
2194
            (CommandBody::Close, "CLOSE"),
2✔
2195
            (CommandBody::Expunge, "EXPUNGE"),
2✔
2196
            (
2✔
2197
                CommandBody::Search {
2✔
2198
                    charset: None,
2✔
2199
                    criteria: Vec1::from(SearchKey::Recent),
2✔
2200
                    uid: true,
2✔
2201
                },
2✔
2202
                "SEARCH",
2✔
2203
            ),
2✔
2204
            (
2✔
2205
                CommandBody::Fetch {
2✔
2206
                    sequence_set: SequenceSet::try_from(1u32).unwrap(),
2✔
2207
                    macro_or_item_names: MacroOrMessageDataItemNames::Macro(Macro::Full),
2✔
2208
                    uid: true,
2✔
2209
                    #[cfg(feature = "ext_condstore_qresync")]
2✔
2210
                    changed_since: None,
2✔
2211
                },
2✔
2212
                "FETCH",
2✔
2213
            ),
2✔
2214
            (
2✔
2215
                CommandBody::Store {
2✔
2216
                    sequence_set: SequenceSet::try_from(1).unwrap(),
2✔
2217
                    flags: vec![],
2✔
2218
                    response: StoreResponse::Silent,
2✔
2219
                    kind: StoreType::Add,
2✔
2220
                    uid: true,
2✔
2221
                    #[cfg(feature = "ext_condstore_qresync")]
2✔
2222
                    unchanged_since: None,
2✔
2223
                },
2✔
2224
                "STORE",
2✔
2225
            ),
2✔
2226
            (
2✔
2227
                CommandBody::Copy {
2✔
2228
                    sequence_set: SequenceSet::try_from(1).unwrap(),
2✔
2229
                    mailbox: Mailbox::Inbox,
2✔
2230
                    uid: true,
2✔
2231
                },
2✔
2232
                "COPY",
2✔
2233
            ),
2✔
2234
            (CommandBody::Idle, "IDLE"),
2✔
2235
            (
2✔
2236
                CommandBody::Enable {
2✔
2237
                    capabilities: Vec1::from(CapabilityEnable::Utf8(Utf8Kind::Only)),
2✔
2238
                },
2✔
2239
                "ENABLE",
2✔
2240
            ),
2✔
2241
            (
2✔
2242
                CommandBody::Compress {
2✔
2243
                    algorithm: CompressionAlgorithm::Deflate,
2✔
2244
                },
2✔
2245
                "COMPRESS",
2✔
2246
            ),
2✔
2247
            (
2✔
2248
                CommandBody::GetQuota {
2✔
2249
                    root: AString::try_from("root").unwrap(),
2✔
2250
                },
2✔
2251
                "GETQUOTA",
2✔
2252
            ),
2✔
2253
            (
2✔
2254
                CommandBody::GetQuotaRoot {
2✔
2255
                    mailbox: Mailbox::Inbox,
2✔
2256
                },
2✔
2257
                "GETQUOTAROOT",
2✔
2258
            ),
2✔
2259
            (
2✔
2260
                CommandBody::SetQuota {
2✔
2261
                    root: AString::try_from("root").unwrap(),
2✔
2262
                    quotas: vec![],
2✔
2263
                },
2✔
2264
                "SETQUOTA",
2✔
2265
            ),
2✔
2266
            (
2✔
2267
                CommandBody::Move {
2✔
2268
                    sequence_set: SequenceSet::try_from(1).unwrap(),
2✔
2269
                    mailbox: Mailbox::Inbox,
2✔
2270
                    uid: true,
2✔
2271
                },
2✔
2272
                "MOVE",
2✔
2273
            ),
2✔
2274
        ];
2✔
2275

2276
        for (test, expected) in tests {
68✔
2277
            assert_eq!(test.name(), expected);
66✔
2278
        }
2279
    }
2✔
2280
}
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