I wrote this as a script for gmail:
/*
Foward Motion detects if they happen within a given time
*/
function processInbox() {
// A search string to get the thread
// Gmail Advanced Search
// https://support.google.com/mail/answer/7190?hl=en
var threads = GmailApp.search('label:unread label:inbox to:me from:me subject:"Record by Motion Detection E-mail"');
// Stop and start times in hours ( 0-23 )
var startTime = 10;
var stopTime = 12+5;
// Start and stop days in days ( 0-6 0=sun 6=sat)
var startDay = 1; //1=Moday
var stopDay = 5; //5=Friday
// Address to forward to
var address = "asdf@asdf.com";
// Log the time
var currentTime = todayDate = new Date();
Logger.log("Current Time: "+currentTime);
for (var i = 0; i < threads.length; i++) {
// get all messages in a given thread
var messages = threads[i].getMessages();
// iterate over each message
for (var j = 0; j < messages.length; j++) {
var message = messages[j];
//Get the date and time of the message
var msgDate = message.getDate();
var msgHour = msgDate.getHours()
var msgDay = msgDate.getDay();
// log subject date and time of the message
Logger.log("Msg Date "+msgDate);
Logger.log("Msg Hour "+msgHour);
Logger.log("Msg Day "+msgDay);
if(
msgHour > startTime && msgHour < stopTime &&
msgDay > startDay && msgDay < stopDay
) {
Logger.log("VALID MESSAGE");
forwardMessage(message,address);
//message.markRead();
message.getThread().moveToArchive();
}
else {
Logger.log("INVALID MESSAGE");
message.moveToTrash();
}
}
}
};
//Forward the email to another account
function forwardMessage(message, address) {
Logger.log("FORWARDED to "+address);
message.forward(address);
}