aboutsummaryrefslogtreecommitdiffstats
path: root/src
AgeCommit message (Collapse)Author
2016-04-06test.rs: Split `build_alias` test into 5 separate testsTeddy Wing
Instead of putting all our asserts in a single test function, make a function for each assert. This allows us to give our test functions more specific names based on what exactly we're testing, and produces better output from `cargo test`. Also, if one of those fails for whatever reason, it's nice to know it will do so with a meaningful name.
2016-04-06build_alias: Remove [,'"] charactersTeddy Wing
Make the function a bit more DRY by taking the `push_str` calls out of the `if` block. Add a new test and some code to remove commas and quotes from aliases.
2016-04-06Implement `build_alias`Teddy Wing
Copy of the functionality in W. Caleb McDaniel's Bash script implemented in Rust: echo "${MESSAGE}" | grep ^"From: " | sed s/[\,\"\']//g | awk '{$1=""; if (NF == 3) {print "alias" $0;} else if (NF == 2) {print "alias" $0 $0;} else if (NF > 3) {print "alias", tolower($(NF-1))"-"tolower($2) $0;}}' Doesn't currently include the [,"'] filtering. Added a couple of new test cases to cover other address formats. Not sure if I should use `if..else if` here or a `match`. I feel like I should return an empty string at the end if we can't build an alias line.
2016-04-06Add a couple tests for `build_alias`Teddy Wing
Create a new `tests` module. This lives in its own file. Not sure if this is idiomatic Rust, but I prefer the idea of my tests living in a different file from my code. This module gets included in `main.rs`. We `use` `build_alias` directly because it's currently a private function, so doing `use super::*` didn't import it. Not sure if I should be making it a public function in order to mitigate this. Add a couple of variant test cases to check the string transformation that this function should be doing.
2016-04-06Create a couple new functions to build our alias (stubs)Teddy Wing
Stub out two new functions. The first, `handle_alias`, will manage the alias appending process. The second, `build_alias`, will transform a `From: ` string into a Mutt alias.
2016-04-05Find "From: " line in inputTeddy Wing
Look for the line that begins "From: " in the email message given to us. When we find it, we'll call a function that we're going to define soon that handles adding an alias to our Mutt aliases file.
2016-04-05Remove old commented code from 55b07581cf2e414460461e9e1591059b5dc459d3Teddy Wing
2016-04-05Read stdinTeddy Wing
Tried a few different times, copying code from different places. Didn't quite get it figured out at first. Wanted to add STDIN lines to a string. Got that working with option 3, but that `push_str` didn't appear to preserve newlines. Ended up using this solution from StackOverflow: http://stackoverflow.com/questions/13579266/how-to-read-user-input-in-rust/36374135#36374135 It adds the lines to a vector instead of a single string. Printing each line individually then gives us out newlines. This way is probably nicer also for getting the first line that starts with "From: ".
2016-04-05Add a comment with some implementation detailsTeddy Wing
Clarify what we want to do.
2016-03-27Initial commit. Base Rust 1.7.0 project.Teddy Wing
Generated with $ cargo new mutt-alias-auto-add --bin