# HG changeset patch # User Paul Boddie # Date 1384353874 -3600 # Node ID 254ce4ba34062a9a5acb586f20313a60f80c98e5 # Parent b98c498cdfbc217b8c050b927440e5bfc12f3f6f Exposed author information on received messages, originating either from the authenticated user that posted the message or from any signature found within encrypted message parts. diff -r b98c498cdfbc -r 254ce4ba3406 MoinShare.py --- a/MoinShare.py Tue Nov 12 23:07:50 2013 +0100 +++ b/MoinShare.py Wed Nov 13 15:44:34 2013 +0100 @@ -13,7 +13,7 @@ from MoinSupport import * from ItemSupport import ItemStore from MoinMessage import GPG, is_encrypted, is_signed, MoinMessageError -from MoinMessageSupport import get_homedir +from MoinMessageSupport import get_homedir, get_username_for_fingerprint from MoinMoin.support.htmlmarkup import HTMLParseError, HTMLSanitizer, Markup from MoinMoin import wikiutil from email.parser import Parser @@ -92,6 +92,7 @@ self.content = None self.content_type = None self.updated = None + self.author = None # Page-related attributes. @@ -127,6 +128,7 @@ update.title = self.title update.link = self.link update.updated = self.updated + update.author = self.author update.fragment = self.fragment update.preferred = self.preferred update.message_number = self.message_number @@ -235,17 +237,23 @@ update.fragment = update.updated = getDateTimeFromRFC2822(message.get("date")) update.title = message.get("subject", "Update #%d" % message_number) + update.author = message.get("moin-user") update.message_number = message_number - update.content, update.content_type, update.parts = getUpdateContentFromPart(message, request) + update.content, update.content_type, update.parts, actual_author = \ + getUpdateContentFromPart(message, request) + + if actual_author: + update.author = actual_author + return update def getUpdateContentFromPart(part, request): """ - Return decoded content, the content type and any subparts in a tuple for a - given 'part'. + Return decoded content, the content type, any subparts, and any author + identity in a tuple for a given 'part'. """ # Determine whether the part has several representations. @@ -254,7 +262,7 @@ if not part.is_multipart(): content, content_type = getPartContent(part) - return content, content_type, None + return content, content_type, None, None # For a collection of related parts, use the first as the update content # and assume that the formatter will reference the other parts. @@ -262,21 +270,22 @@ elif part.get_content_subtype() == "related": main_part = part.get_payload()[0] content, content_type = getPartContent(main_part) - return content, content_type, [main_part] + return content, content_type, [main_part], None # Encrypted content cannot be meaningfully separated. elif part.get_content_subtype() == "encrypted": try: - part = getDecryptedParts(part, request) - return getUpdateContentFromPart(part, request) + part, author = getDecryptedParts(part, request) + content, content_type, parts, _author = getUpdateContentFromPart(part, request) + return content, content_type, parts, author except MoinMessageError: - return None, part.get_content_type(), part.get_payload() + return None, part.get_content_type(), part.get_payload(), None # Otherwise, just obtain the parts for separate display. else: - return None, part.get_content_type(), part.get_payload() + return None, part.get_content_type(), part.get_payload(), None def getDecryptedParts(part, request): @@ -292,15 +301,14 @@ 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 content, get_username_for_fingerprint(request, fingerprint) - return part + return part, None def getPartContent(part): diff -r b98c498cdfbc -r 254ce4ba3406 css/moinshare.css --- a/css/moinshare.css Tue Nov 12 23:07:50 2013 +0100 +++ b/css/moinshare.css Wed Nov 13 15:44:34 2013 +0100 @@ -17,6 +17,7 @@ position: relative; } +div.moinshare-author, div.moinshare-date { margin: 0.5em; text-align: right; diff -r b98c498cdfbc -r 254ce4ba3406 macros/SharedContent.py --- a/macros/SharedContent.py Tue Nov 12 23:07:50 2013 +0100 +++ b/macros/SharedContent.py Wed Nov 13 15:44:34 2013 +0100 @@ -331,6 +331,11 @@ if show_content: append(fmt.div(on=1, css_class="moinshare-update")) + if update.author: + append(fmt.div(on=1, css_class="moinshare-author")) + append(fmt.text(update.author)) + append(fmt.div(on=0)) + append(formatUpdate(update, request, fmt)) append(fmt.div(on=1, css_class="moinshare-date"))