text: Q:
  
  Google apps script, forward all emails except one
  
  I have a script that forwards all of my emails that come in during specific times to email@domain.com. 
  The problem I am having, is that sometimes email@domain.com sends me an email during that time. 
  Can anyone suggest a way to add a rule that it should forward to all addresses except forwarding address?
  
  function forwardEmails() {
    try {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var settings = ss.getSheetByName('Settings').getDataRange().getValues();
      if (settings[1][1] == 'No')
        return;
      if (settings[2][1] == "")
        throw new Error('Please set Forward Email!');    
      
      var email   = PropertiesService.getScriptProperties().getProperty('email');
      if (!email)
        throw new Error('First authorize script by clicking on menu: Email Forwarder >> Authorize Script');    
      var today   = (new Date());
      var applicableRules = validRules(today);
      if (applicableRules) {
        var unread  = GmailApp.getInboxUnreadCount();
        if (!unread)
          return;
        var threads = GmailApp.getInboxThreads(0, unread>100?100:unread);
        var cutOff = today.getTime() - (MINUTES*60*1000 + 100); // 10 mins + 100 ms
    
        for (var i=0; i<threads.length; i++) {
          var msgs = threads[i].getMessages();    
          for (var j=0; j<msgs.length; j++) {          
            var from      = msgs[j].getFrom();
            var msgDate   = msgs[j].getDate();
            var msgTime   = (new Date(msgDate)).getTime();
            var diff1     = msgTime - cutOff;  
    
                        
            if (diff1 > 0 && from.indexOf(email) == -1) {                      
              var to        = msgs[j].getTo();
              var subject   = msgs[j].getSubject();
              var attach    = msgs[j].getAttachments();
              var body      = msgs[j].getBody();
              var plainBody = msgs[j].getPlainBody();
              var replyTo   = msgs[j].getReplyTo();             
              
              var options   = {replyTo:  from};      
              if (attach.length > 0)
                options.attachment = attach;
              
  
              
              GmailApp.sendEmail(settings[2][1],  subject, plainBody, options  );
            }
          }    
        }
      }  
    } catch (error) {    
      var html  = '<p>'+ error + '</p><br><br><a href="'+ss.getUrl()+'">Email Forwarder Rules & Settings</a><p>Line: '+ error.lineNumber + ', Filename: ' + error.fileName + '</p>';
      if (!email)
        email = Session.getActiveUser().getEmail();
      MailApp.sendEmail(email, 'Email Forwarder Script Failed!', error + '\n\nEmail Forwarder Rules & Settings URL: ' + ss.getUrl(), {htmlBody: html});
    }
  }
  
  A:
  
  Instead of using getInboxThreads() use search().
  getInboxThreads() will return threads in your inbox while search() will return those that meet the search query. The following query will include include messages in your inbox but exclude those from email@domain.com
  in:inbox -from:email@domain.com
  
  