Add method to determine if a DKIM signature is present
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
dkimpy |
Fix Released
|
Wishlist
|
Scott Kitterman |
Bug Description
I wish to use dkimpy to verify the authenticity of some emails, however not all of them have a DKIM check present in the header. I want to be able to differentiate between an invalid DKIM signature and no signature present.
I've looked at the source code for the verify() function (The one on line 848 of __init__.py) and it seems the first return is only triggered when no DKIM signature is present.
I've modified this function locally for my own purposes and it works great, but I was wondering if a "dkim.present()" feature could be added to the official dkimpy module so it becomes standard. I imagine it would have similar parameters to the verify() function, but it would just return "len([(x,y) for x,y in self.headers if x.lower() == b"dkim-signature"]) == 0" instead.
I've never made a patch before and I am rather new to Python so I'm not sure how that works, but this is what the new function would look like
#: Checks if any DKIM signature is present
#: @return: True if there is one or more DKIM signatures present or False otherwise
def present(self):
return (len([(x,y)] for x,y in self.headers if x.lower() == b"dkim-signature"]) > 0)
This function is a part of the dkim class (I put it just above the verify function. For reference here is how I call it:
message = *INSERT MESSAGE HERE*
d = dkim.DKIM(message)
present = d.present()
verify = d.verify()
I did have issues when trying to do "present = dkim.present(
Changed in dkimpy: | |
assignee: | nobody → Scott Kitterman (kitterman) |
importance: | Undecided → Wishlist |
milestone: | none → 1.0.0 |
status: | New → Triaged |
This will be in the next release.
- Add new DKIM.present function to allow applications to test if a DKIM
signature is present without doing validation (LP: #1851141)