Skip to content

Commit b4dfb86

Browse files
author
KHALID SAHIH
committed
[FIX] mail_server_manager: Use simple % formatting for translations
- Fix W8302: use %s with simple % instead of .format() - Revert to simple positional placeholders
1 parent 971250e commit b4dfb86

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

mail_server_manager/models/mail_account.py

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,18 @@ def _check_email_format(self):
143143
if not self._EMAIL_REGEX.match(record.email):
144144
raise ValidationError(
145145
self.env._(
146-
"Invalid email address format: '%(email)s'.\n\n"
146+
"Invalid email address format: '%s'.\n\n"
147147
"Only alphanumeric characters, dots, underscores, hyphens, "
148148
"and plus signs are allowed."
149-
).format(email=record.email)
149+
)
150+
% record.email
150151
)
151152

152153
# Validate using Odoo's email_normalize
153154
normalized = email_normalize(record.email)
154155
if not normalized:
155156
raise ValidationError(
156-
self.env._("Invalid email address: '%(email)s'.").format(
157+
self.env._("Invalid email address: '%s'.").format(
157158
email=record.email
158159
)
159160
)
@@ -162,16 +163,13 @@ def _check_email_format(self):
162163
local_part, domain = record.email.split("@")
163164
if not local_part or not domain:
164165
raise ValidationError(
165-
self.env._(
166-
"Invalid email address: '%(email)s'. Missing username.."
167-
).format(email=record.email)
166+
self.env._("Invalid email address: '%s'. Missing username..")
167+
% record.email
168168
)
169169

170170
if "." not in domain:
171171
raise ValidationError(
172-
self.env._(
173-
"Invalid domain: '%(domain)s'. Must contain a dot."
174-
).format(domain=domain)
172+
self.env._("Invalid domain: '%s'. Must contain a dot.") % domain
175173
)
176174

177175
# Note: _get_mail_domain, _get_mail_config_path, _get_smtp_host,
@@ -245,9 +243,8 @@ def _write_to_accounts_file(self, email, password_hash, action="add"):
245243
existing = f.read()
246244
if email in existing:
247245
raise UserError(
248-
self.env._(
249-
"Email address %(email)s already exists."
250-
).format(email=email)
246+
self.env._("Email address %(email)s already exists.")
247+
% email
251248
)
252249
# Append by rewriting atomically
253250
self._atomic_write(accounts_file, existing + line)
@@ -527,7 +524,7 @@ def _delete_email_alias(self):
527524
if not line.startswith(f"{self.email} "):
528525
f.write(line)
529526

530-
_logger.info("Deleted email alias for: %(emails)s", self.email)
527+
_logger.info("Deleted email alias for: %s", self.email)
531528
except Exception as e:
532529
_logger.warning("Error deleting email alias: %s", e)
533530

@@ -549,7 +546,7 @@ def _delete_email_alias_by_email(self, email):
549546
if not line.startswith(f"{email} "):
550547
f.write(line)
551548

552-
_logger.info("Deleted email alias for: %(emails)s", email)
549+
_logger.info("Deleted email alias for: %s", email)
553550
except Exception as e:
554551
_logger.warning("Error deleting email alias for %s: %s", email, e)
555552

@@ -644,9 +641,8 @@ def create(self, vals_list):
644641

645642
record.state = "error"
646643
raise UserError(
647-
self.env._(
648-
"Failed to create mail account '%(email)s': %(error)s"
649-
).format(email=record.email, error=str(e))
644+
self.env._("Failed to create mail account '%s': %(error)s")
645+
% (record.email, str(e))
650646
) from e
651647

652648
# Q35: Send reminder notification for IMAP server confirmation
@@ -666,7 +662,7 @@ def create(self, vals_list):
666662
"message": self.env._(
667663
"Please confirm IMAP server(s) in "
668664
"Settings → Technical → Incoming Mail Servers "
669-
"for: %(emails)s"
665+
"for: %s"
670666
)
671667
% {
672668
"emails": ", ".join(
@@ -715,7 +711,7 @@ def unlink(self):
715711
try:
716712
smtp_servers_to_delete.sudo().unlink()
717713
_logger.info(
718-
"Batch deleted %(count)d SMTP servers", len(smtp_servers_to_delete)
714+
"Batch deleted %d SMTP servers", len(smtp_servers_to_delete)
719715
)
720716
except Exception as e:
721717
_logger.warning("Failed to batch delete SMTP servers: %s", e)
@@ -826,9 +822,7 @@ def action_sync_from_server(self):
826822
"tag": "display_notification",
827823
"params": {
828824
"title": self.env._("Sync Completed"),
829-
"message": self.env._("%(count)d new accounts imported.").format(
830-
count=synced
831-
),
825+
"message": self.env._("%d new accounts imported.").format(count=synced),
832826
"type": "success",
833827
},
834828
}
@@ -910,9 +904,8 @@ def action_recover_from_error(self):
910904
except Exception as e:
911905
_logger.exception("Failed to recover mail account %s", record.email)
912906
raise UserError(
913-
self.env._(
914-
"Failed to recover mail account '%(email)s': %(error)s"
915-
).format(email=record.email, error=str(e))
907+
self.env._("Failed to recover mail account '%s': %(error)s")
908+
% (record.email, str(e))
916909
) from e
917910

918911
return {
@@ -947,7 +940,7 @@ def action_fix_smtp_owner(self):
947940
)
948941
fixed_count += 1
949942
_logger.info(
950-
"Fixed SMTP server for: %(emails)s (filter: %s)",
943+
"Fixed SMTP server for: %s (filter: %s)",
951944
record.email,
952945
from_filter,
953946
)
@@ -958,8 +951,9 @@ def action_fix_smtp_owner(self):
958951
"params": {
959952
"title": self.env._("SMTP Servers Fixed"),
960953
"message": self.env._(
961-
"%(count)d SMTP server(s) updated with correct from_filter."
962-
).format(count=fixed_count),
954+
"%d SMTP server(s) updated with correct from_filter."
955+
)
956+
% fixed_count,
963957
"type": "success",
964958
},
965959
}
@@ -987,7 +981,7 @@ def action_fix_all_smtp_owners(self):
987981
)
988982
fixed_count += 1
989983
_logger.info(
990-
"Batch fixed SMTP server for: %(emails)s (filter: %s)",
984+
"Batch fixed SMTP server for: %s (filter: %s)",
991985
account.email,
992986
from_filter,
993987
)
@@ -998,8 +992,9 @@ def action_fix_all_smtp_owners(self):
998992
"params": {
999993
"title": self.env._("Batch Fix Complete"),
1000994
"message": self.env._(
1001-
"%(count)d SMTP server(s) fixed with correct from_filter."
1002-
).format(count=fixed_count),
995+
"%d SMTP server(s) fixed with correct from_filter."
996+
)
997+
% fixed_count,
1003998
"type": "success",
1004999
},
10051000
}

mail_server_manager/models/mail_mail.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ def _check_email_limit(self, mail_account):
136136
if mail_account.emails_sent_today >= limit:
137137
raise UserError(
138138
self.env._(
139-
"Daily email limit reached (%(limit)s emails). "
139+
"Daily email limit reached (%s emails). "
140140
"Please try again tomorrow or contact your administrator."
141-
).format(limit=limit)
141+
)
142+
% limit
142143
)
143144

144145
return True

0 commit comments

Comments
 (0)