aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs36
3 files changed, 42 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b639a77..6512fcd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -85,6 +85,7 @@ version = "0.0.1"
dependencies = [
"mailparse",
"whatlang",
+ "xdg",
]
[[package]]
@@ -101,3 +102,9 @@ checksum = "783066160df650d0cc2629fa4f616ef4fcf00817803789e92ca09a55eba6ff05"
dependencies = [
"hashbrown",
]
+
+[[package]]
+name = "xdg"
+version = "2.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57"
diff --git a/Cargo.toml b/Cargo.toml
index 9a9987f..6e47203 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,3 +6,4 @@ edition = "2018"
[dependencies]
mailparse = "0.13.2"
whatlang = "0.11.1"
+xdg = "2.2.0"
diff --git a/src/main.rs b/src/main.rs
index 433018f..d98d998 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,21 @@
use mailparse;
-use whatlang;
+use whatlang::{self, Lang};
+use xdg;
use std::error::Error;
-use std::io::{self, Read};
+use std::fs::File;
+use std::io::{self, Read, Write};
+
+
+const PROGRAM_NAME: &'static str = "ottolangy";
+const MUTTRC_FILENAME: &'static str = "attribution.muttrc";
+
+const ATTRIBUTION_FR: &'static str =
+ r#"set attribution = "Le %{%e %b. %Y à %H:%M %Z}, %f a écrit:"
+"#;
+const ATTRIBUTION_EN: &'static str =
+ r#"set attribution = "On %{%b %e, %Y, at %I:%M %p %Z}, %f wrote:"
+"#;
fn main() {
@@ -16,6 +29,14 @@ fn main() {
let lang_info = whatlang::detect(&body).unwrap();
println!("{:?}", lang_info);
+
+ let attribution_config = if lang_info.lang() == Lang::Fra {
+ ATTRIBUTION_FR
+ } else {
+ ATTRIBUTION_EN
+ };
+
+ write_attribution(&attribution_config).unwrap();
}
fn get_email_body(email: &[u8]) -> Result<String, Box<dyn Error>> {
@@ -41,3 +62,14 @@ fn get_email_body(email: &[u8]) -> Result<String, Box<dyn Error>> {
Err("parse".into())
}
+
+fn write_attribution(config: &str) -> Result<(), Box<dyn Error>> {
+ let xdg_dirs = xdg::BaseDirectories::with_prefix(PROGRAM_NAME).unwrap();
+
+ let muttrc_path = xdg_dirs.place_data_file(MUTTRC_FILENAME).unwrap();
+
+ let mut file = File::create(muttrc_path).unwrap();
+ file.write_all(config.as_bytes()).unwrap();
+
+ Ok(())
+}