aboutsummaryrefslogtreecommitdiffstats
path: root/src/alias.rs
diff options
context:
space:
mode:
authorTeddy Wing2016-04-24 09:31:25 -0400
committerTeddy Wing2016-04-24 09:31:25 -0400
commit2e844b5c528a39e75702d0b412b0396080fa103e (patch)
treeb3b97c61601bfef24f3f8bab5075e4b1362adf65 /src/alias.rs
parent7c9439bc11ae95b6f2da59eabf2950d15df4d558 (diff)
downloadmutt-alias-auto-add-2e844b5c528a39e75702d0b412b0396080fa103e.tar.bz2
Write alias even if we haven't found a matching one
If we get an `AliasSearchError::NotFound` error we still want to write the alias to the file. After all, it's an email we haven't encountered yet so we should store an alias for it. If the email exists, we can do what we were doing before and change the current alias to be unique. Rename our "append" `write_to_file` test method to be a little more clear about its purpose. Create a new `write_to_file` test function that tests the case we're adding here. Note that having these two tests together seems to cause a race condition because they're both using the same temporary test file. If we run tests with `RUST_TEST_THREADS=1 cargo test` then they pass. Will see about fixing that next.
Diffstat (limited to 'src/alias.rs')
-rw-r--r--src/alias.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/alias.rs b/src/alias.rs
index 8a66db8..0fd05d2 100644
--- a/src/alias.rs
+++ b/src/alias.rs
@@ -75,8 +75,11 @@ impl Alias {
}
pub fn write_to_file<P: AsRef<Path>>(&mut self, file: P) -> Result<(), AliasSearchError> {
- let similar_aliases = try!(self.find_in_file(&file));
- self.update_alias_id(similar_aliases);
+ match self.find_in_file(&file) {
+ Ok(similar_aliases) => self.update_alias_id(similar_aliases),
+ Err(AliasSearchError::NotFound) => {},
+ Err(e) => return Err(e),
+ };
let mut f = try!(OpenOptions::new().append(true).open(file));
try!(f.write_all(format!("{}\n", self.to_string()).as_bytes()));