]>
Commit | Line | Data |
---|---|---|
768227f7 RBR |
1 | //! # olden-mail |
2 | //! | |
3 | //! `olden-mail` is an IMAP & SMTP proxy that allows you to connect to SSL | |
4 | //! enabled mail servers using insecure plaintext connections. | |
5 | //! | |
6 | //! This is of course very insecure, but it's intended to allow vintage | |
7 | //! computers that don't have SSL capability or ther right ciphers to still | |
8 | //! be used for e-mail. | |
9 | //! | |
10 | //! ## Installation | |
11 | //! | |
12 | //! ### Pre-built binaries and packages | |
13 | //! | |
2fdda21d RBR |
14 | //! Binaries are available for macos and linux, for both aarch64 and `x86_64` |
15 | //! from <https://build.r.bdr.sh/olden-mail>, including `.deb` and `.rpm` | |
768227f7 RBR |
16 | //! packages. |
17 | //! | |
18 | //! ### Homebrew | |
19 | //! | |
20 | //! You can also install this on macos via homebrew. | |
21 | //! | |
22 | //! ``` | |
23 | //! % brew tap rbdr/apps git@git.sr.ht:~rbdr/homebrew-apps | |
24 | //! % brew install rbdr/apps/olden-mail | |
25 | //! ``` | |
26 | //! | |
27 | //! ### From source | |
28 | //! | |
29 | //! You can run `make` for a debug build, or `make -e profile=release` for a | |
30 | //! release build. | |
31 | //! | |
32 | //! ## Usage | |
33 | //! | |
34 | //! The proxy requires you to set environment variables, but otherwise takes | |
35 | //! no options. | |
36 | //! | |
37 | //! * `LOCAL_IMAP_PORT` u16, the port in which the server will listen for | |
2fdda21d | 38 | //! IMAP clients. Defaults to 143. |
768227f7 | 39 | //! * `LOCAL_IMAP_BIND_ADDRESS` String, the address on which to listen for |
2fdda21d | 40 | //! IMAP clients. Defaults to 0.0.0.0. |
768227f7 | 41 | //! * `REMOTE_IMAP_PORT` u16, the port to which the server will forward the |
2fdda21d | 42 | //! IMAP messages. Defaults to 993. |
768227f7 | 43 | //! * `REMOTE_IMAP_HOST` String, the host to which the server will forward the |
2fdda21d | 44 | //! IMAP messages. Required. |
768227f7 RBR |
45 | //! |
46 | //! * `LOCAL_SMTP_PORT` u16, the port in which the server will listen for | |
2fdda21d | 47 | //! SMTP clients. Defaults to 25. |
768227f7 | 48 | //! * `LOCAL_SMTP_BIND_ADDRESS` String, the address on which to listen for |
2fdda21d | 49 | //! SMTP clients. Defaults to 0.0.0.0. |
768227f7 | 50 | //! * `REMOTE_SMTP_PORT` u16, the port to which the server will forward the |
2fdda21d | 51 | //! SMTP messages. Defaults to 465. |
768227f7 | 52 | //! * `REMOTE_SMTP_HOST` String, the host to which the server will forward the |
2fdda21d | 53 | //! SMTP messages. Required. |
768227f7 RBR |
54 | //! |
55 | //! This means the minimum invocation is this (Shown here with inline | |
56 | //! environment variables) | |
57 | //! | |
58 | //! ``` | |
6dca7b58 | 59 | //! % REMOTE_IMAP_HOST=imap.coolmailsite.example REMOTE_SMTP_HOST=smtp.coolmailsite.example olden-mail |
768227f7 RBR |
60 | //! ``` |
61 | //! | |
62 | //! ## Debugging | |
63 | //! | |
64 | //! You can control how much it prints by setting `RUST_LOG`. Setting it to | |
65 | //! `debug` will output the whole protocol stream. The default level is | |
66 | //! `info`. | |
67 | ||
68 | use env_logger::{Builder, Env}; | |
69 | use log::{error, info}; | |
70 | use std::process::exit; | |
71 | use std::sync::mpsc; | |
72 | ||
dc3d6821 | 73 | mod configuration; |
573aaf2a | 74 | mod middleware; |
dc3d6821 RBR |
75 | mod proxy; |
76 | ||
77 | use configuration::Configuration; | |
2fdda21d | 78 | use proxy::Server; |
dc3d6821 RBR |
79 | |
80 | fn main() { | |
768227f7 RBR |
81 | Builder::from_env(Env::default().default_filter_or("info")) |
82 | .format_timestamp_millis() | |
83 | .init(); | |
84 | ||
85 | let configuration = Configuration::new().unwrap_or_else(|error| { | |
86 | error!("{error}"); | |
87 | exit(1); | |
88 | }); | |
89 | ||
90 | let (tx, rx) = mpsc::channel(); | |
91 | ||
2fdda21d RBR |
92 | let mut imap_proxy = Server::new(configuration.imap_configuration); |
93 | let mut smtp_proxy = Server::new(configuration.smtp_configuration); | |
dc3d6821 | 94 | |
768227f7 RBR |
95 | ctrlc::set_handler(move || { |
96 | info!("Shutting down..."); | |
97 | imap_proxy.shutdown(); | |
98 | smtp_proxy.shutdown(); | |
99 | let _ = tx.send(()); | |
100 | }) | |
101 | .unwrap_or_else(|e| { | |
102 | error!("Error setting Ctrl-C handler: {e}"); | |
103 | std::process::exit(1); | |
104 | }); | |
dc3d6821 | 105 | |
768227f7 RBR |
106 | // Block until we get a shutdown |
107 | rx.recv().unwrap_or(()); | |
dc3d6821 | 108 | } |