Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RFC 4314/2086 ACL extension to imap-proto #142

Merged
merged 1 commit into from
Apr 26, 2022

Conversation

urkle
Copy link
Contributor

@urkle urkle commented Apr 23, 2022

Implement parsing of the ACL response types specified in RFC 4314/2086 (and the Annotation right from RFC 5257)

ACL response
LISTRIGHTS response
MYRIGHTS response

@urkle urkle force-pushed the feat-acl-protocol branch 2 times, most recently from 99d6986 to 51d572e Compare April 23, 2022 21:03
Copy link
Owner

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! Some feedback below, most of it is stylistic.

imap-proto/src/parser/rfc4314.rs Show resolved Hide resolved
imap-proto/src/parser/rfc4314.rs Outdated Show resolved Hide resolved
imap-proto/src/types.rs Outdated Show resolved Hide resolved
imap-proto/src/types.rs Outdated Show resolved Hide resolved
imap-proto/src/parser/tests.rs Outdated Show resolved Hide resolved
imap-proto/src/parser/rfc4314.rs Outdated Show resolved Hide resolved
}

#[derive(Debug, Eq, PartialEq)]
pub struct ACLRightList {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious that we should have this type inside imap-proto. I think we should instead use a Vec<AclRight> which directly reflects what the server sent us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.. I factored this out

@urkle
Copy link
Contributor Author

urkle commented Apr 25, 2022

@djc thanks for the review.. I've updated the branch with your requested changes.

Comment on lines 91 to 93
let v: String = items.into_iter().flat_map(|s| s.chars()).collect();

Ok((rest, map_text_to_rights(&v)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to have an intermediate allocation for no good reason. Can you rewrite to something that converts directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah.. let me see if I can rework this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.. I reworked it to remove the String and to have it convert more directly.

}
}

pub(crate) type AclRightList = Vec<AclRight>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to avoid the alias; IMO these usually make it harder to understand the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah.. sorry that was supposed to be removed.. I have it removed now.

/// helper routine to map a string to a vec of AclRights
fn map_text_to_rights(i: &str) -> Vec<AclRight> {
i.chars()
.into_iter()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the type returned by chars() is an Iterator, so no need to call into_iter() on it?

@djc
Copy link
Owner

djc commented Apr 25, 2022

Also I thought I wrote a comment about this, but please order the type definitions in the new module as top down. Most complex type (with dependencies on other types) first, simplest type (AclRight) last.

@urkle urkle force-pushed the feat-acl-protocol branch 2 times, most recently from 1968048 to b82adb8 Compare April 25, 2022 22:15
@urkle urkle requested a review from djc April 25, 2022 22:16
Copy link
Owner

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, almost there! Just need to fix up the lints.

Ok((
rest,
items.into_iter()
.flat_map(|s| map_text_to_rights(s))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to resolve this lint still. I think the fix here is not to use map_text_to_rights() but to just use s.chars().map(|c| c.into()) directly, which would avoid allocating a Vec which will be dropped again immediately after.

ACL response
LISTRIGHTS response
MYRIGHTS response
@urkle urkle requested a review from djc April 26, 2022 16:07
@djc djc merged commit f6c618d into djc:main Apr 26, 2022
@urkle
Copy link
Contributor Author

urkle commented May 9, 2022

@djc do you perhaps know when you'll make a new release of this crate? (so I can use it over in jonhoo/rust-imap#227 )

@djc
Copy link
Owner

djc commented May 10, 2022

0.16.1 is on crates.io now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants