-
Notifications
You must be signed in to change notification settings - Fork 22
Closed
Description
Hello!
I wrote a minimal example of my code, which works totally fine when only one guy sends an email. However, when I try to send an email from two different email addresses to server at the same time, my server panics.
Cargo.toml
[package]
name = "imap_test"
version = "0.1.0"
authors = ["Kevin Per <kevp.per@gmail.com>"]
[dependencies]
imap = "0.8.1"
native-tls = "0.1"
mailparse = "0.6.2"
main.rs:
extern crate imap;
extern crate mailparse;
extern crate native_tls;
use imap::client::Client;
use native_tls::{TlsConnector, TlsStream};
use std::net::TcpStream;
use mailparse::*;
fn main() {
let domain = "";
let email = "";
let password = "";
let socket_addr = (domain.clone(), 993);
let ssl_connector = TlsConnector::builder().unwrap().build().unwrap();
let mut imap_socket =
imap::client::Client::secure_connect(socket_addr, domain.clone(), &ssl_connector)
.unwrap();
imap_socket
.login(email, password)
.unwrap();
loop {
match imap_socket.select("INBOX") {
Ok(mailbox) => {
println!("{}", mailbox);
}
Err(e) => println!("Error selecting INBOX: {}", e),
};
let mut unseen = imap_socket
.run_command_and_read_response("UID SEARCH UNSEEN 1:*")
.unwrap();
// remove last line of response (OK Completed)
unseen.pop();
let mut uids = Vec::new();
let unseen = ::std::str::from_utf8(&unseen[..]).unwrap();
let unseen = unseen.split_whitespace().skip(2);
for uid in unseen.take_while(|&e| e != "" && e != "Completed") {
if let Ok(uid) = usize::from_str_radix(uid, 10) {
uids.push(format!("{}", uid));
}
}
uids.reverse(); //latest first
for uid in uids.iter() {
let raw = imap_socket.uid_fetch(uid, "RFC822").unwrap(); //here it panics!
for message in raw.iter() {
let m = message.rfc822();
if m.is_none() {
continue;
}
let parsed = parse_mail(m.unwrap()).unwrap();
let subject = parsed.headers.get_first_value("Subject").unwrap().unwrap();
let from = parsed.headers.get_first_value("From").unwrap().unwrap();
if parsed.subparts.len() > 0 {
let body = parsed.subparts[0].get_body().unwrap();
println!("From: {}", from);
println!("Subject: {}", subject);
println!("Body: {}", body);
}
}
}
}
}
Metadata
Metadata
Assignees
Labels
No labels