From ef5d91154713635f63e401353d83978e558c6f1f Mon Sep 17 00:00:00 2001
From: Nite <67828948+Niteletsplay@users.noreply.github.com>
Date: Mon, 10 Apr 2023 19:44:06 +0200
Subject: [PATCH 01/11] save
---
.gitignore | 1 +
web/css/tempmail.css | 19 +++++++++++++++----
web/js/tempmail.js | 2 +-
web/tempmail.html | 5 ++++-
4 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/.gitignore b/.gitignore
index fd9b3c20..1de8a281 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ main.h
a.out
notes.txt
data.json.old
+data/
dist/
diff --git a/web/css/tempmail.css b/web/css/tempmail.css
index aae4f9ce..39299aa8 100644
--- a/web/css/tempmail.css
+++ b/web/css/tempmail.css
@@ -6,10 +6,21 @@
background-color: var(--bg-bright);
background: linear-gradient(0deg, var(--bg-bright) 50%, var(--bg) 100%);
box-shadow: 0.3rem 0.3rem 0.6rem var(--shadow-1), -0.2rem -0.2rem 0.5rem var(--shadow-2);
+ display: flex;
+ align-content: center;
+ flex-wrap: wrap;
}
-.create-mail-btn {
- width: 10vw;
- height: 10vh;
- margin: 9rem;
+.tempmail-manage {
+ height: 6vh;
+ margin-bottom: unset;
+ justify-content: center;
+}
+
+.tempmail-new-email,
+.tempmail-delete-email {
+ width: 5rem;
+ color: var(--textColor-1);
+ font-size: 1.5rem;
+ text-align: center;
}
\ No newline at end of file
diff --git a/web/js/tempmail.js b/web/js/tempmail.js
index f2bda899..74e8d081 100644
--- a/web/js/tempmail.js
+++ b/web/js/tempmail.js
@@ -24,7 +24,7 @@ const myBtn = document.querySelector(".create-mail-btn");
const myPara = document.querySelector(".email-headline");
myBtn.addEventListener("click", () => {
- fetch("https://cors-anywhere.herokuapp.com/https://www.developermail.com/api/v1/mailbox", {
+ fetch("http://localhost:8081/api/mailbox", {
method: "PUT",
headers: {
"accept": "application/json"
diff --git a/web/tempmail.html b/web/tempmail.html
index e5fef59a..121ed7ae 100644
--- a/web/tempmail.html
+++ b/web/tempmail.html
@@ -32,7 +32,10 @@
From 2a59c46fd6cd7b811c90edefd49e2aa33778ba6a Mon Sep 17 00:00:00 2001
From: 9glenda
Date: Fri, 21 Apr 2023 07:33:02 +0000
Subject: [PATCH 02/11] allow cors credentials
---
api/temp_mail.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/api/temp_mail.go b/api/temp_mail.go
index 16c4bed4..1880f938 100644
--- a/api/temp_mail.go
+++ b/api/temp_mail.go
@@ -13,6 +13,7 @@ func (config ApiConfig) ServeTempMail() {
// Add CORS middleware to allow all requests
corsConfig := cors.DefaultConfig()
corsConfig.AllowAllOrigins = true
+ corsConfig.AllowCredentials = true
router.Use(cors.New(corsConfig))
// Reverse proxy to https://www.developermail.com/api/v1/
From 075431e35973251a90c55ba9ed773a059ad579a2 Mon Sep 17 00:00:00 2001
From: 9glenda
Date: Fri, 21 Apr 2023 07:35:41 +0000
Subject: [PATCH 03/11] allow headers
---
api/temp_mail.go | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/api/temp_mail.go b/api/temp_mail.go
index 1880f938..2a7f0568 100644
--- a/api/temp_mail.go
+++ b/api/temp_mail.go
@@ -14,6 +14,10 @@ func (config ApiConfig) ServeTempMail() {
corsConfig := cors.DefaultConfig()
corsConfig.AllowAllOrigins = true
corsConfig.AllowCredentials = true
+ corsConfig.AllowHeaders = []string{
+ "X-MailboxToken",
+ //"accept",
+ }
router.Use(cors.New(corsConfig))
// Reverse proxy to https://www.developermail.com/api/v1/
From 613ba94c3be699ae71bc6411dba9a3005a84f1d9 Mon Sep 17 00:00:00 2001
From: Nite <67828948+Niteletsplay@users.noreply.github.com>
Date: Fri, 21 Apr 2023 22:26:57 +0200
Subject: [PATCH 04/11] WIP
---
api/temp_mail.go | 6 +-
web/css/tempmail.css | 238 ++++++++++++++++++++++++++++++++++++++++++-
web/desktop.html | 6 +-
web/js/tempmail.js | 206 ++++++++++++++++++++++++++++++++-----
web/tempmail.html | 110 +++++++++++++++++++-
5 files changed, 527 insertions(+), 39 deletions(-)
diff --git a/api/temp_mail.go b/api/temp_mail.go
index 2a7f0568..23442e33 100644
--- a/api/temp_mail.go
+++ b/api/temp_mail.go
@@ -1,10 +1,11 @@
package api
import (
- "github.com/gin-contrib/cors"
- "github.com/gin-gonic/gin"
"net/http/httputil"
"net/url"
+
+ "github.com/gin-contrib/cors"
+ "github.com/gin-gonic/gin"
)
func (config ApiConfig) ServeTempMail() {
@@ -16,6 +17,7 @@ func (config ApiConfig) ServeTempMail() {
corsConfig.AllowCredentials = true
corsConfig.AllowHeaders = []string{
"X-MailboxToken",
+ "Content-Type",
//"accept",
}
router.Use(cors.New(corsConfig))
diff --git a/web/css/tempmail.css b/web/css/tempmail.css
index 39299aa8..54f8b258 100644
--- a/web/css/tempmail.css
+++ b/web/css/tempmail.css
@@ -1,3 +1,5 @@
+/* TOP NAV BAR */
+
.dd-nav-bar {
position: absolute;
top: 0;
@@ -15,12 +17,238 @@
height: 6vh;
margin-bottom: unset;
justify-content: center;
+ width: fit-content;
}
-.tempmail-new-email,
-.tempmail-delete-email {
- width: 5rem;
- color: var(--textColor-1);
+#create-mail-btn,
+#del-mail-btn {
+ width: 6.5rem;
+ height: 3.5rem;
font-size: 1.5rem;
- text-align: center;
+ justify-content: center;
+ margin: 0.5rem;
+}
+
+#show-current-mail {
+ position: absolute;
+ left: 50%;
+ display: flex;
+ align-items: center;
+ top: 50%;
+ -ms-transform: translateY(-50%) translateX(-50%);
+ transform: translateY(-50%) translateX(-50%);
+}
+
+#current-mail {
+ width: 28rem;
+ height: 4rem;
+ border: none;
+ border-radius: 1rem;
+ font-size: 1.4rem;
+ padding-left: 3.8rem;
+ box-shadow: var(--shadowPreset-2);
+ background: none;
+ font-family: inherit;
+ color: var(--textColor-1);
+}
+
+#current-mail::placeholder {
+ color: var(--textColor-1);
+}
+
+#current-mail::-moz-placeholder {
+ color: var(--textColor-1);
+}
+
+#current-mail:-ms-input-placeholder {
+ color: var(--textColor-1);
+}
+
+.tempmail-icon {
+ height: 2rem;
+ position: absolute;
+ font-size: 2rem;
+ padding: 0 1rem;
+ display: flex;
+ color: var(--textColor-1);
+ transition: 0.3s ease;
+}
+
+#mail-token {
+ width: 0;
+ height: 0;
+ color: transparent;
+}
+
+/* MAIL INBOX */
+
+.tempmail-scroll-box {
+ overflow: hidden;
+ overflow-y: scroll;
+ align-items: unset;
+}
+
+.tempmail-scroll-box p {
+ display: flex;
+}
+
+.tempmail-scroll-box::-webkit-scrollbar {
+ width: 12px;
+ -webkit-appearance: none;
+}
+
+.tempmail-scroll-box::-webkit-scrollbar-thumb {
+ background: var(--bg);
+ border-radius: 3rem;
+ box-shadow: var(--shadowPreset-6);
+}
+
+#mail-view-scroll-box {
+ position: relative;
+ margin-top: 11vh;
+ width: 55%;
+ height: 87vh;
+}
+
+#content-view-scroll-box {
+ position: relative;
+ margin-top: 11vh;
+ width: 45%;
+ height: 87vh;
+ margin-right: 1.75rem;
+}
+
+#emails {
+ width: 100%;
+ display: flex;
+ flex-direction: column;
+ padding-top: 2rem;
+}
+
+#split-view {
+ display: flex;
+ flex-direction: row;
+ width: 100%;
+ height: 100%;
+}
+
+#content {
+ width: 100%;
+ display: flex;
+ padding-top: 2rem;
+ flex-direction: column;
+}
+
+
+.mail-chip {
+ width: 95.5%;
+ height: 6vh;
+ display: flex;
+ font-size: 1.6rem;
+ color: var(--textColor-1);
+ cursor: pointer;
+ align-items: unset;
+ transition: 0.3s ease;
+ margin-left: 2rem;
+ align-items: center;
+ flex-direction: row;
+}
+
+.mail-chip-detail {
+ display: block;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ display: block !important;
+}
+
+.mail-chip-detail.mail-header {
+ font-weight: bold;
+ margin-right: 2rem;
+ width: calc(35% - 2rem);
+}
+
+.mail-chip-detail.mail-sender {
+ margin-right: 2rem;
+ width: calc(45% - 2rem);
+}
+
+.mail-chip-detail.mail-date {
+ margin-left: 2rem;
+ width: calc(20% - 2rem);
+}
+
+.mail-header-chip {
+ width: 95%;
+ min-height: calc(12vh + 2rem);
+ display: flex;
+ font-size: 1.6rem;
+ color: var(--textColor-1);
+ align-items: unset;
+ transition: 0.3s ease;
+ padding: 2rem;
+ flex-direction: column;
+}
+
+.mail-content-detail {
+ margin-bottom: 0.5rem;
+}
+
+.top-header {
+ flex-direction: column;
+}
+
+#content-mail-header {
+ margin-bottom: 0;
+ margin-left: 0;
+ margin-top: 0.5rem;
+ font-weight: bold;
+ font-size: 2rem;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ display: block !important;
+}
+
+#content-mail-header {
+ width: 100%;
+ height: 100%;
+}
+
+#mail-loading-spinner {
+ align-self: center;
+ position: unset;
+ margin-left: 1rem;
+}
+
+#refresh-loading-spinner {
+ align-self: center;
+ position: unset;
+ margin-left: 1rem;
+ position: absolute;
+ top: 0;
+ right: 0;
+ top: 50%;
+ -ms-transform: translateY(-50%) translateX(-50%);
+ transform: translateY(-50%) translateX(-50%);
+}
+
+#refresh-btn {
+ position: absolute;
+ top: 0;
+ right: 0;
+ width: 4rem;
+ height: 4rem;
+ border-radius: 4rem;
+ position: absolute;
+ display: flex;
+ align-items: center;
+ top: 50%;
+ -ms-transform: translateY(-50%) translateX(-50%);
+ transform: translateY(-50%) translateX(-50%);
+ margin: 0 !important;
+}
+
+#refresh-icon {
+ font-size: 2rem;
}
\ No newline at end of file
diff --git a/web/desktop.html b/web/desktop.html
index 07944f9c..8d9a4023 100644
--- a/web/desktop.html
+++ b/web/desktop.html
@@ -50,9 +50,9 @@
-
-
-
+
+

+
diff --git a/web/js/tempmail.js b/web/js/tempmail.js
index 74e8d081..8ff688b2 100644
--- a/web/js/tempmail.js
+++ b/web/js/tempmail.js
@@ -20,31 +20,185 @@ channel.addEventListener('message', (event) => {
-const myBtn = document.querySelector(".create-mail-btn");
-const myPara = document.querySelector(".email-headline");
-
-myBtn.addEventListener("click", () => {
- fetch("http://localhost:8081/api/mailbox", {
- method: "PUT",
- headers: {
- "accept": "application/json"
- },
- body: ""
- })
- .then(response => response.json()) // Parse the response as JSON
- .then(data => {
- // Check if the API call was successful and there are no errors
- if (data.success && data.errors === null) {
- // Set the text of the paragraph tag to the name and token values
- myPara.textContent = `Name: ${data.result.name}, Token: ${data.result.token}`;
- } else {
- // Set the text of the paragraph tag to indicate an error occurred
- myPara.textContent = "An error occurred.";
+const mailDetailsFrame = document.getElementById("content")
+const mailDetailsDate = document.getElementById("content-mail-date")
+const mailDetailsSender = document.getElementById("content-mail-sender")
+const mailDetailsHeader = document.getElementById("content-mail-header")
+const mailDetailsBody = document.getElementById("content-mail-body")
+
+const mailListFrame = document.getElementById("emails")
+const newBtn = document.getElementById("create-mail-btn");
+const delBtn = document.getElementById("del-mail-btn");
+const refreshBtn = document.getElementById("refresh-btn");
+const currentMail = document.getElementById("current-mail");
+const mailToken = document.getElementById("mail-token");
+const loadingSpinner = document.getElementById("mail-loading-spinner");
+const refreshLoadingSpinner = document.getElementById("refresh-loading-spinner");
+
+newBtn.addEventListener("click", () => {
+ if (mailToken.innerHTML == "") {
+ loadingSpinner.style.display = "flex";
+
+ fetch("http://localhost:8569/developermail/api/mailbox", {
+ method: "PUT",
+ headers: {
+ "accept": "application/json"
+ },
+ body: ""
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (data.success && data.errors === null) {
+ currentMail.value = data.result.name + "@developermail.com";
+
+ mailToken.innerHTML = data.result.token;
+ } else {
+ currentMail.value = "An error occurred.";
+ }
+ })
+ .then(() => {
+ loadingSpinner.style.display = "none";
+ })
+ .catch(error => {
+ currentMail.value = "An error occurred.";
+ console.error(error);
+ });
+ }
+});
+
+delBtn.addEventListener("click", () => {
+ if (mailToken.innerHTML != "") {
+ loadingSpinner.style.display = "flex";
+
+ fetch("http://localhost:8569/developermail/api/mailbox/" + currentMail.value.split("@")[0], {
+ method: "DELETE",
+ headers: {
+ "accept": "application/json",
+ "X-MailboxToken": mailToken.innerHTML
+ },
+ body: ""
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (data.success && data.errors === null) {
+ mailToken.innerHTML = "";
+
+ currentMail.value = "Tempmail deleted!";
+
+ setTimeout(() => {
+ currentMail.value = "";
+ }, 3000);
+ } else {
+ currentMail.value = "An error occurred.";
+ }
+ })
+ .then(() => {
+ loadingSpinner.style.display = "none";
+ })
+ .catch(error => {
+ currentMail.value = "An error occurred.";
+ console.error(error);
+ });
+ }
+});
+
+refreshBtn.addEventListener("click", () => {
+ if (mailToken.innerHTML != "") {
+ refreshLoadingSpinner.style.display = "flex";
+
+ // Get message IDs
+
+ fetch("http://localhost:8569/developermail/api/mailbox/" + currentMail.value.split("@")[0], {
+ method: "GET",
+ headers: {
+ "accept": "application/json",
+ "X-MailboxToken": mailToken.innerHTML
}
})
- .catch(error => {
- // Set the text of the paragraph tag to indicate an error occurred
- myPara.textContent = "An error occurred.";
- console.error(error);
- });
-});
\ No newline at end of file
+ .then(response => response.json())
+ .then(data => {
+ if (data.success && data.errors === null) {
+
+ console.log(data.result);
+
+ // Get messages using IDs
+
+ if (data.result.length > 0) {
+ fetch("http://localhost:8569/developermail/api/mailbox/" + currentMail.value.split("@")[0] + "/messages", {
+ method: "POST",
+ headers: {
+ "accept": "application/json",
+ "X-MailboxToken": mailToken.innerHTML,
+ "Content-Type": "application/json"
+ },
+ body: JSON.stringify(data.result)
+ })
+ .then(response => {
+ if (response.ok) {
+ return response.json();
+ } else {
+ throw new Error('Network response was not ok.');
+ }
+ })
+ .then(data => {
+ if (data.success && data.errors === null) {
+ for (let i = 0; i < data.result.length; i++) {
+ const mailChip = document.createElement("div");
+ mailChip.className = "mail-chip chip";
+
+ const mailDate = document.createElement("p");
+ mailDate.className = "mail-chip-detail mail-date";
+ mailDate.innerHTML = data.result[i].value.split("Date: ")[1].split("\r\nMessage-ID")[0].match(/\d{2}:\d{2}/)[0];
+
+ const mailSender = document.createElement("p");
+ mailSender.className = "mail-chip-detail mail-sender";
+ mailSender.innerHTML = data.result[i].value.split("From: ")[1].split("\r\nDate:")[0].match(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/)[0];
+
+ const mailHeader = document.createElement("p");
+ mailHeader.className = "mail-chip-detail mail-header";
+ mailHeader.innerHTML = data.result[i].value.split("Subject: ")[1].split("\r\nTo: ")[0];
+
+
+ mailListFrame.appendChild(mailChip);
+ mailChip.appendChild(mailDate);
+ mailChip.appendChild(mailSender);
+ mailChip.appendChild(mailHeader);
+
+ mailChip.addEventListener("click", () => {
+ mailDetailsDate.innerHTML = data.result[i].value.split("Date: ")[1].split("\r\nMessage-ID")[0].match(/\d{2}:\d{2}/)[0];
+ mailDetailsSender.innerHTML = data.result[i].value.split("From: ")[1].split("\r\nDate:")[0].match(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/)[0];
+ mailDetailsHeader.innerHTML = data.result[i].value.split("Subject: ")[1].split("\r\nTo: ")[0];
+ mailDetailsBody.innerHTML = data.result[i].value.split("Content-Type: text/plain; charset=\"UTF-8\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n")[1].split("\r\n\r\n--")[0];
+ });
+ }
+ } else {
+ console.log("An error occurred.");
+ }
+ })
+ .then(() => {
+ refreshLoadingSpinner.style.display = "none";
+ })
+ .catch(error => {
+ console.log("An error occurred.");
+ console.error(error);
+ });
+ }
+ } else {
+ console.log("An error occurred.");
+ }
+ })
+ .then(() => {
+ refreshLoadingSpinner.style.display = "none";
+ })
+ .catch(error => {
+ console.log("An error occurred.");
+ console.error(error);
+ });
+ }
+});
+
+
+// {
+// "key": "638176942571524819",
+// "value": "Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-3f17e584462so20288345e9.2\r\n for ; Fri, 21 Apr 2023 10:17:35 -0700 (PDT)\r\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n d=gmail.com; s=20221208; t=1682097454; x=1684689454;\r\n h=to:subject:message-id:date:from:mime-version:from:to:cc:subject\r\n :date:message-id:reply-to;\r\n bh=MGtAwkOPhhOK6xhGXRsv5NlFTcVWDQz1Orv8i2rlbkE=;\r\n b=QB/rjB2l4YQmRuhq3hl1Wd5GecPv3okJCqDxG0oI5LPa7dEqPcH8S6g2yEPZRCvQtT\r\n 0NOO5pFYIQ1dxDCd+1VWUrN2mSIxwyY0YJQR5AvY3hiRaYvPJqFmECiFjSSi6umAT0ho\r\n 1eRb/QjtuoBiKvTt5D7uR0SKMAubpTZFM5Aiih8rWVgvdzSZMb96Wn1CIC1dMeobn6Ye\r\n bj17iX7TwyOfej5akLhT2K6cx64+/9WSP9DWhHuxk6Dvgb6V/TKm3qc6xPZiZJDv2VKQ\r\n bs+SJdkjCe+vMvq1Ee6ZLXWRhd1QkjUPF+FvcA+mHpwbgU0cd6N0kb7u/lHf85I5Tan+\r\n 4lWA==\r\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n d=1e100.net; s=20221208; t=1682097454; x=1684689454;\r\n h=to:subject:message-id:date:from:mime-version:x-gm-message-state\r\n :from:to:cc:subject:date:message-id:reply-to;\r\n bh=MGtAwkOPhhOK6xhGXRsv5NlFTcVWDQz1Orv8i2rlbkE=;\r\n b=TjyrN2qPfyCTyC7J/x2BveiPKZE66Gg5bpqzlHN0FpkXTJRXjmBsfiEj6tUXRf0Dre\r\n Pw71HMqyRytSqNcHX4rZ0yR7kgf959m5u4Iba2n/pV/QLdEMJtQWJc8LajGcFb1bF0f1\r\n qsN9rWegP6GyO8fDU09LXgHFqr+/CxTCGuF5ZUQdy4r6clNeve+8BPMbtJcNQDQ+rT7a\r\n BQLQlOhjtk8QJq0wTIS6ssack7teXHvGWTa4kUp6HCTVLHDZLiO/mqd+8JXy3/NpsTb+\r\n 1cdYaOWLPaZNw5u+H87/6f2hYL7HOFJy9CFshha+zEeXxETqempsgkyDSFl07YLyAIBl\r\n h+CQ==\r\nX-Gm-Message-State: AAQBX9e5DIHZrK2Z5bcOYriiKNYIZrqwyhD98F2q2aivgAdQXeAw82XT\r\n\tFKLEM8VkPdk7aaV8aS+yJ9qFxWKlf1OrkO0OnKy9eDRA\r\nX-Google-Smtp-Source: AKy350ZCj9rTseJsPkP9ztIj6wDbyQzbpR/YWZfvLJHtYL50AsFFjM7Am2lYXtx6DJ2eJRybacDK9zGlYeD8eUfh9Ec=\r\nX-Received: by 2002:adf:fc87:0:b0:2d1:e517:4992 with SMTP id\r\n g7-20020adffc87000000b002d1e5174992mr4524402wrr.69.1682097453980; Fri, 21 Apr\r\n 2023 10:17:33 -0700 (PDT)\r\nMIME-Version: 1.0\r\nFrom: Forks are better than spoons \r\nDate: Fri, 21 Apr 2023 19:17:22 +0200\r\nMessage-ID: \r\nSubject: tets\r\nTo: z-tsmyw5@developermail.com\r\nContent-Type: multipart/alternative; boundary=\"00000000000038e10805f9dbd5a5\"\r\n\r\n--00000000000038e10805f9dbd5a5\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\n\r\nte\r\n\r\n--00000000000038e10805f9dbd5a5\r\nContent-Type: text/html; charset=\"UTF-8\"\r\n\r\nte
\r\n\r\n--00000000000038e10805f9dbd5a5--"
+// }
\ No newline at end of file
diff --git a/web/tempmail.html b/web/tempmail.html
index 121ed7ae..5347f718 100644
--- a/web/tempmail.html
+++ b/web/tempmail.html
@@ -31,13 +31,117 @@
+
+
-
New
-
Delete
+
New
+
Delete
+
+
+
+
+
+
+
+
+
+
-
+