Skip to content

Commit

Permalink
Merge e035119 into b62c9e0
Browse files Browse the repository at this point in the history
  • Loading branch information
duesee committed Feb 14, 2024
2 parents b62c9e0 + e035119 commit 2c3bc8a
Show file tree
Hide file tree
Showing 17 changed files with 929 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
--workspace \
--exclude tokio-client --exclude tokio-server --exclude tokio-support \
--feature-powerset \
--group-features starttls,ext_condstore_qresync,ext_login_referrals,ext_mailbox_referrals,ext_id,ext_sort_thread,ext_binary \
--group-features starttls,ext_condstore_qresync,ext_login_referrals,ext_mailbox_referrals,ext_id,ext_sort_thread,ext_binary,ext_metadata \
--exclude-features ext,split
test:
Expand Down
1 change: 1 addition & 0 deletions imap-codec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ext_mailbox_referrals = ["imap-types/ext_mailbox_referrals"]
ext_id = ["imap-types/ext_id"]
ext_sort_thread = ["imap-types/ext_sort_thread"]
ext_binary = ["imap-types/ext_binary"]
ext_metadata = ["ext_binary", "imap-types/ext_binary", "imap-types/ext_metadata"]
# </Forward to imap-types>

# IMAP quirks
Expand Down
52 changes: 51 additions & 1 deletion imap-codec/src/codec/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,44 @@ impl<'a> EncodeIntoContext for CommandBody<'a> {
None => ctx.write_all(b"NIL"),
}
}
#[cfg(feature = "ext_metadata")]
CommandBody::SetMetadata {
mailbox,
entry_values,
} => {
ctx.write_all(b"SETMETADATA ")?;
mailbox.encode_ctx(ctx)?;
ctx.write_all(b" (")?;
join_serializable(entry_values.as_ref(), b" ", ctx)?;
ctx.write_all(b")")
}
#[cfg(feature = "ext_metadata")]
CommandBody::GetMetadata {
options,
mailbox,
entries,
} => {
ctx.write_all(b"GETMETADATA")?;

if !options.is_empty() {
ctx.write_all(b" (")?;
join_serializable(options, b" ", ctx)?;
ctx.write_all(b")")?;
}

ctx.write_all(b" ")?;
mailbox.encode_ctx(ctx)?;

ctx.write_all(b" ")?;

if entries.as_ref().len() == 1 {
entries.as_ref()[0].encode_ctx(ctx)
} else {
ctx.write_all(b"(")?;
join_serializable(entries.as_ref(), b" ", ctx)?;
ctx.write_all(b")")
}
}
}
}
}
Expand Down Expand Up @@ -1174,6 +1212,11 @@ impl<'a> EncodeIntoContext for Code<'a> {
Code::CompressionActive => ctx.write_all(b"COMPRESSIONACTIVE"),
Code::OverQuota => ctx.write_all(b"OVERQUOTA"),
Code::TooBig => ctx.write_all(b"TOOBIG"),
#[cfg(feature = "ext_metadata")]
Code::Metadata(code) => {
ctx.write_all(b"METADATA ")?;
code.encode_ctx(ctx)
}
Code::Other(unknown) => unknown.encode_ctx(ctx),
}
}
Expand Down Expand Up @@ -1344,6 +1387,13 @@ impl<'a> EncodeIntoContext for Data<'a> {
}
}
}
#[cfg(feature = "ext_metadata")]
Data::Metadata { mailbox, items } => {
ctx.write_all(b"* METADATA ")?;
mailbox.encode_ctx(ctx)?;
ctx.write_all(b" ")?;
items.encode_ctx(ctx)?;
}
}

ctx.write_all(b"\r\n")
Expand Down Expand Up @@ -1722,7 +1772,7 @@ impl<'a> EncodeIntoContext for CommandContinuationRequest<'a> {
}
}

mod utils {
pub(crate) mod utils {
use std::io::Write;

use super::{EncodeContext, EncodeIntoContext};
Expand Down
45 changes: 28 additions & 17 deletions imap-codec/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ use nom::{

#[cfg(feature = "ext_id")]
use crate::extensions::id::id;
#[cfg(feature = "ext_metadata")]
use crate::extensions::metadata::{getmetadata, setmetadata};
#[cfg(feature = "ext_sort_thread")]
use crate::extensions::sort::sort;
#[cfg(feature = "ext_sort_thread")]
use crate::extensions::thread::thread;
use crate::extensions::{sort::sort, thread::thread};
use crate::{
auth::auth_type,
core::{astring, base64, literal, tag_imap},
Expand Down Expand Up @@ -107,20 +107,27 @@ pub(crate) fn command_any(input: &[u8]) -> IMAPResult<&[u8], CommandBody> {

// # Command Auth

/// `command-auth = append /
/// create /
/// delete /
/// examine /
/// list /
/// lsub /
/// rename /
/// select /
/// status /
/// subscribe /
/// unsubscribe /
/// idle ; RFC 2177
/// enable ; RFC 5161
/// compress ; RFC 4978`
/// ```abnf
/// command-auth = append /
/// create /
/// delete /
/// examine /
/// list /
/// lsub /
/// rename /
/// select /
/// status /
/// subscribe /
/// unsubscribe /
/// idle / ; RFC 2177
/// enable / ; RFC 5161
/// compress / ; RFC 4978
/// getquota / ; RFC 9208
/// getquotaroot / ; RFC 9208
/// setquota / ; RFC 9208
/// setmetadata / ; RFC 5464
/// getmetadata ; RFC 5464
/// ```
///
/// Note: Valid only in Authenticated or Selected state
pub(crate) fn command_auth(input: &[u8]) -> IMAPResult<&[u8], CommandBody> {
Expand All @@ -142,6 +149,10 @@ pub(crate) fn command_auth(input: &[u8]) -> IMAPResult<&[u8], CommandBody> {
getquota,
getquotaroot,
setquota,
#[cfg(feature = "ext_metadata")]
setmetadata,
#[cfg(feature = "ext_metadata")]
getmetadata,
))(input)
}

Expand Down
2 changes: 2 additions & 0 deletions imap-codec/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod enable;
pub mod id;
pub mod idle;
pub mod literal;
#[cfg(feature = "ext_metadata")]
pub mod metadata;
pub mod r#move;
pub mod quota;
#[cfg(feature = "ext_sort_thread")]
Expand Down
18 changes: 17 additions & 1 deletion imap-codec/src/extensions/binary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Cow;
use std::{borrow::Cow, io::Write};

#[cfg(not(feature = "quirk_crlf_relaxed"))]
use abnf_core::streaming::crlf;
Expand All @@ -15,6 +15,7 @@ use nom::{
use crate::{
core::number,
decode::{IMAPErrorKind, IMAPParseError, IMAPResult},
encode::{EncodeContext, EncodeIntoContext},
};

#[allow(unused)] // TODO(444)
Expand Down Expand Up @@ -64,3 +65,18 @@ pub(crate) fn literal8(input: &[u8]) -> IMAPResult<&[u8], Literal8> {
},
))
}

impl<'a> EncodeIntoContext for Literal8<'a> {
fn encode_ctx(&self, ctx: &mut EncodeContext) -> std::io::Result<()> {
match self.mode {
LiteralMode::Sync => write!(ctx, "~{{{}}}\r\n", self.data.len())?,
LiteralMode::NonSync => write!(ctx, "~{{{}+}}\r\n", self.data.len())?,
}

ctx.push_line();
ctx.write_all(&self.data)?;
ctx.push_literal(self.mode);

Ok(())
}
}

0 comments on commit 2c3bc8a

Please sign in to comment.