(20241203) Minor upgrades.
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
"""
|
||||
|
||||
AUTHOR:
|
||||
|
||||
Khushal P Soonderji
|
||||
|
||||
DATE:
|
||||
|
||||
Tuesday, 3rd Dec., 2024
|
||||
|
||||
OBJECTIVE:
|
||||
|
||||
To enlist and retrieve mails for various filtering conditions.
|
||||
|
||||
REFERENCES:
|
||||
|
||||
N/A
|
||||
|
||||
DOWNLOADS:
|
||||
|
||||
N/A
|
||||
|
||||
"""
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** IMPORT ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
# To make sibling directories accessible for imports:
|
||||
import sys
|
||||
sys.path.append(".")
|
||||
sys.path.append("..")
|
||||
|
||||
# My async utils:
|
||||
from utils_v2.string import json
|
||||
from utils_v2.date_time import date_time
|
||||
from utils_v2.database.async_mongo_v2 import AsyncMongo
|
||||
|
||||
# Base model:
|
||||
from models.behaviour.base import BaseModel
|
||||
|
||||
# To work with MongoDB:
|
||||
from bson import ObjectId
|
||||
|
||||
# To work with datatypes:
|
||||
from typing import Literal
|
||||
|
||||
# For asynchronous activities:
|
||||
import asyncio
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** MACROS / ONE-TIME INIT ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
# --- Nothing Yet
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** VARIABLES ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
# --- Nothing Yet
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** FUNCTIONS ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
# --- Nothing Yet
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** CLASSES ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
class MailRetrieveModel(BaseModel):
|
||||
|
||||
# For MongoDB:
|
||||
AUTH_COLLECTION = "_authTokens"
|
||||
MAIL_COLLECTION = "_messages"
|
||||
|
||||
async def get_mail(
|
||||
self,
|
||||
mongo_conn: AsyncMongo,
|
||||
mail_identifier: str | ObjectId
|
||||
):
|
||||
|
||||
"""
|
||||
Retrieves one full mail from the database.
|
||||
:param mongo_conn: The instance of the database connector to use to get the mail's data.
|
||||
:param mail_identifier: The '_id' of the document that holds the mail.
|
||||
:return: Either the JSON that describes the mail or None if such a mail does not exist.
|
||||
"""
|
||||
|
||||
mail_data = await mongo_conn.find_one(
|
||||
collection = self.MAIL_COLLECTION,
|
||||
filter = {"_id": ObjectId(mail_identifier)},
|
||||
projection = {
|
||||
"mailId": "_id",
|
||||
"serviceType": True,
|
||||
"client": True,
|
||||
"payload.ts": True,
|
||||
"payload.readTs": True,
|
||||
"payload.from": True,
|
||||
"payload.to": True,
|
||||
"payload.cc": True,
|
||||
"payload.bcc": True,
|
||||
"payload.parts": True,
|
||||
"payload.attachments": True,
|
||||
"payload.labels": True,
|
||||
"payload.snippet": True,
|
||||
"payload.aiSnippet": "payload.aiSnippet.snippet",
|
||||
}
|
||||
)
|
||||
if mail_data: mail_data["mailId"] = str(mail_data["mailId"])
|
||||
return mail_data
|
||||
|
||||
async def list_by_account_identifier(
|
||||
self,
|
||||
mongo_conn: AsyncMongo,
|
||||
account_identifier: str | ObjectId,
|
||||
limit: int = 25,
|
||||
skip: int = 0
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** MAIN PROGRAM ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
pass
|
||||
Reference in New Issue
Block a user