| 1 | <?php |
| 2 | /** |
| 3 | ** Message and Spam Filter Plugin |
| 4 | ** |
| 5 | ** Copyright (c) 1999-2001 The Squirrelmail Development Team |
| 6 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
| 7 | ** |
| 8 | ** This plugin filters your inbox into different folders based upon given |
| 9 | ** criteria. It is most useful for people who are subscibed to mailing lists |
| 10 | ** to help organize their messages. The argument stands that filtering is |
| 11 | ** not the place of the client, which is why this has been made a plugin for |
| 12 | ** SquirrelMail. You may be better off using products such as Sieve or |
| 13 | ** Procmail to do your filtering so it happens even when SquirrelMail isn't |
| 14 | ** running. |
| 15 | ** |
| 16 | ** If you need help with this, or see improvements that can be made, please |
| 17 | ** email me directly at the address above. I definately welcome suggestions |
| 18 | ** and comments. This plugin, as is the case with all SquirrelMail plugins, |
| 19 | ** is not directly supported by the developers. Please come to me off the |
| 20 | ** mailing list if you have trouble with it. |
| 21 | ** |
| 22 | ** Also view plugins/README.plugins for more information. |
| 23 | ** |
| 24 | **/ |
| 25 | |
| 26 | chdir ('..'); |
| 27 | require_once('../src/validate.php'); |
| 28 | require_once('../functions/page_header.php'); |
| 29 | require_once('../functions/imap.php'); |
| 30 | require_once('../src/load_prefs.php'); |
| 31 | |
| 32 | global $AllowSpamFilters; |
| 33 | |
| 34 | displayPageHeader($color, 'None'); |
| 35 | |
| 36 | if (isset($filter_submit)) { |
| 37 | if (!isset($theid)) $theid = 0; |
| 38 | $filter_what = ereg_replace(",", " ", $filter_what); |
| 39 | $filter_what = str_replace("\\\\", "\\", $filter_what); |
| 40 | $filter_what = str_replace("\\\"", "\"", $filter_what); |
| 41 | $filter_what = str_replace("\"", """, $filter_what); |
| 42 | |
| 43 | setPref($data_dir, $username, "filter".$theid, $filter_where.",".$filter_what.",".$filter_folder); |
| 44 | $filters[$theid]["where"] = $filter_where; |
| 45 | $filters[$theid]["what"] = $filter_what; |
| 46 | $filters[$theid]["folder"] = $filter_folder; |
| 47 | } elseif (isset($action) && $action == 'delete') { |
| 48 | remove_filter($theid); |
| 49 | } elseif (isset($action) && $action == 'move_up') { |
| 50 | filter_swap($theid, $theid - 1); |
| 51 | } elseif (isset($action) && $action == 'move_down') { |
| 52 | filter_swap($theid, $theid + 1); |
| 53 | } |
| 54 | |
| 55 | $filters = load_filters(); |
| 56 | |
| 57 | if (isset($action) && ($action == 'add' || $action == 'edit')) { |
| 58 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 59 | $boxes = sqimap_mailbox_list($imapConnection); |
| 60 | sqimap_logout($imapConnection); |
| 61 | if ( !isset($theid) ) { |
| 62 | $theid = count($filters); |
| 63 | } |
| 64 | echo '<center>'. |
| 65 | '<form action="options.php" method=post>'. |
| 66 | '<br><table cellpadding=2 cellspacing=0 border=0>'. |
| 67 | '<tr>'. |
| 68 | '<td> </td>'. |
| 69 | '<td>'. |
| 70 | '<select name=filter_where>'; |
| 71 | |
| 72 | $L = isset($filters[$theid]['where']); |
| 73 | |
| 74 | $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':''); |
| 75 | echo "<option value=\"From\" $sel>" . _ ("From") . '</option>'; |
| 76 | |
| 77 | $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':''); |
| 78 | echo "<option value=\"To\" $sel>" . _ ("To") . '</option>'; |
| 79 | |
| 80 | $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':''); |
| 81 | echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>'; |
| 82 | |
| 83 | $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':''); |
| 84 | echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>'; |
| 85 | |
| 86 | $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':''); |
| 87 | echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>'; |
| 88 | |
| 89 | echo '</select>'. |
| 90 | '</td>'. |
| 91 | '</tr>'. |
| 92 | '<tr>'. |
| 93 | '<td align=right>'. |
| 94 | _("Contains:"). |
| 95 | '</td>'. |
| 96 | '<td>'. |
| 97 | '<input type=text size=32 name=filter_what value="'; |
| 98 | if (isset($filters[$theid]['what'])) { |
| 99 | echo $filters[$theid]["what"]; |
| 100 | } |
| 101 | echo '">'. |
| 102 | '</td>'. |
| 103 | '</tr>'. |
| 104 | '<tr>'. |
| 105 | '<td>'. |
| 106 | _("Move to:"). |
| 107 | '</td>'. |
| 108 | '<td>'. |
| 109 | '<tt>'. |
| 110 | '<select name=filter_folder>'; |
| 111 | |
| 112 | for ($i = 0; $i < count($boxes); $i++) { |
| 113 | if (! in_array('noselect', $boxes[$i]['flags'])) { |
| 114 | $box = $boxes[$i]['unformatted']; |
| 115 | $box2 = str_replace(' ', ' ', $boxes[$i]['formatted']); |
| 116 | if (isset($filters[$theid]['folder']) && |
| 117 | $filters[$theid]['folder'] == $box) |
| 118 | echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>"; |
| 119 | else |
| 120 | echo "<OPTION VALUE=\"$box\">$box2</option>"; |
| 121 | } |
| 122 | } |
| 123 | echo '</tt>'. |
| 124 | '</select>'. |
| 125 | '</td>'. |
| 126 | '</tr>'. |
| 127 | '</table>'. |
| 128 | '<input type=submit name=filter_submit value=' . _("Submit") . '>'. |
| 129 | "<input type=hidden name=theid value=$theid>". |
| 130 | '</form>'. |
| 131 | '</center>'; |
| 132 | |
| 133 | } |
| 134 | |
| 135 | echo '<br>' . |
| 136 | '<table width=95% align=center border=0 cellpadding=2 cellspacing=0>'. |
| 137 | "<tr><td bgcolor=\"$color[0]\">". |
| 138 | '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>'. |
| 139 | '</td></tr></table>'. |
| 140 | '<br><center>[<a href="options.php?action=add">' . _("New") . |
| 141 | '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br>' . |
| 142 | '<table border=0 cellpadding=3 cellspacing=0 align=center>'; |
| 143 | |
| 144 | for ($i=0; $i < count($filters); $i++) { |
| 145 | |
| 146 | $clr = (($i % 2)?$color[0]:$color[9]); |
| 147 | $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"]; |
| 148 | echo "<tr bgcolor=\"$clr\"><td><small>". |
| 149 | "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'. |
| 150 | '</small></td><td><small>'. |
| 151 | "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'. |
| 152 | '</small></td><td align=center><small>['; |
| 153 | |
| 154 | if (isset($filters[$i + 1])) { |
| 155 | echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>'; |
| 156 | if ($i > 0) { |
| 157 | echo ' | '; |
| 158 | } |
| 159 | } |
| 160 | if ($i > 0) { |
| 161 | echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>'; |
| 162 | } |
| 163 | echo ']</small></td><td> - '; |
| 164 | printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr ); |
| 165 | echo '</td></tr>'; |
| 166 | |
| 167 | } |
| 168 | echo '</table>'. |
| 169 | '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'. |
| 170 | '<tr><td> </td></tr>'. |
| 171 | '</table>'; |
| 172 | |
| 173 | ?> |