update: recipient name check

This commit is contained in:
2025-07-22 15:45:35 +08:00
parent 833dcc493c
commit 655ceea5b5

View File

@@ -121,7 +121,7 @@ def main():
def contains_non_latin_alphabet(string: str):
for char in string:
if unicodedata.category(char).startswith('L') and not unicodedata.name(char, '').startswith('LATIN'):
if char.isdigit() or (unicodedata.category(char).startswith('L') and not unicodedata.name(char, '').startswith('LATIN')):
return True
return False
@@ -228,11 +228,12 @@ def main():
wrapper = locate("div.io-ox-mail-compose-window div[data-extension-id='to'] > div.mail-input")
to = locate("input.token-input.tt-input[tabindex='0']", parent=wrapper)
if name is not None and (string := str(name).strip()) and not contains_non_latin_alphabet(string):
if name is not None and (name := str(name).strip().title()) and not contains_non_latin_alphabet(name):
# 填入客户称呼
firstname = string.split()[0].title()
parts = name.split()
firstname = parts[0] if len(parts) == 1 or (len(parts[0]) > 3 and '.' not in parts[0]) else " ".join([parts[0], parts[1]])
action = ActionChains(driver).send_keys(Keys.END)
for attempt in range(args.retry): action.perform()
for attempt in range(len(firstname)): action.perform()
ActionChains(driver, 5000).key_down(Keys.SHIFT).send_keys(Keys.LEFT).key_up(Keys.SHIFT).key_down(Keys.CONTROL).send_keys('x').key_up(Keys.CONTROL).perform()
ActionChains(driver, 5000).send_keys(Keys.SPACE).send_keys(firstname).key_down(Keys.CONTROL).send_keys('v').key_up(Keys.CONTROL).perform()