(20241203) Working with labels.
This commit is contained in:
@@ -153,6 +153,40 @@ async def handle_gmail_callback() -> render_template:
|
|||||||
failure_hint = f"We were expecting authorization from '{placeholder_token['clientUserId']['email']}' but got authorization from '{tokens.email}' instead."
|
failure_hint = f"We were expecting authorization from '{placeholder_token['clientUserId']['email']}' but got authorization from '{tokens.email}' instead."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# We create standard labels that we will use:
|
||||||
|
labels = [
|
||||||
|
{
|
||||||
|
"name": "TCAOFF",
|
||||||
|
"textColor": "#434343",
|
||||||
|
"backgroundColor": "#cccccc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "CA-Doc",
|
||||||
|
"textColor": "#434343",
|
||||||
|
"backgroundColor": "#cccccc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "CA-AI",
|
||||||
|
"textColor": "#434343",
|
||||||
|
"backgroundColor": "#cccccc"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
tasks = [
|
||||||
|
current_app.gmail_client.create_label(
|
||||||
|
tokens = tokens,
|
||||||
|
label_name = label["name"],
|
||||||
|
label_visibility = "labelShow",
|
||||||
|
message_visibility = "show",
|
||||||
|
label_text_color = label["textColor"],
|
||||||
|
label_background_color = label["backgroundColor"]
|
||||||
|
) for label in labels
|
||||||
|
]
|
||||||
|
client_responses = await asyncio.gather(*tasks)
|
||||||
|
|
||||||
|
# Add the labels to the tokens data:
|
||||||
|
client_response = await current_app.gmail_client.list_labels(tokens = tokens)
|
||||||
|
tokens.labels = client_response.data if client_response.success else None
|
||||||
|
|
||||||
# Now that we have passed the check,
|
# Now that we have passed the check,
|
||||||
# we save the tokens to the database:
|
# we save the tokens to the database:
|
||||||
tokens_saved = await current_app.mail_oauth_model.set_token(
|
tokens_saved = await current_app.mail_oauth_model.set_token(
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
# To make sibling directories accessible for imports:
|
# To make sibling directories accessible for imports:
|
||||||
import sys
|
import sys
|
||||||
|
from logging import exception
|
||||||
|
|
||||||
sys.path.append(".")
|
sys.path.append(".")
|
||||||
sys.path.append("..")
|
sys.path.append("..")
|
||||||
|
|
||||||
@@ -134,7 +136,6 @@ class MailSyncModel(BaseModel):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def __save_one_attachment(
|
async def __save_one_attachment(
|
||||||
self,
|
|
||||||
session_token: str,
|
session_token: str,
|
||||||
attachment: Dict[str, Any],
|
attachment: Dict[str, Any],
|
||||||
attachment_tags: List[str],
|
attachment_tags: List[str],
|
||||||
@@ -453,6 +454,14 @@ class MailSyncModel(BaseModel):
|
|||||||
requests = mongo_operations
|
requests = mongo_operations
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Apply the labels to the read messages:
|
||||||
|
try: client_response = await mail_client.modify_messages(
|
||||||
|
tokens = tokens,
|
||||||
|
message_ids = [v["id"] for v in messages_list],
|
||||||
|
add_label_ids = [tokens.labels.get("TCAOFF")]
|
||||||
|
)
|
||||||
|
except Exception as exception: self._printer(exception)
|
||||||
|
|
||||||
# Done here:
|
# Done here:
|
||||||
sync_results.message = f"{sync_results.successCount}/{sync_results.totalCount} mail(s) sync'd from gmail"
|
sync_results.message = f"{sync_results.successCount}/{sync_results.totalCount} mail(s) sync'd from gmail"
|
||||||
return sync_results
|
return sync_results
|
||||||
|
|||||||
Reference in New Issue
Block a user