maildir: conditionally accept invalid subdirs
If directory is invalid (i.e. has no {cur,new,tmp} subfolders), accept it ONLY if it contains subdirs of any depth that are valid maildir paths. For example, this change will accept the following directory tree: ``` invalid_maildir βββ valid_maildir βββ cur βββ new βββ tmp ```async
parent
bd404e6937
commit
bea0ca61f5
|
@ -170,6 +170,7 @@ impl MaildirMailbox {
|
|||
file_name: String,
|
||||
parent: Option<MailboxHash>,
|
||||
children: Vec<MailboxHash>,
|
||||
accept_invalid: bool,
|
||||
settings: &AccountSettings,
|
||||
) -> Result<Self> {
|
||||
let pathbuf = PathBuf::from(&path);
|
||||
|
@ -215,7 +216,9 @@ impl MaildirMailbox {
|
|||
unseen: Arc::new(Mutex::new(0)),
|
||||
total: Arc::new(Mutex::new(0)),
|
||||
};
|
||||
ret.is_valid()?;
|
||||
if !accept_invalid {
|
||||
ret.is_valid()?;
|
||||
}
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
|
|
|
@ -778,6 +778,7 @@ impl MaildirType {
|
|||
path.file_name().unwrap().to_str().unwrap().to_string(),
|
||||
None,
|
||||
Vec::new(),
|
||||
false,
|
||||
&settings,
|
||||
) {
|
||||
f.children = recurse_mailboxes(mailboxes, settings, &path)?;
|
||||
|
@ -787,6 +788,33 @@ impl MaildirType {
|
|||
.count();
|
||||
children.push(f.hash);
|
||||
mailboxes.insert(f.hash, f);
|
||||
} else {
|
||||
/* If directory is invalid (i.e. has no {cur,new,tmp} subfolders),
|
||||
* accept it ONLY if it contains subdirs of any depth that are
|
||||
* valid maildir paths
|
||||
*/
|
||||
let subdirs = recurse_mailboxes(mailboxes, settings, &path)?;
|
||||
if !subdirs.is_empty() {
|
||||
if let Ok(f) = MaildirMailbox::new(
|
||||
path.to_str().unwrap().to_string(),
|
||||
path.file_name().unwrap().to_str().unwrap().to_string(),
|
||||
None,
|
||||
subdirs,
|
||||
true,
|
||||
&settings,
|
||||
) {
|
||||
f.children
|
||||
.iter()
|
||||
.map(|c| {
|
||||
mailboxes
|
||||
.get_mut(c)
|
||||
.map(|f| f.parent = Some(f.hash))
|
||||
})
|
||||
.count();
|
||||
children.push(f.hash);
|
||||
mailboxes.insert(f.hash, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -814,6 +842,7 @@ impl MaildirType {
|
|||
root_path.file_name().unwrap().to_str().unwrap().to_string(),
|
||||
None,
|
||||
Vec::with_capacity(0),
|
||||
false,
|
||||
settings,
|
||||
) {
|
||||
mailboxes.insert(f.hash, f);
|
||||
|
|
Loadingβ¦
Reference in New Issue