Add port field to MailConfig

This commit is contained in:
Kitaiti Makoto 2022-01-03 17:20:57 +09:00
parent d4549704b9
commit 00324f668f
2 changed files with 11 additions and 0 deletions

View File

@ -1,4 +1,5 @@
use crate::search::TokenizerKind as SearchTokenizer;
use crate::smtp::{SMTP_PORT, SUBMISSIONS_PORT, SUBMISSION_PORT};
use rocket::config::Limits;
use rocket::Config as RocketConfig;
use std::collections::HashSet;
@ -248,6 +249,7 @@ impl SearchTokenizerConfig {
pub struct MailConfig {
pub server: String,
pub port: u16,
pub helo_name: String,
pub username: String,
pub password: String,
@ -256,6 +258,14 @@ pub struct MailConfig {
fn get_mail_config() -> Option<MailConfig> {
Some(MailConfig {
server: env::var("MAIL_SERVER").ok()?,
port: env::var("MAIL_PORT").map_or(SUBMISSIONS_PORT, |port| match port.as_str() {
"smtp" => SMTP_PORT,
"submissions" => SUBMISSIONS_PORT,
"submission" => SUBMISSION_PORT,
number => number
.parse()
.expect(r#"MAIL_PORT must be "smtp", "submissions", "submission" or an integer."#),
}),
helo_name: env::var("MAIL_HELO_NAME").unwrap_or_else(|_| "localhost".to_owned()),
username: env::var("MAIL_USER").ok()?,
password: env::var("MAIL_PASSWORD").ok()?,

1
plume-models/src/lib.rs Executable file → Normal file
View File

@ -16,6 +16,7 @@ extern crate serde_json;
#[macro_use]
extern crate tantivy;
pub use lettre::smtp;
use once_cell::sync::Lazy;
use plume_common::activity_pub::{inbox::InboxError, request, sign};
use posts::PostEvent;