MailTask plugin - no longer operating?

inaraghj

New member
As of now, MailTask is no longer operating. The service has been discontinued and is no longer available. I heard about this.
 

Dimlos

Well-known member
What's new says Removed features not allowed anymore by Google and features have been reduced.
Depending on what you want to do, consider using the Aqua Mail plugin or the Gmail API.
 

Pseudocyclic

Well-known member
I was using MacroDroid + MailTask to permanently delete messages from spam folder that were starred (I used normal Gmail filters to do the starring).

Any suggestions on how to do that without MailTask?
 

Dimlos

Well-known member
I were able to delete emails from a test account in the test environment using the Gmail API.

It is necessary to prepare an environment in which the Gmail API works in advance, but I am not familiar with it, so I cannot help you build the environment.

Python:
from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import os.path

SCOPES = ['https://mail.google.com/']

def authenticate_gmail():
    creds = None
    if os.path.exists('token.json'):
        creds = Credentials.from_authorized_user_file('token.json', SCOPES)
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        with open('token.json', 'w') as token:
            token.write(creds.to_json())
    return build('gmail', 'v1', credentials=creds)

def delete_starred_emails_from_junk():
    service = authenticate_gmail()
    query = 'is:starred in:spam'
    results = service.users().messages().list(userId='me', q=query).execute()
    messages = results.get('messages', [])

    if not messages:
        print('No starred emails found in junk folder.')
        return

    for message in messages:
        service.users().messages().delete(userId='me', id=message['id']).execute()
        print(f'Deleted message with ID: {message["id"]}')

if __name__ == '__main__':
    delete_starred_emails_from_junk()
 
Top