Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text_bodies does not seem to return a useful iterator #73

Open
Bengreen opened this issue Dec 17, 2023 · 1 comment
Open

text_bodies does not seem to return a useful iterator #73

Bengreen opened this issue Dec 17, 2023 · 1 comment

Comments

@Bengreen
Copy link

The iterator returned by text_bodies returns an object that is not necessarily a text element. But can become a text element.

Perhaps it might be better to have an iterator that returns a generic object that can be converted to text using functions such as those found in body_text (https://github.com/stalwartlabs/mail-parser/blob/65533d3faf6f147fa288fa30eae0bb4df80b2948/src/core/message.rs#L407C12-L407C21)
and perhaps make the body_text function generically available as a helper function rather than a method.

Alternatively include the text transforms of body_text to be included in the iterator of text_bodies so that the relevant text is returned.

What I found difficult about the current implementation is that an iterator using the text code returns "<html><p>I was thinking about quitting the &ldquo;exporting&rdquo; to focus just on the &ldquo;importing&rdquo;,</p><p>but then I thought, why not do both? &#x263A;</p></html>" for .text_contents() rather than I was thinking about quitting the “exporting” to focus just on the “importing”, but then I thought, why not do both? ☺ which would seem a more natural return.

@Bengreen
Copy link
Author

maybe something like this might be useful

fn part_to_text<'x>(msg: &'x MessagePart<'x>) -> Option<Cow<'x, str>> {
    match &msg.body {
        PartType::Text(text) => Some(text.as_ref().into()),
        PartType::Html(html) => Some(html_to_text(html.as_ref()).into()),
        PartType::Binary(_) => todo!(),
        PartType::InlineBinary(_) => todo!(),
        PartType::Message(_) => todo!(),
        PartType::Multipart(_) => todo!(),
    }
}


for message_text in message.text_bodies().map(part_to_text) {
    println!("got message = {}", message_text.unwrap());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant