Created
May 4, 2016 16:42
-
-
Save ericduran/fb18134d1888e8056f658f8812bc853f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 saveLinks() { | |
var LABEL_ID = "Conference"; | |
var SHEET_ID = "EXAMPLE"; | |
var message, messageById, body; | |
var ssNew = SpreadsheetApp.create(SHEET_ID); | |
var label = GmailApp.getUserLabelByName(LABEL_ID); | |
var threads = label.getThreads(); | |
for (var i = 0; i < threads.length; i++) { | |
message = threads[i].getMessages()[0]; | |
messageById = message.getId(); | |
body = message.getPlainBody(); | |
links = getURLS(body); | |
links.forEach(function(element, index, array) { | |
if (linkFilter(element)) { | |
Logger.log(element) | |
} | |
ssNew.appendRow([element]); | |
}); | |
} | |
Logger.log(ssNew.getUrl()); | |
} | |
function expandURL(shortLink) { | |
// Going to be Crazy expensive (time). Maybe queue them up? | |
// Also only do this optionally. | |
var URL_EXPANDER = 'http://api.longurl.org/v2/expand?url='; | |
} | |
function linkFilter(link) { | |
// ADD TO ARRAY for filter by strings | |
var FILTER_ARRAY = [ | |
'unsubscribe', 'corporate' | |
]; | |
for (var i = 0; i < FILTER_ARRAY.length; i++) { | |
if (FILTER_ARRAY[i].indexOf(link) == -1) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function getURLS(text) { | |
var URL_MATCH = /(((https?):\/\/)[\-\w@:%_\+.~#?,&\/\/=]+)/g; | |
var source = (text || '').toString(); | |
var urlArray = []; | |
var url; | |
var matchArray; | |
// Iterate through any URLs in the text. | |
while( (matchArray = URL_MATCH.exec( source )) !== null ) { | |
var token = matchArray[0]; | |
urlArray.push( token ); | |
} | |
return urlArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment