chore: sync mailcore v0.1.0-beta.1
This commit is contained in:
18
mailcore/examples/test_dns.rs
Normal file
18
mailcore/examples/test_dns.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use mailcore::dns::discover_mail_server;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let email = std::env::args().nth(1).expect("Usage: test_dns <email>");
|
||||
|
||||
println!("Discovering server for: {}", email);
|
||||
|
||||
match discover_mail_server(&email).await {
|
||||
Ok(config) => {
|
||||
println!("✓ IMAP: {}:{}", config.imap_host, config.imap_port);
|
||||
println!("✓ SMTP: {}:{}", config.smtp_host, config.smtp_port);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("✗ Error: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
52
mailcore/examples/test_imap.rs
Normal file
52
mailcore/examples/test_imap.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use mailcore::dns::discover_mail_server;
|
||||
use mailcore::imap::ImapClient;
|
||||
use std::io::{self, Write};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
if args.len() < 2 {
|
||||
eprintln!("Usage: test_imap <email>");
|
||||
std::process::exit(1);
|
||||
}
|
||||
let email = &args[1];
|
||||
|
||||
println!("Discovering server for: {}", email);
|
||||
let config = match discover_mail_server(email).await {
|
||||
Ok(c) => {
|
||||
println!("✓ IMAP: {}:{}", c.imap_host, c.imap_port);
|
||||
c
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("✗ DNS Error: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
print!("Password for {}: ", email);
|
||||
io::stdout().flush().unwrap();
|
||||
let mut password = String::new();
|
||||
io::stdin().read_line(&mut password).unwrap();
|
||||
let password = password.trim();
|
||||
|
||||
let mut client = ImapClient::new(config, email.to_string());
|
||||
|
||||
println!("Connecting...");
|
||||
match client.connect(password).await {
|
||||
Ok(_) => {
|
||||
println!("✓ Connected and authenticated successfully!");
|
||||
|
||||
println!("Listing folders...");
|
||||
match client.list_folders(true).await {
|
||||
Ok(folders) => {
|
||||
println!("\nFolders:");
|
||||
for folder in folders {
|
||||
println!(" - {} ({:?})", folder.name, folder.folder_type);
|
||||
}
|
||||
}
|
||||
Err(e) => eprintln!("✗ Failed to list folders: {}", e),
|
||||
}
|
||||
}
|
||||
Err(e) => eprintln!("✗ Connection Error: {}", e),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user