[zopeorg-checkins] CVS: Products/ZWiki - ZWikiPage.py:1.69

Ken Manheimer klm at zope.com
Mon Dec 17 19:29:13 EST 2001


Update of /cvs-zopeorg/Products/ZWiki
In directory cvs.zope.org:/tmp/cvs-serv27310

Modified Files:
	ZWikiPage.py 
Log Message:
Changed what's used as the notification 'from' address:

  If the wiki has (directly or by inheritance) a non-empty
  'email_from_address' attribute, use that, otherwise use the address
  of the person making the change.

(Using 'email_from_address' because that's what the CMF uses for this
purpose.)

.notificationFromAddr(): implements new policy.

.sendMailTo(): Apply new policy.  Also, tweaked the message template,
including moving the text to a global variable, refining the layout,
and including some RFC 2369 maillist header fields.



=== Products/ZWiki/ZWikiPage.py 1.68 => 1.69 ===
 #wikiname2        = r'[A-Z]'+IU+'[A-Z'+IU+']+[a-z'+IL+'][A-Za-z'+IA+']*'
 
-
+NOTIFICATION_TEMPLATE = \
+"""From: "Wikis on %(wiki_host)s" <%(from_email)s>
+Sender: %(sender_email)s
+To: Wiki notification recipients <>
+Subject: Wiki updates - %(qualifier)s: %(id)s
+X-Wiki-URL: %(url)s
+List-Unsubscribe: %(subscribe_url)s
+List-Subscribe: %(subscribe_url)s
+
+Wiki page %(qualifier)s (%(num_recips)s recipient%(recips_plural)s):
+  %(url)s
+
+%(delim)s
+%(text)s
+%(delim)s
+To change your page subscription, visit:
+  %(subscribe_url)s
+"""
 
 class ZWikiPage(DTMLDocument, CatalogAware, ZWikiDiffMixin, SubscriberList):
     """A ZWikiPage is a DTML Document which knows how to render itself in 
@@ -1082,7 +1099,7 @@
 
         return t
 
-    def _process_comment(self, comment, text, ack_requested, REQUEST=None,
+    def _process_comment(self, comment, text, ack_requested=0, REQUEST=None,
                          preexp=re.compile('<pre>'), strip=string.strip):
         """Return formatted comment, escaping cited text.
 
@@ -1350,6 +1367,22 @@
 
     def editTimestamp(self): return str(self._p_mtime)
 
+    def notificationFromAddr(self):
+        """Return the 'from' address for a notification message.
+
+        If the wiki has (directly or by inheritance) a non-empty
+        'email_from_address' attribute, use that, otherwise use the address of
+        the person making the change."""
+        got = getattr(self, 'email_from_address', None)
+        if not got:
+            userobj = getSecurityManager().getUser()
+            userid = str(userobj)
+            if ((userobj is not None)
+                and (userid != str(self.acl_users._nobody))
+                and hasattr(userobj, 'email')):
+                got = userobj.email
+        return got
+
     def sendMailToSubscribers(self, text, REQUEST,
                               qualifier='edited'):
         """
@@ -1369,6 +1402,7 @@
 
         We return None if successful, or else a string describing the problem.
         """
+
         # ugLy temp hack
         # strip out message heading typically prepended on *Discussion pages
         mailouttext = re.sub(r'(?s)(<hr>)?<b>(.*?)</b><br>\n',r'',text)
@@ -1387,47 +1421,37 @@
                     addrs_list.append(e)
             if not addrs_list:
                 return "No update notice sent - no email addrs resolved"
-            addrs = string.join(addrs_list, ', ')
+            recipients = string.join(addrs_list, ', ')
+            num_recips = len(addrs_list)
+            recips_plural = ((num_recips != 1) and "s") or ""
 
             wiki_host = REQUEST.BASE0
             if wiki_host[:7] == 'http://':
                 wiki_host = wiki_host[7:]
-            sender_email = "webmaster@" + wiki_host
+            sender_email = "<wikis@" + string.split(wiki_host, ':')[0] + ">"
+            from_email = (self.notificationFromAddr()
+                          or sender_email)
+            subscribe_url = self.absolute_url() + "/subscribeform"
+            
             userobj = getSecurityManager().getUser()
             userid = str(userobj)
             if (userobj is None) or (userid == str(self.acl_users._nobody)):
                 userid = 'anonymous'
-            elif hasattr(userobj, 'email'):
-                sender_email = userobj.email
-            mhost=self.MailHost
+
             try:
-                # send message - make this configurable
-                # the \ is required
-                mhost.send("""\
-From: "Wikis on %s for" <%s>
-To: %s
-Subject: Wiki updates - %s: %s
-
-Wiki page change notification - %s:
-  %s
-
-%s
-%s
-%s
-To change your page subscription, visit:
-  %s/subscribeform
-""" % (wiki_host,
-       sender_email,
-       addrs,
-       qualifier,
-       self.id(),
-       qualifier,
-       self.absolute_url(),
-       SECTION_DELIM,
-       mailouttext,
-       SECTION_DELIM,
-       self.absolute_url(),
-       ))
+                msg = NOTIFICATION_TEMPLATE % {'wiki_host': wiki_host,
+                                               'from_email': from_email,
+                                               'sender_email': sender_email,
+                                               'qualifier': qualifier,
+                                               'num_recips': len(addrs_list),
+                                               'recips_plural': recips_plural,
+                                               'id': self.id(),
+                                               'url': self.absolute_url(),
+                                               'subscribe_url': subscribe_url,
+                                               'delim': SECTION_DELIM,
+                                               'text': mailouttext,
+                                               }
+                self.MailHost.send(msg, mto=recipients)
                 return None
             except:
                 import sys





More information about the zopeorg-checkins mailing list