mirror of
https://github.com/lelgenio/maildir-notify-daemon.git
synced 2024-11-09 16:21:42 -03:00
fix reading invalid utf-8
This commit is contained in:
parent
5cdd18fb72
commit
2bd4b95bf4
17
src/main.rs
17
src/main.rs
|
@ -16,9 +16,7 @@ fn main() {
|
||||||
.expect("hotwatch failed to initialize!");
|
.expect("hotwatch failed to initialize!");
|
||||||
|
|
||||||
std::env::args().for_each(|arg| {
|
std::env::args().for_each(|arg| {
|
||||||
hotwatch
|
hotwatch.watch(arg, handle_event).ok();
|
||||||
.watch(arg, handle_event)
|
|
||||||
.expect("hotwatch failed to initialize!");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
hotwatch.run();
|
hotwatch.run();
|
||||||
|
@ -33,7 +31,7 @@ fn handle_event(event: hotwatch::Event) -> hotwatch::blocking::Flow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _handle_event(newfile: PathBuf) {
|
fn _handle_event(newfile: PathBuf) {
|
||||||
let raw_content = match std::fs::read_to_string(&newfile) {
|
let raw_content = match std::fs::read(&newfile) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
|
@ -45,7 +43,7 @@ fn _handle_event(newfile: PathBuf) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mail_content = match mailparse::parse_mail(raw_content.as_bytes()) {
|
let mail_content = match mailparse::parse_mail(&raw_content) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
|
@ -67,17 +65,16 @@ fn _handle_event(newfile: PathBuf) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let subject = match headers.get_first_value("Subject") {
|
let subject = headers.get_first_value("Subject").unwrap_or_else(|| {
|
||||||
Some(sub) => sub,
|
mail_content
|
||||||
None => mail_content
|
|
||||||
.get_body()
|
.get_body()
|
||||||
.unwrap_or("".to_string())
|
.unwrap_or("".to_string())
|
||||||
.lines()
|
.lines()
|
||||||
.filter(|line| line.len() != 0)
|
.filter(|line| line.len() != 0)
|
||||||
.next()
|
.next()
|
||||||
.unwrap_or("")
|
.unwrap_or("")
|
||||||
.to_string(),
|
.to_string()
|
||||||
};
|
});
|
||||||
|
|
||||||
Notification::new()
|
Notification::new()
|
||||||
.summary(&format!("From: {}", from))
|
.summary(&format!("From: {}", from))
|
||||||
|
|
Loading…
Reference in a new issue