Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
4
fetchmail_attach_from_folder/match_algorithm/__init__.py
Executable file
4
fetchmail_attach_from_folder/match_algorithm/__init__.py
Executable file
@@ -0,0 +1,4 @@
|
||||
# Copyright - 2013-2024 Therp BV <https://therp.nl>.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from . import email_exact
|
||||
from . import email_domain
|
||||
29
fetchmail_attach_from_folder/match_algorithm/email_domain.py
Executable file
29
fetchmail_attach_from_folder/match_algorithm/email_domain.py
Executable file
@@ -0,0 +1,29 @@
|
||||
# Copyright - 2013-2024 Therp BV <https://therp.nl>.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from .email_exact import EmailExact
|
||||
|
||||
|
||||
class EmailDomain(EmailExact):
|
||||
"""Search objects by domain name of email address.
|
||||
|
||||
Beware of match_first here, this is most likely to get it wrong (gmail).
|
||||
"""
|
||||
|
||||
def search_matches(self, folder, message_dict):
|
||||
"""Returns recordset of matching objects."""
|
||||
matches = super().search_matches(folder, message_dict)
|
||||
if not matches:
|
||||
object_model = folder.env[folder.model_id.model]
|
||||
domains = []
|
||||
for addr in self._get_mailaddresses(folder, message_dict):
|
||||
domains.append(addr.split("@")[-1])
|
||||
matches = object_model.search(
|
||||
self._get_mailaddress_search_domain(
|
||||
folder,
|
||||
message_dict,
|
||||
operator="like",
|
||||
values=["%@" + domain for domain in set(domains)],
|
||||
),
|
||||
order=folder.model_order,
|
||||
)
|
||||
return matches
|
||||
35
fetchmail_attach_from_folder/match_algorithm/email_exact.py
Executable file
35
fetchmail_attach_from_folder/match_algorithm/email_exact.py
Executable file
@@ -0,0 +1,35 @@
|
||||
# Copyright - 2013-2024 Therp BV <https://therp.nl>.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo.tools.mail import email_split
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class EmailExact:
|
||||
"""Search for exactly the mailadress as noted in the email"""
|
||||
|
||||
def _get_mailaddresses(self, folder, message_dict):
|
||||
mailaddresses = []
|
||||
fields = folder.mail_field.split(",")
|
||||
for field in fields:
|
||||
if field in message_dict:
|
||||
mailaddresses += email_split(message_dict[field])
|
||||
return [addr.lower() for addr in mailaddresses]
|
||||
|
||||
def _get_mailaddress_search_domain(
|
||||
self, folder, message_dict, operator="=", values=None
|
||||
):
|
||||
mailaddresses = values or self._get_mailaddresses(folder, message_dict)
|
||||
if not mailaddresses:
|
||||
return [(0, "=", 1)]
|
||||
search_domain = (
|
||||
(["|"] * (len(mailaddresses) - 1))
|
||||
+ [(folder.model_field, operator, addr) for addr in mailaddresses]
|
||||
+ safe_eval(folder.domain or "[]")
|
||||
)
|
||||
return search_domain
|
||||
|
||||
def search_matches(self, folder, message_dict):
|
||||
"""Returns recordset of matching objects."""
|
||||
object_model = folder.env[folder.model_id.model]
|
||||
search_domain = self._get_mailaddress_search_domain(folder, message_dict)
|
||||
return object_model.search(search_domain, order=folder.model_order)
|
||||
Reference in New Issue
Block a user