Browse Source

melib: move lookup_ipv4() to connection module

master
Manos Pitsidianakis 2 years ago
parent
commit
c7bbf7ed7e
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 16
      melib/src/backends/imap/connection.rs
  2. 13
      melib/src/connections.rs

16
melib/src/backends/imap/connection.rs

@ -21,7 +21,7 @@
use super::protocol_parser::{ImapLineSplit, ImapResponse, RequiredResponses};
use crate::backends::MailboxHash;
use crate::connections::Connection;
use crate::connections::{lookup_ipv4, Connection};
use crate::email::parser::BytesExt;
use crate::error::*;
extern crate native_tls;
@ -31,7 +31,6 @@ pub use smol::Async as AsyncWrapper;
use std::collections::HashSet;
use std::future::Future;
use std::iter::FromIterator;
use std::net::SocketAddr;
use std::pin::Pin;
use std::sync::Arc;
use std::time::Instant;
@ -758,16 +757,3 @@ async fn read(
}
None
}
fn lookup_ipv4(host: &str, port: u16) -> Result<SocketAddr> {
use std::net::ToSocketAddrs;
let addrs = (host, port).to_socket_addrs()?;
for addr in addrs {
if let SocketAddr::V4(_) = addr {
return Ok(addr);
}
}
Err(MeliError::new("Cannot lookup address"))
}

13
melib/src/connections.rs

@ -139,3 +139,16 @@ impl std::os::unix::io::AsRawFd for Connection {
}
}
}
pub fn lookup_ipv4(host: &str, port: u16) -> crate::Result<std::net::SocketAddr> {
use std::net::ToSocketAddrs;
let addrs = (host, port).to_socket_addrs()?;
for addr in addrs {
if let std::net::SocketAddr::V4(_) = addr {
return Ok(addr);
}
}
Err(crate::error::MeliError::new("Cannot lookup address"))
}
Loading…
Cancel
Save