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 ```memfd
parent
bd404e6937
commit
bea0ca61f5
|
@ -170,6 +170,7 @@ impl MaildirMailbox {
|
||||||
file_name: String,
|
file_name: String,
|
||||||
parent: Option<MailboxHash>,
|
parent: Option<MailboxHash>,
|
||||||
children: Vec<MailboxHash>,
|
children: Vec<MailboxHash>,
|
||||||
|
accept_invalid: bool,
|
||||||
settings: &AccountSettings,
|
settings: &AccountSettings,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let pathbuf = PathBuf::from(&path);
|
let pathbuf = PathBuf::from(&path);
|
||||||
|
@ -215,7 +216,9 @@ impl MaildirMailbox {
|
||||||
unseen: Arc::new(Mutex::new(0)),
|
unseen: Arc::new(Mutex::new(0)),
|
||||||
total: Arc::new(Mutex::new(0)),
|
total: Arc::new(Mutex::new(0)),
|
||||||
};
|
};
|
||||||
ret.is_valid()?;
|
if !accept_invalid {
|
||||||
|
ret.is_valid()?;
|
||||||
|
}
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -778,6 +778,7 @@ impl MaildirType {
|
||||||
path.file_name().unwrap().to_str().unwrap().to_string(),
|
path.file_name().unwrap().to_str().unwrap().to_string(),
|
||||||
None,
|
None,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
|
false,
|
||||||
&settings,
|
&settings,
|
||||||
) {
|
) {
|
||||||
f.children = recurse_mailboxes(mailboxes, settings, &path)?;
|
f.children = recurse_mailboxes(mailboxes, settings, &path)?;
|
||||||
|
@ -787,6 +788,33 @@ impl MaildirType {
|
||||||
.count();
|
.count();
|
||||||
children.push(f.hash);
|
children.push(f.hash);
|
||||||
mailboxes.insert(f.hash, f);
|
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(),
|
root_path.file_name().unwrap().to_str().unwrap().to_string(),
|
||||||
None,
|
None,
|
||||||
Vec::with_capacity(0),
|
Vec::with_capacity(0),
|
||||||
|
false,
|
||||||
settings,
|
settings,
|
||||||
) {
|
) {
|
||||||
mailboxes.insert(f.hash, f);
|
mailboxes.insert(f.hash, f);
|
||||||
|
|
Loading…
Reference in New Issue