filepath added
parent
cd1693fd43
commit
d48048bb7a
|
|
@ -128,7 +128,7 @@ def _decode_attachments_sync(
|
|||
ext = Path(attachment.get("name") or "").suffix.lower()
|
||||
if ext not in _DECODERS:
|
||||
continue
|
||||
path = _decode_one(attachment, dest_dir)
|
||||
path = _decode_one(attachment, dest_dir).resolve()
|
||||
paths.append(str(path))
|
||||
|
||||
return paths
|
||||
|
|
@ -143,6 +143,6 @@ async def decode_attachment(
|
|||
|
||||
Designed for views: ``await decode_attachment(data.get("attachments"))``.
|
||||
Accepts None, a single attachment dict, or a list of attachment dicts.
|
||||
Returns absolute/relative path strings for successfully written files.
|
||||
Returns absolute file_path strings for successfully converted files.
|
||||
"""
|
||||
return await asyncio.to_thread(_decode_attachments_sync, attachments, out_dir)
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class Inbox_Messages(SQLModel, table=True):
|
|||
return email_data.get("bodyPreview") or ""
|
||||
|
||||
@classmethod
|
||||
def _fields_from_email(cls, email_data: dict) -> dict:
|
||||
def _fields_from_email(cls, email_data: dict, file_path: list[str] | None = None) -> dict:
|
||||
return {
|
||||
"message_subject": email_data.get("subject") or "",
|
||||
"message_body": cls._body_text(email_data),
|
||||
|
|
@ -99,15 +99,21 @@ class Inbox_Messages(SQLModel, table=True):
|
|||
[r["emailAddress"]["address"] for r in email_data.get("replyTo", [])]
|
||||
),
|
||||
"message_id": email_data.get("id"),
|
||||
"file_name":",".join(
|
||||
"file_name": ",".join(
|
||||
[r.get("name") for r in email_data.get("attachments", [])]
|
||||
),
|
||||
"file_path": ",".join(file_path) if file_path else None,
|
||||
"full_email_response": email_data,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
async def insert_email(cls, session: AsyncSession, email_data: dict):
|
||||
fields = cls._fields_from_email(email_data)
|
||||
async def insert_email(
|
||||
cls,
|
||||
session: AsyncSession,
|
||||
email_data: dict,
|
||||
file_path: list[str] | None = None,
|
||||
):
|
||||
fields = cls._fields_from_email(email_data, file_path)
|
||||
external_id = fields.get("message_id")
|
||||
|
||||
if external_id:
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Email:
|
|||
if response.status_code==200:
|
||||
data=response.json()
|
||||
re_create_file=await decode_attachment(data.get("attachments"))
|
||||
insert_func=await Inbox_Messages.insert_email(session=self.session,email_data=data)
|
||||
insert_func=await Inbox_Messages.insert_email(session=self.session,email_data=data,file_path=re_create_file)
|
||||
return response.json()
|
||||
else:
|
||||
raise HTTPException(status_code=response.status_code,detail=response.text)
|
||||
|
|
@ -50,5 +50,11 @@ class Email:
|
|||
messages=await Inbox_Messages.get_inbox_messages(self.session,top,skip,search)
|
||||
return [serialize_message(m) for m in messages]
|
||||
|
||||
async def get_inbox_message_by_id(self,record_id):
|
||||
message=await Inbox_Messages.get_inbox_message_by_id(self.session,record_id)
|
||||
if not message:
|
||||
raise HTTPException(status_code=404,detail="Message not found")
|
||||
return serialize_message(message)
|
||||
|
||||
async def count_inbox_messages(self,search=None):
|
||||
return await Inbox_Messages.count_inbox_messages(self.session,search)
|
||||
|
|
|
|||
Loading…
Reference in New Issue