15 from google.oauth2.credentials import Credentials, UserAccessTokenCredentials |
15 from google.oauth2.credentials import Credentials, UserAccessTokenCredentials |
16 from google_auth_oauthlib.flow import InstalledAppFlow |
16 from google_auth_oauthlib.flow import InstalledAppFlow |
17 from googleapiclient import discovery, errors |
17 from googleapiclient import discovery, errors |
18 from PyQt6.QtCore import QObject, pyqtSignal |
18 from PyQt6.QtCore import QObject, pyqtSignal |
19 |
19 |
20 from eric7 import Globals |
20 from eric7 import EricUtilities |
21 |
21 |
22 from .EricGoogleMailHelpers import CLIENT_SECRET_FILE, SCOPES, TOKEN_FILE |
22 from .EricGoogleMailHelpers import CLIENT_SECRET_FILE, SCOPES, TOKEN_FILE |
23 |
23 |
24 |
24 |
25 class EricGoogleMail(QObject): |
25 class EricGoogleMail(QObject): |
76 """ |
76 """ |
77 Private method to start an authorized session and optionally execute the |
77 Private method to start an authorized session and optionally execute the |
78 authorization flow. |
78 authorization flow. |
79 """ |
79 """ |
80 # check for availability of secrets file |
80 # check for availability of secrets file |
81 if not os.path.exists(os.path.join(Globals.getConfigDir(), CLIENT_SECRET_FILE)): |
81 if not os.path.exists( |
|
82 os.path.join(EricUtilities.getConfigDir(), CLIENT_SECRET_FILE) |
|
83 ): |
82 self.sendResult.emit( |
84 self.sendResult.emit( |
83 False, |
85 False, |
84 self.tr( |
86 self.tr( |
85 "The client secrets file is not present. Has the Gmail" |
87 "The client secrets file is not present. Has the Gmail" |
86 " API been enabled?" |
88 " API been enabled?" |
97 credentials.refresh(Request()) |
99 credentials.refresh(Request()) |
98 except RefreshError: |
100 except RefreshError: |
99 credentials = None |
101 credentials = None |
100 if not credentials or not credentials.valid: |
102 if not credentials or not credentials.valid: |
101 flow = InstalledAppFlow.from_client_secrets_file( |
103 flow = InstalledAppFlow.from_client_secrets_file( |
102 os.path.join(Globals.getConfigDir(), CLIENT_SECRET_FILE), SCOPES |
104 os.path.join(EricUtilities.getConfigDir(), CLIENT_SECRET_FILE), |
|
105 SCOPES, |
103 ) |
106 ) |
104 credentials = flow.run_local_server(port=0) |
107 credentials = flow.run_local_server(port=0) |
105 # Save the credentials for the next run |
108 # Save the credentials for the next run |
106 self.__saveCredentials(credentials) |
109 self.__saveCredentials(credentials) |
107 |
110 |
190 "<li>At the end of the process select the <b>Download</b> button below the" |
193 "<li>At the end of the process select the <b>Download</b> button below the" |
191 "Client-ID. Save the credentials file to the eric configuration directory" |
194 "Client-ID. Save the credentials file to the eric configuration directory" |
192 " <code>{1}</code> with the name <code>{2}</code>.</li>" |
195 " <code>{1}</code> with the name <code>{2}</code>.</li>" |
193 "</ol>".format( |
196 "</ol>".format( |
194 "https://console.developers.google.com/start/api?id=gmail", |
197 "https://console.developers.google.com/start/api?id=gmail", |
195 Globals.getConfigDir(), |
198 EricUtilities.getConfigDir(), |
196 CLIENT_SECRET_FILE, |
199 CLIENT_SECRET_FILE, |
197 ) |
200 ) |
198 ) |
201 ) |