| Age | Commit message (Collapse) | Author |
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
|
|
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: ".
|
|
Clarify what we want to do.
|
|
Generated with
$ cargo new mutt-alias-auto-add --bin
|