root/alternc-procmail/trunk/procmail_add.php

Revision 2248, 6.6 kB (checked in by benjamin, 4 months ago)

procmail_builder now working on sqw-1.4.9 and alternc-0.9.8 with register_globals=off

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2
3 global $username, $key, $imapServerAddress, $imapPort;
4
5 define('SM_PATH','../../');
6 /* SquirrelMail required files. */
7 require_once(SM_PATH . 'include/validate.php');
8 require_once(SM_PATH . 'functions/global.php');
9 require_once(SM_PATH . 'functions/page_header.php');
10 require_once(SM_PATH . 'functions/imap.php');
11 require_once(SM_PATH . 'include/load_prefs.php');
12 require_once(SM_PATH . "plugins/procmail_builder/config.php");
13
14
15 /** COOKIE VARS */
16 sqgetGlobalVar('key',       $key,           SQ_COOKIE);
17
18 /** SESSION VARS */
19 sqgetGlobalVar('username'$username,      SQ_SESSION);
20 sqgetGlobalVar('onetimepad',$onetimepad,    SQ_SESSION);
21 sqgetGlobalVar('base_uri'$base_uri,      SQ_SESSION);
22 sqgetGlobalVar('delimiter', $delimiter,     SQ_SESSION);
23
24
25 textdomain("procmail_builder");
26
27 $raction=intval($_REQUEST["raction"]);
28 if (!$raction) {
29     $raction=1;
30 }
31
32 $accook=$_REQUEST["accook"];
33 $crit=$_REQUEST["crit"];
34 $crittext=$_REQUEST["crittext"];
35 $del=$_REQUEST["del"];
36 $createit=$_REQUEST["createit"];
37 $rcreateit=$_REQUEST["rcreateit"];
38 $dropit=$_REQUEST["dropit"];
39 $rdropit=$_REQUEST["rdropit"];
40 $newcrittxt=$_REQUEST["newcrittxt"];
41 $newcrit=$_REQUEST["newcrit"];
42
43 $crittypecount=7;
44 if (!is_array($crit)) {
45     $crit=array();
46 }
47 if (!is_array($crittext)) {
48     $crittext=array();
49 }
50 if ($createit && $accook==2) {
51     $newcrit=intval($newcrit);
52     $crit[]=$newcrit;
53     $a=_("procmail_crit_$newcrit");   
54     if (substr($a,strlen($a)-3)=="...")
55         $crittext[]=$newcrittxt;
56     else
57         $crittext[]="";
58 }
59 if ($dropit && $accook==2 && is_array($del)) {
60     $nc=$crit;
61     $nct=$crittext;
62     $crit=array();
63     $crittext=array();
64     for ($i=0;$i<count($nc);$i++) {
65         if (!in_array($i+1,$del)) {
66             $crit[]=$nc[$i];
67             $crittext[]=$nct[$i];
68         }
69     }
70 }
71
72 if ($rcreateit && $accook==2) {
73     if (!$r=$pr->buildrule($_REQUEST["rulename"],$crit,$crittext,$raction,$_REQUEST["foldertogo"],$_REQUEST["emailto"],$_REQUEST["autoreplytxt"])) {
74         $error=$er->errstr();
75     } else {
76         if ($pr->addrule($r)) {
77             $error="La règle a été ajoutée avec succès";
78             $already=1;
79             include_once("procmail_opt.php");
80             exit();
81         } else {
82             $error=$er->errstr();
83         }
84     }
85 }
86
87 if ($rdropit && $accook==2) {
88     $already=1;
89     include_once("procmail_opt.php");
90     exit();
91 }
92
93 ?>
94 <br>
95 <form method=post action="procmail_add.php">
96 <input type="hidden" name="accook" value="2">
97 <table width=95% align=center cellpadding=2 cellspacing=2 border=0>
98 <tr><td bgcolor="<?php echo $color[0] ?>">
99    <center><b><?php __("Create a new rule"); ?></b></center>
100 </td>
101 </tr>
102 <?php
103
104 if ($error) echo "<tr><td><b>$error</b></td></tr>";
105
106 ?>
107 <tr><td>
108 <?php __("Name of this rule"); ?> : <input type="text" name="rulename" size="20" maxlength="128" value="<?php echo str_replace("\"","&quote;",$rulename); ?>">
109 </td></tr>
110 <tr><td bgcolor="<?php echo $color[0] ?>">
111    <?php __("CRITERIA"); ?>
112 </td></tr>
113 <tr><td>
114 <?php if (count($crit)==0) {
115      __("No Criteria defined yet, all messages selected");
116 } else {
117     // Liste des critères
118     echo "<table cellpadding=\"4\" cellspacing=\"0\">";
119     for($i=0;$i<count($crit);$i++) {
120         echo "<tr>";
121         echo "<td><input type=\"checkbox\" name=\"del[]\" value=\"".($i+1)."\"></td>";
122         echo "<td><select name=\"crit[$i]\">";
123         for($j=0;$j<$crittypecount;$j++)  {
124             echo "<option value=\"$j\"";
125             if ($crit[$i]==$j) echo " selected";
126             echo ">"._("procmail_crit_$j")."</option>\n";
127         }
128         echo "</select></td>";
129         echo "<td><input type=\"text\" name=\"crittext[$i]\" size=\"20\" value=\"".str_replace("\"","&quote;",$crittext[$i])."\" maxlength=\"255\"></td>";
130         echo "</tr>";
131     }
132     echo "</table>";
133 }
134 ?>
135 </td></tr>
136 <tr><td>
137 <hr>
138 <select name="newcrit">
139 <?php
140 for($i=0;$i<$crittypecount;$i++)  {
141     echo "<option value=\"$i\">"._("procmail_crit_$i")."</option>\n";
142 }
143 ?>
144 </select>
145 &nbsp;&nbsp;
146 <input type="text" name="newcrittxt" size="20" value="" maxlength="255">&nbsp;&nbsp;
147 <input type="submit" name="createit" value="<?php __("Add this new criterium"); ?>">&nbsp;
148 <input type="submit" name="dropit" value="<?php __("Drop checked criteria"); ?>">&nbsp;
149 </td></tr>
150 <tr><td><p>&nbsp;</p></td></tr>
151 <tr><td bgcolor="<?php echo $color[0] ?>">
152    <?php __("PROCESS"); ?>
153 </td></tr>
154
155 <tr><td>
156 <table cellpadding="4" cellspacing="0">
157     <tr><td><input type="radio" name="raction" id="moveit" value="1"<?php if ($raction==1) echo " checked"; ?>></td>
158         <td><label for="moveit"><?php __("Move the message to this folder"); ?></label></td>
159         <td><select name="foldertogo"><?php
160 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
161 $boxes = sqimap_mailbox_list($imapConnection);
162
163 for ($i = 0; $i < count($boxes); $i++) {
164     if (!in_array('noinferiors', $boxes[$i]['flags'])) {
165         if ((strtolower($boxes[$i]['unformatted']) == 'inbox') &&
166             $default_sub_of_inbox) {
167             $box = $boxes[$i]['unformatted'];
168             $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
169             echo "<OPTION SELECTED VALUE=\"$box\">$box2</option>\n";
170         } else {
171             $box = $boxes[$i]['unformatted'];
172             $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
173             if (strtolower($imap_server_type) != 'courier' ||
174                   strtolower($box) != "inbox.trash")
175                 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
176         }
177     }
178 }
179
180 ?></select></td></tr>
181     <tr><td><input type="radio" name="raction" id="r2" value="2"<?php if ($raction==2) echo " checked"; ?>></td>
182         <td colspan="2"><label for="r2"><?php __("Filter the message through SpamAssassin"); ?></label></td></tr>
183     <tr><td><input type="radio" name="raction" id="r3" value="3"<?php if ($raction==3) echo " checked"; ?>></td>
184         <td colspan="2"><label for="r3"><?php __("Discard the message (for good !)"); ?></label></td></tr>
185     <tr><td><input type="radio" name="raction" id="r4" value="4"<?php if ($raction==4) echo " checked"; ?>></td>
186         <td><label for="r4"><?php __("Forward the mail to"); ?></label></td><td><input type="text" name="emailto" value="<?php echo str_replace("\"","&quote;",$emailto); ?>" size="30" maxlength="255"></td></tr>
187     <tr><td valign="top"><input type="radio" name="raction" id="r5" value="5"<?php if ($raction==5) echo " checked"; ?>></td>   
188         <td valign="top"><label for="r5"><?php __("Auto-reply"); ?><br><?php __("Enter auto-reply text below"); ?></label></td><td><textarea cols="32" rows="10" name="autoreplytxt"><?php echo str_replace("<","&lt;",$autoreplytxt); ?></textarea></td></tr>
189 </table>
190 </td></tr>
191 <tr><td>
192     <input type="submit" name="rcreateit" value="<?php __("Create this rule"); ?>">&nbsp;
193     <input type="submit" name="rdropit" value="<?php __("Go back to the rule list"); ?>">&nbsp;
194 </td></tr>
195
196 <tr><td><p>&nbsp;</p></td></tr>
197 <tr><td>
198 <small><?php __("help_procmail_2"); ?></small>
199 </td></tr>
200 </body>
201 </html>
202 <?php
203 textdomain("squirrelmail");
204 ?>
205
Note: See TracBrowser for help on using the browser.