I want to use this answer to remove all attachments for certain emails which have > 5 MB attachment.
In order to do this, I first search, in the Gmail GUI, has:attachment larger:5m
, and then I add these threads to a label to_process
. Then I can run the method shown here:
var emails = GmailApp.search('label:to_process');
for (var i = 0; i < emails.length; i++) {
removeAttachment(...);
}
Problem: when there is a thread with 10 messages and only one of them has a > 5MB attachment, then all the messages of this thread will be in to_process
label!
I see here a method to only add messages and not threads to a label, but I still haven't found a solution for this:
How to add all messages with a > 5 MB attachment to this label, but only the messages, without adding all the thread?