Skip to content

Instantly share code, notes, and snippets.

@oshliaer
Last active May 24, 2018 13:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oshliaer/0cf5570fbb66232c1cb1a8574c220337 to your computer and use it in GitHub Desktop.
Save oshliaer/0cf5570fbb66232c1cb1a8574c220337 to your computer and use it in GitHub Desktop.
Создать приложение
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