-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgmail.html
More file actions
220 lines (200 loc) · 10.8 KB
/
gmail.html
File metadata and controls
220 lines (200 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gmail Setup — DontMailMe</title>
<meta property="og:title" content="DontMailMe — Stop the noise.">
<meta property="og:description" content="Auto-unsubscribe from newsletters. Runs locally. Zero data access. Plants trees.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://dontmailme.org/gmail">
<meta name="twitter:card" content="summary_large_image">
<link rel="icon" type="image/svg+xml" href="favicon.svg">
<link rel="stylesheet" href="styles.css">
<style>
.whitelist-manager {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 12px;
padding: 24px;
margin: 32px 0;
text-align: left;
}
.input-group {
display: flex;
gap: 12px;
margin-top: 12px;
}
.input-group input {
flex: 1;
padding: 12px;
border-radius: 6px;
border: 1px solid var(--border);
font-family: var(--font-body);
font-size: 1rem;
}
.chip-container {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 16px;
}
.chip {
background: var(--accent);
color: white;
padding: 4px 12px;
border-radius: 20px;
font-size: 0.85rem;
display: flex;
align-items: center;
gap: 8px;
}
.chip button {
background: none;
border: none;
color: white;
cursor: pointer;
font-weight: bold;
padding: 0;
line-height: 1;
}
.copy-banner {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 32px;
margin-bottom: 8px;
}
#copy-btn {
font-size: 0.9rem;
padding: 8px 16px;
}
</style>
</head>
<body>
<header>
<a href="/" class="brand">DontMailMe.org</a>
<nav class="nav-links">
<a href="/gmail">Gmail Tool</a>
<a href="/outlook">Outlook</a>
<a href="/impact">Impact</a>
</nav>
</header>
<main>
<section>
<h1 class="page-title" style="font-size: 3rem; margin-bottom: 16px;">Gmail Setup</h1>
<p style="font-size: 1.25rem; color: var(--text-muted); margin-bottom: 64px;">Takes about 3 minutes. Runs completely within your own Google account.</p>
<div class="step">
<h2><span class="step-number">1</span> Create a new Script</h2>
<p>Go to <a href="https://script.google.com" target="_blank">script.google.com</a> and click <strong>New Project</strong>.</p>
</div>
<div class="step">
<h2><span class="step-number">2</span> Enable Gmail API</h2>
<p>Click the <strong>Services (+)</strong> icon. Select <strong>Gmail API</strong> and click <strong>Add</strong>.</p>
</div>
<div class="step">
<h2><span class="step-number">3</span> Personalize & Copy Code</h2>
<p>Add email addresses you want to <strong>keep</strong> (whitelist):</p>
<div class="whitelist-manager">
<label style="font-weight: 500;">Safe Senders List</label>
<div class="input-group">
<input type="email" id="email-input" placeholder="newsletter@favorite.com">
<button id="add-email-btn" class="btn" style="padding: 10px 20px;">Add</button>
</div>
<div class="chip-container" id="chip-container">
</div>
</div>
<div class="copy-banner">
<label style="font-weight: 700; color: var(--accent);">Your Custom Script:</label>
<button id="copy-btn" class="btn">Copy Code</button>
</div>
<pre><code id="script-block"></code></pre>
</div>
<div class="step">
<h2><span class="step-number">4</span> Test safely</h2>
<p>Select <strong>testDryRun</strong> and click <strong>Run</strong>. Check the logs to see what would happen.</p>
</div>
<div class="step">
<h2><span class="step-number">5</span> Activate</h2>
<p>Select <strong>installTrigger</strong> and click <strong>Run</strong>.</p>
<p style="margin-top: 16px; color: var(--accent); font-weight: 700;">Done. Your inbox cleans itself every 15 minutes.</p>
</div>
</section>
</main>
<footer>
<p>A Green IT Suite initiative. Built for personal productivity and planetary health.</p>
<div style="margin-top: 16px; display: flex; justify-content: center; gap: 16px;">
<a href="https://github.com/sein-io/dontmailme">GitHub</a>
<a href="/privacy">Privacy</a>
<a href="/imprint">Imprint</a>
</div>
</footer>
<script>
const emailInput = document.getElementById('email-input');
const addBtn = document.getElementById('add-email-btn');
const chipContainer = document.getElementById('chip-container');
const scriptBlock = document.getElementById('script-block');
const copyBtn = document.getElementById('copy-btn');
let whitelist = ['newsletter@favorite.com', 'news@stripe.com'];
function updateScript() {
const emailsFormatted = whitelist.map(e => "'" + e + "'").join(', ');
const code = "'use strict';\n\nconst ALLOWED_SENDERS = [" + emailsFormatted + "];\n\nfunction testDryRun() {\n Logger.log('START');\n processEmails(true);\n Logger.log('END');\n}\n\nfunction installTrigger() {\n ScriptApp.getProjectTriggers().forEach(function(t) {\n ScriptApp.deleteTrigger(t);\n });\n ScriptApp.newTrigger('runJob').timeBased().everyMinutes(15).create();\n}\n\nfunction runJob() {\n processEmails(false);\n}\n\nfunction processEmails(isDryRun) {\n const query = 'is:unread (category:promotions OR list:unsubscribe)';\n const threads = GmailApp.search(query, 0, 50);\n let processedCount = 0;\n\n for (let i = 0; i < threads.length; i++) {\n const messages = threads[i].getMessages();\n for (let j = 0; j < messages.length; j++) {\n const message = messages[j];\n if (!message.isUnread()) continue;\n const id = message.getId();\n const sender = message.getFrom();\n const emailMatch = sender.match(/<([^>]+)>/);\n const email = emailMatch ? emailMatch[1].toLowerCase() : sender.toLowerCase();\n const isWhitelisted = ALLOWED_SENDERS.some(function(s) { return email === s.toLowerCase(); });\n if (isWhitelisted) continue;\n try {\n const metadata = Gmail.Users.Messages.get('me', id, { \n format: 'metadata', \n metadataHeaders: ['List-Unsubscribe', 'List-Unsubscribe-Post'] \n });\n let listUnsub = '';\n let listUnsubPost = '';\n if (metadata.payload && metadata.payload.headers) {\n metadata.payload.headers.forEach(function(header) {\n if (header.name.toLowerCase() === 'list-unsubscribe') listUnsub = header.value;\n if (header.name.toLowerCase() === 'list-unsubscribe-post') listUnsubPost = header.value;\n });\n }\n if (listUnsubPost.indexOf('List-Unsubscribe=One-Click') !== -1) {\n const urlMatch = listUnsub.match(/<(https:\\/\\/[^>]+)>/i);\n if (urlMatch && urlMatch[1]) {\n const postUrl = urlMatch[1];\n if (!isDryRun) {\n const response = UrlFetchApp.fetch(postUrl, {\n method: 'post',\n contentType: 'application/x-www-form-urlencoded',\n payload: 'List-Unsubscribe=One-Click',\n muteHttpExceptions: true,\n followRedirects: true\n });\n const code = response.getResponseCode();\n if (code >= 200 && code < 400) {\n Gmail.Users.Messages.remove('me', id);\n }\n }\n processedCount++;\n }\n }\n } catch (e) {}\n }\n }\n Logger.log('Processed: ' + processedCount);\n}";
scriptBlock.textContent = code;
}
function renderChips() {
chipContainer.innerHTML = '';
whitelist.forEach((email, index) => {
const chip = document.createElement('div');
chip.className = 'chip';
const emailSpan = document.createElement('span');
emailSpan.textContent = email;
const removeBtn = document.createElement('button');
removeBtn.textContent = '×';
removeBtn.addEventListener('click', () => removeEmail(index));
chip.appendChild(emailSpan);
chip.appendChild(removeBtn);
chipContainer.appendChild(chip);
});
updateScript();
}
window.removeEmail = function(index) {
whitelist.splice(index, 1);
renderChips();
};
addBtn.addEventListener('click', () => {
const email = emailInput.value.trim().toLowerCase();
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!email) return;
if (!emailRegex.test(email)) {
emailInput.setCustomValidity('Invalid email address');
emailInput.reportValidity();
return;
}
emailInput.setCustomValidity('');
if (!whitelist.includes(email)) {
whitelist.push(email);
emailInput.value = '';
renderChips();
}
});
emailInput.addEventListener('input', () => { emailInput.setCustomValidity(''); });
emailInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') addBtn.click(); });
copyBtn.addEventListener('click', () => {
if (!navigator.clipboard) {
copyBtn.textContent = 'Copy failed';
return;
}
navigator.clipboard.writeText(scriptBlock.textContent).then(() => {
const originalText = copyBtn.textContent;
copyBtn.textContent = 'Copied!';
copyBtn.style.backgroundColor = 'var(--accent-hover)';
setTimeout(() => {
copyBtn.textContent = originalText;
copyBtn.style.backgroundColor = '';
}, 2000);
});
});
renderChips();
</script>
</body>
</html>