gmailsorter 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/PKG-INFO +10 -6
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/pyproject.toml +10 -5
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/_version.py +2 -2
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/daemon/daemon.py +45 -26
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/daemon/shared.py +23 -14
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/google/database.py +13 -7
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/google/mail.py +14 -10
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/google/message.py +2 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/app.py +9 -3
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/googleapi.py +21 -2
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/.gitignore +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/LICENSE +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/README.md +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/__init__.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/__main__.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/daemon/__init__.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/daemon/__main__.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/daemon/tasks.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/google/__init__.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/google/authentication.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/local.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/__init__.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/__main__.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/config.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/database.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/render.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/css/main.css +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/css/util.css +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-Black.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-BlackItalic.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-Bold.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-BoldItalic.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-ExtraBold.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-ExtraBoldItalic.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-ExtraLight.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-ExtraLightItalic.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-Italic.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-Light.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-LightItalic.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-Medium.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-MediumItalic.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-Regular.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-SemiBold.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-SemiBoldItalic.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-Thin.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-ThinItalic.ttf +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/images/bg-01.jpg +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/images/icons/favicon.ico +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/templates/login.html +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/templates/user.html +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/user.py +0 -0
- {gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/wsgi.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: gmailsorter
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Assign labels to emails in Google Mail based on their similarity to other emails assigned to the same label.
|
|
5
5
|
Project-URL: Homepage, https://github.com/jan-janssen/gmailsorter
|
|
6
6
|
Author-email: Jan Janssen <jan.janssen@outlook.com>
|
|
@@ -15,15 +15,19 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.13
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.14
|
|
17
17
|
Requires-Python: >=3.10
|
|
18
|
-
Requires-Dist: google-api-python-client>=2.
|
|
18
|
+
Requires-Dist: google-api-python-client>=2.202.0
|
|
19
19
|
Requires-Dist: google-auth-oauthlib>=1.5.0
|
|
20
|
-
Requires-Dist: google-auth>=2.
|
|
21
|
-
Requires-Dist: mailsort>=0.0.
|
|
22
|
-
Requires-Dist: sqlalchemy>=2.
|
|
20
|
+
Requires-Dist: google-auth>=2.63.0
|
|
21
|
+
Requires-Dist: mailsort>=0.0.6
|
|
22
|
+
Requires-Dist: sqlalchemy>=2.1.9
|
|
23
|
+
Provides-Extra: docs
|
|
24
|
+
Requires-Dist: myst-parser; extra == 'docs'
|
|
25
|
+
Requires-Dist: nbsphinx; extra == 'docs'
|
|
26
|
+
Requires-Dist: sphinx; extra == 'docs'
|
|
23
27
|
Provides-Extra: webapp
|
|
24
28
|
Requires-Dist: flask-login>=0.6.3; extra == 'webapp'
|
|
25
29
|
Requires-Dist: flask>=3.1.3; extra == 'webapp'
|
|
26
|
-
Requires-Dist: gunicorn>=
|
|
30
|
+
Requires-Dist: gunicorn>=27.0.1; extra == 'webapp'
|
|
27
31
|
Description-Content-Type: text/markdown
|
|
28
32
|
|
|
29
33
|
# Gmailsorter - Similarity based email sorting for Google Mail
|
|
@@ -23,19 +23,24 @@ classifiers = [
|
|
|
23
23
|
"Programming Language :: Python :: 3.14",
|
|
24
24
|
]
|
|
25
25
|
dependencies = [
|
|
26
|
-
"google-api-python-client>=2.
|
|
27
|
-
"google-auth>=2.
|
|
26
|
+
"google-api-python-client>=2.202.0",
|
|
27
|
+
"google-auth>=2.63.0",
|
|
28
28
|
"google-auth-oauthlib>=1.5.0",
|
|
29
|
-
"mailsort>=0.0.
|
|
30
|
-
"sqlalchemy>=2.
|
|
29
|
+
"mailsort>=0.0.6",
|
|
30
|
+
"sqlalchemy>=2.1.9",
|
|
31
31
|
]
|
|
32
32
|
|
|
33
33
|
[project.optional-dependencies]
|
|
34
34
|
webapp = [
|
|
35
|
-
"gunicorn>=
|
|
35
|
+
"gunicorn>=27.0.1",
|
|
36
36
|
"flask>=3.1.3",
|
|
37
37
|
"flask-login>=0.6.3",
|
|
38
38
|
]
|
|
39
|
+
docs = [
|
|
40
|
+
"nbsphinx",
|
|
41
|
+
"sphinx",
|
|
42
|
+
"myst-parser",
|
|
43
|
+
]
|
|
39
44
|
|
|
40
45
|
[project.urls]
|
|
41
46
|
Homepage = "https://github.com/jan-janssen/gmailsorter"
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '0.2.
|
|
22
|
-
__version_tuple__ = version_tuple = (0, 2,
|
|
21
|
+
__version__ = version = '0.2.2'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 2, 2)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import traceback
|
|
1
2
|
from typing import Any
|
|
2
3
|
|
|
3
4
|
from google.auth.exceptions import RefreshError
|
|
@@ -22,6 +23,17 @@ from gmailsorter.daemon.tasks import (
|
|
|
22
23
|
)
|
|
23
24
|
|
|
24
25
|
|
|
26
|
+
def _mark_task_failed(session: Session, user_id: int, task_name: str) -> None:
|
|
27
|
+
traceback.print_exc()
|
|
28
|
+
session.rollback()
|
|
29
|
+
update_task_status(
|
|
30
|
+
session=session,
|
|
31
|
+
user_id=user_id,
|
|
32
|
+
task_name=task_name,
|
|
33
|
+
status=JOB_STATUS_FAIL,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
25
37
|
def load_user_data_from_database(
|
|
26
38
|
session: Session, mode: str
|
|
27
39
|
) -> tuple[dict[str, list[int]], dict[int, dict[str, Any]]]:
|
|
@@ -101,28 +113,36 @@ def iterate_over_users(
|
|
|
101
113
|
task_name="update",
|
|
102
114
|
status=JOB_STATUS_PROGRESS,
|
|
103
115
|
)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
try:
|
|
117
|
+
gmail.update_database(quick=False)
|
|
118
|
+
gmail.fit_machine_learning_model_to_database(
|
|
119
|
+
n_estimators=n_estimators,
|
|
120
|
+
max_features=max_features,
|
|
121
|
+
random_state=random_state,
|
|
122
|
+
bootstrap=bootstrap,
|
|
123
|
+
include_deleted=include_deleted,
|
|
124
|
+
max_workers=max_workers,
|
|
125
|
+
)
|
|
126
|
+
if status_start == JOB_STATUS_INIT:
|
|
127
|
+
update_task_status(
|
|
128
|
+
session=session,
|
|
129
|
+
user_id=user_database_id,
|
|
130
|
+
task_name="fetch",
|
|
131
|
+
status=JOB_STATUS_INIT,
|
|
132
|
+
)
|
|
114
133
|
update_task_status(
|
|
115
134
|
session=session,
|
|
116
135
|
user_id=user_database_id,
|
|
117
|
-
task_name="
|
|
118
|
-
status=
|
|
136
|
+
task_name="update",
|
|
137
|
+
status=JOB_STATUS_SUCCESS,
|
|
119
138
|
)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
139
|
+
except Exception:
|
|
140
|
+
# Never leave the task in progress, otherwise it is not executed again.
|
|
141
|
+
_mark_task_failed(
|
|
142
|
+
session=session, user_id=user_database_id, task_name="update"
|
|
143
|
+
)
|
|
144
|
+
finally:
|
|
145
|
+
gmail.close_database_connection()
|
|
126
146
|
elif filter_messages:
|
|
127
147
|
update_task_status(
|
|
128
148
|
session=session,
|
|
@@ -136,20 +156,19 @@ def iterate_over_users(
|
|
|
136
156
|
recommendation_ratio=recommendation_ratio,
|
|
137
157
|
label_prefix="labels_Label_",
|
|
138
158
|
)
|
|
139
|
-
except HttpError:
|
|
140
|
-
update_task_status(
|
|
141
|
-
session=session,
|
|
142
|
-
user_id=user_database_id,
|
|
143
|
-
task_name="fetch",
|
|
144
|
-
status=JOB_STATUS_FAIL,
|
|
145
|
-
)
|
|
146
|
-
else:
|
|
147
159
|
update_task_status(
|
|
148
160
|
session=session,
|
|
149
161
|
user_id=user_database_id,
|
|
150
162
|
task_name="fetch",
|
|
151
163
|
status=JOB_STATUS_SUCCESS,
|
|
152
164
|
)
|
|
165
|
+
except Exception:
|
|
166
|
+
# Never leave the task in progress, otherwise it is not executed again.
|
|
167
|
+
_mark_task_failed(
|
|
168
|
+
session=session, user_id=user_database_id, task_name="fetch"
|
|
169
|
+
)
|
|
170
|
+
finally:
|
|
171
|
+
gmail.close_database_connection()
|
|
153
172
|
else:
|
|
154
173
|
raise ValueError(
|
|
155
174
|
"Neither database_update or filter_messages was selected."
|
|
@@ -10,12 +10,20 @@ from mailsort.api import (
|
|
|
10
10
|
get_email_database,
|
|
11
11
|
get_machine_learning_database,
|
|
12
12
|
)
|
|
13
|
-
from sqlalchemy import
|
|
13
|
+
from sqlalchemy import (
|
|
14
|
+
Column,
|
|
15
|
+
DateTime,
|
|
16
|
+
Engine,
|
|
17
|
+
Integer,
|
|
18
|
+
String,
|
|
19
|
+
Text,
|
|
20
|
+
create_engine,
|
|
21
|
+
)
|
|
14
22
|
from sqlalchemy.orm import Session, declarative_base, sessionmaker
|
|
15
23
|
|
|
16
24
|
from gmailsorter.google import GoogleMailBase
|
|
25
|
+
from gmailsorter.google.database import SHORT_STRING_LENGTH, get_token_database
|
|
17
26
|
from gmailsorter.google.database import DatabaseInterface as TokenDatabaseInterface
|
|
18
|
-
from gmailsorter.google.database import get_token_database
|
|
19
27
|
|
|
20
28
|
# Modifying the labels of emails requires /auth/gmail.modify
|
|
21
29
|
# https://developers.google.com/gmail/api/reference/rest/v1/users.messages/modify
|
|
@@ -46,12 +54,12 @@ Base = declarative_base()
|
|
|
46
54
|
class GoogleToken(Base):
|
|
47
55
|
__tablename__ = "google_token"
|
|
48
56
|
id = Column(Integer, primary_key=True)
|
|
49
|
-
token = Column(
|
|
50
|
-
refresh_token = Column(
|
|
51
|
-
token_uri = Column(String)
|
|
52
|
-
client_id = Column(String)
|
|
53
|
-
client_secret = Column(String)
|
|
54
|
-
scopes = Column(
|
|
57
|
+
token = Column(Text)
|
|
58
|
+
refresh_token = Column(Text)
|
|
59
|
+
token_uri = Column(String(SHORT_STRING_LENGTH))
|
|
60
|
+
client_id = Column(String(SHORT_STRING_LENGTH))
|
|
61
|
+
client_secret = Column(String(SHORT_STRING_LENGTH))
|
|
62
|
+
scopes = Column(Text)
|
|
55
63
|
expiry = Column(DateTime)
|
|
56
64
|
user_id = Column(Integer)
|
|
57
65
|
|
|
@@ -59,18 +67,19 @@ class GoogleToken(Base):
|
|
|
59
67
|
class SQLUser(Base):
|
|
60
68
|
__tablename__ = "google_user"
|
|
61
69
|
id = Column(Integer, primary_key=True)
|
|
62
|
-
google_id = Column(String)
|
|
63
|
-
name = Column(String)
|
|
64
|
-
email = Column(String)
|
|
65
|
-
|
|
70
|
+
google_id = Column(String(SHORT_STRING_LENGTH))
|
|
71
|
+
name = Column(String(SHORT_STRING_LENGTH))
|
|
72
|
+
email = Column(String(SHORT_STRING_LENGTH))
|
|
73
|
+
# The profile picture is a URL, which has no upper bound on its length
|
|
74
|
+
profile_pic = Column(Text)
|
|
66
75
|
|
|
67
76
|
|
|
68
77
|
class Task(Base):
|
|
69
78
|
__tablename__ = "google_task"
|
|
70
79
|
id = Column(Integer, primary_key=True)
|
|
71
|
-
task_name = Column(String)
|
|
80
|
+
task_name = Column(String(SHORT_STRING_LENGTH))
|
|
72
81
|
date = Column(DateTime)
|
|
73
|
-
status = Column(String)
|
|
82
|
+
status = Column(String(SHORT_STRING_LENGTH))
|
|
74
83
|
user_id = Column(Integer)
|
|
75
84
|
|
|
76
85
|
|
|
@@ -2,21 +2,27 @@ from typing import Any
|
|
|
2
2
|
|
|
3
3
|
from google.oauth2.credentials import Credentials
|
|
4
4
|
from mailsort.base.database import DatabaseTemplate
|
|
5
|
-
from sqlalchemy import Column, DateTime, Engine, Integer, String
|
|
5
|
+
from sqlalchemy import Column, DateTime, Engine, Integer, String, Text
|
|
6
6
|
from sqlalchemy.orm import Session, declarative_base
|
|
7
7
|
|
|
8
8
|
Base = declarative_base()
|
|
9
9
|
|
|
10
|
+
# MySQL requires a length for VARCHAR columns. Identifiers, URIs and secrets fit
|
|
11
|
+
# in VARCHAR(255), while Google access tokens (up to 2048 bytes), refresh tokens
|
|
12
|
+
# (up to 512 bytes) and the list of scopes can exceed 255 characters and are
|
|
13
|
+
# stored as TEXT.
|
|
14
|
+
SHORT_STRING_LENGTH = 255
|
|
15
|
+
|
|
10
16
|
|
|
11
17
|
class GoogleToken(Base):
|
|
12
18
|
__tablename__ = "google_token"
|
|
13
19
|
id = Column(Integer, primary_key=True)
|
|
14
|
-
token = Column(
|
|
15
|
-
refresh_token = Column(
|
|
16
|
-
token_uri = Column(String)
|
|
17
|
-
client_id = Column(String)
|
|
18
|
-
client_secret = Column(String)
|
|
19
|
-
scopes = Column(
|
|
20
|
+
token = Column(Text)
|
|
21
|
+
refresh_token = Column(Text)
|
|
22
|
+
token_uri = Column(String(SHORT_STRING_LENGTH))
|
|
23
|
+
client_id = Column(String(SHORT_STRING_LENGTH))
|
|
24
|
+
client_secret = Column(String(SHORT_STRING_LENGTH))
|
|
25
|
+
scopes = Column(Text)
|
|
20
26
|
expiry = Column(DateTime)
|
|
21
27
|
user_id = Column(Integer)
|
|
22
28
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from typing import Any
|
|
2
2
|
|
|
3
|
+
from google.auth.exceptions import RefreshError
|
|
3
4
|
from googleapiclient.discovery import Resource
|
|
4
5
|
from mailsort.api import DatabaseInterface as EmailDatabaseInterface
|
|
5
6
|
from mailsort.api import (
|
|
@@ -79,17 +80,20 @@ class GoogleMailBase(AbstractMailBox):
|
|
|
79
80
|
email_format = self._email_download_format
|
|
80
81
|
if metadata_headers is None:
|
|
81
82
|
metadata_headers = []
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
try:
|
|
84
|
+
return (
|
|
85
|
+
self._service.users()
|
|
86
|
+
.messages()
|
|
87
|
+
.get(
|
|
88
|
+
userId=self._userid,
|
|
89
|
+
id=message_id,
|
|
90
|
+
format=email_format,
|
|
91
|
+
metadataHeaders=metadata_headers,
|
|
92
|
+
)
|
|
93
|
+
.execute()
|
|
90
94
|
)
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
except RefreshError:
|
|
96
|
+
return {}
|
|
93
97
|
|
|
94
98
|
def _get_messages_page(
|
|
95
99
|
self,
|
|
@@ -10,6 +10,8 @@ from mailsort.base.message import (
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def get_email_dict(message: dict[str, Any]) -> dict[str, Any] | None:
|
|
13
|
+
if len(message) == 0: # The message could not be downloaded
|
|
14
|
+
return None
|
|
13
15
|
try:
|
|
14
16
|
return Message(message_dict=message).to_dict()
|
|
15
17
|
except ValueError as e:
|
|
@@ -148,10 +148,14 @@ def reset_status() -> str | flask.Response:
|
|
|
148
148
|
def oauth2callback() -> flask.Response | tuple[str, int]:
|
|
149
149
|
# Specify the state when creating the flow in the callback so that it can
|
|
150
150
|
# verified in the authorization server response.
|
|
151
|
-
state = flask.session
|
|
152
|
-
code_verifier = flask.session
|
|
151
|
+
state = flask.session.pop("state", None)
|
|
152
|
+
code_verifier = flask.session.pop("code_verifier", None)
|
|
153
|
+
if state is None or code_verifier is None:
|
|
154
|
+
# The callback was reached without starting the login flow in this
|
|
155
|
+
# session (stale link, reload, crawler or blocked cookies).
|
|
156
|
+
return flask.redirect(flask.url_for("index"))
|
|
153
157
|
|
|
154
|
-
credentials_dict = get_google_credentials(
|
|
158
|
+
credentials_dict, error_scopes = get_google_credentials(
|
|
155
159
|
client_config=CLIENT_SECRETS_CONFIG,
|
|
156
160
|
scopes=SCOPES,
|
|
157
161
|
state=state,
|
|
@@ -159,6 +163,8 @@ def oauth2callback() -> flask.Response | tuple[str, int]:
|
|
|
159
163
|
authorization_response=flask.request.url,
|
|
160
164
|
code_verifier=code_verifier,
|
|
161
165
|
)
|
|
166
|
+
if error_scopes is not None:
|
|
167
|
+
return error_scopes, 403
|
|
162
168
|
|
|
163
169
|
flask.session["credentials"] = credentials_dict
|
|
164
170
|
user_info_dict, error_user, _ = get_user_info(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Based on https://developers.google.com/identity/protocols/oauth2/web-server#python
|
|
2
|
+
import os
|
|
2
3
|
from datetime import datetime
|
|
3
4
|
from typing import Any
|
|
4
5
|
|
|
@@ -7,8 +8,15 @@ import google_auth_oauthlib.flow
|
|
|
7
8
|
import googleapiclient.discovery
|
|
8
9
|
from google.auth.exceptions import RefreshError
|
|
9
10
|
from googleapiclient.errors import HttpError
|
|
11
|
+
from oauthlib.oauth2.rfc6749.utils import scope_to_list
|
|
10
12
|
from sqlalchemy import Engine
|
|
11
13
|
|
|
14
|
+
# Google's granular consent screen lets users deselect individual scopes, and
|
|
15
|
+
# include_granted_scopes can add previously granted ones. In both cases the
|
|
16
|
+
# granted scopes differ from the requested ones and oauthlib raises a Warning
|
|
17
|
+
# unless relaxed. The granted scopes are validated in get_google_credentials().
|
|
18
|
+
os.environ["OAUTHLIB_RELAX_TOKEN_SCOPE"] = "1"
|
|
19
|
+
|
|
12
20
|
from gmailsorter.daemon import (
|
|
13
21
|
GoogleMail,
|
|
14
22
|
create_tasks_for_new_users,
|
|
@@ -47,7 +55,7 @@ def get_google_credentials(
|
|
|
47
55
|
code_verifier: str,
|
|
48
56
|
redirect_uri: str,
|
|
49
57
|
authorization_response: str,
|
|
50
|
-
) -> dict[str, Any]:
|
|
58
|
+
) -> tuple[dict[str, Any] | None, str | None]:
|
|
51
59
|
# Create flow instance to manage the OAuth 2.0 Authorization Grant Flow steps.
|
|
52
60
|
flow = google_auth_oauthlib.flow.Flow.from_client_config(
|
|
53
61
|
client_config=client_config, scopes=scopes, state=state
|
|
@@ -58,10 +66,21 @@ def get_google_credentials(
|
|
|
58
66
|
# Use the authorization server's response to fetch the OAuth 2.0 tokens.
|
|
59
67
|
flow.fetch_token(authorization_response=authorization_response)
|
|
60
68
|
|
|
69
|
+
# The user may have deselected some of the requested scopes on the consent
|
|
70
|
+
# screen, see https://github.com/jan-janssen/gmailsorter/issues/516
|
|
71
|
+
granted_scopes = scope_to_list(flow.oauth2session.token.get("scope")) or []
|
|
72
|
+
missing_scopes = [s for s in scopes if s not in granted_scopes]
|
|
73
|
+
if missing_scopes:
|
|
74
|
+
return None, (
|
|
75
|
+
"gmailsorter requires all requested permissions to sort your emails. "
|
|
76
|
+
"Please log in again and grant the following permissions: "
|
|
77
|
+
+ ", ".join(missing_scopes)
|
|
78
|
+
)
|
|
79
|
+
|
|
61
80
|
# Store credentials in the session.
|
|
62
81
|
# ACTION ITEM: In a production app, you likely want to save these
|
|
63
82
|
# credentials in a persistent database instead.
|
|
64
|
-
return _credentials_to_dict(credentials=flow.credentials)
|
|
83
|
+
return _credentials_to_dict(credentials=flow.credentials), None
|
|
65
84
|
|
|
66
85
|
|
|
67
86
|
def get_user_status(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-Bold.ttf
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/fonts/poppins/Poppins-Thin.ttf
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{gmailsorter-0.2.0 → gmailsorter-0.2.2}/src/gmailsorter/webapp/static/images/icons/favicon.ico
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|