Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions dms/models/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,9 @@ def _process_message(self, msg_dict, extra_values=False):
"directory_id": self.id,
"name": uname,
}
try:
vals["content"] = base64.b64encode(attachment.content)
except Exception:
vals["content"] = attachment.content
if isinstance(contents_raw := attachment.content, str):
contents_raw = contents_raw.encode()
vals["content"] = base64.b64encode(contents_raw)
self.env["dms.file"].sudo().create(vals)
names.append(uname)

Expand Down
9 changes: 5 additions & 4 deletions dms/tests/test_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2021-2022 Tecnativa - Víctor Martínez
# Copyright 2024 Subteno - Timothée Vannier (https://www.subteno.com).
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import base64
import os

from odoo import Command
Expand Down Expand Up @@ -300,13 +300,14 @@ def setUpClass(cls):
@mute_logger("odoo.addons.mail.mail_thread")
def test_mail_alias_files(self):
self.directory.write({"alias_process": "files", "alias_name": "directory+test"})
self._handle_mail_reception()

def _handle_mail_reception(self):
with open(os.path.join(_path, "tests", "data", "mail01.eml")) as file:
self.env["mail.thread"].message_process(None, file.read())
with open(os.path.join(_path, "tests", "data", "mail02.eml")) as file:
self.env["mail.thread"].message_process(None, file.read())
# Check file created from mail02.eml further, ensure we can decode b64 contents.
dms_file = self.env["dms.file"].search([], limit=1, order="id desc")
self.assertEqual(dms_file.name, "bookmarks-really-short.html")
self.assertNotEqual(base64.b64decode(dms_file.content), dms_file.content)

@mute_logger("odoo.addons.mail.mail_thread")
def test_mail_alias_directory(self):
Expand Down
Loading