]> Untitled Git - lemmy.git/blobdiff - server/src/lib.rs
Merge branch 'dev' into federation
[lemmy.git] / server / src / lib.rs
index 8257dab9a6720a126143090915da494a977d0552..2c78cfc2643d3813a10027daf06dcf5868a2bce2 100644 (file)
@@ -16,6 +16,8 @@ pub extern crate dotenv;
 pub extern crate jsonwebtoken;
 pub extern crate lettre;
 pub extern crate lettre_email;
+extern crate log;
+pub extern crate openssl;
 pub extern crate rand;
 pub extern crate regex;
 pub extern crate rss;
@@ -34,7 +36,7 @@ pub mod version;
 pub mod websocket;
 
 use crate::settings::Settings;
-use chrono::{DateTime, NaiveDateTime, Utc};
+use chrono::{DateTime, FixedOffset, Local, NaiveDateTime};
 use isahc::prelude::*;
 use lettre::smtp::authentication::{Credentials, Mechanism};
 use lettre::smtp::extension::ClientId;
@@ -48,10 +50,6 @@ use rand::{thread_rng, Rng};
 use regex::{Regex, RegexBuilder};
 use serde::Deserialize;
 
-pub fn to_datetime_utc(ndt: NaiveDateTime) -> DateTime<Utc> {
-  DateTime::<Utc>::from_utc(ndt, Utc)
-}
-
 pub fn naive_now() -> NaiveDateTime {
   chrono::prelude::Utc::now().naive_utc()
 }
@@ -60,6 +58,11 @@ pub fn naive_from_unix(time: i64) -> NaiveDateTime {
   NaiveDateTime::from_timestamp(time, 0)
 }
 
+pub fn convert_datetime(datetime: NaiveDateTime) -> DateTime<FixedOffset> {
+  let now = Local::now();
+  DateTime::<FixedOffset>::from_utc(datetime, *now.offset())
+}
+
 pub fn is_email_regex(test: &str) -> bool {
   EMAIL_REGEX.is_match(test)
 }
@@ -112,7 +115,7 @@ pub fn send_email(
   to_username: &str,
   html: &str,
 ) -> Result<(), String> {
-  let email_config = Settings::get().email.as_ref().ok_or("no_email_setup")?;
+  let email_config = Settings::get().email.ok_or("no_email_setup")?;
 
   let email = Email::builder()
     .to((to_email, to_username))
@@ -127,7 +130,7 @@ pub fn send_email(
   } else {
     SmtpClient::new(&email_config.smtp_server, ClientSecurity::None).unwrap()
   }
-  .hello_name(ClientId::Domain(Settings::get().hostname.to_owned()))
+  .hello_name(ClientId::Domain(Settings::get().hostname))
   .smtp_utf8(true)
   .authentication_mechanism(Mechanism::Plain)
   .connection_reuse(ConnectionReuseParameters::ReuseUnlimited);