#485: can moderate pure-HTML mails
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 28 Oct 2006 22:17:02 +0000 (22:17 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 28 Oct 2006 22:17:02 +0000 (22:17 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1031 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
bin/lists.rpc.py
modules/lists.php
templates/listes/moderate_mail.tpl

index f6555e8..c6efa72 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -30,6 +30,9 @@ Bug/Wish:
     * Events:
         - #517: URL catcher update (www).                                  -Car
 
+    * Lists:
+        - #485: Can moderate pure-HTML mails                               -FRU
+
     * Profile:
         - #451: vCard are RFC compliant                                    -FRU
         - #502: Use 'alias' instead of 'aka' to specify the nickname       -FRU
index b2bc053..7f5a5f0 100755 (executable)
@@ -560,17 +560,23 @@ def get_pending_mail(userdesc, perms, vhost, listname, id, raw=0):
 
         if raw:
             return str(msg)
-        results = []
+        results_plain = []
+        results_html  = []
         for part in typed_subpart_iterator(msg, 'text', 'plain'):
             c = part.get_payload()
-            if c is not None: results.append (c)
-        results = map(lambda x: quote(x), results)
+            if c is not None: results_plain.append (c)
+        results_plain = map(lambda x: quote(x), results_plain)
+        for part in typed_subpart_iterator(msg, 'text', 'html'):
+            c = part.get_payload()
+            if c is not None: results_html.append (c)
+        results_html = map(lambda x: quote(x), results_html)
         return {'id'    : id,
                 'sender': quote(sender, True),
                 'size'  : size,
                 'subj'  : quote(subject, True),
                 'stamp' : ptime,
-                'parts' : results }
+                'parts_plain' : results_plain,
+                'parts_html': results_html }
     except:
         mlist.Unlock()
         return 0
index 0682ea9..ef748a8 100644 (file)
@@ -60,6 +60,16 @@ class ListsModule extends PLModule
         return $globals->mail->domain;
     }
 
+    function clean_html($res)
+    {
+        $res = html_entity_decode($res);
+        $res = preg_replace('@<a[^>]*href=["\']([^ >]+)["\'][^>]*>([^<]*)</a>@i', "\\2 [\\1]", $res);
+        $res = preg_replace("@<(/br|p|/div)[^>]*>(\\s*\n)?@i", "\n", $res); 
+        $res = trim(strip_tags($res));
+        $res = preg_replace("/\n(\\s*\n)+/", "\n\n", $res);
+        return htmlentities($res);
+    }
+
     function handler_lists(&$page)
     {
         $this->prepare_client($page);
@@ -321,6 +331,7 @@ class ListsModule extends PLModule
 
         $page->register_modifier('qpd', 'quoted_printable_decode');
         $page->register_modifier('hdc', 'list_header_decode');
+        $page->register_modifier('clean_html', array($this, 'clean_html'));
 
         if (Env::has('sadd')) { /* 4 = SUBSCRIBE */
             $this->client->handle_request($liste,Env::v('sadd'),4,'');
index 17767b7..b8d4994 100644 (file)
@@ -48,9 +48,9 @@
   Contenu du mail en attente
 </h1>
 
-{if $mail.parts|@count}
+{if $mail.parts_plain|@count}
 <table class='bicol' cellpadding='0' cellspacing='0'>
-  {foreach from=$mail.parts item=part key=i}
+  {foreach from=$mail.parts_plain item=part key=i}
   <tr><th>Partie n°{$i}</th></tr>
   <tr class='{cycle values="impair,pair"}'>
     <td><tt>{$part|qpd|nl2br}</tt></td>
 <br />
 {/if}
 
+{if $mail.parts_html|@count}
+<table class='bicol' cellpadding='0' cellspacing='0'>
+  {foreach from=$mail.parts_html item=part key=i}
+  <tr><th>Partie n°{$i}</th></tr>
+  <tr class='{cycle values="impair,pair"}'>
+    <td><tt>{$part|qpd|clean_html|nl2br}</tt></td>
+  </tr>
+  {/foreach}
+</table>
+<br />
+{/if}
+
 <form method='post' action='{$platal->pl_self(1)}'>
   <table class='tinybicol' cellpadding='0' cellspacing='0'>
     <tr>