Skip to content

Commit

Permalink
Show link URLs on hover
Browse files Browse the repository at this point in the history
I don't think it's possible to do this (yet?) with ammonia, cf.
rust-ammonia/ammonia#163.
  • Loading branch information
OJFord committed Jun 23, 2022
1 parent 3d09903 commit a708696
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions notmuch-more/src/parse/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,11 +35,17 @@ pub(crate) fn parse_body_part(part: &mailparse::ParsedMail) -> Result<EmlBody, N
match MimeMultipartType::from_content_type(mimect) {
None => 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)
Expand Down

0 comments on commit a708696

Please sign in to comment.