maildir: check for moved mail before moving
When moving mail from new/ to cur/ in a Maildir folder, don't panic if it fails; someone else must have moved it.embed
parent
250129665b
commit
5a262f3ffc
|
@ -165,7 +165,7 @@ pub(super) fn get_file_hash(file: &Path) -> EnvelopeHash {
|
||||||
hasher.finish()
|
hasher.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_to_cur(p: PathBuf) -> PathBuf {
|
fn move_to_cur(p: PathBuf) -> Result<PathBuf> {
|
||||||
let mut new = p.clone();
|
let mut new = p.clone();
|
||||||
let file_name = p.to_string_lossy();
|
let file_name = p.to_string_lossy();
|
||||||
let slash_pos = file_name.bytes().rposition(|c| c == b'/').unwrap() + 1;
|
let slash_pos = file_name.bytes().rposition(|c| c == b'/').unwrap() + 1;
|
||||||
|
@ -178,8 +178,8 @@ fn move_to_cur(p: PathBuf) -> PathBuf {
|
||||||
new.set_extension(":2,");
|
new.set_extension(":2,");
|
||||||
}
|
}
|
||||||
debug!("moved to cur: {}", new.display());
|
debug!("moved to cur: {}", new.display());
|
||||||
fs::rename(&p, &new).unwrap();
|
fs::rename(&p, &new)?;
|
||||||
new
|
Ok(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MailBackend for MaildirType {
|
impl MailBackend for MaildirType {
|
||||||
|
@ -229,7 +229,15 @@ impl MailBackend for MaildirType {
|
||||||
if path_is_new!(pathbuf) {
|
if path_is_new!(pathbuf) {
|
||||||
debug!("path_is_new");
|
debug!("path_is_new");
|
||||||
/* This creates a Rename event that we will receive later */
|
/* This creates a Rename event that we will receive later */
|
||||||
pathbuf = move_to_cur(pathbuf);
|
pathbuf = match move_to_cur(pathbuf) {
|
||||||
|
Ok(p) => p,
|
||||||
|
Err(e) => {
|
||||||
|
debug!("error: {}", e.to_string());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
let folder_hash = get_path_hash!(pathbuf);
|
let folder_hash = get_path_hash!(pathbuf);
|
||||||
let file_name = pathbuf
|
let file_name = pathbuf
|
||||||
|
@ -696,7 +704,7 @@ impl MaildirType {
|
||||||
path.push("new");
|
path.push("new");
|
||||||
for d in path.read_dir()? {
|
for d in path.read_dir()? {
|
||||||
if let Ok(p) = d {
|
if let Ok(p) = d {
|
||||||
move_to_cur(p.path());
|
move_to_cur(p.path()).ok().take();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
path.pop();
|
path.pop();
|
||||||
|
|
Loading…
Reference in New Issue