From 7e73268bb75d7c089a47804c503273b5c40c7edd Mon Sep 17 00:00:00 2001 From: ClaraCrazy Date: Sat, 28 Sep 2024 04:44:13 +0200 Subject: [PATCH] /raw endpoint working --- application/imap-service.js | 11 +++++--- application/mail-processing-service.js | 4 +-- .../web/public/stylesheets/custom.css | 6 ++++- infrastructure/web/routes/inbox.js | 8 +++--- infrastructure/web/views/raw.twig | 26 ++++++++++--------- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/application/imap-service.js b/application/imap-service.js index cbfa672..1be5f60 100644 --- a/application/imap-service.js +++ b/application/imap-service.js @@ -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']]) diff --git a/application/mail-processing-service.js b/application/mail-processing-service.js index 228d305..1bdf750 100644 --- a/application/mail-processing-service.js +++ b/application/mail-processing-service.js @@ -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() { diff --git a/infrastructure/web/public/stylesheets/custom.css b/infrastructure/web/public/stylesheets/custom.css index bec7440..3314227 100644 --- a/infrastructure/web/public/stylesheets/custom.css +++ b/infrastructure/web/public/stylesheets/custom.css @@ -6,7 +6,11 @@ body { min-height: 100vh; background-color: #131516; color: #cccccc; - overflow: hidden; + +} + +body::-webkit-scrollbar { + display: none; } main { diff --git a/infrastructure/web/routes/inbox.js b/infrastructure/web/routes/inbox.js index 6ef25f6..6eb48b1 100644 --- a/infrastructure/web/routes/inbox.js +++ b/infrastructure/web/routes/inbox.js @@ -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, '
') 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 { diff --git a/infrastructure/web/views/raw.twig b/infrastructure/web/views/raw.twig index 9cfa659..8328d6e 100644 --- a/infrastructure/web/views/raw.twig +++ b/infrastructure/web/views/raw.twig @@ -1,18 +1,20 @@ -{% extends 'layout.twig' %} - {% block body %} + + {{ title }} + + + -
-

Not yet...

-{% for header, html in mail.headers %} -

This doesnt work rn

- {# 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. - #} + + -{% endfor %} -
+ + + + + + + {{ mail | raw }} {% endblock %}