Skip to content
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

Saving generated emails locally #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

mborger
Copy link

@mborger mborger commented Feb 5, 2016

Added an option to save the generated emails locally instead of sending through an SMTP server. This is useful if you're signing keys from an air gapped machine.

@jaymzh
Copy link
Owner

jaymzh commented Feb 5, 2016

You then just hand these to postfix or sendmail or whatever?

I'd been asked for a similar feature, but had been planning it differently - write out the signatures and some metadata, and then have another option to slurp that in and send them off...

I'm not entirely sure which I like better.

Your approach is definitely simpler and less code. Less to keep track of, less to refactor. The downside is that it requires more know-how on the part of the user to then send those messages off... for example, at the very least you have to have a mailserver configured to send properly - which many don't (which is why pius can speak to remote mailservers directly with auth).

Let me ponder it it for a bit. I'll get back to you. :)

@mborger
Copy link
Author

mborger commented Feb 5, 2016

Yup, I transferred the emails to my mail server and handed each of them off to sendmail.
for f in $(ls); do sendmail -t < $f; done
The -t option just tells sendmail to use the header fields for the recipient and sender information instead of specifying them on the commandline.

I see your point that a fair number of people don't have an MTA setup for this to work. If you don't want to add another mode to Pius for just sending the generated emails, perhaps we can get mailx to send the emails in a fashion similar to sendmail. This is what I have so far but it doesn't seem to be pulling the recipients out of the email metadata like sendmail does.
mailx -t -S smtp="mail.example.com:25" -S smtp-auth=login -S smtp-auth-user="[email protected]" -S smtp-auth-password="password" < emailFile

# must re-ehlo after STARTTLS
smtp.ehlo()
# Don't want to send auth information unless we're TLS'd
if self.user:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I think about this approach the more I like it.

However... how do we handle the email_override and the BCC-the-user bit here?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the extremely late reply. I think these options can be handled by moving their logic to the beginning of the add_options method. Then they will be printed out to the email file or passed to sendmail.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you aren't actually writing it to the file... env_to isn't in the object you write out.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, keeping py2 compat for now. BUt also as mentioned I think we should only add that Bcc header to the message when we're saving it as a proxy for a proper envelope header.

@jaymzh
Copy link
Owner

jaymzh commented Jan 14, 2018

@mborger - you still interested in finishing this?

@mborger
Copy link
Author

mborger commented Jan 16, 2018

Sure. What's next on your mind to look into?

@jaymzh
Copy link
Owner

jaymzh commented Jan 16, 2018

I think all that's left is:

  • Documentation on how to hand this to an MTA
  • the ability to handle email_override and the BCC-the-user options
  • rebase on current master

And then we're good.

@mborger mborger force-pushed the localMail branch 2 times, most recently from df7299c to fb7b273 Compare January 17, 2018 06:30
@mborger
Copy link
Author

mborger commented Jan 17, 2018

Check out my changes. I combined the two address override conditionals to the beginning of the _send_mail method.

if not os.path.isdir(self.local_mail_dir):
os.mkdir(self.local_mail_dir)
email = open(os.path.join(self.local_mail_dir, msg['To']), 'w')
email.write(str(msg))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the env_to isn't being written here...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch but this opens another question. Do we need the copy to yourself to be blind? There is no standard for a BCC header within an email that a sender is supposed to strip before the SMTP submission. We could look into finding a client that does that or add another command to pius to handle sending these emails. If we don't really need the self copy to be blind then we can just add the extra To header to the message and mail senders should send it to both addresses.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, sendmail's -t does this. It reads all address headers from the message (to,cc,bcc), acts on them and strips out BCC from the message.

I just tried postfix'q sendmail compat mode, and it also does this.

So... that's probably sufficient.

I would say that if the mailqueue mode is activated, take any env_tos that are not in the standard to and add them as Bcc in the message.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a Bcc header and included a helper function to generate the to_addrs parameter of the send_mail method. Newer versions of python have a send_message method which will extract the headers from the message. I included it with some comments but I think you're still trying to support Python2.

doc/pius.1 Outdated
@@ -47,6 +47,8 @@ Hostname of SMTP server. [default: \fIlocalhost\fP]
Use the pexpect module for signing and drop to the gpg shell for entering the passphrase. [default: false]
.IP "\fB\-I\fP, \fB\-\-import\fP"
Also import the unsigned keys from the keyring into the default keyring. Ignored if \fB\-r\fP is not specified, or if it's the same as the default keyring.
.IP "\fB\-L\fP, \fB\-\-local\-mail\-dir\fP"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably call this --save-to-mail-dir or something

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to --save-to-mail-dir

if not os.path.isdir(self.local_mail_dir):
os.mkdir(self.local_mail_dir)
email = open(os.path.join(self.local_mail_dir, msg['To']), 'w')
email.write(str(msg))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, sendmail's -t does this. It reads all address headers from the message (to,cc,bcc), acts on them and strips out BCC from the message.

I just tried postfix'q sendmail compat mode, and it also does this.

So... that's probably sufficient.

I would say that if the mailqueue mode is activated, take any env_tos that are not in the standard to and add them as Bcc in the message.

else:
msg['To'] = to
env_to = [to, self.mail]
msg['BCC'] = self.mail
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should be Bcc

@@ -256,38 +258,50 @@ def _send_mail(self, to, msg):
msg['To'] = self.address_override
else:
msg['To'] = to
msg['Bcc'] = self.mail
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should only do this in the case of self.local_mail_dir

@mborger mborger force-pushed the localMail branch 2 times, most recently from e2562c9 to 6987bca Compare January 24, 2018 05:46
@jaymzh
Copy link
Owner

jaymzh commented Jan 28, 2018

@mborger - This code looks great! Thanks for working through the long review process on this one. The only thing left before merging is some docs. Probably a simple command people can run to send off all the emails, in the help for -L is sufficient, but I"m also open to a separate doc explaining the use-case.

to a given folder instead of sending via SMTP.
@jaymzh
Copy link
Owner

jaymzh commented Mar 19, 2018

Hey @mborger - wanna rebase and add some simple comments to the README on this and I can merge it?

@jaymzh
Copy link
Owner

jaymzh commented Mar 24, 2018

@mborger ?

@jaymzh jaymzh added the waitingonsubmitter Waiting on the sbumitter label Sep 21, 2018
@jaymzh jaymzh self-assigned this Sep 21, 2018
@abrahamcuenca
Copy link

Looks like this PR grew a bit stale. Should it be closed?

@jaymzh
Copy link
Owner

jaymzh commented Mar 9, 2020

one last call, @mborger ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waitingonsubmitter Waiting on the sbumitter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants