3
votes

I am working on a script which extracts Gmail attachments from received email addresses assigned to specific labels and to move the attachments to specific folders in Google Drive now my problem is when I receive an email from the same sender of the same email subject saved in different labels the script disregards to move the attachments to different folders in Google Drive because Google groups emails of the same subject as conversations but when I turn off the conversation view in Gmail the script works. Is there a way around this or a function in Google App Script to turn on and Off conversation view? example:

   { // subject1 >>
    "filter": "from:[email protected]", // Email to extract attachments from 
    "folder": "folder1/Belasting/20000/Berario/", // Folder to send attachments to in Gdrive
     "filenameTo": "'%s' ~ yyyy MM dd", // format of renaming files if {RenameFile is set to true}
     "Renamefile": false, // Turn renaming of files on and off
     "globalFilter": "has:attachment in:label1-coj-berario -in:trash -in:drafts -in:spam", // Labels to fetch attachments from in Gmail
     "markUsRead": false,
    "newerThan": "1m", // how far back to fetch attachments
    "archive": true // Turn achiving on and off
     },

    { // subject1
     "filter": "from:[email protected]", // Email to extract attachments from 
    "folder": "folder1/Belasting/20000/Tan", // Folder to send attachments to in Gdrive
    "filenameTo": "'%s' ~ yyyy MM dd", // format of renaming files if {RenameFile is set to true}
   "Renamefile": false, // Turn renaming of files on and off
    "globalFilter": "has:attachment in:label2-coj-berenice-tan -in:trash -in:drafts -in:spam", // Labels to fetch attachments from in Gmail
   "markUsRead": false,
    "newerThan": "1m", // how far back to fetch attachments
    "archive": true // Turn achiving on and off
    },

The emai has same subject different labels and folders to be saved in but becaused the emails has the same subject and grouped in conversation view the script extracts the attachments and saves them in the same folder

2
Did you ever find a way to toggle conversation view in Apps Script? I would like to do that also.Scott

2 Answers

0
votes

You can switch the conversation from gmail app setting. Click on view all setting. Scroll down and you will find this. Conversation view: (sets whether emails of the same topic are grouped together)
Conversation view on Conversation view off

just click on conversation view off.

0
votes

I don't know that it's possible to toggle conversation view (or even see a user's conversation view setting) from within Apps Script. At time of writing and in general, the Gmail V1 API doesn't appear to support interacting with gmail.com UI settings. It's unclear from the question what information you have access to in your script, but you may be able to solve your goal using the messageId and threadId properties of individual emails. As you point out, Gmail automatically groups emails into threads which share the same threadId, but individual emails also have a unique messageId. By comparing the messageId of emails which otherwise have the same subject, you should be able to differentiate them.