diff --git a/Files/manifest.json b/Files/manifest.json new file mode 100644 index 0000000..698a4df --- /dev/null +++ b/Files/manifest.json @@ -0,0 +1,16 @@ +{ + "manifest_version": 2, + "name": "Mailcow Temp Mail", + "version": "1.0", + "description": "Fetch and generate temporary emails via Mailcow", + "permissions": ["cookies", "storage", "clipboardWrite", "activeTab", "https://mail.pandem.fr*"], + "browser_action": { + "default_popup": "popup.html", + "default_icon": "icon.png" + }, + "background": { + "scripts": ["background.js"], + "persistent": false + } + } + \ No newline at end of file diff --git a/Files/popup.html b/Files/popup.html new file mode 100644 index 0000000..a93e899 --- /dev/null +++ b/Files/popup.html @@ -0,0 +1,19 @@ + + + + Mailcow Temp Mail + + + +

Mailcow Temp Mail

+ + + + + + + diff --git a/Files/popup.js b/Files/popup.js new file mode 100644 index 0000000..e20d658 --- /dev/null +++ b/Files/popup.js @@ -0,0 +1,63 @@ +const API_BASE = "https://mail.paxcia.net"; +const GET_ALIAS_ENDPOINT = "/api/v1/get/alias"; +const ADD_ALIAS_ENDPOINT = "/api/v1/add/alias"; + +document.getElementById("fetch").addEventListener("click", async () => { + try { + const response = await fetch(API_BASE + GET_ALIAS_ENDPOINT, { + credentials: "include" // Ensures the request uses the user's Mailcow session + }); + + if (!response.ok) throw new Error("Failed to fetch emails"); + + const aliases = await response.json(); + + if (aliases.length > 0) { + const latestEmail = aliases[0].address; + document.getElementById("email").value = latestEmail; + } else { + document.getElementById("email").value = "No temp email found"; + } + } catch (error) { + console.error(error); + alert("Error fetching email"); + } +}); + +document.getElementById("generate").addEventListener("click", async () => { + const emailPrefix = "temp" + Date.now(); + const domain = "paxcia.net"; + const newEmail = `${emailPrefix}@${domain}`; + + const requestData = { + address: newEmail, + goto: "your_main@paxcia.net", // Redirect emails to your main inbox + active: true + }; + + try { + const response = await fetch(API_BASE + ADD_ALIAS_ENDPOINT, { + method: "POST", + credentials: "include", // Uses session login + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(requestData) + }); + + if (!response.ok) throw new Error("Failed to generate email"); + + document.getElementById("email").value = newEmail; + alert("New email created: " + newEmail); + } catch (error) { + console.error(error); + alert("Error creating email"); + } +}); + +document.getElementById("copy").addEventListener("click", () => { + const emailField = document.getElementById("email"); + emailField.select(); + document.execCommand("copy"); + alert("Copied: " + emailField.value); +});