From a708696189516563d7be4d57a78f7d902a10ac55 Mon Sep 17 00:00:00 2001 From: Oliver Ford Date: Thu, 23 Jun 2022 20:36:30 +0100 Subject: [PATCH] Show link URLs on hover I don't think it's possible to do this (yet?) with ammonia, cf. rust-ammonia/ammonia#163. --- notmuch-more/src/parse/body.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/notmuch-more/src/parse/body.rs b/notmuch-more/src/parse/body.rs index 23b5158..9400a1c 100644 --- a/notmuch-more/src/parse/body.rs +++ b/notmuch-more/src/parse/body.rs @@ -2,6 +2,7 @@ use anyhow::anyhow; use email::mimeheaders::MimeContentType; use email::MimeMultipartType; use itertools::Itertools; +use regex::Regex; use serde::Serialize; use crate::NotmuchMoreError; @@ -34,11 +35,17 @@ pub(crate) fn parse_body_part(part: &mailparse::ParsedMail) -> Result match part.ctype.mimetype.as_str() { "text/html" => Ok(EmlBody { - content: ammonia::Builder::default() - .set_tag_attribute_value("a", "target", "_blank") - .rm_tag_attributes("img", &["src"]) - .clean(&part.get_body()?) - .to_string(), + content: { + let b = ammonia::Builder::default() + .set_tag_attribute_value("a", "target", "_blank") + .rm_tag_attributes("img", &["src"]) + .clean(&part.get_body()?); + + Regex::new("href=\"([^\"]+)") + .unwrap() + .replace_all(&b.to_string(), "href=\"$1\" title=\"$1\"") + .into() + }, content_base64: match part.get_body_encoded() { mailparse::body::Body::Base64(body) => { String::from_utf8(body.get_raw().into()).map_or_else(|_| None, Some)