From 4606b115d29a62b3a9b4fe01a8538abe11d53af1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 9 Mar 2021 00:54:42 +0100 Subject: Use 'whatlang' to detect the language of the email body --- Cargo.lock | 32 ++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 4 ++++ 3 files changed, 37 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 6ef8110..b639a77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,17 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "ahash" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + [[package]] name = "base64" version = "0.10.1" @@ -46,6 +58,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "hashbrown" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96282e96bfcd3da0d3aa9938bedf1e50df3269b6db08b4876d2da0bb1a0841cf" +dependencies = [ + "ahash", + "autocfg", +] + [[package]] name = "mailparse" version = "0.13.2" @@ -62,6 +84,7 @@ name = "ottolangy" version = "0.0.1" dependencies = [ "mailparse", + "whatlang", ] [[package]] @@ -69,3 +92,12 @@ name = "quoted_printable" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47b080c5db639b292ac79cbd34be0cfc5d36694768d8341109634d90b86930e2" + +[[package]] +name = "whatlang" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "783066160df650d0cc2629fa4f616ef4fcf00817803789e92ca09a55eba6ff05" +dependencies = [ + "hashbrown", +] diff --git a/Cargo.toml b/Cargo.toml index 070936c..9a9987f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,4 @@ edition = "2018" [dependencies] mailparse = "0.13.2" +whatlang = "0.11.1" diff --git a/src/main.rs b/src/main.rs index 734e302..433018f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use mailparse; +use whatlang; use std::error::Error; use std::io::{self, Read}; @@ -12,6 +13,9 @@ fn main() { let body = get_email_body(&email_input).unwrap(); print!("{}", body); + + let lang_info = whatlang::detect(&body).unwrap(); + println!("{:?}", lang_info); } fn get_email_body(email: &[u8]) -> Result> { -- cgit v1.2.3