aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2016-04-17 21:32:53 -0400
committerTeddy Wing2016-04-17 21:32:53 -0400
commitad2d9e0e1fa965ef94fcbf6e239729008cc34ba2 (patch)
treea09d63f4c19165cb3fb6a3fd66f05f4f38cffd6c /src/main.rs
parent9240db56a7202b238b7880da9c82b1e73089f02e (diff)
downloadmutt-alias-auto-add-ad2d9e0e1fa965ef94fcbf6e239729008cc34ba2.tar.bz2
Create a function that will check whether an alias is in a file
This will allow us to pass an alias and grep for it in a given file. Just a rough outline to start. Added a super basic test and a file in "testdata" to operate on for testing.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 5e02b38..1677e5c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,6 @@
-use std::io::{self, BufRead};
+use std::io::{self, BufRead, BufReader};
+use std::fs::File;
+use std::path::Path;
#[cfg(test)]
mod tests;
@@ -34,6 +36,26 @@ fn build_alias(s: &str) -> String {
alias_line
}
+fn is_alias_in_file(alias: &str, file: &str) -> Result<(), io::Error> {
+ let alias_parts: Vec<&str> = alias.split_whitespace().collect();
+
+ let f = try!(File::open(file));
+ let mut file = BufReader::new(&f);
+ for line in file.lines() {
+ let line = line.unwrap();
+ let split: Vec<&str> = line.split_whitespace().collect();
+
+ // if email is in alias file
+ // return true
+
+ if split[1].starts_with(alias_parts[1]) {
+ println!("booya");
+ }
+ }
+
+ Ok(())
+}
+
fn main() {
let stdin = io::stdin();
let input: Vec<String> = stdin.lock().lines().map(|line| line.unwrap()).collect();