# HG changeset patch # User Paul Boddie # Date 1391296545 -3600 # Node ID 8e31bbf1fcf1d464a7a991db57abe12bc42c38a2 # Parent e33539cc607c0ada87c1173b1d523623f0b5e650 Moved conditional signing logic into a separate function. Added a utility function to get the relaying user. Tidied up the "too old" message rejection response to use formatted times. diff -r e33539cc607c -r 8e31bbf1fcf1 MoinMessageSupport.py --- a/MoinMessageSupport.py Sat Feb 01 01:17:27 2014 +0100 +++ b/MoinMessageSupport.py Sun Feb 02 00:15:45 2014 +0100 @@ -119,7 +119,7 @@ # Get the relaying user page and select it. - relaying_user = getattr(self.request.cfg, "moinmessage_gpg_relaying_user") + relaying_user = get_relaying_user(request) relaying_page = relaying_user and get_local_homepage(request, relaying_user) if not relaying_page: @@ -127,15 +127,11 @@ request.write("This site is not able to forward the message to the recipient.") return + # Stored messages should then be processed asynchronously. + self.page = Page(request, relaying_page) new_user = relaying_user - # The stored messages should then be processed - # asynchronously. - - # NOTE: An action should be able to process stored messages, - # NOTE: by invoking code that is also used asynchronously. - # Remember the original message for later processing. self.message = message @@ -269,7 +265,7 @@ if message.date.to_utc().as_tuple() < last_date: writeHeaders(request, "text/plain", getMetadata(self.page), "403 Forbidden") - request.write("The message is too old: %s versus %s." % (message.date, last_date)) + request.write("The message is too old: %s versus %s." % (message.date, time.strftime("%Y-%m-%d %H:%M:%S", last_date))) return # Reject messages without dates if so configured. @@ -373,6 +369,12 @@ getattr(request.cfg, "moinmessage_gpg_relays_page", "MoinMessageRelayDict"), request) +def get_relaying_user(request): + + "Return the relaying username or None if no relaying user is configured." + + return getattr(request.cfg, "moinmessage_gpg_relaying_user") + def get_recipients(request, main=False, sending=True, fetching=True): """ @@ -524,6 +526,34 @@ return result +# Moin-specific messaging functions. + +def get_signing_identity(request, type): + + """ + Using the 'request' and indicated delivery 'type', return the appropriate + signing identity for a message, or None if no additional signature is to be + performed. + """ + + signing_users = get_signing_users(request) + signer = signing_users and signing_users.get(request.user.name) + + # Send relayed messages with an extra signature. + + if type == "relay": + relaying_user = get_relaying_user(request) + + # Signing with the current identity if no special relaying user is + # defined. + + if relaying_user and request.user.name != relaying_user: + signer = signing_users and signing_users.get(relaying_user) + + return signer + + return None + # Access to static Moin content. htdocs = None diff -r e33539cc607c -r 8e31bbf1fcf1 actions/SendMessage.py --- a/actions/SendMessage.py Sat Feb 01 01:17:27 2014 +0100 +++ b/actions/SendMessage.py Sun Feb 02 00:15:45 2014 +0100 @@ -13,7 +13,7 @@ from MoinMessage import GPG, MoinMessageError, Message, sendMessage, timestamp, \ as_string from MoinMessageSupport import get_signing_users, get_recipients, get_relays, \ - get_recipient_details, \ + get_recipient_details, get_signing_identity, \ MoinMessageRecipientError, OutgoingHTMLFormatter from MoinSupport import * from ItemSupport import ItemStore @@ -256,7 +256,7 @@ # Obtain the actual location if a relay is specified. - if parameters["type"] == "relay": + if type == "relay": relays = get_relays(request) if not relays: return 0, _("No relays are defined for MoinMessage, but one is specified for the recipient.") @@ -275,18 +275,9 @@ message = gpg.signMessage(message, signer) message = gpg.encryptMessage(message, parameters["fingerprint"]) - - # Send relayed messages with an extra signature. - - if type == "relay": - relaying_user = getattr(request.cfg, "moinmessage_gpg_relaying_user") + signer = get_signing_identity(request, type) - # Signing with the same identity if no special relaying user is - # defined. - - if relaying_user: - signer = signing_users and signing_users.get(relaying_user) - + if signer: timestamp(message) message["Update-Action"] = "store" message = gpg.signMessage(message, signer)