Skip to content

Commit

Permalink
Feature: html and text tabs (#23)
Browse files Browse the repository at this point in the history
* Added tabs for HTML and Text parts of an email

* Only store plaintext in text field of message
  • Loading branch information
marlonbaeten authored Mar 6, 2023
1 parent fc82196 commit 0488cf4
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 125 deletions.
4 changes: 2 additions & 2 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 23 additions & 9 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ fn load_index() -> Option<String> {
let index: String = std::fs::read_to_string("dist/index.html").ok()?;

// remove slash from start of asset includes, so they are loaded by relative path
Some(index
.replace("href=\"/", "href=\"./static/")
.replace("'/mailcrab-frontend", "'./static/mailcrab-frontend"))
Some(
index
.replace("href=\"/", "href=\"./static/")
.replace("'/mailcrab-frontend", "'./static/mailcrab-frontend"),
)
}

#[tokio::main]
Expand Down Expand Up @@ -141,13 +143,25 @@ mod test {
.to(format!("{to_name} <{to}>").parse().unwrap())
.subject(CatchPhase().fake::<String>());

let mut multipart = MultiPart::mixed().multipart(
MultiPart::alternative()
.singlepart(SinglePart::plain(body))
.singlepart(SinglePart::html(html)),
);

let r: u8 = rng.gen();
let mut multipart = MultiPart::mixed().build();

match r % 3 {
0 => {
multipart = multipart.multipart(
MultiPart::alternative()
.singlepart(SinglePart::plain(body))
.singlepart(SinglePart::html(html)),
);
}
1 => {
multipart = multipart.singlepart(SinglePart::plain(body));
}
_ => {
multipart = multipart.singlepart(SinglePart::html(html));
}
};

let filebody = std::fs::read("blank.pdf").unwrap();
let content_type = ContentType::parse("application/pdf").unwrap();

Expand Down
5 changes: 4 additions & 1 deletion backend/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ impl TryFrom<mail_parser::Message<'_>> for MailMessage {

let subject = message.subject().unwrap_or_default().to_owned();

let text = match message.text_bodies().next() {
let text = match message
.text_bodies()
.find(|p| p.is_text() && !p.is_text_html())
{
Some(item) => item.to_string(),
_ => Default::default(),
};
Expand Down
71 changes: 40 additions & 31 deletions frontend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mailcrab-frontend"
version = "0.6.0"
version = "0.7.0"
edition = "2021"
publish = false

Expand Down
53 changes: 2 additions & 51 deletions frontend/src/formatted.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{api::get_api_path, types::MailMessage};
use crate::{api::get_api_path, message_header::MessageHeader, types::MailMessage};
use wasm_bindgen::JsCast;
use web_sys::{Event, HtmlIFrameElement, HtmlLinkElement};
use yew::{function_component, html, Html, Properties};
Expand Down Expand Up @@ -54,56 +54,7 @@ pub fn view(props: &FormattedProps) -> Html {

html! {
<>
<table>
<tbody>
<tr>
<th>{"From"}</th>
<td>
<span class="name">
{message.from.clone().name.unwrap_or_default()}
</span>
<span class="email">
{message.from.clone().email.unwrap_or_default()}
</span>
</td>
</tr>
<tr>
<th>{"To"}</th>
<td>
{message.to.iter().map(|to| {
html! {
<span class="user">
<span class="name">
{to.clone().name.unwrap_or_default()}
</span>
<span class="email">
{to.clone().email.unwrap_or_default()}
</span>
</span>
}
}).collect::<Html>()}
</td>
</tr>
<tr>
<th>{"Subject"}</th>
<td>{&message.subject}</td>
</tr>
</tbody>
</table>
<div class="attachments">
{message.attachments.iter().map(|a| {
html! {
<a
href={format!("data:{};base64,{}", &a.mime, &a.content)}
download={a.filename.clone()}
class={&a.mime.replace('/', "-")}
>
{&a.filename}
<span class="size">{&a.size}</span>
</a>
}
}).collect::<Html>()}
</div>
<MessageHeader message={message.clone()} />
<div class="body">
<iframe onload={onload} src={body_src}></iframe>
</div>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use overview::Overview;
mod api;
mod formatted;
mod list;
mod message_header;
mod overview;
mod plaintext;
mod types;
mod view;
mod websocket;
Expand Down
Loading

0 comments on commit 0488cf4

Please sign in to comment.