Last active
May 24, 2018 13:36
-
-
Save oshliaer/0cf5570fbb66232c1cb1a8574c220337 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 run() { | |
var values = getEmail_('label:test is:unread'); | |
var sheet = SpreadsheetApp.openById('1UExbfTLilG9vYIq4U76wljHBLH5fdLty1NmjTTqVRQg') | |
.getSheets()[0]; | |
sheet.getRange(sheet.getLastRow() + 1, 1, values.length, values[0].length) | |
.setValues(values); | |
} | |
function parsingBody(str){ | |
return (str.length > 1000 ? 'Oh, it\'s very difficult. Give me something simpler.': 'Well, it\'s quite simple.') + ' In any case, here are some of the symbols: ' + str.substr(0, 100); | |
} | |
function getEmail_(query) { | |
return GmailApp.search(query, 0, 10).reduce(function(accumulator, thread) { | |
return thread.getMessages().reduce(function(accumulator, gmailMessage) { | |
if (gmailMessage.isUnread()) { | |
// Parsing here | |
var data = parsingBody(gmailMessage.getBody()); | |
accumulator.push([gmailMessage.getFrom(), gmailMessage.getSubject(), data]); | |
gmailMessage.markRead(); | |
} | |
return accumulator; | |
}, accumulator); | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment