This commit is contained in:
Kovid Goyal 2025-05-12 04:24:55 +05:30
parent 43912e02bc
commit ef9b5a1950
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 5 additions and 9 deletions

View File

@ -170,12 +170,8 @@ def send_mails(jobnames, callback, attachments, to_s, subjects,
# file internal metadata so don't nuke the filename.
# https://www.mobileread.com/forums/showthread.php?t=349290
aname = f'{uuid4()}.' + aname.rpartition('.')[-1]
import random
from calibre.utils.random_ua import common_english_words, random_english_text
words = common_english_words()
num_in_subject = random.randrange(3, 9)
subject = ' '.join(random.choice(words) for i in range(num_in_subject))
from calibre.utils.random_ua import random_english_text
subject = random_english_text(min_words_per_sentence=3, max_words_per_sentence=9, max_num_sentences=1).rstrip('.')
text = random_english_text()
job = ThreadedJob('email', description, gui_sendmail, (attachment, aname, to,
subject, text), {}, callback)

View File

@ -23,13 +23,13 @@ def common_english_words():
return ans
def random_english_text():
def random_english_text(max_num_sentences=3, min_words_per_sentence=8, max_words_per_sentence=41):
import random
num_sentences = random.randrange(1, 4)
num_sentences = random.randrange(1, max_num_sentences+1)
words = common_english_words()
def sentence():
num_words = random.randrange(23, 42)
num_words = random.randrange(min_words_per_sentence, max_words_per_sentence+1)
return ' '.join(random.choice(words) for i in range(num_words)).capitalize() + '.'
return ' '.join(sentence() for i in range(num_sentences))