Browse Source

melib: decode text inline message/rfc822 attachments

jmap-eventsource
Manos Pitsidianakis 1 year ago
parent
commit
b9c07bacef
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 25
      melib/src/email/attachments.rs
  2. 8
      src/components/mail/view.rs
  3. 6
      src/components/mail/view/envelope.rs

25
melib/src/email/attachments.rs

@ -763,15 +763,9 @@ pub fn interpret_format_flowed(_t: &str) -> String {
unimplemented!()
}
fn decode_rfc822(_raw: &[u8]) -> Attachment {
// FIXME
let builder = AttachmentBuilder::new(b"message/rfc822 cannot be displayed");
builder.build()
}
type Filter<'a> = Box<dyn FnMut(&'a Attachment, &mut Vec<u8>) -> () + 'a>;
type Filter<'a> = Box<dyn FnMut(&Attachment, &mut Vec<u8>) -> () + 'a>;
fn decode_rec_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) -> Vec<u8> {
fn decode_rec_helper<'a, 'b>(a: &'a Attachment, filter: &mut Option<Filter<'b>>) -> Vec<u8> {
match a.content_type {
ContentType::Other { .. } => Vec::new(),
ContentType::Text { .. } => decode_helper(a, filter),
@ -780,8 +774,13 @@ fn decode_rec_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) ->
}
ContentType::PGPSignature => Vec::new(),
ContentType::MessageRfc822 => {
let temp = decode_rfc822(a.body());
decode_rec(&temp, None)
if a.content_disposition.kind.is_inline() {
let b = AttachmentBuilder::new(a.body()).build();
let ret = decode_rec_helper(&b, filter);
ret
} else {
b"message/rfc822 attachment".to_vec()
}
}
ContentType::Multipart {
ref kind,
@ -820,11 +819,11 @@ fn decode_rec_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) ->
}
}
pub fn decode_rec<'a>(a: &'a Attachment, mut filter: Option<Filter<'a>>) -> Vec<u8> {
pub fn decode_rec<'a, 'b>(a: &'a Attachment, mut filter: Option<Filter<'b>>) -> Vec<u8> {
decode_rec_helper(a, &mut filter)
}
fn decode_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) -> Vec<u8> {
fn decode_helper<'a, 'b>(a: &'a Attachment, filter: &mut Option<Filter<'b>>) -> Vec<u8> {
let charset = match a.content_type {
ContentType::Text { charset: c, .. } => c,
_ => Default::default(),
@ -861,6 +860,6 @@ fn decode_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) -> Vec<
ret
}
pub fn decode<'a>(a: &'a Attachment, mut filter: Option<Filter<'a>>) -> Vec<u8> {
pub fn decode<'a, 'b>(a: &'a Attachment, mut filter: Option<Filter<'b>>) -> Vec<u8> {
decode_helper(a, &mut filter)
}

8
src/components/mail/view.rs

@ -332,16 +332,12 @@ impl MailView {
}
/// Returns the string to be displayed in the Viewer
fn attachment_to_text<'closure, 's: 'closure, 'context: 's>(
&'s mut self,
body: &'context Attachment,
context: &'context mut Context,
) -> String {
fn attachment_to_text(&mut self, body: &Attachment, context: &mut Context) -> String {
let finder = LinkFinder::new();
let coordinates = self.coordinates;
let body_text = String::from_utf8_lossy(&decode_rec(
body,
Some(Box::new(move |a: &'closure Attachment, v: &mut Vec<u8>| {
Some(Box::new(move |a: &Attachment, v: &mut Vec<u8>| {
if a.content_type().is_text_html() {
/* FIXME: duplication with view/html.rs */
if let Some(filter_invocation) =

6
src/components/mail/view/envelope.rs

@ -84,11 +84,7 @@ impl EnvelopeView {
}
/// Returns the string to be displayed in the Viewer
fn attachment_to_text<'closure, 's: 'closure, 'context: 's>(
&'s self,
body: &'context Attachment,
context: &'context mut Context,
) -> String {
fn attachment_to_text(&self, body: &Attachment, context: &mut Context) -> String {
let finder = LinkFinder::new();
let body_text = String::from_utf8_lossy(&decode_rec(
&body,

Loading…
Cancel
Save