| Crates.io | mailguard-rs |
| lib.rs | mailguard-rs |
| version | 0.1.0 |
| created_at | 2025-07-30 02:53:51.773799+00 |
| updated_at | 2025-07-30 02:53:51.773799+00 |
| description | A fast temporary email and malicious domain detection library using SURBL DNS queries |
| homepage | https://github.com/longcipher/mailguard-rs |
| repository | https://github.com/longcipher/mailguard-rs |
| max_upload_size | |
| id | 1773058 |
| size | 108,312 |
π‘οΈ A fast temporary email and malicious domain detection library using SURBL DNS queries
This library detects temporary emails and malicious domains by querying DNS A records for domain.tempmail.so.multi.surbl.org. If the query returns an IP address in the 127.0.0.x range, it indicates the domain is blacklisted.
Threat types are determined by the last octet of the returned IP address:
| Last Octet | Threat Type | Severity | Description |
|---|---|---|---|
| 2, 9 | Spam | 2 | Spam source |
| 3 | Phishing | 4 | Phishing website |
| 4, 6, 7, 11 | Malware | 5 | Malware |
| 5 | Botnet | 4 | Botnet |
| 10 | PUP | 1 | Potentially Unwanted Program |
Add the following to your Cargo.toml:
[dependencies]
mailguard-rs = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
This library supports optional features:
cache - Enable LRU caching functionality (disabled by default)To enable caching:
[dependencies]
mailguard-rs = { version = "0.1.0", features = ["cache"] }
tokio = { version = "1.0", features = ["full"] }
use mailguard_rs::check_email;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Check a single email
let status = check_email("test@10minutemail.com").await?;
if status.is_threat {
println!("β οΈ Detected temporary email: {}", status.email);
if let Some(threat_type) = &status.threat_type {
println!("Threat type: {} (Level: {})",
threat_type.description(),
threat_type.severity_level()
);
}
} else {
println!("β
Email is safe: {}", status.email);
}
Ok(())
}
use mailguard_rs::{MailGuard, MailGuardConfig};
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create detector with custom configuration
let config = MailGuardConfig {
dns_timeout: Duration::from_secs(3),
enable_cache: true,
cache_ttl: Duration::from_secs(600), // 10 minutes cache
};
let detector = MailGuard::with_config(config);
// Batch detection
let emails = vec![
"user1@gmail.com",
"user2@10minutemail.com",
"user3@guerrillamail.com",
];
let results = detector.check_emails_batch(&emails).await;
for (email, result) in emails.iter().zip(results.iter()) {
match result {
Ok(status) => {
let cache_indicator = if status.from_cache { " [cached]" } else { "" };
println!("{}: {} {}",
email,
if status.is_threat { "β οΈ Temporary" } else { "β
Safe" },
cache_indicator
);
}
Err(e) => {
println!("{}: β Error: {}", email, e);
}
}
}
// Show cache statistics
if let Some(cache_size) = detector.cache_stats() {
println!("Cache entries: {}", cache_size);
}
Ok(())
}
use mailguard_rs::check_domain;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let status = check_domain("mailinator.com").await?;
if status.is_threat {
println!("β οΈ Malicious domain: {}", status.domain);
} else {
println!("β
Domain is safe: {}", status.domain);
}
Ok(())
}
EmailStatuspub struct EmailStatus {
pub email: String, // Email address
pub domain: String, // Domain name
pub is_threat: bool, // Whether it's a threat
pub threat_type: Option<ThreatType>, // Threat type if any
pub from_cache: bool, // Whether result is from cache
}
DomainStatuspub struct DomainStatus {
pub domain: String, // Domain name
pub is_threat: bool, // Whether it's a threat
pub threat_type: Option<ThreatType>, // Threat type if any
pub from_cache: bool, // Whether result is from cache
}
ThreatTypepub enum ThreatType {
Spam, // Spam source
Phishing, // Phishing website
Malware, // Malware
Botnet, // Botnet
Pup, // Potentially Unwanted Program
Unknown(u8), // Unknown threat type
}
check_email(email: &str) -> Result<EmailStatus, MailGuardError>check_domain(domain: &str) -> Result<DomainStatus, MailGuardError>check_emails_batch(emails: &[&str]) -> Vec<Result<EmailStatus, MailGuardError>># Clone the repository
git clone https://github.com/longcipher/mailguard-rs.git
cd mailguard-rs
# Run the main example
cargo run
# Run simple example
cargo run --example simple_usage
# Run advanced example
cargo run --example advanced_usage
# Run tests
cargo test
use mailguard_rs::{check_email, MailGuardError};
match check_email("invalid-email").await {
Ok(status) => println!("Detection result: {:?}", status),
Err(MailGuardError::InvalidEmail(email)) => {
println!("Invalid email format: {}", email);
}
Err(MailGuardError::DnsError(e)) => {
println!("DNS query failed: {}", e);
}
Err(e) => {
println!("Other error: {}", e);
}
}
MailGuardConfigpub struct MailGuardConfig {
pub dns_timeout: Duration, // DNS query timeout (default: 5s)
pub enable_cache: bool, // Enable caching (default: true)
pub cache_ttl: Duration, // Cache TTL (default: 5 minutes)
}
tokio - Async runtimetrust-dns-resolver - DNS queriesregex - Email validationthiserror - Error handlingserde - Serialization supportlru - Cache implementationtracing - Structured logging supportApache-2.0 License
Issues and Pull Requests are welcome!
See CHANGELOG.md for detailed version history.
If you find this project helpful, please consider giving it a β on GitHub!