Skip to content

Instantly share code, notes, and snippets.

@cesardv
Forked from siygle/gist:9678772
Created November 22, 2017 06:06
Show Gist options
  • Save cesardv/4c2c4d6875f56fb14a3d1920c869daed to your computer and use it in GitHub Desktop.
Save cesardv/4c2c4d6875f56fb14a3d1920c869daed to your computer and use it in GitHub Desktop.

Revisions

  1. @siygle siygle revised this gist Mar 21, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,7 @@ function processInboxToSheet() {

    var content = messages[0].getPlainBody();

    // implement your own parsing rule inside
    if (content) {
    var tmp;
    tmp = content.match(/Name:\s*([A-Za-z0-9\s]+)(\r?\n)/);
  2. @siygle siygle created this gist Mar 21, 2014.
    33 changes: 33 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    function processInboxToSheet() {
    //var threads = GmailApp.getInboxThreads();
    // Have to get data separate to avoid google app script limit!
    var start = 0;
    var threads = GmailApp.getInboxThreads(start, 100);
    var sheet = SpreadsheetApp.getActiveSheet();
    var result = [];

    for (var i = 0; i < threads.length; i++) {
    var messages = threads[i].getMessages();

    var content = messages[0].getPlainBody();

    if (content) {
    var tmp;
    tmp = content.match(/Name:\s*([A-Za-z0-9\s]+)(\r?\n)/);
    var username = (tmp && tmp[1]) ? tmp[1].trim() : 'No username';

    tmp = content.match(/Email:\s*([A-Za-z0-9@.]+)/);
    var email = (tmp && tmp[1]) ? tmp[1].trim() : 'No email';

    tmp = content.match(/Subject:\s*([A-Za-z0-9\s]+)(\r?\n)/);
    var subject = (tmp && tmp[1]) ? tmp[1].trim() : 'No subject';

    tmp = content.match(/Comments:\s*([\s\S]+)/);
    var comment = (tmp && tmp[1]) ? tmp[1] : 'No comment';

    sheet.appendRow([username, email, subject, comment]);

    Utilities.sleep(500);
    }
    }
    };