Improve mail-id handling
This commit is contained in:
parent
cb47c68771
commit
84c8cbdc82
1 changed files with 19 additions and 7 deletions
|
@ -112,6 +112,7 @@ fn read_mail(mailbox: &str, mail: &mut MailEntry) -> Result<()> {
|
||||||
let mailbox = make_maildir_path(mailbox);
|
let mailbox = make_maildir_path(mailbox);
|
||||||
let mailbox = mailbox.to_str().chain_err(|| "Invalid path")?;
|
let mailbox = mailbox.to_str().chain_err(|| "Invalid path")?;
|
||||||
let message_id = get_message_id(mail)?;
|
let message_id = get_message_id(mail)?;
|
||||||
|
let message_id = message_id.replace("$", ".");
|
||||||
let read_command = format!(
|
let read_command = format!(
|
||||||
"push <limit>~(~i{})<return><search>~i{}<return><display-message>",
|
"push <limit>~(~i{})<return><search>~i{}<return><display-message>",
|
||||||
message_id,
|
message_id,
|
||||||
|
@ -129,12 +130,14 @@ fn sort_mail(
|
||||||
dialog: &mut impl DialogProvider,
|
dialog: &mut impl DialogProvider,
|
||||||
mut mail: MailEntry,
|
mut mail: MailEntry,
|
||||||
mailbox: &SortBox,
|
mailbox: &SortBox,
|
||||||
|
blacklist: &mut HashSet<String>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
enum Options {
|
enum Options {
|
||||||
Ignore,
|
Ignore,
|
||||||
ReadNow,
|
ReadNow,
|
||||||
MoveTo(String),
|
MoveTo(String),
|
||||||
};
|
};
|
||||||
|
let message_id = get_message_id(&mut mail).unwrap_or("".to_owned());
|
||||||
let mut options = vec![
|
let mut options = vec![
|
||||||
("Read now: Open in mutt now".to_owned(), Options::ReadNow),
|
("Read now: Open in mutt now".to_owned(), Options::ReadNow),
|
||||||
("Ignore: Ignore this mail".to_owned(), Options::Ignore),
|
("Ignore: Ignore this mail".to_owned(), Options::Ignore),
|
||||||
|
@ -152,11 +155,13 @@ fn sort_mail(
|
||||||
let msg = format!("Handling E-mail:\n{}", print_headers(&mut mail)?);
|
let msg = format!("Handling E-mail:\n{}", print_headers(&mut mail)?);
|
||||||
let choice = dialog.select_option(msg, options)?;
|
let choice = dialog.select_option(msg, options)?;
|
||||||
match choice {
|
match choice {
|
||||||
Options::Ignore => {}
|
Options::Ignore => {
|
||||||
|
blacklist.insert(message_id);
|
||||||
|
}
|
||||||
Options::ReadNow => {
|
Options::ReadNow => {
|
||||||
read_mail(mailbox.mailbox, &mut mail)?;
|
read_mail(mailbox.mailbox, &mut mail)?;
|
||||||
if let Some(mail) = get_maildir(mailbox.mailbox).find(mail.id()) {
|
if let Some(mail) = get_maildir(mailbox.mailbox).find(mail.id()) {
|
||||||
return sort_mail(dialog, mail, mailbox);
|
return sort_mail(dialog, mail, mailbox, blacklist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Options::MoveTo(new_mailbox) => move_mail(&mail, mailbox.mailbox, &new_mailbox)?,
|
Options::MoveTo(new_mailbox) => move_mail(&mail, mailbox.mailbox, &new_mailbox)?,
|
||||||
|
@ -164,11 +169,16 @@ fn sort_mail(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_mail(mailbox: &SortBox, read: bool) -> Result<Option<MailEntry>> {
|
fn next_mail(
|
||||||
|
mailbox: &SortBox,
|
||||||
|
read: bool,
|
||||||
|
blacklist: &mut HashSet<String>,
|
||||||
|
) -> Result<Option<MailEntry>> {
|
||||||
let maildir = get_maildir(mailbox.mailbox);
|
let maildir = get_maildir(mailbox.mailbox);
|
||||||
for mail in maildir.list_cur() {
|
for mail in maildir.list_cur() {
|
||||||
let mail = mail?;
|
let mut mail = mail?;
|
||||||
if !mail.is_seen() || read {
|
let message_id = get_message_id(&mut mail).unwrap_or("".to_owned());
|
||||||
|
if (!mail.is_seen() || read) && !blacklist.contains(&message_id) {
|
||||||
return Ok(Some(mail));
|
return Ok(Some(mail));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,8 +191,9 @@ pub fn sort_mailbox(
|
||||||
sort_read: bool,
|
sort_read: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
update_mailbox(mailbox.mailbox)?;
|
update_mailbox(mailbox.mailbox)?;
|
||||||
while let Some(mail) = next_mail(mailbox, sort_read)? {
|
let mut blacklist = HashSet::default();
|
||||||
sort_mail(dialog, mail, mailbox)?;
|
while let Some(mail) = next_mail(mailbox, sort_read, &mut blacklist)? {
|
||||||
|
sort_mail(dialog, mail, mailbox, &mut blacklist)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -229,6 +240,7 @@ fn create_task(mail: &mut MailEntry) -> Result<Task> {
|
||||||
let from = MAIL_REGEX.replace(&from, "");
|
let from = MAIL_REGEX.replace(&from, "");
|
||||||
let from = from.trim_matches(|x: char| x.is_whitespace() || x == '"');
|
let from = from.trim_matches(|x: char| x.is_whitespace() || x == '"');
|
||||||
let message_id = get_message_id(mail)?;
|
let message_id = get_message_id(mail)?;
|
||||||
|
let message_id = message_id.trim().trim_matches(|x| x == '<' || x == '>');
|
||||||
let mut t = TaskBuilder::default()
|
let mut t = TaskBuilder::default()
|
||||||
.description(format!("Mail: {}: {}", from, subject))
|
.description(format!("Mail: {}: {}", from, subject))
|
||||||
.build()
|
.build()
|
||||||
|
|
Loading…
Reference in a new issue