1.1 --- a/MoinMessageSupport.py Sat Feb 01 01:17:27 2014 +0100
1.2 +++ b/MoinMessageSupport.py Sun Feb 02 00:15:45 2014 +0100
1.3 @@ -119,7 +119,7 @@
1.4
1.5 # Get the relaying user page and select it.
1.6
1.7 - relaying_user = getattr(self.request.cfg, "moinmessage_gpg_relaying_user")
1.8 + relaying_user = get_relaying_user(request)
1.9 relaying_page = relaying_user and get_local_homepage(request, relaying_user)
1.10
1.11 if not relaying_page:
1.12 @@ -127,15 +127,11 @@
1.13 request.write("This site is not able to forward the message to the recipient.")
1.14 return
1.15
1.16 + # Stored messages should then be processed asynchronously.
1.17 +
1.18 self.page = Page(request, relaying_page)
1.19 new_user = relaying_user
1.20
1.21 - # The stored messages should then be processed
1.22 - # asynchronously.
1.23 -
1.24 - # NOTE: An action should be able to process stored messages,
1.25 - # NOTE: by invoking code that is also used asynchronously.
1.26 -
1.27 # Remember the original message for later processing.
1.28
1.29 self.message = message
1.30 @@ -269,7 +265,7 @@
1.31
1.32 if message.date.to_utc().as_tuple() < last_date:
1.33 writeHeaders(request, "text/plain", getMetadata(self.page), "403 Forbidden")
1.34 - request.write("The message is too old: %s versus %s." % (message.date, last_date))
1.35 + request.write("The message is too old: %s versus %s." % (message.date, time.strftime("%Y-%m-%d %H:%M:%S", last_date)))
1.36 return
1.37
1.38 # Reject messages without dates if so configured.
1.39 @@ -373,6 +369,12 @@
1.40 getattr(request.cfg, "moinmessage_gpg_relays_page", "MoinMessageRelayDict"),
1.41 request)
1.42
1.43 +def get_relaying_user(request):
1.44 +
1.45 + "Return the relaying username or None if no relaying user is configured."
1.46 +
1.47 + return getattr(request.cfg, "moinmessage_gpg_relaying_user")
1.48 +
1.49 def get_recipients(request, main=False, sending=True, fetching=True):
1.50
1.51 """
1.52 @@ -524,6 +526,34 @@
1.53
1.54 return result
1.55
1.56 +# Moin-specific messaging functions.
1.57 +
1.58 +def get_signing_identity(request, type):
1.59 +
1.60 + """
1.61 + Using the 'request' and indicated delivery 'type', return the appropriate
1.62 + signing identity for a message, or None if no additional signature is to be
1.63 + performed.
1.64 + """
1.65 +
1.66 + signing_users = get_signing_users(request)
1.67 + signer = signing_users and signing_users.get(request.user.name)
1.68 +
1.69 + # Send relayed messages with an extra signature.
1.70 +
1.71 + if type == "relay":
1.72 + relaying_user = get_relaying_user(request)
1.73 +
1.74 + # Signing with the current identity if no special relaying user is
1.75 + # defined.
1.76 +
1.77 + if relaying_user and request.user.name != relaying_user:
1.78 + signer = signing_users and signing_users.get(relaying_user)
1.79 +
1.80 + return signer
1.81 +
1.82 + return None
1.83 +
1.84 # Access to static Moin content.
1.85
1.86 htdocs = None
2.1 --- a/actions/SendMessage.py Sat Feb 01 01:17:27 2014 +0100
2.2 +++ b/actions/SendMessage.py Sun Feb 02 00:15:45 2014 +0100
2.3 @@ -13,7 +13,7 @@
2.4 from MoinMessage import GPG, MoinMessageError, Message, sendMessage, timestamp, \
2.5 as_string
2.6 from MoinMessageSupport import get_signing_users, get_recipients, get_relays, \
2.7 - get_recipient_details, \
2.8 + get_recipient_details, get_signing_identity, \
2.9 MoinMessageRecipientError, OutgoingHTMLFormatter
2.10 from MoinSupport import *
2.11 from ItemSupport import ItemStore
2.12 @@ -256,7 +256,7 @@
2.13
2.14 # Obtain the actual location if a relay is specified.
2.15
2.16 - if parameters["type"] == "relay":
2.17 + if type == "relay":
2.18 relays = get_relays(request)
2.19 if not relays:
2.20 return 0, _("No relays are defined for MoinMessage, but one is specified for the recipient.")
2.21 @@ -275,18 +275,9 @@
2.22 message = gpg.signMessage(message, signer)
2.23
2.24 message = gpg.encryptMessage(message, parameters["fingerprint"])
2.25 -
2.26 - # Send relayed messages with an extra signature.
2.27 -
2.28 - if type == "relay":
2.29 - relaying_user = getattr(request.cfg, "moinmessage_gpg_relaying_user")
2.30 + signer = get_signing_identity(request, type)
2.31
2.32 - # Signing with the same identity if no special relaying user is
2.33 - # defined.
2.34 -
2.35 - if relaying_user:
2.36 - signer = signing_users and signing_users.get(relaying_user)
2.37 -
2.38 + if signer:
2.39 timestamp(message)
2.40 message["Update-Action"] = "store"
2.41 message = gpg.signMessage(message, signer)