|
1
|
use anyhow::Result; |
|
2
|
use smbcloud_mail::listen::listen; |
|
3
|
use smbcloud_mail::listen_pop3::listen_pop3; |
|
4
|
use smbcloud_mail::pop3_storage::Pop3Mailbox; |
|
5
|
|
|
6
|
#[tokio::main] |
|
7
|
async fn main() -> Result<()> { |
|
8
|
// Initialize tracing subscriber for logging |
|
9
|
tracing_subscriber::fmt::init(); |
|
10
|
|
|
11
|
// Create shared POP3 mailbox |
|
12
|
let mailbox = Pop3Mailbox::new(); |
|
13
|
|
|
14
|
// Add some sample messages for testing |
|
15
|
mailbox.add_message("test", "From: sender@example.com\r\nTo: test@example.com\r\nSubject: Test Message 1\r\n\r\nThis is the first test message.".to_string()); |
|
16
|
mailbox.add_message("test", "From: sender@example.com\r\nTo: test@example.com\r\nSubject: Test Message 2\r\n\r\nThis is the second test message.".to_string()); |
|
17
|
|
|
18
|
// Run both SMTP and POP3 servers concurrently |
|
19
|
let smtp_server = tokio::spawn(async move { |
|
20
|
if let Err(e) = listen().await { |
|
21
|
tracing::error!("SMTP server error: {:?}", e); |
|
22
|
} |
|
23
|
}); |
|
24
|
|
|
25
|
let pop3_server = tokio::spawn(async move { |
|
26
|
if let Err(e) = listen_pop3(mailbox).await { |
|
27
|
tracing::error!("POP3 server error: {:?}", e); |
|
28
|
} |
|
29
|
}); |
|
30
|
|
|
31
|
// Wait for both servers (they run indefinitely) |
|
32
|
tokio::select! { |
|
33
|
_ = smtp_server => {}, |
|
34
|
_ = pop3_server => {}, |
|
35
|
} |
|
36
|
|
|
37
|
Ok(()) |
|
38
|
} |