gmail-to-google-sheets-script icon indicating copy to clipboard operation
gmail-to-google-sheets-script copied to clipboard

"from:" and "is:sent" not being respected

Open crysman opened this issue 2 years ago • 2 comments

This is a wonderful code, thanks!

But... it does not respect the "from:" filter :( - native Gmail does neither - it counts the whole conversation tree.

Any ideas how to actually get sent e-mails only?

Sample query: is:sent from:[email protected] -notwantthisma.il -filename:.ics after:2022/6/15

Result: Threads' incoming e-mails are included, too.

Expected behavior: Only sent mails included.

crysman avatar Jun 16 '22 13:06 crysman

Hi @crysman .

I tested here and got the same results, it gets more than expected.

But it's not under my control, it's related to the gmail filtering way..

We can, maybe, think on a way to loop the results and filter by code it, resulting in only the emails you want, but, I don't know if it is doable.

TiagoGouvea avatar Jun 22 '22 10:06 TiagoGouvea

I've got a workaround - adding a filter like this:

//filter
function filterSheet() {
  console.info("adding filter...");
	var spreadsheet = SpreadsheetApp.getActive()
	spreadsheet.getRange('A:D').createFilter();
        //var QUERY_SENDER = Session.getActiveUser().getEmail();
	var criteria1 = SpreadsheetApp.newFilterCriteria()
	.whenTextContains(`${QUERY_SENDER}`)
  if ( ONLY_MYDOMAIN ) {
    console.info("filtering... (📥 INTERNAL mails only)...")
	  var criteria2 = SpreadsheetApp.newFilterCriteria()
      .whenTextContains("@mydomain.com")
  } else {
    console.info("filtering... (📤 EXTERNAL mails only)...")
    var criteria2 = SpreadsheetApp.newFilterCriteria()
      .whenTextDoesNotContain("@mydomain.com")
  }
  //columns are:
  //Date | Subject | Sender (from) | Recipients (to) | Recipients (cc,bcc)    
  spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(3, criteria1);
  spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(4, criteria2);
  console.info(getFilteredRows()+" rows filtered-out");
}

function clearFilter() {
//to clear the filter before next run...
  var spreadsheet = SpreadsheetApp.getActive()
  console.log("Clearing sheet's filters...");
  spreadsheet.getActiveSheet().getFilter() && spreadsheet.getActiveSheet().getFilter().remove();
}

crysman avatar Jul 01 '22 19:07 crysman