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

View File

@ -718,7 +718,7 @@ impl MaildirType {
))); )));
} }
let mut children = Vec::new(); 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() { 'entries: for f in f.iter_mut() {
{ {
let path = f.path(); let path = f.path();
@ -787,10 +787,10 @@ impl MaildirType {
.count(); .count();
folders.get_mut(&root_hash).map(|f| f.children = children); 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() { 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 = let mut hash_indexes =