fn find_first_mail_sent_before(
        buf: &mut Vec<u8>,
        parsing_state: &mut ParsingState,
        next_day_start: &DateTime<Local>,
    ) -> Result<Option<(Vec<u8>, DateTime<Local>)>> {
        loop {
            let email_bytes = Email::read_next_mail(buf, parsing_state)?;
            let email_headers = email_bytes
                .as_ref()
                .map(|bytes| mailparse::parse_headers(bytes))
                .transpose()?;
            let email_date = email_headers.and_then(|h| Email::parse_email_headers_date(&h.0));
            match email_date {
                None => {
                    return Ok(None); // no more emails
                }
                Some(date) if date < *next_day_start => {
                    // first date before my end date
                    return Ok(Some((email_bytes.unwrap(), date)));
                }
                Some(_) => {} // email, but after my end date
            }
        }
    }
// skip emails which are newer than the date i'm interested in.
// remember we're reading from the end.
// it's ok to just read headers for now (I just want the date)
skip emails which are newer than the date i'm interested in.
remember we're reading from the end.
it's ok to just read headers for now (I just want the date)
skip emails which are newer than the date i ' m interested in . remember we ' re reading from the end . it ' s ok to just read headers for now ( I just want the date )
fn find_first_mail_sent_before(
        buf: &mut Vec<u8>,
        parsing_state: &mut ParsingState,
        next_day_start: &DateTime<Local>,
    ) -> Result<Option<(Vec<u8>, DateTime<Local>)>> {
        loop {
            let email_bytes = Email::read_next_mail(buf, parsing_state)?;
            let email_headers = email_bytes
                .as_ref()
                .map(|bytes| mailparse::parse_headers(bytes))
                .transpose()?;
            let email_date = email_headers.and_then(|h| Email::parse_email_headers_date(&h.0));
            match email_date {
                None => {
                    return Ok(None); // no more emails
                }
                Some(date) if date < *next_day_start => {
                    // first date before my end date
                    return Ok(Some((email_bytes.unwrap(), date)));
                }
                Some(_) => {} // email, but after my end date
            }
        }
    }
fn find_first_mail_sent_before ( buf : & mut Vec < u8 > , parsing_state : & mut ParsingState , next_day_start : & DateTime < Local > , ) -> Result < Option < ( Vec < u8 > , DateTime < Local > ) > > { loop { let email_bytes = Email :: read_next_mail ( buf , parsing_state ) ? ; let email_headers = email_bytes . as_ref ( ) . map ( | bytes | mailparse :: parse_headers ( bytes ) ) . transpose ( ) ? ; let email_date = email_headers . and_then ( | h | Email :: parse_email_headers_date ( & h . 0 ) ) ; match email_date { None => { return Ok ( None ) ; // no more emails } Some ( date ) if date < * next_day_start => { // first date before my end date return Ok ( Some ( ( email_bytes . unwrap ( ) , date ) ) ) ; } Some ( _ ) => { } // email, but after my end date } } }
skip emails which are newer than the date i'm interested in.
skip emails which are newer than the date i ' m interested in .
buf
&mut Vec<u8>
parsing_state
&mut ParsingState
next_day_start
&DateTime<Local>
buf
&mut Vec<u8>
parsing_state
&mut ParsingState
next_day_start
&DateTime<Local>