/raw endpoint working

pull/16/head
ClaraCrazy 2024-09-28 04:44:13 +02:00
parent b0d9014a00
commit 7e73268bb7
5 changed files with 34 additions and 21 deletions

View File

@ -262,7 +262,7 @@ class ImapService extends EventEmitter {
return Mail.create(to, from, date, subject, uid)
}
async fetchOneFullMail(to, uid) {
async fetchOneFullMail(to, uid, raw = false) {
if (!this.connection) {
// Here we 'fail fast' instead of waiting for the connection.
throw new Error('imap connection not ready')
@ -281,10 +281,15 @@ class ImapService extends EventEmitter {
if (messages.length === 0) {
return("womp womp")
}
const fullBody = _.find(messages[0].parts, {which: ''})
return simpleParser(fullBody.body)
if (!raw) {
const fullBody = await _.find(messages[0].parts, {which: ''})
return simpleParser(fullBody.body)
} else {
return messages[0].parts[1].body
}
}
async _getAllUids() {
// We ignore mails that are flagged as DELETED, but have not been removed (expunged) yet.
const uids = await this._searchWithoutFetch([['!DELETED']])

View File

@ -37,8 +37,8 @@ class MailProcessingService extends EventEmitter {
}
}
getOneFullMail(address, uid) {
return this.cachedFetchFullMail(address, uid)
getOneFullMail(address, uid, raw = false) {
return this.cachedFetchFullMail(address, uid, raw)
}
getAllMailSummaries() {

View File

@ -6,7 +6,11 @@ body {
min-height: 100vh;
background-color: #131516;
color: #cccccc;
overflow: hidden;
}
body::-webkit-scrollbar {
display: none;
}
main {

View File

@ -101,15 +101,17 @@ router.get(
async (req, res, next) => {
try {
const mailProcessingService = req.app.get('mailProcessingService')
const mail = await mailProcessingService.getOneFullMail(
mail = await mailProcessingService.getOneFullMail(
req.params.address,
req.params.uid
req.params.uid,
true
)
mail = mail.replace(/(?:\r\n|\r|\n)/g, '<br>')
if (mail && mail != "womp womp") {
// Emails are immutable, cache if found
res.set('Cache-Control', 'private, max-age=600')
res.render('raw', {
title: mail.subject + " | raw | " + req.params.address,
title: req.params.uid + " | raw | " + req.params.address,
mail
})
} else {

View File

@ -1,18 +1,20 @@
{% extends 'layout.twig' %}
{% block body %}
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimal-ui">
<meta name="darkreader" content="stfu">
<div class="mail_body">
<p>Not yet...</p>
{% for header, html in mail.headers %}
<p>This doesnt work rn</p>
{# TODO:
Make raw email. show all headers, preferrably even attachment raws and ofc mail.
need inspiration? open a mail "raw" in gmail. thats what I wanna mirror.
#}
<meta name="description" content="Dont give shady companies your real email. Use 48hr.email to protect your privacy!">
<meta property="og:image" content="/images/logo.png">
{% endfor %}
</div>
<link rel="shortcut icon" href="/images/logo.ico">
<link rel='stylesheet' href='/dependencies/milligram.css' />
<link rel='stylesheet' href='/stylesheets/custom.css' />
<script src="/socket.io/socket.io.js" defer="true"></script>
<script src="/javascripts/notifications.js" defer="true"></script>
</head>
{{ mail | raw }}
{% endblock %}