<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://www.grafactory.net/blog/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>L'appartement - mail</title>
  <link>http://www.grafactory.net/blog/</link>
  <description></description>
  <language>fr</language>
  <pubDate>Sun, 24 Aug 2008 20:09:44 +0100</pubDate>
  <copyright></copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Script minimaliste : nettoyer une boite aux lettres avec une expression rationnelle</title>
    <link>http://www.grafactory.net/blog/post/2008/04/11/Ntettoyer-de-la-boite-mail-avec-PHP-CLI</link>
    <guid isPermaLink="false">urn:md5:bc1dd449a911787a357b4d56e93ef3f1</guid>
    <pubDate>Fri, 11 Apr 2008 22:13:00 +0200</pubDate>
    <dc:creator>Yves Tannier</dc:creator>
        <category>Le PHP</category>
        <category>cli</category><category>mail</category><category>php</category>    
    <description>    &lt;p&gt;Dans la catégorie des scripts minimalistes (mais néanmoins utiles), je vous propose un petit script qui permet d'effacer, en ligne de commande avec PHP &lt;acronym title=&quot;Commande Line Interface&quot;&gt;CLI&lt;/acronym&gt;, certains messages d'un compte mail en fonction d'une expression régulière précisée en paramètre et qui &lt;em&gt;matche&lt;/em&gt; le sujet du mail.&lt;/p&gt;


&lt;p&gt;Par exemple, effacer les centaines de messages de spam qui se trouvent dans une de vos nombreuses boites tant inutiles que nécessaires &lt;img src=&quot;/blog/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt; Autre exemple, j'exécute ce script via un cron pour nettoyer tous ce qui traine dans des boites genre &lt;em&gt;postmaster&lt;/em&gt;, &lt;em&gt;abuse&lt;/em&gt; (encore que cette dernière n'est pas trop pourrie par le SPAM), et autres bal «&amp;nbsp;no-reply&amp;nbsp;» qu'il reste quand même, pour certaines, nécessaires de consulter &lt;del&gt;tous les ans&lt;/del&gt; régulièrement.&lt;/p&gt;


&lt;p&gt;C'est un script clairement dédié à de la maintenance.  Je vous déconseille de laisser trainer ce code n'importe ou accessible via le web.&lt;/p&gt;


&lt;h4&gt;Utilisation&amp;nbsp;:&lt;/h4&gt;

&lt;pre&gt;
cleanmail -u=nom_utilisateur -p=mot_de_passe -s=imap.mondomain.tld:143 -e=&amp;quot;/SPAM/i&amp;quot;
&lt;/pre&gt;


&lt;h4&gt;Pour être sur que tous le monde a compris&amp;nbsp;:&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-u=&lt;/strong&gt; nom d'utilisateur du compte mail&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-p=&lt;/strong&gt; mot de passe du compte mail&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-s=&lt;/strong&gt; serveur (pop ou imap). Toutes les options disponibles sur la fonction &lt;a href=&quot;http://fr2.php.net/manual/fr/function.imap-open.php&quot;&gt;imap_open&lt;/a&gt; de PHP sont disponible&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;-e=&lt;/strong&gt; expression régulière qui sera «&amp;nbsp;passée&amp;nbsp;» à &lt;a href=&quot;http://fr2.php.net/preg_match&quot; hreflang=&quot;fr&quot;&gt;preg_match&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;Le script&amp;nbsp;:&lt;/h4&gt;

&lt;code class=&quot;php&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#!/usr/bin/php&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// on supprime la limite d'éxecution d'un script php&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.php.net/set_time_limit&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;set_time_limit&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;br /&gt;
&amp;nbsp;* cleanmail supprimer des mails d'une boite imap avec une pattern définie&lt;br /&gt;
&amp;nbsp;*&lt;br /&gt;
&amp;nbsp;* PHP versions 5&lt;br /&gt;
&amp;nbsp;*&lt;br /&gt;
&amp;nbsp;* LICENSE: Ce programme est un logiciel libre distribue sous licence GNU/GPL&lt;br /&gt;
&amp;nbsp;*&lt;br /&gt;
&amp;nbsp;* @author &amp;nbsp; &amp;nbsp; Yves Tannier &amp;lt;yvesSANSPAM grafactory.net&amp;gt;&lt;br /&gt;
&amp;nbsp;* @copyright &amp;nbsp;2008 Yves Tannier&lt;br /&gt;
&amp;nbsp;* @license &amp;nbsp; &amp;nbsp;http://www.gnu.org/copyleft/lesser.html &amp;nbsp;LGPL License 2.1&lt;br /&gt;
&amp;nbsp;* @version &amp;nbsp; &amp;nbsp;0.1.0 &lt;br /&gt;
&amp;nbsp;* @link &amp;nbsp; &amp;nbsp; &amp;nbsp; http://www.grafactory.net&lt;br /&gt;
&amp;nbsp;*/&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// aide contextuelle&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$help_string&lt;/span&gt; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Parametres :&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -u : utilisateur&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -p : mot de passe&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -s : serveur et port (localhost:143, localhost:110, localhost:143/novalidate-cert...)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -e : expression régulière&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -h, --help : afficher cette aide...&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// recuperer les parametres passe en CLI&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'argv'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$param&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// utilisateur&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/strpos&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;strpos&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$param&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;u=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$login_imap&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/str_replace&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;str_replace&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;-u=&amp;quot;&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;,&lt;span style=&quot;color: #0000ff;&quot;&gt;$param&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;continue&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// mot de passe&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/strpos&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;strpos&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$param&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;p=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$passwd_imap&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/str_replace&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;str_replace&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;-p=&amp;quot;&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;,&lt;span style=&quot;color: #0000ff;&quot;&gt;$param&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;continue&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// serveur et port&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/strpos&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;strpos&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$param&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;s=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$server_imap&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/str_replace&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;str_replace&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;-s=&amp;quot;&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;,&lt;span style=&quot;color: #0000ff;&quot;&gt;$param&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;continue&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// expression reguliere&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/strpos&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;strpos&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$param&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;e=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$pattern&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/str_replace&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;str_replace&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'-e='&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;''&lt;/span&gt;,&lt;span style=&quot;color: #0000ff;&quot;&gt;$param&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;continue&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;switch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$param&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'-h'&lt;/span&gt; :&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'--help'&lt;/span&gt; :&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$help_string&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/exit&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;exit&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'SCRIPT_NAME'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; :&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/unset&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;unset&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'argv'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;default&lt;/span&gt; :&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;Paramètre inconnu : &amp;quot;&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$param&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/exit&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;exit&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// pas d'argument&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/empty&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;empty&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'argv'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;Veuillez preciser au moins un paramÃ¨tre !&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$help_string&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/exit&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;exit&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// connexion&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$mbox&lt;/span&gt; = imap_open&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;{&amp;quot;&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$server_imap&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;}INBOX&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$login_imap&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$passwd_imap&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; or &lt;a href=&quot;http://www.php.net/die&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Impossible de se connecter : &amp;quot;&lt;/span&gt;.imap_last_error&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Connexion...&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// recup des headers&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$headers&lt;/span&gt; = imap_headers&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$mbox&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// parcourir les messages&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;!&lt;a href=&quot;http://www.php.net/empty&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;empty&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$headers&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Recherche avec l'expression : &amp;quot;&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$pattern&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$msgnum&lt;/span&gt; = &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$headers&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$val&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$msgnum&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$msgnum&lt;/span&gt; + &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$header&lt;/span&gt; = imap_headerinfo&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$mbox&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$msgnum&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$subject&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$header&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;subject&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/preg_match&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;preg_match&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$pattern&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$subject&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$mailmarked&lt;/span&gt; = imap_delete&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$mbox&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$msgnum&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Message &amp;quot;&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$msgnum&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot; supprimé&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Aucun message dans la boite&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Fin de la transaction&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// quitter et vider en meme temps&lt;/span&gt;&lt;br /&gt;
imap_close&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$mbox&lt;/span&gt;,CL_EXPUNGE&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/code&gt;


&lt;p&gt;Bientôt le même mais en perl &lt;img src=&quot;/blog/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://www.grafactory.net/blog/post/2008/04/11/Ntettoyer-de-la-boite-mail-avec-PHP-CLI#comment-form</comments>
      <wfw:comment>http://www.grafactory.net/blog/post/2008/04/11/Ntettoyer-de-la-boite-mail-avec-PHP-CLI#comment-form</wfw:comment>
      <wfw:commentRss>http://www.grafactory.net/blog/feed/rss2/comments/160</wfw:commentRss>
      </item>
    
  <item>
    <title>Installer DomainKeys sur Postfix (Debian Etch, Amavisd-new...)</title>
    <link>http://www.grafactory.net/blog/post/2007/11/04/Installer-DomainKeys-sur-Postfix-Debian-Etch-Amavisd-new</link>
    <guid isPermaLink="false">urn:md5:b3d3901baee1b8cfd722b82e08824f6c</guid>
    <pubDate>Sun, 04 Nov 2007 13:58:00 +0100</pubDate>
    <dc:creator>Yves Tannier</dc:creator>
        <category>Le pingouin</category>
        <category>amavis</category><category>dkim</category><category>domainkeys</category><category>mail</category><category>postfix</category>    
    <description>&lt;p&gt;&lt;strong&gt;Mise à jour le 12 mars 2008&lt;/strong&gt;&amp;nbsp;: le même billet adapté pour DKIM est disponible&amp;nbsp;: &lt;a href=&quot;http://www.grafactory.net/blog/post/2008/03/12/Installer-la-signature-DKIM-sur-Postfix-Debian-Etch-Amavisd-new&quot; hreflang=&quot;fr&quot;&gt;Installer la signature DKIM sur Postfix avec DKIMproxy&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Dans ma lutte incessante pour que mes messages n'aient pas comme destination finale les dossiers &quot;courrier indésirable&quot; des &quot;grands&quot; fournisseurs tels que Yahoo!, Hotmail/MSN, Gmail ect... Je vous propose aujourd'hui l'installation de la signature Domainkeys sur vos mails.&lt;/p&gt;


&lt;p&gt;DomainKeys est un protocole de communication créé par Yahoo! (et défini par une RFC 4870). Wikipedia vous donnera un plus d'informations sur le sujet&amp;nbsp;: &lt;a href=&quot;http://en.wikipedia.org/wiki/DomainKeys&quot; hreflang=&quot;en&quot;&gt;DomainKeys&lt;/a&gt; sur Wikipedia&lt;/p&gt;


&lt;p&gt;Même s'il fonctionne totalement et est déployé sur de nombreux serveurs, sachez qu'il est maintenant &lt;em&gt;remplacé&lt;/em&gt; par une RFC plus &quot;globale&quot;&amp;nbsp;: &lt;a href=&quot;http://www.ietf.org/rfc/rfc4871.txt&quot; hreflang=&quot;en&quot;&gt;DKIM&lt;/a&gt;  (Domain Keys Identified Mail). J'aborderais les différences et l'implémentation de DKIM dans un autre post.&lt;/p&gt;


&lt;p&gt;D'autres liens&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://fr.docs.yahoo.com/mail/spamguard_domainkeys.html&quot; hreflang=&quot;fr&quot;&gt;Prouver et sécuriser l'identité des expéditeurs&lt;/a&gt; par Yahoo!&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://domainkeys.sourceforge.net/&quot; hreflang=&quot;en&quot;&gt;DomainKey Implementor's Tools and Library for email servers &amp;amp; clients&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DomainKeys bien reconnu chez Yahoo! (forcément ;))
&lt;img src=&quot;http://www.grafactory.net/blog/public/images/domain_keys.jpg&quot; alt=&quot;DomainKeys&quot; /&gt;&lt;/p&gt;



&lt;p&gt;Voici la configuration du serveur de messagerie sur lequel se base ce tutoriel&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Distribution Linux &lt;a href=&quot;http://www.debian.org/&quot; hreflang=&quot;fr&quot;&gt;Debian&lt;/a&gt; Etch&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.postfix.org/&quot; hreflang=&quot;en&quot;&gt;Postfix&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amavis.org/&quot; hreflang=&quot;en&quot;&gt;Amavis&lt;/a&gt; (antivirus+antispam)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nous allons mettre en place la configuration suivante&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
postfix -&amp;gt; dkfilter -&amp;gt; postfix -&amp;gt; amavis -&amp;gt; postfix
&lt;/pre&gt;


&lt;p&gt;&lt;a href=&quot;http://jason.long.name/dkfilter/&quot; hreflang=&quot;en&quot;&gt;Dkfilter&lt;/a&gt; est un proxy de signature et de vérification des signatures pour DomainKeys.&lt;/p&gt;


&lt;p&gt;Ceci peut paraitre un peu lourd en regardant le schéma, mais postfix gère ce type de configuration très bien via les &lt;a href=&quot;http://www.postfix.org/FILTER_README.html&quot; hreflang=&quot;en&quot;&gt;content filter&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;&lt;em&gt;Comme je suis gentil et que l'informaticien est souvent fainéant, j'ai écris ce howto avec plein de copier/coller &lt;img src=&quot;/blog/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/em&gt;&lt;/p&gt;    &lt;h2&gt;Installer dkfilter&lt;/h2&gt;


&lt;p&gt;Il n'existe, à l'heure où j'écris ces lignes, pas de paquet Debian Etch pour dkfilter mais l'installation est relativement simple.&lt;/p&gt;


&lt;h3&gt;Installez les modules perl suivant (ici, via cpan)&amp;nbsp;:&lt;/h3&gt;

&lt;pre&gt;
perl -MCPAN -e shell

install Crypt::OpenSSL::RSA
install Mail::Address
install MIME::Base64
install Net::DNS
install Net::Server
install Test::More
install AppConfig::File
&lt;/pre&gt;


&lt;p&gt;Placez vous dans /usr/src/&lt;/p&gt;

&lt;pre&gt;
cd /usr/src/
&lt;/pre&gt;


&lt;h3&gt;Téléchargez dkfilter&lt;/h3&gt;

&lt;pre&gt;
wget http://jason.long.name/dkfilter/dkfilter-0.11.tar.gz
&lt;/pre&gt;


&lt;p&gt;Décompressez l'archive&lt;/p&gt;

&lt;pre&gt;
tar zxvf dkfilter-0.11.tar.gz
&lt;/pre&gt;


&lt;h3&gt;Patcher pour l'utilisation de dkfilter sur plusieurs domaines&lt;/h3&gt;


&lt;p&gt;Pour mon installation, j'ai besoin que &lt;strong&gt;Domain Keys&lt;/strong&gt; soit utilisable pour &lt;strong&gt;plusieurs domaines&lt;/strong&gt; sur le même serveur.&lt;/p&gt;


&lt;p&gt;Ca tombe bien, un gentil contributeur nous propose un &lt;em&gt;patch&lt;/em&gt; de dkfilter pour gérer les différentes clés et paramètres par domaine depuis un simple fichier de configuration.&lt;/p&gt;


&lt;p&gt;Téléchargez donc le patch en question&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
wget -P /usr/src/dkfilter-0.11/scripts/ http://jason.long.name/dkfilter/config_file.patch
&lt;/pre&gt;


&lt;p&gt;Patchez le programme&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
cd /usr/src/dkfilter-0.11/scripts/
patch &amp;lt; config_file.patch
&lt;/pre&gt;


&lt;p&gt;Ensuite, créez le répertoire d'installation de dkfilter dans /usr/local par exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
mkdir /usr/local/dkfilter
&lt;/pre&gt;


&lt;p&gt;Lancez le &quot;configure&quot; en précisant dans l'option votre répertoire d'installation&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
./configure --prefix=/usr/local/dkfilter
&lt;/pre&gt;


&lt;p&gt;Installez&lt;/p&gt;

&lt;pre&gt;
make install
&lt;/pre&gt;


&lt;p&gt;Si il n'y a pas d'erreur, vous pouvez continuer. Vous devez voir dans /usr/local/dkfilter, un dossier lib/ et un dossier bin/&lt;/p&gt;

&lt;pre&gt;
ls -l /usr/local/dkfilter
&lt;/pre&gt;


&lt;h2&gt;Créer l'utilisateur et le groupe dkfilter&lt;/h2&gt;

&lt;pre&gt;
adduser dkfilter --no-create-home --disabled-password --disabled-login
&lt;/pre&gt;


&lt;h2&gt;Installer le script de démarrage de dkfilter&lt;/h2&gt;


&lt;p&gt;Un script d'exemple est fourni dans l'archive de dkfilter. On le copie dans /etc/init.d/.&lt;/p&gt;

&lt;pre&gt;
cp /usr/scr/dkfilter-0.11/sample-dkfilter-init-script.sh /etc/init.d/dkfilter
&lt;/pre&gt;


&lt;p&gt;Il faut ensuite modifier le script pour l'adapter à votre configuration et au patch de gestion multi-domaines. On édite donc le script.&lt;/p&gt;

&lt;pre&gt;
vi /etc/init.d/dkfilter
&lt;/pre&gt;


&lt;p&gt;Voici la partie modifiée du fichier&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
...
DKFILTERUSER=dkfilter
DKFILTERGROUP=dkfilter
DKFILTERDIR=/usr/local/dkfilter

HOSTNAME=`hostname -f`
DOMAIN=`hostname -d`
DKFILTER_IN_ARGS=&amp;quot;
    --hostname=$HOSTNAME
    127.0.0.1:12025 127.0.0.1:12026&amp;quot;
DKFILTER_OUT_ARGS=&amp;quot;
        --configfile=/etc/dkfilter.conf
    --headers
    127.0.0.1:12027 127.0.0.1:12028&amp;quot;
...
&lt;/pre&gt;


&lt;p&gt;Soyez vigilant sur&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;les ports de dkfilter.ini (vérification des signatures des mails entrants)&lt;/li&gt;
&lt;li&gt;les ports de dkfilter.out (signature des mails sortants)&lt;/li&gt;
&lt;li&gt;le chemin vers le fichier de configuration.&lt;/li&gt;
&lt;li&gt;le groupe et l'utilisateur dkfilter créés précédemment&lt;/li&gt;
&lt;li&gt;la modification de l'argument --configfile pour prendre en compte votre fichier de configuration qui sera créé plus bas.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Créer une clé publique/privée&lt;/h2&gt;


&lt;p&gt;Chaque domaine possèdera sa propre clé. On crée un dossier dans lequel on stockera les clés.&lt;/p&gt;

&lt;pre&gt;
mkdir /urs/local/dkfilter/keys
cd /urs/local/dkfilter/keys
&lt;/pre&gt;


&lt;p&gt;&lt;em&gt;On suppose que vous avez le paquet openssl installé et que votre domaine est exemple.tld&lt;/em&gt;&lt;/p&gt;


&lt;p&gt;La clé privée&lt;/p&gt;

&lt;pre&gt;
openssl genrsa -out exempletld.key 1024
&lt;/pre&gt;


&lt;p&gt;La clé publique&lt;/p&gt;

&lt;pre&gt;
openssl rsa -in exempletld.key -pubout -out exempletld_pub.key
&lt;/pre&gt;


&lt;p&gt;Changer les droits sur la clé privée pour la rendre uniquement accessible à l'utilisateur dkfilter&lt;/p&gt;

&lt;pre&gt;
chown dkfilter; exempletld.key
chmod 640 exempletld.key
&lt;/pre&gt;


&lt;h2&gt;Ajouter l'enregistrement TXT à la zone DNS&lt;/h2&gt;


&lt;p&gt;Une fois la clé générée, il va falloir ajouter un enregistrement TXT à la zone de chaque domaine. Prenons l'exemple du domaine exemple.tld&lt;/p&gt;


&lt;p&gt;On édite le fichier de zone &lt;em&gt;/var/cache/bind/exemple.tld.hosts&lt;/em&gt; et on ajoute l'enregistrement TXT suivant. La valeur de &quot;p=&quot; correspond à la clé publique sur une seule ligne.  Notez également le nom exempletld qui sera utile pour la suite (nous l'appellerons &quot;selecteur&quot;).&lt;/p&gt;

&lt;pre&gt;
; DomainKeys
_domainkey.exemple.tld.            IN TXT  &amp;quot;t=y; o=-;&amp;quot;
exempletld._domainkey.exemple.tld.    IN TXT  &amp;quot;g=; k=rsa; p=ici_la_cle_publique_hyper_longue;&amp;quot;
&lt;/pre&gt;


&lt;p&gt;N'oubliez pas d'incrémenter le numéro de série de votre zone pour que les changements soient pris en compte et relancer bind&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
/etc/init.d/bind9 restart
&lt;/pre&gt;


&lt;p&gt;Vous pouvez vérifier la bonne configuration de votre zone sur le site officiel de DomainKeys&amp;nbsp;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://domainkeys.sourceforge.net/selectorcheck.html&quot; hreflang=&quot;en&quot;&gt;testez avec le nom du sélecteur&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://domainkeys.sourceforge.net/policycheck.html&quot; hreflang=&quot;en&quot;&gt;testez l'implémentation de DomainKeys sur la zone&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Créer le fichier de configuration de dkfilter&lt;/h2&gt;


&lt;p&gt;Il faut maintenant créer le fichier de configuration qu'utilisera dkfilter au démarrage du service dans &lt;em&gt;/ect/dkfilter.conf&lt;/em&gt;&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
# ------------------------------------------
# exemple.tdl
[domain]
name        = exemple.tdl
method      = simple
selector    = exempletld
private_key = /usr/local/dkfilter/keys/exempletld.key
&lt;/pre&gt;


&lt;p&gt;La ligne &lt;em&gt;selector&lt;/em&gt; correspond au sélecteur indiqué dans la zone.&lt;/p&gt;


&lt;h2&gt;Lancer dkfilter&lt;/h2&gt;


&lt;p&gt;Avant d'envisager la configuration de Postfix, il faut vérifier que dkfilter se lance correctement&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
/etc/init.d/dkfilter start
&lt;/pre&gt;


&lt;p&gt;Si il n'y a pas d'erreur on vérifie que le service est fonctionnel&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
ps aux | grep dkfilter
&lt;/pre&gt;


&lt;p&gt;Il doit y avoir des lignes avec dkfilter.in et des lignes avec dkfilter.out. Vérifier également que les options sont correctes. Notamment l'appel au fichier de configuration.&lt;/p&gt;


&lt;p&gt;Maintenant que la zone est modifié, dkfilter installé et fonctionnel, nous pouvons enfin passer à la configuration de postfix.&lt;/p&gt;


&lt;h2&gt;Configurer de Postfix&lt;/h2&gt;


&lt;p&gt;Dans ma configuration, avant l'installation de DomainKeys, j'utilise déjà Amavisd-new pour le filtrage antivirus (clamav) et antispam (spamassassin et dspam).&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Edit le 25 février&lt;/strong&gt;&amp;nbsp;: &lt;em&gt;on me demande comment s'effectue la vérification de la signature des mails entrants dans ma configuration. C'est en fait Amavis via SpamAssassin et l'intégration du module CPAN Mail::Dkim qui effectue cette vérification. Si vous utilisez déjà SpamAssassin via Amavis, Il suffit d'activer et de configurer le module DKIM dans le fichier /etc/spamassassin/v312.pre. On peux donc, dans ce cas, se poser la question de l&quot;utilité de lancer également le process dkfilter.in dans cette configuration...&lt;/em&gt;&lt;/p&gt;


&lt;p&gt;J'ajoute donc dkfilter dans le process avant l'analyse par Amavis.&lt;/p&gt;


&lt;p&gt;Dans le main.cf, je remplace&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
content_filter = amavis:[127.0.0.1]:10024
&lt;/pre&gt;


&lt;p&gt;par&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
 content_filter = dksign:[127.0.0.1]:12027
&lt;/pre&gt;


&lt;p&gt;[Je ne sais pas pourquoi mais si je ne précise pas le content_filter dans le main.cf, les mails envoyés par des process locaux (par exemple, la fonction &lt;em&gt;mail&lt;/em&gt; de PHP) ne passe pas par amavis et dkfilter]&lt;/p&gt;


&lt;p&gt;Dans le master.cf, voici la configuration&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;Au début du fichier&lt;/p&gt;

&lt;pre&gt;
# relayer sur dksign sur le port 10028
smtp      inet  n       -       -       -       200     smtpd
        -o receive_override_options=no_address_mappings
        -o content_filter=dksign:[127.0.0.1]:12027

# Le smtp securise SSL
smtps     inet  n       -       -       -       -       smtpd
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o content_filter=dksign:[127.0.0.1]:12027
  -o receive_override_options=no_address_mappings
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

# envoyer directement a dksign
submission  inet  n     -       n       -       -       smtpd
    -o smtpd_etrn_restrictions=reject
    -o smtpd_sasl_auth_enable=yes
    -o content_filter=dksign:[127.0.0.1]:12027
    -o receive_override_options=no_address_mappings
    -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
    #-o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
&lt;/pre&gt;


&lt;p&gt;A la fin&lt;/p&gt;

&lt;pre&gt;
# Pour amavis
amavis  unix    -   -   -   -   20  smtp
        -o smtp_helo_timeout=300 
        -o smtp_data_done_timeout=1200
        -o smtp_send_xforward_command=yes
    -o disable_dns_lookups=yes
127.0.0.1:10025 inet n - - - - smtpd
        -o content_filter=
        -o local_recipient_maps=
        -o relay_recipient_maps=
        -o smtpd_restriction_classes=
        -o smtpd_client_restrictions=
        -o smtpd_helo_restrictions=
        -o smtpd_sender_restrictions=
        -o smtpd_recipient_restrictions=permit_mynetworks,reject
        -o mynetworks=127.0.0.0/8
        -o strict_rfc821_envelopes=yes
        -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
        -o smtpd_bind_address=127.0.0.1
    -o disable_dns_lookups=yes

#
# signature domainkeys
#
dksign    unix  -       -       n       -       10      smtp
    -o smtp_send_xforward_command=yes
    -o smtp_discard_ehlo_keywords=8bitmime

#
# signature domainkeys
#
127.0.0.1:12028 inet  n  -      n       -       10      smtpd
    -o content_filter=amavis:[127.0.0.1]:10024
    -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
    -o smtpd_helo_restrictions=
    -o smtpd_client_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o mynetworks=127.0.0.0/8
    -o smtpd_authorized_xforward_hosts=127.0.0.0/8
&lt;/pre&gt;


&lt;p&gt;Vous pouvez ensuite relancer postfix&lt;/p&gt;

&lt;pre&gt;
/etc/init.d/postfix restart
&lt;/pre&gt;


&lt;h2&gt;Vérifier la signature&lt;/h2&gt;


&lt;p&gt;Envoyez un mail et regardez dans les logs&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
tail -f /var/log/mail.info
&lt;/pre&gt;


&lt;p&gt;Vous devez avoir pour un message envoyé par une adresse de exemple.tld&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
DomainKeys signing - signed; from=&amp;lt;yves@exemple.tld&amp;gt;, message-id=...
&lt;/pre&gt;


&lt;p&gt;Pour les autres&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
DomainKeys signing - skipped (wrong sender domain); from=&amp;lt;test@autredomain.tld
&lt;/pre&gt;


&lt;p&gt;Vous pouvez également vérifier votre configuration en envoyant un mail à l'adresse&amp;nbsp;: &lt;strong&gt;check-auth ici_le_chez verifier.port25.com&lt;/strong&gt;. Cette sympathique adresse vous renvoi les informations sur l'installation des différents protocoles d'authentification des mails sur votre domaine.&lt;/p&gt;


&lt;p&gt;Vous devez également avoir les informations sur DomainKeys dans l'entête du message signé&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
DomainKey-Signature : a=rsa-sha1; h=Received:Message-ID:Date:From:Organization:User-Agent:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding; b=LhoN2HSlL...6mkkDXfIw=; c=simple; d=exemple.tld; q=dns; s=exempletld
&lt;/pre&gt;


&lt;p&gt;Voilà, peut-être que vos messages ne finiront plus dans les spambox ;). n'hésitez pas à me signaler les erreurs présentent dans ce howto.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.grafactory.net/blog/post/2007/11/04/Installer-DomainKeys-sur-Postfix-Debian-Etch-Amavisd-new#comment-form</comments>
      <wfw:comment>http://www.grafactory.net/blog/post/2007/11/04/Installer-DomainKeys-sur-Postfix-Debian-Etch-Amavisd-new#comment-form</wfw:comment>
      <wfw:commentRss>http://www.grafactory.net/blog/feed/rss2/comments/152</wfw:commentRss>
      </item>
    
</channel>
</rss>