-
Notifications
You must be signed in to change notification settings - Fork 43
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 dkim client support #154
Conversation
I reopened the issue. fix #21 |
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.
Looks good overall. Thanks for doing this! I had a few changes for you then it should be good to merge.
setup.py
Outdated
@@ -33,6 +33,7 @@ | |||
namespace_packages=['slimta'], | |||
install_requires=['gevent >= 1.1rc', | |||
'pysasl >= 0.4.0', | |||
'dkimpy >= 0.9.0', |
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.
I'd like to keep this dependency as optional. A few things:
Please move this to an extras_require
parameter:
extras_require={'dkim': ['dkimpy >= 0.9.0']},
And then move your new policy class to its own module (maybe slimta.policy.dkimheader
). The test can stay put, just add dkimpy >= 0.9.0
as a new line in test/requirements.txt
.
slimta/policy/headers.py
Outdated
@@ -132,4 +135,61 @@ def apply(self, envelope): | |||
envelope.prepend_header('Received', data) | |||
|
|||
|
|||
class AddDkimHeader(QueuePolicy): |
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.
Please rename this to AddDKIMHeader
.
slimta/policy/headers.py
Outdated
self.logger = logging.getLogger(__name__) | ||
|
||
def apply(self, envelope): | ||
from dkim import dkim_sign, DKIMException |
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.
Once you separate this class into its own file, this import can go up to the top.
slimta/policy/headers.py
Outdated
**dict(sender=envelope.sender,domain=dom) ) | ||
return | ||
data = hd.replace(b'\r\n',b'').decode('utf-8').split(':',1)[1] | ||
envelope.prepend_header('DKIM-Signature', data) |
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.
This should be:
envelope.headers['DKIM-Signature'] = data
Prepending is typically only desired for the Received
header.
'signature_algorithm': 'rsa-sha1', | ||
'include_headers': ['from','subject'] } | ||
AddDkimHeader(dkim).apply(env) | ||
self.assertTrue(env.headers['DKIM-Signature']) |
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.
Can you add a few assertIn
checks for some of the expected tag=value pairs in the header?
2 points
|
It has to do with keeping the I do see your point, however, of organizing the files in a way that makes sense. How about this, move
Sorry about that, I hadn't looked at that yet, thanks for the link! You were correct to prepend. |
About PEP-8 I'd say it is exceedingly onerous to try to conform to it everywhere, especially for import. I have looked a bit and autopep8 do not try to fix non module level import, pep8 itself https://pep8.readthedocs.io/en/1.4.4/_modules/pep8.html do not even conform stricly, and python-slimta either: https://github.com/slimta/python-slimta/blob/master/slimta/queue/__init__.py putting the headers.py code in init.py is just hiding away the inconsistency - I will refrain to pursue my drawer metaphor here -. I think a better compromise is to just add after the headers import something along the lines of
I don't know if a 'pass' instruction is subjected to the honours of code quality control (I'll check it) And by the way, the import of dkimpy in the Apply method was a remnant of my first implementation, that was indeed setting dkimpy as an optional dependency. I just forgot to move it to the file beginning. |
I'd be happy with this pattern that I've seen often, e.g. in the Python codebase: try:
import dkim
except ImportError:
dkim = None # inside AddDKIMHeader.__init__()
if dkim is None:
raise ImportError('dkimpy is not installed') Raising the exception in the policy constructor should bring the error to attention during initialization rather than once an email goes through, so I'd place it there. |
Thanks, now I just have to do the rest of the job :-) |
err, hello again. |
Related to closed issue #21