(20241213) Mail Module Reworked!
This commit is contained in:
+78
-5
@@ -283,14 +283,12 @@ class MailController:
|
||||
async def get_token(
|
||||
mongo_conn: AsyncMongo,
|
||||
token_id: ObjectId | str = None,
|
||||
**kwargs
|
||||
) -> CoreAuthTokenModel | None:
|
||||
|
||||
# Simply call the core model:
|
||||
return await current_app.core_auth_token_controller.get_token(
|
||||
mongo_conn = mongo_conn,
|
||||
token_id = token_id,
|
||||
**kwargs
|
||||
token_id = token_id
|
||||
)
|
||||
|
||||
# ┏┓ ┳┳┓
|
||||
@@ -364,8 +362,15 @@ class MailController:
|
||||
client = auth_token.client,
|
||||
clientMessageId = message_id,
|
||||
clientThreadId = client_response.data["threadId"],
|
||||
preview = client_response.data["subject"],
|
||||
message = client_response.data
|
||||
isSent = False,
|
||||
isBroadcast = False,
|
||||
sentSuccessfully = False,
|
||||
sender = client_response.data["from"][0]["name"],
|
||||
chat = None,
|
||||
message = client_response.data,
|
||||
snippet = client_response.data["subject"],
|
||||
aiSnippet = None,
|
||||
tags = ["email", "gmail"]
|
||||
)
|
||||
|
||||
# Give a quick indicator of whether this mail is an inbox mail or sent mail:
|
||||
@@ -564,6 +569,74 @@ class MailController:
|
||||
sync_results.message = f"no such mail client '{auth_token.client}'"
|
||||
return sync_results
|
||||
|
||||
# ┓ • ┏┓ ┏┓ ┳┳┓
|
||||
# ┃ ┓┏╋ ┣╋ ┃┓┏┓╋ ┃┃┃┏┓┏┏┏┓┏┓┏┓┏
|
||||
# ┗┛┗┛┗ ┗┻ ┗┛┗ ┗ ┛ ┗┗ ┛┛┗┻┗┫┗ ┛
|
||||
# ┛
|
||||
|
||||
# These are simply for retrieving mails. You need to already have them sync'd to the database. These methods don't
|
||||
# fetch the mails from the third-party clients.
|
||||
|
||||
@staticmethod
|
||||
async def list_mails(
|
||||
mongo_conn: AsyncMongo,
|
||||
token_ids: List[ObjectId | str],
|
||||
limit: int = 100,
|
||||
skip: int = 0,
|
||||
additional_filter: dict = None
|
||||
) -> List[CoreMessageModel] | None:
|
||||
|
||||
# regardless of what additional filter is provided from outside,
|
||||
# we add a mail-selecting filter here:
|
||||
if additional_filter is None: additional_filter = {}
|
||||
additional_filter["serviceType"] = "email"
|
||||
|
||||
# Simply call the core model:
|
||||
return await current_app.core_message_controller.get_previews(
|
||||
mongo_conn = mongo_conn,
|
||||
token_ids = token_ids,
|
||||
limit = limit,
|
||||
skip = skip,
|
||||
additional_filter = additional_filter
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
async def get_one_mail(
|
||||
mongo_conn: AsyncMongo,
|
||||
token_id: ObjectId | str,
|
||||
message_id: ObjectId | str
|
||||
) -> CoreMessageModel | None:
|
||||
|
||||
# Simply call the core model:
|
||||
return await current_app.core_message_controller.get_message(
|
||||
mongo_conn = mongo_conn,
|
||||
token_id = token_id,
|
||||
message_id = message_id
|
||||
)
|
||||
|
||||
# ┳┳ ┓
|
||||
# ┃┃┏┓┏┫┏┓╋┏┓
|
||||
# ┗┛┣┛┗┻┗┻┗┗
|
||||
# ┛
|
||||
|
||||
@staticmethod
|
||||
async def update_tags(
|
||||
mongo_conn: AsyncMongo,
|
||||
token_id: ObjectId | str,
|
||||
message_id: ObjectId | str,
|
||||
unset_tags: List[str] = None,
|
||||
set_tags: List[str] = None
|
||||
) -> bool:
|
||||
|
||||
# Simply call the core model:
|
||||
return await current_app.core_message_controller.update_tags(
|
||||
mongo_conn = mongo_conn,
|
||||
token_id = token_id,
|
||||
message_id = message_id,
|
||||
unset_tags = unset_tags,
|
||||
set_tags = set_tags
|
||||
)
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
|
||||
Reference in New Issue
Block a user