1.1 --- a/MoinShare.py Tue May 14 23:14:39 2013 +0200
1.2 +++ b/MoinShare.py Thu May 16 15:34:49 2013 +0200
1.3 @@ -7,9 +7,10 @@
1.4 """
1.5
1.6 from ContentTypeSupport import getContentPreferences
1.7 -from DateSupport import getCurrentTime
1.8 +from DateSupport import getCurrentTime, getDateTimeFromRFC2822
1.9 from MoinSupport import *
1.10 from MoinMoin import wikiutil
1.11 +from email.parser import Parser
1.12 import re
1.13
1.14 try:
1.15 @@ -85,9 +86,9 @@
1.16
1.17 latest_timestamp = metadata.get("last-modified")
1.18 if latest_timestamp:
1.19 - return latest_timestamp.as_ISO8601_datetime_string()
1.20 + return latest_timestamp
1.21 else:
1.22 - return getCurrentTime().as_ISO8601_datetime_string()
1.23 + return getCurrentTime()
1.24
1.25 def getUpdateSources(request, sources_page):
1.26
1.27 @@ -118,6 +119,10 @@
1.28 self.fragment = None
1.29 self.preferred = None
1.30
1.31 + # Message-related attributes.
1.32 +
1.33 + self.parts = None
1.34 +
1.35 def __cmp__(self, other):
1.36 if self.updated is None and other.updated is not None:
1.37 return 1
1.38 @@ -148,11 +153,11 @@
1.39
1.40 for n, (format, attributes, body) in enumerate(getFragments(page.get_raw_body())):
1.41
1.42 + update = Update()
1.43 +
1.44 # Produce a fragment identifier.
1.45 # NOTE: Choose a more robust identifier where none is explicitly given.
1.46
1.47 - update = Update()
1.48 -
1.49 update.fragment = attributes.get("fragment", str(n))
1.50 update.title = attributes.get("summary", "Update #%d" % n)
1.51
1.52 @@ -189,6 +194,44 @@
1.53
1.54 return updates
1.55
1.56 +# Update retrieval from message stores.
1.57 +
1.58 +def getUpdatesFromStore(page, request):
1.59 +
1.60 + """
1.61 + Get updates from the message store associated with the given 'page' using
1.62 + the 'request'. A list of update objects is returned.
1.63 + """
1.64 +
1.65 + updates = []
1.66 +
1.67 + metadata = getMetadata(page)
1.68 + updated = getUpdatedTime(metadata)
1.69 +
1.70 + store = ItemStore(page, "messages", "message-locks")
1.71 +
1.72 + for n, message_text in enumerate(iter(store)):
1.73 +
1.74 + update = Update()
1.75 + message = Parser().parse(StringIO(message_text))
1.76 +
1.77 + # Produce a fragment identifier.
1.78 +
1.79 + update.fragment = update.updated = getDateTimeFromRFC2822(message.get("date"))
1.80 + update.title = message.get("subject", "Update #%d" % n)
1.81 +
1.82 + # Determine whether the message has several representations.
1.83 +
1.84 + if not message.is_multipart():
1.85 + update.content = message.get_payload()
1.86 + update.content_type = message.get_content_type()
1.87 + else:
1.88 + update.parts = message.get_payload()
1.89 +
1.90 + updates.append(update)
1.91 +
1.92 + return updates
1.93 +
1.94 # Source management.
1.95
1.96 def getUpdateSources(pagename, request):
2.1 --- a/actions/SharedUpdates.py Tue May 14 23:14:39 2013 +0200
2.2 +++ b/actions/SharedUpdates.py Thu May 16 15:34:49 2013 +0200
2.3 @@ -103,7 +103,7 @@
2.4 "title" : escape(path_info[1:]),
2.5 "link" : escape(link),
2.6 "href" : escattr(link),
2.7 - "updated" : escape(updated),
2.8 + "updated" : escape(updated.as_ISO8601_datetime_string()),
2.9 }
2.10
2.11 # Start the output.
2.12 @@ -136,7 +136,7 @@
2.13 "fragment_link" : escape(fragment_link),
2.14 "download_links" : "\r\n".join(download_links),
2.15 "content" : update.content and ('<content type="html">%s</content>' % escape(update.content)) or "",
2.16 - "updated" : escape(update.updated),
2.17 + "updated" : escape(update.updated.as_ISO8601_datetime_string()),
2.18 }
2.19
2.20 # Write the entry output.
3.1 --- a/macros/SharedContent.py Tue May 14 23:14:39 2013 +0200
3.2 +++ b/macros/SharedContent.py Thu May 16 15:34:49 2013 +0200
3.3 @@ -10,7 +10,7 @@
3.4 from MoinMoin.Page import Page
3.5 from MoinRemoteSupport import *
3.6 from MoinSupport import parseMacroArguments, getParsersForContentType, formatText
3.7 -from MoinShare import getUpdateSources, getUpdatesFromPage, Update
3.8 +from MoinShare import getUpdateSources, getUpdatesFromPage, getUpdatesFromStore, Update
3.9 from email.utils import parsedate
3.10 import xml.dom.pulldom
3.11
3.12 @@ -289,6 +289,21 @@
3.13 )
3.14 ))
3.15
3.16 + # Retrieve updates from message stores.
3.17 +
3.18 + elif source_parameters.get("type") == "store":
3.19 + page = Page(request, location)
3.20 + updates += getUpdatesFromStore(page, request)
3.21 +
3.22 + # Build feed-equivalent information for the update source.
3.23 +
3.24 + feeds.append((
3.25 + page.url(request, {"action" : "SharedUpdates", "store" : "1", "doit" : "1"}), (
3.26 + "internal", _("Updates from message store on page %s") % location,
3.27 + page.url(request)
3.28 + )
3.29 + ))
3.30 +
3.31 # Prepare the output.
3.32
3.33 output = []