# HG changeset patch # User Paul Boddie # Date 1373474619 -7200 # Node ID 11fbdf6b2ff885283bfcd59c27fdb31cc45fce25 # Parent b05b1aa058dec1105e445b202b0081e9e58c6605 Added support for message decryption to MoinShare (making use of MoinMessage) instead of using an encrypted content parser on encrypted message parts. diff -r b05b1aa058de -r 11fbdf6b2ff8 MoinShare.py --- a/MoinShare.py Wed Jul 10 18:08:15 2013 +0200 +++ b/MoinShare.py Wed Jul 10 18:43:39 2013 +0200 @@ -11,6 +11,8 @@ from ContentTypeSupport import getContentPreferences from DateSupport import getCurrentTime, getDateTimeFromRFC2822 from MoinSupport import * +from MoinMessage import GPG, is_encrypted, is_signed +from MoinMessageSupport import get_homedir from MoinMoin.support.htmlmarkup import HTMLParseError, HTMLSanitizer, Markup from MoinMoin import wikiutil from email.parser import Parser @@ -215,13 +217,13 @@ store = ItemStore(page, "messages", "message-locks") for n, message_text in enumerate(iter(store)): - update = getUpdateFromMessageText(message_text, n) + update = getUpdateFromMessageText(message_text, n, request) update.page = page updates.append(update) return updates -def getUpdateFromMessageText(message_text, message_number): +def getUpdateFromMessageText(message_text, message_number, request): "Return an update for the given 'message_text' and 'message_number'." @@ -235,10 +237,10 @@ update.message_number = message_number - update.content, update.content_type, update.parts = getUpdateContentFromPart(message) + update.content, update.content_type, update.parts = getUpdateContentFromPart(message, request) return update -def getUpdateContentFromPart(part): +def getUpdateContentFromPart(part, request): """ Return decoded content, the content type and any subparts in a tuple for a @@ -264,13 +266,37 @@ # Encrypted content cannot be meaningfully separated. elif part.get_content_subtype() == "encrypted": - return part.as_string(), part.get_content_type(), None + return getUpdateContentFromPart(getDecryptedParts(part, request), request) # Otherwise, just obtain the parts for separate display. else: return None, part.get_content_type(), part.get_payload() +def getDecryptedParts(part, request): + + "Decrypt the given 'part', returning the decoded content." + + homedir = get_homedir(request) + gpg = GPG(homedir) + + # Decrypt the part. + + if is_encrypted(part): + text = gpg.decryptMessage(part) + part = Parser().parse(StringIO(text)) + + # Extract any signature details. + # NOTE: Incorporate the signature into the output. + + if is_signed(part): + result = gpg.verifyMessage(part) + if result: + fingerprint, identity, content = result + return content + + return part + def getPartContent(part): "Decode the 'part', returning the decoded payload and the content type." @@ -279,15 +305,15 @@ payload = part.get_payload(decode=True) return (charset and unicode(payload, charset) or payload), part.get_content_type() -def getUpdateFromPart(parent, part, part_number): +def getUpdateFromPart(parent, part, part_number, request): "Using the 'parent' update, return an update object for the given 'part'." update = parent.copy(part_number) - update.content, update.content_type, update.parts = getUpdateContentFromPart(part) + update.content, update.content_type, update.parts = getUpdateContentFromPart(part, request) return update -def getUpdatesForFormatting(update): +def getUpdatesForFormatting(update, request): "Get a list of updates for formatting given 'update'." @@ -297,8 +323,8 @@ if update.parts: for n, part in enumerate(update.parts): - update_part = getUpdateFromPart(update, part, n) - updates += getUpdatesForFormatting(update_part) + update_part = getUpdateFromPart(update, part, n, request) + updates += getUpdatesForFormatting(update_part, request) else: updates.append(update) @@ -340,7 +366,7 @@ result = [] append = result.append - updates = getUpdatesForFormatting(update) + updates = getUpdatesForFormatting(update, request) single = len(updates) == 1 # Format some navigation tabs. diff -r b05b1aa058de -r 11fbdf6b2ff8 PKG-INFO --- a/PKG-INFO Wed Jul 10 18:08:15 2013 +0200 +++ b/PKG-INFO Wed Jul 10 18:43:39 2013 +0200 @@ -12,7 +12,7 @@ Description: The MoinShare extension for MoinMoin provides mechanisms for sharing content with and between MoinMoin sites. Keywords: MoinMoin Wiki content sharing -Requires: MoinMoin MoinSupport +Requires: MoinMoin MoinSupport MoinMessage Classifier: Development Status :: 3 - Alpha Classifier: License :: OSI Approved :: GNU General Public License (GPL) Classifier: Programming Language :: Python