-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to save generated emails #92
Open
cbrownstein
wants to merge
7
commits into
jaymzh:main
Choose a base branch
from
cbrownstein:localMail
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
14dcc42
Added option to save generated emails
ea8af92
Delete redundant import
cbrownstein 5f03ccb
Fix typo
cbrownstein ed1bff1
Fix permissions
cbrownstein 3a76309
Add back deleted lines
cbrownstein 6e63ff5
Fix indentation
cbrownstein d3d6beb
Use more descriptive metavar
cbrownstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
|
||
class PiusMailer(object): | ||
def __init__(self, mail, display_name, host, port, user, tls, no_mime, | ||
override, msg_text, tmp_dir): | ||
override, msg_text, tmp_dir, local_mail_dir): | ||
self.mail = mail | ||
self.display_name = display_name | ||
self.host = host | ||
|
@@ -33,6 +33,7 @@ def __init__(self, mail, display_name, host, port, user, tls, no_mime, | |
self.address_override = override | ||
self.message_text = msg_text | ||
self.tmp_dir = tmp_dir | ||
self.local_mail_dir = local_mail_dir | ||
|
||
@staticmethod | ||
def add_options(parser): | ||
|
@@ -258,40 +259,51 @@ def _send_mail(self, to, msg): | |
msg['From'] = self.mail | ||
if self.address_override: | ||
msg['To'] = self.address_override | ||
env_to = [msg['To']] | ||
else: | ||
msg['To'] = to | ||
env_to = [msg['To'], self.mail] | ||
msg['Date'] = formatdate(localtime=True) | ||
|
||
try: | ||
smtp = smtplib.SMTP(self.host, self.port) | ||
if self.tls: | ||
# NOTE WELL: SECURITY IMPORTANT NOTE! | ||
# In python 2.6 if you attempt to starttls() and the server doesn't | ||
# understand an exception is raised. However before that, it just | ||
# carried on and one could attempt to auth over a plain-text session. | ||
# This is BAD! | ||
# | ||
# So, in order be secure on older pythons we ehlo() and then check the | ||
# response before attempting startls. | ||
smtp.ehlo() | ||
if not smtp.has_extn('STARTTLS'): | ||
# Emulate 2.6 behavior | ||
raise smtplib.SMTPException('Server does not support STARTTLS') | ||
smtp.starttls() | ||
# must re-ehlo after STARTTLS | ||
smtp.ehlo() | ||
# Don't want to send auth information unless we're TLS'd | ||
if self.user: | ||
smtp.login(self.user, self.password) | ||
if self.address_override: | ||
env_to = self.address_override | ||
else: | ||
# BCC the user... | ||
env_to = [msg['To'], self.mail] | ||
|
||
smtp.sendmail(self.mail, env_to, msg.as_string()) | ||
smtp.quit() | ||
except smtplib.SMTPException as emsg: | ||
raise MailSendError(emsg) | ||
except socket.error as emsg: | ||
raise MailSendError(emsg) | ||
if self.local_mail_dir: | ||
if not os.path.isdir(self.local_mail_dir): | ||
os.mkdir(self.local_mail_dir) | ||
if not self.address_override: | ||
msg['Bcc'] = self.mail | ||
email = open(os.path.join(self.local_mail_dir, msg['To']), 'w') | ||
email.write(str(msg)) | ||
email.close() | ||
else: | ||
try: | ||
smtp = smtplib.SMTP(self.host, self.port) | ||
if self.tls: | ||
# NOTE WELL: SECURITY IMPORTANT NOTE! | ||
# In python 2.6 if you attempt to starttls() and the server doesn't | ||
# understand an exception is raised. However before that, it just | ||
# carried on # and one could attempt to auth over a plain-text session. | ||
# This is BAD! | ||
# | ||
# So, in order be secure on older pythons we ehlo() and then check the | ||
# response before attempting startls. | ||
smtp.ehlo() | ||
if not smtp.has_extn('STARTTLS'): | ||
# Emulate 2.6 behavior | ||
raise smtplib.SMTPException('Server does not support STARTTLS') | ||
smtp.starttls() | ||
# must re-ehlo after STARTTLS | ||
smtp.ehlo() | ||
# Don't want to send auth information unless we're TLS'd | ||
if self.user: | ||
smtp.login(self.user, self.password) | ||
if self.address_override: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is no longer needed, you do it above. |
||
env_to = self.address_override | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
# BCC the user... | ||
env_to = [msg['To'], self.mail] | ||
|
||
smtp.sendmail(self.mail, env_to, msg.as_string()) | ||
smtp.quit() | ||
except smtplib.SMTPException as emsg: | ||
raise MailSendError(emsg) | ||
except socket.error as emsg: | ||
raise MailSendError(emsg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.