Changeable mail encryption, fix recursion limit

This commit is contained in:
octo@swiss 2022-11-07 17:33:38 +01:00
parent 191d49845f
commit d620cdc4f2
2 changed files with 19 additions and 7 deletions

View File

@ -11,10 +11,11 @@ Feeds = [
]
# SMTP configuration (only required for sending mail).
MailUsername = "example@example.com"
MailUsername = "example@example.com" # Your full email address.
MailPassword = "Example"
MailServer = "smtp.example.com"
MailPort = 465
MailPort = 465 # (Usually) 465 for SSL, 587 for TLS, 25 for No encryption.
MailEncryption = "SSL" # SSL, TLS, or None.
# How often to refresh the feeds (in seconds). Set to 0 for a single run, instead of having the program sleep.
LoopTime = 300

View File

@ -55,9 +55,9 @@ def HandleFeed(URLs, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo
LastEntryIsNew, PageOlder = HandleURL(True, URL, Usertag, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo)
if LastEntryIsNew and PageOlder:
Pages += [PageOlder]
while LastEntryIsNew and PageOlder and len(Pages) < MaxPagesRecursion:
while LastEntryIsNew and PageOlder and (MaxPagesRecursion <= 0 or len(Pages) < MaxPagesRecursion):
LastEntryIsNew, PageOlder = HandleURL(True, PageOlder, Usertag, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo)
if LastEntryIsNew and PageOlder and MaxPagesRecursion:
if LastEntryIsNew and PageOlder:
Pages += [PageOlder]
Pages.reverse()
for Page in Pages:
@ -171,9 +171,20 @@ def HandleURL(IsFirstRun, URL, Usertag, IncludeRetoots, IncludeReplies, LocalSav
.replace('{ Replace:MastodonFeedHTML:MediaDescs }', MakeMediaDescsBlock(MediaDescs)), 'html'))
for File in MailAttach:
Message.attach(File)
with smtplib.SMTP_SSL(MailServer, MailPort, context=ssl.create_default_context()) as Client:
Client.login(MailUsername, MailPassword)
Client.sendmail(MailUsername, MailTo, Message.as_string())
if MailEncryption.lower() == 'ssl':
Mailer = smtplib.SMTP_SSL(MailServer, MailPort, context=ssl.create_default_context())
elif MailEncryption.lower() in ('tls', 'none'):
Mailer = smtplib.SMTP(MailServer, MailPort)
if MailEncryption.lower() == 'tls':
Mailer.starttls(context=ssl.create_default_context())
else:
print("[E] MailEncryption variable is set incorrectly. Cannot continue. Please check your config.")
exit(1)
Mailer.login(MailUsername, MailPassword)
Mailer.sendmail(MailUsername, MailTo, Message.as_string())
Mailer.quit()
SleepPrint(MailSleep)
if LocalSave: