1.1 --- a/MoinShare.py Wed Jul 10 18:08:15 2013 +0200
1.2 +++ b/MoinShare.py Wed Jul 10 18:43:39 2013 +0200
1.3 @@ -11,6 +11,8 @@
1.4 from ContentTypeSupport import getContentPreferences
1.5 from DateSupport import getCurrentTime, getDateTimeFromRFC2822
1.6 from MoinSupport import *
1.7 +from MoinMessage import GPG, is_encrypted, is_signed
1.8 +from MoinMessageSupport import get_homedir
1.9 from MoinMoin.support.htmlmarkup import HTMLParseError, HTMLSanitizer, Markup
1.10 from MoinMoin import wikiutil
1.11 from email.parser import Parser
1.12 @@ -215,13 +217,13 @@
1.13 store = ItemStore(page, "messages", "message-locks")
1.14
1.15 for n, message_text in enumerate(iter(store)):
1.16 - update = getUpdateFromMessageText(message_text, n)
1.17 + update = getUpdateFromMessageText(message_text, n, request)
1.18 update.page = page
1.19 updates.append(update)
1.20
1.21 return updates
1.22
1.23 -def getUpdateFromMessageText(message_text, message_number):
1.24 +def getUpdateFromMessageText(message_text, message_number, request):
1.25
1.26 "Return an update for the given 'message_text' and 'message_number'."
1.27
1.28 @@ -235,10 +237,10 @@
1.29
1.30 update.message_number = message_number
1.31
1.32 - update.content, update.content_type, update.parts = getUpdateContentFromPart(message)
1.33 + update.content, update.content_type, update.parts = getUpdateContentFromPart(message, request)
1.34 return update
1.35
1.36 -def getUpdateContentFromPart(part):
1.37 +def getUpdateContentFromPart(part, request):
1.38
1.39 """
1.40 Return decoded content, the content type and any subparts in a tuple for a
1.41 @@ -264,13 +266,37 @@
1.42 # Encrypted content cannot be meaningfully separated.
1.43
1.44 elif part.get_content_subtype() == "encrypted":
1.45 - return part.as_string(), part.get_content_type(), None
1.46 + return getUpdateContentFromPart(getDecryptedParts(part, request), request)
1.47
1.48 # Otherwise, just obtain the parts for separate display.
1.49
1.50 else:
1.51 return None, part.get_content_type(), part.get_payload()
1.52
1.53 +def getDecryptedParts(part, request):
1.54 +
1.55 + "Decrypt the given 'part', returning the decoded content."
1.56 +
1.57 + homedir = get_homedir(request)
1.58 + gpg = GPG(homedir)
1.59 +
1.60 + # Decrypt the part.
1.61 +
1.62 + if is_encrypted(part):
1.63 + text = gpg.decryptMessage(part)
1.64 + part = Parser().parse(StringIO(text))
1.65 +
1.66 + # Extract any signature details.
1.67 + # NOTE: Incorporate the signature into the output.
1.68 +
1.69 + if is_signed(part):
1.70 + result = gpg.verifyMessage(part)
1.71 + if result:
1.72 + fingerprint, identity, content = result
1.73 + return content
1.74 +
1.75 + return part
1.76 +
1.77 def getPartContent(part):
1.78
1.79 "Decode the 'part', returning the decoded payload and the content type."
1.80 @@ -279,15 +305,15 @@
1.81 payload = part.get_payload(decode=True)
1.82 return (charset and unicode(payload, charset) or payload), part.get_content_type()
1.83
1.84 -def getUpdateFromPart(parent, part, part_number):
1.85 +def getUpdateFromPart(parent, part, part_number, request):
1.86
1.87 "Using the 'parent' update, return an update object for the given 'part'."
1.88
1.89 update = parent.copy(part_number)
1.90 - update.content, update.content_type, update.parts = getUpdateContentFromPart(part)
1.91 + update.content, update.content_type, update.parts = getUpdateContentFromPart(part, request)
1.92 return update
1.93
1.94 -def getUpdatesForFormatting(update):
1.95 +def getUpdatesForFormatting(update, request):
1.96
1.97 "Get a list of updates for formatting given 'update'."
1.98
1.99 @@ -297,8 +323,8 @@
1.100
1.101 if update.parts:
1.102 for n, part in enumerate(update.parts):
1.103 - update_part = getUpdateFromPart(update, part, n)
1.104 - updates += getUpdatesForFormatting(update_part)
1.105 + update_part = getUpdateFromPart(update, part, n, request)
1.106 + updates += getUpdatesForFormatting(update_part, request)
1.107 else:
1.108 updates.append(update)
1.109
1.110 @@ -340,7 +366,7 @@
1.111 result = []
1.112 append = result.append
1.113
1.114 - updates = getUpdatesForFormatting(update)
1.115 + updates = getUpdatesForFormatting(update, request)
1.116 single = len(updates) == 1
1.117
1.118 # Format some navigation tabs.