Sun, 24 Feb 2019 17:55:36 +0100
E5GoogleMail: changed code to no longer use the deprecated oauth2client library.
--- a/APIs/Python3/eric6.api Sun Feb 24 13:01:58 2019 +0100 +++ b/APIs/Python3/eric6.api Sun Feb 24 17:55:36 2019 +0100 @@ -1499,13 +1499,14 @@ eric6.E5Network.E5Ftp.E5FtpProxyType.UserAtServer?7 eric6.E5Network.E5GoogleMail.APPLICATION_NAME?7 eric6.E5Network.E5GoogleMail.CLIENT_SECRET_FILE?7 +eric6.E5Network.E5GoogleMail.CREDENTIALS_FILE?7 eric6.E5Network.E5GoogleMail.GoogleMailHelp?4() eric6.E5Network.E5GoogleMail.GoogleMailSendMessage?4(message) eric6.E5Network.E5GoogleMail.SCOPES?7 eric6.E5Network.E5GoogleMail._prepareMessage_v2?5(message) eric6.E5Network.E5GoogleMail._prepareMessage_v3?5(message) eric6.E5Network.E5GoogleMail.getCredentials?4() -eric6.E5Network.E5GoogleMail.isCredentialsFileAvailable?4() +eric6.E5Network.E5GoogleMail.isClientSecretFileAvailable?4() eric6.E5Network.E5NetworkHeaderDetailsDialog.E5NetworkHeaderDetailsDialog.setData?4(name, value) eric6.E5Network.E5NetworkHeaderDetailsDialog.E5NetworkHeaderDetailsDialog?1(parent=None) eric6.E5Network.E5NetworkIcon.E5NetworkIcon.isOnline?4()
--- a/Documentation/Help/source.qhp Sun Feb 24 13:01:58 2019 +0100 +++ b/Documentation/Help/source.qhp Sun Feb 24 17:55:36 2019 +0100 @@ -19312,9 +19312,9 @@ <keyword name="instance" id="instance" ref="eric6.WebBrowser.ZoomManager.ZoomManager.html#instance" /> <keyword name="ircFilter" id="ircFilter" ref="eric6.Network.IRC.IrcUtilities.html#ircFilter" /> <keyword name="ircTimestamp" id="ircTimestamp" ref="eric6.Network.IRC.IrcUtilities.html#ircTimestamp" /> + <keyword name="isClientSecretFileAvailable" id="isClientSecretFileAvailable" ref="eric6.E5Network.E5GoogleMail.html#isClientSecretFileAvailable" /> <keyword name="isCondaAvailable" id="isCondaAvailable" ref="eric6.CondaInterface.__init__.html#isCondaAvailable" /> <keyword name="isConfigured" id="isConfigured" ref="eric6.Preferences.__init__.html#isConfigured" /> - <keyword name="isCredentialsFileAvailable" id="isCredentialsFileAvailable" ref="eric6.E5Network.E5GoogleMail.html#isCredentialsFileAvailable" /> <keyword name="isCupsAvailable" id="isCupsAvailable" ref="eric6.WebBrowser.Tools.FilePrinter.html#isCupsAvailable" /> <keyword name="isDrive" id="isDrive" ref="eric6.Utilities.__init__.html#isDrive" /> <keyword name="isExecutable" id="isExecutable" ref="eric6.Utilities.__init__.html#isExecutable" />
--- a/Documentation/Source/eric6.E5Network.E5GoogleMail.html Sun Feb 24 13:01:58 2019 +0100 +++ b/Documentation/Source/eric6.E5Network.E5GoogleMail.html Sun Feb 24 17:55:36 2019 +0100 @@ -25,7 +25,7 @@ </p> <h3>Global Attributes</h3> <table> -<tr><td>APPLICATION_NAME</td></tr><tr><td>CLIENT_SECRET_FILE</td></tr><tr><td>SCOPES</td></tr> +<tr><td>APPLICATION_NAME</td></tr><tr><td>CLIENT_SECRET_FILE</td></tr><tr><td>CREDENTIALS_FILE</td></tr><tr><td>SCOPES</td></tr> </table> <h3>Classes</h3> <table> @@ -49,8 +49,8 @@ <td><a href="#getCredentials">getCredentials</a></td> <td>Module function to get the Google credentials.</td> </tr><tr> -<td><a href="#isCredentialsFileAvailable">isCredentialsFileAvailable</a></td> -<td>Module function to check, if the credentials file has been installed.</td> +<td><a href="#isClientSecretFileAvailable">isClientSecretFileAvailable</a></td> +<td>Module function to check, if the client secret file has been installed.</td> </tr> </table> <hr /><hr /> @@ -155,11 +155,11 @@ </dl> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> -<a NAME="isCredentialsFileAvailable" ID="isCredentialsFileAvailable"></a> -<h2>isCredentialsFileAvailable</h2> -<b>isCredentialsFileAvailable</b>(<i></i>) +<a NAME="isClientSecretFileAvailable" ID="isClientSecretFileAvailable"></a> +<h2>isClientSecretFileAvailable</h2> +<b>isClientSecretFileAvailable</b>(<i></i>) <p> - Module function to check, if the credentials file has been installed. + Module function to check, if the client secret file has been installed. </p><dl> <dt>Returns:</dt> <dd>
--- a/E5Network/E5GoogleMail.py Sun Feb 24 13:01:58 2019 +0100 +++ b/E5Network/E5GoogleMail.py Sun Feb 24 17:55:36 2019 +0100 @@ -16,13 +16,11 @@ import os import sys import base64 - -import httplib2 - -import oauth2client.file -from oauth2client import client, tools +import pickle from googleapiclient import discovery +from google_auth_oauthlib.flow import InstalledAppFlow +from google.auth.transport.requests import Request from PyQt5.QtCore import QCoreApplication @@ -31,12 +29,13 @@ SCOPES = 'https://www.googleapis.com/auth/gmail.send' CLIENT_SECRET_FILE = 'eric_client_secret.json' +CREDENTIALS_FILE = 'eric-python-email-send.pickle' APPLICATION_NAME = 'Eric Python Send Email' -def isCredentialsFileAvailable(): +def isClientSecretFileAvailable(): """ - Module function to check, if the credentials file has been installed. + Module function to check, if the client secret file has been installed. @return flag indicating, that the credentials file is there @rtype bool @@ -52,19 +51,30 @@ @return Google Mail credentials """ homeDir = os.path.expanduser('~') - credentialDir = os.path.join(homeDir, '.credentials') - if not os.path.exists(credentialDir): - os.makedirs(credentialDir) - credentialPath = os.path.join(credentialDir, - 'eric-python-email-send.json') - store = oauth2client.file.Storage(credentialPath) - credentials = store.get() - if not credentials or credentials.invalid: - flow = client.flow_from_clientsecrets( - os.path.join(Globals.getConfigDir(), CLIENT_SECRET_FILE), - SCOPES) - flow.user_agent = APPLICATION_NAME - credentials = tools.run_flow(flow, store) + credentialsDir = os.path.join(homeDir, '.credentials') + if not os.path.exists(credentialsDir): + os.makedirs(credentialsDir) + credentialsPath = os.path.join(credentialsDir, CREDENTIALS_FILE) + + credentials = None + # The file eric-python-email-send.pickle stores the user's access and + # refresh tokens, and is created automatically when the authorization + # flow completes for the first time. + if os.path.exists(credentialsPath): + with open(credentialsPath, 'rb') as token: + credentials = pickle.load(token) + # If there are no (valid) credentials available, let the user log in. + if not credentials or not credentials.valid: + if credentials and credentials.expired and credentials.refresh_token: + credentials.refresh(Request()) + else: + flow = InstalledAppFlow.from_client_secrets_file( + os.path.join(Globals.getConfigDir(), CLIENT_SECRET_FILE), + SCOPES) + credentials = flow.run_local_server() + # Save the credentials for the next run + with open(credentialsPath, 'wb') as credentialsFile: + pickle.dump(credentials, credentialsFile) return credentials @@ -87,8 +97,7 @@ try: credentials = getCredentials() - http = credentials.authorize(httplib2.Http()) - service = discovery.build('gmail', 'v1', http=http) + service = discovery.build('gmail', 'v1', credentials=credentials) if sys.version_info[0] == 2: message1 = _prepareMessage_v2(message) else:
--- a/Preferences/ConfigurationPages/EmailPage.py Sun Feb 24 13:01:58 2019 +0100 +++ b/Preferences/ConfigurationPages/EmailPage.py Sun Feb 24 17:55:36 2019 +0100 @@ -44,8 +44,8 @@ self.googleMailCheckBox.setChecked( Preferences.getUser("UseGoogleMailOAuth2")) - from E5Network.E5GoogleMail import isCredentialsFileAvailable - if not isCredentialsFileAvailable(): + from E5Network.E5GoogleMail import isClientSecretFileAvailable + if not isClientSecretFileAvailable(): # credentials file is not installed self.googleMailCheckBox.setChecked(False) self.googleMailCheckBox.setEnabled(False) @@ -60,7 +60,7 @@ self.googleMailInfoLabel.setText(self.tr( "<p>The Google Mail Client API is not installed." " Use <code>pip install --upgrade google-api-python-client" - " oauth2client</code> to install it.</p>")) + " google-auth-oauthlib</code> to install it.</p>")) self.googleHelpButton.setEnabled(False) Preferences.setUser("UseGoogleMailOAuth2", False)
--- a/i18n/eric6_cs.ts Sun Feb 24 13:01:58 2019 +0100 +++ b/i18n/eric6_cs.ts Sun Feb 24 17:55:36 2019 +0100 @@ -15688,7 +15688,7 @@ </message> <message> <location filename="../Preferences/ConfigurationPages/EmailPage.py" line="60"/> - <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client oauth2client</code> to install it.</p></source> + <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> to install it.</p></source> <translation type="unfinished"></translation> </message> </context> @@ -25180,7 +25180,7 @@ <context> <name>GoogleMailSendMessage</name> <message> - <location filename="../E5Network/E5GoogleMail.py" line="83"/> + <location filename="../E5Network/E5GoogleMail.py" line="93"/> <source>The credentials file is not present. Has the Gmail API been enabled?</source> <translation type="unfinished"></translation> </message>
--- a/i18n/eric6_de.ts Sun Feb 24 13:01:58 2019 +0100 +++ b/i18n/eric6_de.ts Sun Feb 24 17:55:36 2019 +0100 @@ -15721,8 +15721,8 @@ </message> <message> <location filename="../Preferences/ConfigurationPages/EmailPage.py" line="60"/> - <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client oauth2client</code> to install it.</p></source> - <translation><p>Das Google Mail Client API ist nicht installiert. Führe <code>pip install --upgrade google-api-python-client oauth2client</code> aus, um es zu installieren.</p></translation> + <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> to install it.</p></source> + <translation><p>Das Google Mail Client API ist nicht installiert. Führe <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> aus, um es zu installieren.</p></translation> </message> </context> <context> @@ -25253,7 +25253,7 @@ <context> <name>GoogleMailSendMessage</name> <message> - <location filename="../E5Network/E5GoogleMail.py" line="83"/> + <location filename="../E5Network/E5GoogleMail.py" line="93"/> <source>The credentials file is not present. Has the Gmail API been enabled?</source> <translation>Die Credentialsdatei ist nicht verfügbar. Wurde das Gmail API aktiviert?</translation> </message>
--- a/i18n/eric6_empty.ts Sun Feb 24 13:01:58 2019 +0100 +++ b/i18n/eric6_empty.ts Sun Feb 24 17:55:36 2019 +0100 @@ -15606,7 +15606,7 @@ </message> <message> <location filename="../Preferences/ConfigurationPages/EmailPage.py" line="60"/> - <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client oauth2client</code> to install it.</p></source> + <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> to install it.</p></source> <translation type="unfinished"></translation> </message> </context> @@ -25085,7 +25085,7 @@ <context> <name>GoogleMailSendMessage</name> <message> - <location filename="../E5Network/E5GoogleMail.py" line="83"/> + <location filename="../E5Network/E5GoogleMail.py" line="93"/> <source>The credentials file is not present. Has the Gmail API been enabled?</source> <translation type="unfinished"></translation> </message>
--- a/i18n/eric6_en.ts Sun Feb 24 13:01:58 2019 +0100 +++ b/i18n/eric6_en.ts Sun Feb 24 17:55:36 2019 +0100 @@ -15623,7 +15623,7 @@ </message> <message> <location filename="../Preferences/ConfigurationPages/EmailPage.py" line="60"/> - <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client oauth2client</code> to install it.</p></source> + <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> to install it.</p></source> <translation type="unfinished"></translation> </message> </context> @@ -25107,7 +25107,7 @@ <context> <name>GoogleMailSendMessage</name> <message> - <location filename="../E5Network/E5GoogleMail.py" line="83"/> + <location filename="../E5Network/E5GoogleMail.py" line="93"/> <source>The credentials file is not present. Has the Gmail API been enabled?</source> <translation type="unfinished"></translation> </message>
--- a/i18n/eric6_es.ts Sun Feb 24 13:01:58 2019 +0100 +++ b/i18n/eric6_es.ts Sun Feb 24 17:55:36 2019 +0100 @@ -15762,7 +15762,7 @@ </message> <message> <location filename="../Preferences/ConfigurationPages/EmailPage.py" line="60"/> - <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client oauth2client</code> to install it.</p></source> + <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> to install it.</p></source> <translation type="unfinished"></translation> </message> </context> @@ -25291,7 +25291,7 @@ <context> <name>GoogleMailSendMessage</name> <message> - <location filename="../E5Network/E5GoogleMail.py" line="83"/> + <location filename="../E5Network/E5GoogleMail.py" line="93"/> <source>The credentials file is not present. Has the Gmail API been enabled?</source> <translation>El archivo de credenciales no está presente. ¿Está habilitada la API de Gmail?</translation> </message>
--- a/i18n/eric6_fr.ts Sun Feb 24 13:01:58 2019 +0100 +++ b/i18n/eric6_fr.ts Sun Feb 24 17:55:36 2019 +0100 @@ -15698,7 +15698,7 @@ </message> <message> <location filename="../Preferences/ConfigurationPages/EmailPage.py" line="60"/> - <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client oauth2client</code> to install it.</p></source> + <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> to install it.</p></source> <translation type="unfinished"></translation> </message> </context> @@ -25192,7 +25192,7 @@ <context> <name>GoogleMailSendMessage</name> <message> - <location filename="../E5Network/E5GoogleMail.py" line="83"/> + <location filename="../E5Network/E5GoogleMail.py" line="93"/> <source>The credentials file is not present. Has the Gmail API been enabled?</source> <translation type="unfinished"></translation> </message>
--- a/i18n/eric6_it.ts Sun Feb 24 13:01:58 2019 +0100 +++ b/i18n/eric6_it.ts Sun Feb 24 17:55:36 2019 +0100 @@ -15715,7 +15715,7 @@ </message> <message> <location filename="../Preferences/ConfigurationPages/EmailPage.py" line="60"/> - <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client oauth2client</code> to install it.</p></source> + <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> to install it.</p></source> <translation type="unfinished"></translation> </message> </context> @@ -25220,7 +25220,7 @@ <context> <name>GoogleMailSendMessage</name> <message> - <location filename="../E5Network/E5GoogleMail.py" line="83"/> + <location filename="../E5Network/E5GoogleMail.py" line="93"/> <source>The credentials file is not present. Has the Gmail API been enabled?</source> <translation type="unfinished"></translation> </message>
--- a/i18n/eric6_pt.ts Sun Feb 24 13:01:58 2019 +0100 +++ b/i18n/eric6_pt.ts Sun Feb 24 17:55:36 2019 +0100 @@ -15723,7 +15723,7 @@ </message> <message> <location filename="../Preferences/ConfigurationPages/EmailPage.py" line="60"/> - <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client oauth2client</code> to install it.</p></source> + <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> to install it.</p></source> <translation type="unfinished"></translation> </message> </context> @@ -25229,7 +25229,7 @@ <context> <name>GoogleMailSendMessage</name> <message> - <location filename="../E5Network/E5GoogleMail.py" line="83"/> + <location filename="../E5Network/E5GoogleMail.py" line="93"/> <source>The credentials file is not present. Has the Gmail API been enabled?</source> <translation type="unfinished"></translation> </message>
--- a/i18n/eric6_ru.ts Sun Feb 24 13:01:58 2019 +0100 +++ b/i18n/eric6_ru.ts Sun Feb 24 17:55:36 2019 +0100 @@ -15804,8 +15804,8 @@ </message> <message> <location filename="../Preferences/ConfigurationPages/EmailPage.py" line="60"/> - <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client oauth2client</code> to install it.</p></source> - <translation><p>Клиент Google Mail API не установлен. Используйте <code>pip install --upgrade google-api-python-client oauth2client</code> для его установки.</p></translation> + <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> to install it.</p></source> + <translation type="unfinished"><p>Клиент Google Mail API не установлен. Используйте <code>pip install --upgrade google-api-python-client oauth2client</code> для его установки.</p></translation> </message> </context> <context> @@ -25340,7 +25340,7 @@ <context> <name>GoogleMailSendMessage</name> <message> - <location filename="../E5Network/E5GoogleMail.py" line="83"/> + <location filename="../E5Network/E5GoogleMail.py" line="93"/> <source>The credentials file is not present. Has the Gmail API been enabled?</source> <translation>Отсутствует файл учетных данных. Подключен ли API Gmail?</translation> </message>
--- a/i18n/eric6_tr.ts Sun Feb 24 13:01:58 2019 +0100 +++ b/i18n/eric6_tr.ts Sun Feb 24 17:55:36 2019 +0100 @@ -15677,7 +15677,7 @@ </message> <message> <location filename="../Preferences/ConfigurationPages/EmailPage.py" line="60"/> - <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client oauth2client</code> to install it.</p></source> + <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> to install it.</p></source> <translation type="unfinished"></translation> </message> </context> @@ -25173,7 +25173,7 @@ <context> <name>GoogleMailSendMessage</name> <message> - <location filename="../E5Network/E5GoogleMail.py" line="83"/> + <location filename="../E5Network/E5GoogleMail.py" line="93"/> <source>The credentials file is not present. Has the Gmail API been enabled?</source> <translation type="unfinished"></translation> </message>
--- a/i18n/eric6_zh_CN.ts Sun Feb 24 13:01:58 2019 +0100 +++ b/i18n/eric6_zh_CN.ts Sun Feb 24 17:55:36 2019 +0100 @@ -15673,7 +15673,7 @@ </message> <message> <location filename="../Preferences/ConfigurationPages/EmailPage.py" line="60"/> - <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client oauth2client</code> to install it.</p></source> + <source><p>The Google Mail Client API is not installed. Use <code>pip install --upgrade google-api-python-client google-auth-oauthlib</code> to install it.</p></source> <translation type="unfinished"></translation> </message> </context> @@ -25169,7 +25169,7 @@ <context> <name>GoogleMailSendMessage</name> <message> - <location filename="../E5Network/E5GoogleMail.py" line="83"/> + <location filename="../E5Network/E5GoogleMail.py" line="93"/> <source>The credentials file is not present. Has the Gmail API been enabled?</source> <translation type="unfinished"></translation> </message>