From: x2003bruneau Date: Sat, 28 Oct 2006 22:17:02 +0000 (+0000) Subject: #485: can moderate pure-HTML mails X-Git-Tag: xorg/0.9.12~159 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=ae0508cbd08c4974520a6d3e80df42842ef34c10;p=platal.git #485: can moderate pure-HTML mails git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1031 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/ChangeLog b/ChangeLog index f6555e8..c6efa72 100644 --- 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 diff --git a/bin/lists.rpc.py b/bin/lists.rpc.py index b2bc053..7f5a5f0 100755 --- a/bin/lists.rpc.py +++ b/bin/lists.rpc.py @@ -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 diff --git a/modules/lists.php b/modules/lists.php index 0682ea9..ef748a8 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -60,6 +60,16 @@ class ListsModule extends PLModule return $globals->mail->domain; } + function clean_html($res) + { + $res = html_entity_decode($res); + $res = preg_replace('@]*href=["\']([^ >]+)["\'][^>]*>([^<]*)@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,''); diff --git a/templates/listes/moderate_mail.tpl b/templates/listes/moderate_mail.tpl index 17767b7..b8d4994 100644 --- a/templates/listes/moderate_mail.tpl +++ b/templates/listes/moderate_mail.tpl @@ -48,9 +48,9 @@ Contenu du mail en attente -{if $mail.parts|@count} +{if $mail.parts_plain|@count} - {foreach from=$mail.parts item=part key=i} + {foreach from=$mail.parts_plain item=part key=i} @@ -60,6 +60,18 @@
{/if} +{if $mail.parts_html|@count} +
Partie n°{$i}
{$part|qpd|nl2br}
+ {foreach from=$mail.parts_html item=part key=i} + + + + + {/foreach} +
Partie n°{$i}
{$part|qpd|clean_html|nl2br}
+
+{/if} +