1.1 --- a/actions/PostMessage.py Mon Oct 29 22:36:16 2012 +0100
1.2 +++ b/actions/PostMessage.py Fri Jan 18 00:36:13 2013 +0100
1.3 @@ -2,15 +2,16 @@
1.4 """
1.5 MoinMoin - PostMessage Action
1.6
1.7 - @copyright: 2012 by Paul Boddie <paul@boddie.org.uk>
1.8 + @copyright: 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
1.9 @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.10 """
1.11
1.12 +from MoinMoin.Page import Page
1.13 from MoinMoin.PageEditor import PageEditor
1.14 from MoinMoin.log import getLogger
1.15 from MoinMoin.user import User
1.16 from MoinSupport import *
1.17 -from MoinMessage import GPG, Message, MoinMessageError
1.18 +from MoinMessage import GPG, Message, MessageStore, MoinMessageError
1.19 from email.parser import Parser
1.20
1.21 try:
1.22 @@ -215,47 +216,59 @@
1.23 # Handle a single part.
1.24
1.25 if not update.is_multipart():
1.26 - self.handle_message_parts([update], to_replace(update))
1.27 + self.handle_message_parts([update], update)
1.28
1.29 # Or a collection of alternative representations for a single
1.30 # update.
1.31
1.32 else:
1.33 - self.handle_message_parts(update.get_payload(), to_replace(update))
1.34 + self.handle_message_parts(update.get_payload(), update)
1.35
1.36 # Default output.
1.37
1.38 writeHeaders(request, "text/plain", getMetadata(self.page), "204 No Content")
1.39
1.40 - def handle_message_parts(self, parts, replace):
1.41 + def handle_message_parts(self, parts, update):
1.42
1.43 """
1.44 - Handle the given message 'parts', replacing the page content if
1.45 - 'replace' is set to a true value.
1.46 + Handle the given message 'parts', using the original 'update' to
1.47 + determine whether the content is to replace or update page content, or
1.48 + whether it will be placed in a message store.
1.49 """
1.50
1.51 - # NOTE: Should either choose preferred content types or somehow retain them
1.52 - # NOTE: all but present one at a time.
1.53 + # Handle the different update actions.
1.54 + # Update a message store for the page.
1.55 +
1.56 + if to_store(update):
1.57 + store = MessageStore(self.page)
1.58 + store.append(update)
1.59
1.60 - body = []
1.61 + # Update the page.
1.62 +
1.63 + else:
1.64 + # NOTE: Should either choose preferred content types or somehow retain them
1.65 + # NOTE: all but present one at a time.
1.66 +
1.67 + body = []
1.68 + replace = to_replace(update)
1.69
1.70 - for part in parts:
1.71 - mimetype = part.get_content_type()
1.72 - encoding = part.get_content_charset()
1.73 - if mimetype == "text/moin":
1.74 - body.append(part.get_payload())
1.75 - if replace:
1.76 - break
1.77 + for part in parts:
1.78 + mimetype = part.get_content_type()
1.79 + encoding = part.get_content_charset()
1.80 + if mimetype == "text/moin":
1.81 + body.append(part.get_payload())
1.82 + if replace:
1.83 + break
1.84
1.85 - if not replace:
1.86 - body.append(self.page.get_raw_body())
1.87 + if not replace:
1.88 + body.append(self.page.get_raw_body())
1.89
1.90 - page_editor = PageEditor(self.request, self.pagename)
1.91 - page_editor.saveText("\n\n".join(body), 0)
1.92 + page_editor = PageEditor(self.request, self.pagename)
1.93 + page_editor.saveText("\n\n".join(body), 0)
1.94
1.95 - # Refresh the page.
1.96 + # Refresh the page.
1.97
1.98 - self.page = Page(self.request, self.pagename)
1.99 + self.page = Page(self.request, self.pagename)
1.100
1.101 def get_homedir(self):
1.102
1.103 @@ -267,12 +280,12 @@
1.104 request.write("Encoded data cannot currently be understood. Please notify the site administrator.")
1.105 return homedir
1.106
1.107 -def is_collection(message):
1.108 - return message.get("Update-Type") == "collection"
1.109 -
1.110 def to_replace(message):
1.111 return message.get("Update-Action") == "replace"
1.112
1.113 +def to_store(message):
1.114 + return message.get("Update-Action") == "store"
1.115 +
1.116 # Action function.
1.117
1.118 def execute(pagename, request):