melib/maildir: fix wrong subscription status in folders

MaildirFolder::new() was checking for subscribed status though that is
supposed to be done in MaildirType::new()
async
Manos Pitsidianakis 2020-02-08 13:42:05 +02:00
parent b107424258
commit 9616fbb544
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 13 additions and 35 deletions

View File

@ -192,42 +192,20 @@ impl MaildirFolder {
children: Vec<FolderHash>,
settings: &AccountSettings,
) -> Result<Self> {
macro_rules! strip_slash {
($v:expr) => {
if $v.ends_with("/") {
&$v[..$v.len() - 1]
} else {
$v
}
};
}
let pathbuf = PathBuf::from(&path);
let mut h = DefaultHasher::new();
pathbuf.hash(&mut h);
/* Check if folder path (Eg `INBOX/Lists/luddites`) is included in the subscribed
* mailboxes in user configuration */
let fname = if let Ok(fname) = pathbuf.strip_prefix(
PathBuf::from(&settings.root_folder)
.expand()
.parent()
.unwrap_or_else(|| &Path::new("/")),
) {
if fname.components().count() != 0
&& !settings
.subscribed_folders
.iter()
.any(|x| x == strip_slash!(fname.to_str().unwrap()))
{
return Err(MeliError::new(format!(
"Folder with name `{}` is not included in configured subscribed mailboxes",
fname.display()
)));
}
Some(fname)
} else {
None
};
let fname = pathbuf
.strip_prefix(
PathBuf::from(&settings.root_folder)
.expand()
.parent()
.unwrap_or_else(|| &Path::new("/")),
)
.ok();
let read_only = if let Ok(metadata) = std::fs::metadata(&pathbuf) {
metadata.permissions().readonly()
@ -243,7 +221,7 @@ impl MaildirFolder {
parent,
children,
usage: Arc::new(RwLock::new(SpecialUsageMailbox::Normal)),
is_subscribed: true,
is_subscribed: false,
permissions: FolderPermissions {
create_messages: !read_only,
remove_messages: !read_only,

View File

@ -718,7 +718,7 @@ impl MaildirType {
)));
}
let mut children = Vec::new();
for mut f in fs::read_dir(p).unwrap() {
for mut f in fs::read_dir(&p).unwrap() {
'entries: for f in f.iter_mut() {
{
let path = f.path();
@ -787,10 +787,10 @@ impl MaildirType {
.count();
folders.get_mut(&root_hash).map(|f| f.children = children);
}
folders.retain(|_, f| is_subscribed(f.path()));
let keys = folders.keys().cloned().collect::<FnvHashSet<FolderHash>>();
for f in folders.values_mut() {
f.children.retain(|c| keys.contains(c));
if is_subscribed(f.path()) {
f.is_subscribed = true;
}
}
let mut hash_indexes =