-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.copycontents
194 lines (170 loc) · 9.97 KB
/
main.copycontents
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
function cleanUpSpam() {
var threads = GmailApp.getInboxThreads(); // Get all inbox threads
var spamKeywords = [
// Promotional and Marketing Keywords
'unsubscribe', 'promotion', 'newsletter', 'marketing', 'discount', 'sale',
'limited time', 'special offer', 'exclusive deal', 'click here', 'buy now',
'free trial', 'order now', 'act now', 'earn money', 'get rich', 'urgent',
'clearance', 'last chance', 'claim your', 'congratulations', 'winner',
'you have won', 'offer expires', 'reward', 'gift card', 'prize', 'risk-free',
'money-back', 'guaranteed', 'investment', 'limited availability', 'special savings',
'trial membership', 'gift voucher', 'freebie', 'VIP access', 'exclusive invitation',
'loyalty rewards', 'VIP event', 'daily deal', 'bargain', 'promo code',
'limited offer', 'bonus offer', 'membership offer', 'special discount',
'hurry up', 'once in a lifetime', 'join free', 'apply today', 'act fast',
'limited spots', 'limited supply', 'only for you', 'exclusive for you',
'one-time offer', 'before it’s too late', 'final sale', 'grand opening sale',
'free shipping', 'flash sale', 'today’s special', 'free trial', 'free download',
'risk-free trial', 'big savings', 'black friday deal', 'cyber monday sale',
'new inventory', 'blowout sale', 'crazy deal', 'stock clearance', 'doorbuster deal',
// Financial and Investment Keywords
'credit card', 'mortgage', 'loan approved', 'apply now', 'low interest',
'approved loan', 'bad credit loans', 'no credit check', 'payday loans',
'fast loan', 'easy credit', 'zero interest', 'improve your credit',
'credit approved', 'repair your credit', 'personal finance', 'IRS notice',
'student loan relief', 'tax refund', 'investment opportunity', 'binary options',
'penny stocks', 'high return', 'make money fast', 'retirement savings',
'financial aid', 'earn cash', 'quick loan', 'cash rewards', 'crypto',
'cryptocurrency', 'bitcoin', 'forex trading', 'investment scheme',
'get paid instantly', 'retirement planning', 'wealth management',
'real estate investment', 'stock market tips', 'day trading', 'huge profit',
'guaranteed profit', 'multi-level marketing', 'pyramid scheme', 'passive income',
'big winnings', 'jackpot', 'lottery winner', 'claim prize', 'win big', 'easy cash',
'fast returns', 'double your money', 'bank transfer', 'Western Union',
'wire money', 'secure transaction', 'money transfer', 'fraudulent activity',
'online banking alert', 'account activity', 'bank account update', 'PayPal',
'no fees', 'no hidden fees', 'low interest loan', 'consolidate debt',
'loan forgiveness', 'debt forgiveness', 'tax season reminder', 'legal settlement',
'IRS filing', 'class action', 'tax rebate', 'personal loan', 'free quote',
// Phishing and Scam Keywords
'urgent response required', 'emergency notification', 'account suspension',
'security warning', 'password reset', 'suspicious activity', 'identity theft',
'unauthorized access', 'compromised account', 'secure transaction',
'account locked', 'security update', 'fraud prevention', 'phishing alert',
'scam alert', 'login attempt', 'emergency', 'action required', 'fraudulent claim',
'fake invoice', 'account compromised', 'fake transaction', 'alert', 'important notice',
'immediate response', 'password update', 'click to restore', 'security alert',
'compromised password', 'email compromise', 'unauthorized login',
'false login attempt', 'account breach', 'suspicious login', 'compromise attempt',
'fake update', 'email alert', 'scam notification', 'security notice',
'unusual activity', 'verify your identity', 'confirm account details',
'verification needed', 'password compromise', 'credit card fraud',
'unauthorized payment', 'sensitive information', 'payment declined',
'account review', 'restricted access', 'locked account', 'reset credentials',
'account details needed', 'compromise warning', 'unauthorized charge',
'reconfirm credentials', 'suspicious payment', 'confirm identity', 'identity verification',
'unauthorized transfer', 'recovery alert', 'suspicious withdrawal', 'payment declined notice',
'chargeback alert', 'fraud alert', 'personal information compromised',
'government impersonation', 'false bank alert', 'bank fraud prevention',
'click to verify', 'confirm your email', 'invalid login attempt',
'review account details', 'false security check', 'malicious login attempt',
// Health and Wellness Keywords
'viagra', 'prescription', 'pharmacy', 'no cost', 'guaranteed results',
'miracle cure', 'herbal treatment', 'natural remedy', 'weight loss',
'lose weight', 'burn fat', 'muscle gain', 'diet pills', 'erectile dysfunction',
'male enhancement', 'build muscle fast', 'diet supplement', 'health supplement',
'skin rejuvenation', 'wrinkle remover', 'anti-aging', 'teeth whitening',
'cosmetic surgery', 'hair loss', 'grow hair', 'pain relief', 'boost libido',
'boost immune system', 'anxiety relief', 'natural supplements', 'herbal remedy',
'wellness tips', 'vitamins', 'calorie burner', 'fat burner', 'boost energy',
'skin care', 'increase stamina', 'diet plan', 'fitness supplement',
'alternative medicine', 'homeopathic remedy', 'miracle weight loss',
'enhance performance', 'immune booster', 'detox your body', 'lose fat fast',
// Miscellaneous Keywords
'free gift', 'free bonus', 'hot deal', 'best price', 'amazing deal',
'unbelievable price', 'instant access', 'best price guarantee', 'cheap flights',
'cheap tickets', 'holiday deals', 'travel offer', 'vacation discount',
'hotel savings', 'luxury vacation', 'holiday package', 'exclusive vacation',
'event promotion', 'as seen on TV', 'limited spots available', 'special invitation',
'risk-free purchase', 'early bird offer', 'exclusive sale', 'save more',
'cheap insurance', 'unbeatable deal', 'prize draw', 'free trial offer',
'lucky draw', 'grand prize', 'win a car', 'lifetime deal', 'act immediately',
'biggest deal of the year', 'new customer special', 'special offer only for you',
'exclusive giveaway', 'free giveaway', 'gift giveaway', 'free download',
'shop now', 'online store', 'earn points', 'money-back guarantee',
'guaranteed satisfaction', 'limited edition', 'only for a limited time'
];
var allowList = ['@myschool.edu', '[email protected]', '[email protected]','@falmouthpowerboatschool.co.uk','[email protected]']; // Add trusted emails or domains
var deletedEmails = [];
var deletedCount = 0;
for (var i = 0; i < threads.length; i++) {
var thread = threads[i];
var messages = thread.getMessages();
var isAllowed = false;
for (var j = 0; j < messages.length; j++) {
var message = messages[j];
var subject = message.getSubject().toLowerCase();
var body = message.getPlainBody().toLowerCase();
var from = message.getFrom().toLowerCase();
// Check if the sender is in the allowlist
for (var k = 0; k < allowList.length; k++) {
if (from.indexOf(allowList[k].toLowerCase()) !== -1) {
isAllowed = true;
break;
}
}
// If sender is not in the allowlist, check for spam keywords
if (!isAllowed) {
for (var k = 0; k < spamKeywords.length; k++) {
if (subject.includes(spamKeywords[k]) || body.includes(spamKeywords[k])) {
// Capture unsubscribe links from headers or body, including around the word "unsubscribe"
var unsubscribeLink = getUnsubscribeLink(message, body);
// Log the email address, subject, thread ID, and unsubscribe link for the summary
deletedEmails.push({
from: message.getFrom(),
subject: message.getSubject(),
threadId: thread.getId(),
unsubscribeLink: unsubscribeLink || 'No unsubscribe link found'
});
// Move the thread to trash
thread.moveToTrash();
deletedCount++;
break;
}
}
}
}
}
// Send summary email if any emails were deleted
if (deletedEmails.length > 0) {
var recipient = "[email protected]"; // Replace with your email address
var subject = "Spam Cleanup Summary: " + deletedCount + " Emails Deleted";
// Build the email body with an HTML table for better formatting
var body = "<p>The following emails were deleted:</p>";
body += "<table border='1' cellpadding='5' cellspacing='0'>";
body += "<tr><th>From</th><th>Subject</th><th>Thread ID</th><th>Restore Link</th><th>Unsubscribe Link</th></tr>";
for (var i = 0; i < deletedEmails.length; i++) {
body += "<tr>";
body += "<td>" + deletedEmails[i].from + "</td>";
body += "<td>" + deletedEmails[i].subject + "</td>";
body += "<td>" + deletedEmails[i].threadId + "</td>";
body += "<td><a href='https://mail.google.com/mail/u/0/#all/" + deletedEmails[i].threadId + "'>Restore</a></td>";
body += "<td>" + deletedEmails[i].unsubscribeLink + "</td>";
body += "</tr>";
}
body += "</table>";
// Send the email as HTML
MailApp.sendEmail({
to: recipient,
subject: subject,
htmlBody: body
});
}
Logger.log('Deleted ' + deletedCount + ' spam threads.');
}
// Function to find unsubscribe link from the email headers or body, focusing on the word "unsubscribe"
function getUnsubscribeLink(message, body) {
var headers = message.getRawContent();
// Search for common patterns of unsubscribe links in the headers and body
var unsubscribePattern = /unsubscribe.*?(<mailto:(.+?)>|<https?:\/\/.+?>)/gi;
var match = unsubscribePattern.exec(headers);
if (match) {
return match[0].replace(/<|>/g, ''); // Clean up the match
}
// If not found in headers, search in the body
match = unsubscribePattern.exec(body);
if (match) {
return match[0].replace(/<|>/g, ''); // Clean up the match
}
return null; // No unsubscribe link found
}