Created
May 10, 2017 21:15
-
-
Save renatomattos2912/cb264cb3232658406c018b8442b57b27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function extractEmailAddresses() { | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = ss.getSheets()[0]; | |
var search = "in:spam is:all "; | |
var threads = GmailApp.search(search); | |
var row, messages, from, email; | |
try { | |
for (var x=0; x<threads.length; x++) { | |
from = threads[x].getMessages()[0].getFrom(); | |
from = from.match(/\S+@\S+\.\S+/g); | |
if ( from.length ) { | |
email = from[0]; | |
email = email.replace(">", ""); | |
email = email.replace("<", ""); | |
row = sheet.getLastRow() + 1; | |
sheet.getRange(row,1).setValue(email); | |
} | |
} | |
} catch (e) { | |
Logger.log(e.toString()); | |
Utilities.sleep(5000); | |
} | |
} | |
// Remove Duplicate Email addresses | |
function cleanList() { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var data = sheet.getRange(4, 1, sheet.getLastRow()).getValues(); | |
var newData = new Array(); | |
for(i in data){ | |
var row = data[i]; | |
var duplicate = false; | |
for(j in newData){ | |
if(row[0] == newData[j][0]){ | |
duplicate = true; | |
} | |
} | |
if(!duplicate){ | |
newData.push(row); | |
} | |
} | |
sheet.getRange(4, 2, newData.length, newData[0].length).setValues(newData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment