Skip to main content

stalwart_lib/
lib.rs

1/*
2 * SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
3 *
4 * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
5 */
6
7//! Stalwart Mail Server — public library API
8//!
9//! Provides an embeddable entry-point for the IMAP+SMTP mail server.
10
11#[path = "../../common/src/lib.rs"]
12pub mod common;
13
14#[path = "../../store/src/lib.rs"]
15pub mod store;
16
17#[path = "../../directory/src/lib.rs"]
18pub mod directory;
19
20#[path = "../../email/src/lib.rs"]
21pub mod email;
22
23#[path = "../../http/src/lib.rs"]
24pub mod http;
25
26#[path = "../../imap/src/lib.rs"]
27pub mod imap;
28
29#[path = "../../smtp/src/lib.rs"]
30pub mod smtp;
31
32#[path = "../../services/src/lib.rs"]
33pub mod services;
34
35#[path = "../../types/src/lib.rs"]
36pub mod types;
37
38#[path = "../../utils/src/lib.rs"]
39pub mod utils;
40
41extern crate self as trc;
42
43#[path = "../../trc/src/lib.rs"]
44pub mod trc_impl;
45
46#[path = "../../migration/src/lib.rs"]
47pub mod migration;
48
49#[path = "../../nlp/src/lib.rs"]
50pub mod nlp;
51
52#[path = "../../spam-filter/src/lib.rs"]
53pub mod spam_filter;
54
55#[path = "../../http-proto/src/lib.rs"]
56pub mod http_proto;
57
58#[path = "../../imap-proto/src/lib.rs"]
59pub mod imap_proto;
60
61#[path = "../../jmap-proto/src/lib.rs"]
62pub mod jmap_proto;
63
64#[path = "../../groupware/src/lib.rs"]
65pub mod groupware;
66
67#[path = "../../dav-proto/src/lib.rs"]
68pub mod dav_proto;
69
70#[path = "../../jmap/src/lib.rs"]
71pub mod jmap;
72
73#[path = "../../dav/src/lib.rs"]
74pub mod dav;
75
76#[path = "../../pop3/src/lib.rs"]
77pub mod pop3;
78
79#[path = "../../managesieve/src/lib.rs"]
80pub mod managesieve;
81
82pub use crate::common::{Server, manager::boot::BootManager};
83pub use crate::trc_impl::*;
84
85/// Start the server and return a [`Server`] handle.
86///
87/// Configuration is read from the `CONFIG_PATH` environment variable, or
88/// defaults to `/etc/stalwart/config.toml` if the variable is not set.
89///
90/// # Process exit
91///
92/// Internally this calls [`BootManager::init`], which prints diagnostics and
93/// calls [`std::process::exit`] if the config file is missing or fatally
94/// invalid. This is intentional for a server binary but may be surprising
95/// when embedded as a library. Make sure a valid config file exists at the
96/// expected path before calling this function.
97pub async fn start_server() -> std::io::Result<Server> {
98    use crate::common::core::BuildServer;
99    let init = Box::pin(BootManager::init()).await;
100    Ok(init.inner.build_server())
101}