Skip to content

Commit

Permalink
Prioritize mail subject in the panel
Browse files Browse the repository at this point in the history
  • Loading branch information
UwUDev committed Sep 28, 2024
1 parent 8edc9c3 commit f7cb65d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,6 @@ async fn info_handler(
Ok(())
}

// TODO: show all FROM and TO
// TODO: Detect if it's not a HTML mail and replace new lines with <br>
async fn preview_mail_handler(
request: Request,
writer: Arc<AsyncMutex<BufWriter<tokio::net::tcp::OwnedWriteHalf>>>,
Expand Down
34 changes: 18 additions & 16 deletions src/pages/panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,18 @@ <h2>System Statistics</h2>
</section>
<section id="mails">
<h2>Mails</h2>
<!-- The delete all button -->
<div id="delete-all-button" onclick="deleteAllMails()">Purge all mails</div>
<table>
<thead>
<tr>
<th>To</th>
<th>From</th>
<th>Body</th>
<th>Description</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="mail-table-body">
<!-- mails rows will be inserted here -->
</tbody>
</table>
<div id="pagination">
Expand Down Expand Up @@ -426,21 +424,25 @@ <h2>Mails</h2>

let bodyText;

if (isHTML(mail.body)) {
const parser = new DOMParser();
const doc = parser.parseFromString(mail.body, 'text/html');

// remove all <style> elements from the document
const styleElements = doc.getElementsByTagName('style');
for (let i = styleElements.length - 1; i >= 0; i--) {
styleElements[i].parentNode.removeChild(styleElements[i]);
if (!mail.subject) {
if (isHTML(mail.body)) {
const parser = new DOMParser();
const doc = parser.parseFromString(mail.body, 'text/html');

// remove all <style> elements from the document
const styleElements = doc.getElementsByTagName('style');
for (let i = styleElements.length - 1; i >= 0; i--) {
styleElements[i].parentNode.removeChild(styleElements[i]);
}

// get the content of the <body> if present, otherwise get the content of the <html>
bodyText = doc.body ? doc.body.textContent : doc.documentElement.textContent || "";
} else {
// no html detected
bodyText = mail.body;
}

// get the content of the <body> if present, otherwise get the content of the <html>
bodyText = doc.body ? doc.body.textContent : doc.documentElement.textContent || "";
} else {
// no html detected
bodyText = mail.body;
bodyText = mail.subject;
}


Expand Down

0 comments on commit f7cb65d

Please sign in to comment.