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
Manos Pitsidianakis 2020-05-28 16:50:22 +03:00
parent bd404e6937
commit bea0ca61f5
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 33 additions and 1 deletions

View File

@ -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)
}

View File

@ -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);