Came up with the solution myself.
As you can see, my label has Chinese characters and GmailApp.Search has no problem with this.
However, LABEL_DONE requires you to put in I guess the unicode (or whatever it's called) of the Chinese characters. Again, I don't know anything about Javascript and so a lot of my code is just copying and pasting code from somewhere else and modifying them to the best of my extent. I had to do a bit of debugging to find out what my Chinese label looks like in the Logger. The result provided by the Logger is the unicode that you see for LABEL_DONE. If you also use non-English characters for your labels, you'll need to test it yourself and find what the corresponding unicode string is.
Anyway, the code below will use GmailApp.Search to search for specific labels (you can mix and match search conditions in there and can test this easily in Gmail search itself). It will then add the emails for those specific labels into Google Calendar, then apply a "Bill Reminder - Processed" label. The next time the Google App Script trigger runs, it will skip these emails, because of the Processed label.
// https://stackoverflow.com/questions/12377640/printing-to-the-console-in-google-apps-script
function testLog(){
Logger.log("Logger.log");
console.log("console.log")
}
function BillReminder_Rates() {
if (!GmailApp) return; // Skip script execution if GMail is currently not available (yes this happens from time to time and triggers spam emails!)
var reminderLabel = "電費,-水費,-垃圾袋,-網路-bill-reminder---processed", //Substitute your label here
calendarName = "Reminders", ////Substitute your Calendar name here
reminderDuration27Days = 648; //duration in hours;
var threads = GmailApp.search('(label:電費,-水費,-垃圾袋,-網路-council-rates---me) AND (-label:電費,-水費,-垃圾袋,-網路-bill-reminder---processed)');
if (threads.length > 0) {
//get calendar by name
var cals = CalendarApp.getCalendarsByName(calendarName);
var now = new Date().getTime();
for (i in threads) {
//cals[0].createEvent(reminderLabel + ' - '+threads[i].getFirstMessageSubject(),
cals[0].createEvent(threads[i].getFirstMessageSubject(),
new Date(now+(60000*60*reminderDuration27Days)),
new Date(now+(60000*60*reminderDuration27Days)), {description: threads[i].getPermalink()});
}
LABEL_DONE = "\u96fb\u8cbb, \u6c34\u8cbb, \u5783\u573e\u888b, \u7db2\u8def/Bill Reminder - Processed";
var label_done = GmailApp.getUserLabelByName(LABEL_DONE);
for (var t in threads) {
var threadblah = threads[t];
// Grab the task data
var taskTitle = threadblah.getFirstMessageSubject();
// Insert the task
//addTask_(taskTitle, TASKLIST);
// Set to 'done' by exchanging labels
//threadblah.removeLabel(label_pending);
threadblah.addLabel(label_done);
}
}
}
function BillReminder_Power_Gas() {
if (!GmailApp) return; // Skip script execution if GMail is currently not available (yes this happens from time to time and triggers spam emails!)
var reminderLabel = "電費,-水費,-垃圾袋,-網路-bill-reminder---processed", //Substitute your label here
calendarName = "Reminders", ////Substitute your Calendar name here
reminderDuration12Days = 288; //duration in hours;
var threads = GmailApp.search('(label:電費,-水費,-垃圾袋,-網路-power -OR label:電費,-水費,-垃圾袋,-網路-gas) AND (-label:電費,-水費,-垃圾袋,-網路-bill-reminder---processed)');
if (threads.length > 0) {
//get calendar by name
var cals = CalendarApp.getCalendarsByName(calendarName);
var now = new Date().getTime();
for (i in threads) {
//cals[0].createEvent(reminderLabel + ' - '+threads[i].getFirstMessageSubject(),
cals[0].createEvent(threads[i].getFirstMessageSubject(),
new Date(now+(60000*60*reminderDuration12Days)),
new Date(now+(60000*60*reminderDuration12Days)), {description: threads[i].getPermalink()});
}
LABEL_DONE = "\u96fb\u8cbb, \u6c34\u8cbb, \u5783\u573e\u888b, \u7db2\u8def/Bill Reminder - Processed";
var label_done = GmailApp.getUserLabelByName(LABEL_DONE);
for (var t in threads) {
var threadblah = threads[t];
// Grab the task data
var taskTitle = threadblah.getFirstMessageSubject();
// Insert the task
//addTask_(taskTitle, TASKLIST);
// Set to 'done' by exchanging labels
//threadblah.removeLabel(label_pending);
threadblah.addLabel(label_done);
}
}
}
function BillReminder_Water() {
if (!GmailApp) return; // Skip script execution if GMail is currently not available (yes this happens from time to time and triggers spam emails!)
var reminderLabel = "電費,-水費,-垃圾袋,-網路-bill-reminder---processed", //Substitute your label here
calendarName = "Reminders", ////Substitute your Calendar name here
reminderDuration15Days = 360; //duration in hours;
var threads = GmailApp.search('(label:電費,-水費,-垃圾袋,-網路-watercare---me) AND (-label:電費,-水費,-垃圾袋,-網路-bill-reminder---processed)');
if (threads.length > 0) {
//get calendar by name
var cals = CalendarApp.getCalendarsByName(calendarName);
var now = new Date().getTime();
for (i in threads) {
//cals[0].createEvent(reminderLabel + ' - '+threads[i].getFirstMessageSubject(),
cals[0].createEvent(threads[i].getFirstMessageSubject(),
new Date(now+(60000*60*reminderDuration15Days)),
new Date(now+(60000*60*reminderDuration15Days)), {description: threads[i].getPermalink()});
}
LABEL_DONE = "\u96fb\u8cbb, \u6c34\u8cbb, \u5783\u573e\u888b, \u7db2\u8def/Bill Reminder - Processed";
var label_done = GmailApp.getUserLabelByName(LABEL_DONE);
for (var t in threads) {
var threadblah = threads[t];
// Grab the task data
var taskTitle = threadblah.getFirstMessageSubject();
// Insert the task
//addTask_(taskTitle, TASKLIST);
// Set to 'done' by exchanging labels
//threadblah.removeLabel(label_pending);
threadblah.addLabel(label_done);
}
}
}
function delete_events()
{
//take care: Date function starts at 0 for the month (January=0)
//{search: 'cycle'+"*"+'Checkpoint'} hier zijn de search terms
var fromDate = new Date(2021,6,1,0,0,0); //This is July 1, 2021
var toDate = new Date(2021,11,1,0,0,0); //This is September 1, 2021 at 00h00'00"
var calendarName = 'Reminders';
var toRemove = 'title_of_the_events';
var calendar = CalendarApp.getCalendarsByName(calendarName)[0];
var events = calendar.getEvents(fromDate, toDate,{search: toRemove});
for(var i=0; i<events.length;i++)
{
var ev = events[i];
if(ev.getTitle()==toRemove) //check if the title matches
{
Logger.log('Item '+ev.getTitle()+' found on '+ev.getStartTime()); // show event name and date in log
ev.deleteEvent(); //uncomment this line to actually do the delete !
}
}
}
function delete_events2()
{
var fromDate = new Date(2021,8,1,0,0,0);
var toDate = new Date(2021,11,27,0,0,0);
var calendarName = 'Reminders';
// delete from Jan 1 to end of Jan 4, 2013 (for month 0 = Jan, 1 = Feb...)
var calendar = CalendarApp.getCalendarsByName(calendarName)[0];
var events = calendar.getEvents(fromDate, toDate);
for(var i=0; i<events.length;i++){
var ev = events[i];
Logger.log(ev.getTitle()); // show event name in log
ev.deleteEvent();
}
}