Compare commits

..

No commits in common. "002393b18e7e5f364971bf57bc10a20c74277479" and "702a6ffb33a4f3ba9109347ae46d943383fbbf64" have entirely different histories.

2 changed files with 11 additions and 28 deletions

View File

@ -6,7 +6,7 @@ Although this is quite minimal and only implements a tiny subset of the IMAP pro
## Installation ##
Get [Rust] and run
Get [rust] and run
cargo build --release
@ -33,15 +33,13 @@ The output of `imapidle --help` does a good job at explaining how to use it:
Note that it only supports TLS encrypted IMAP and plain password authentication. Also, it currently reads the password from the command line, which isn't a great thing to do. I might change that eventually.
## Goals ##
## Why? ##
I made this for the following reasons:
Rust might not be the canonical programming language to do something like this in. And also, this probably already exists somewhere in a more complete and polished form. So this might not useful for anyone else. But I had three goals in making this:
1. I wanted my emails to arrive faster and without having to manually hit the refresh button.
2. I wanted to find out how IMAP works and why it's often so slow (I'm still not really sure).
3. I wanted to try using Rust for something practical and see how well it works. It worked pretty well.
In terms of actual usability, this works fine for me, but I'm sure there are better alternatives out there.
2. I wanted to find out how IMAP works and why it's often so slow (I'm still not sure about the latter).
3. I wanted to try using rust for something practical and see how well it works. The result is it worked, and I would do it again.
[Rust]: https://www.rust-lang.org/
[IMAP]: https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol

View File

@ -2,13 +2,12 @@
use rustls::{OwnedTrustAnchor, ClientConfig, RootCertStore, ClientConnection};
use anyhow::{Result as AResult, bail};
use std::net::{TcpStream, ToSocketAddrs, SocketAddr};
use std::net::{TcpStream, ToSocketAddrs};
use std::io::{self, ErrorKind, Read, Write, Error as IOError};
use std::process::Command;
use std::time::{Duration, SystemTime};
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::cell::RefCell;
use std::thread;
use clap::Parser;
@ -23,10 +22,6 @@ pub struct Cli {
#[arg(long, default_value_t = 993)]
port: u16,
// the resolved address(es)
#[arg(skip)]
addrs: RefCell<Vec<SocketAddr>>,
/// IMAP user name
#[arg(short, long)]
username: String,
@ -51,7 +46,7 @@ pub struct Cli {
#[derive(Debug)]
struct Status {
connected: bool,
last_run: SystemTime,
last_run: SystemTime
}
const CONNECTION_LOST_ERRORS: &[ErrorKind] = &[
@ -167,11 +162,7 @@ pub fn run() -> AResult<()> {
time_to_reconnect = u64::min(time_to_reconnect*2, 1800);
if cli.verbose > 0 {
println!("Error: {:?}", err);
}
println!("Cannot connect currently, retrying in {time_to_reconnect} seconds");
thread::sleep(Duration::from_secs(time_to_reconnect));
continue;
@ -212,16 +203,10 @@ pub fn connect_and_idle<F: Fn(), G: Fn()>(cli: &Cli, connected_callback: F, mail
let mut tls_client = ClientConnection::new(
Arc::new(tls_config),
cli.server.as_str().try_into().unwrap())?;
let mut addrs = cli.addrs.borrow_mut();
if addrs.is_empty() {
addrs.extend(
(cli.server.as_str(), cli.port)
.to_socket_addrs()
.map_err(|e|io::Error::new(ErrorKind::NotConnected, e.to_string()))?
);
}
let addrs = (cli.server.as_str(), cli.port)
.to_socket_addrs()
.map_err(|e|io::Error::new(ErrorKind::NotConnected, e.to_string()))?
.collect::<Vec<_>>();
let mut socket = TcpStream::connect(addrs.as_slice())?;
let mut state = ImapState::Unauthenticated;