updated/moved plugin from plugins/abook_take to squirrelmail/plugins/abook_take
[squirrelmail.git] / plugins / abook_take / setup.php
CommitLineData
e8b140ab 1<?php
2
3
4/* Address Take -- steals addresses from incoming email messages. Searches
5 the To, Cc, From and Reply-To headers, also searches the body of the
6 message. */
7
8function squirrelmail_plugin_init_abook_take()
9{
10 global $squirrelmail_plugin_hooks;
11
12 $squirrelmail_plugin_hooks['read_body_bottom']['abook_take'] = 'abook_take_read';
13 $squirrelmail_plugin_hooks['loading_prefs']['abook_take'] = 'abook_take_pref';
14 $squirrelmail_plugin_hooks['options_display_inside']['abook_take'] = 'abook_take_options';
15 $squirrelmail_plugin_hooks['options_display_save']['abook_take'] = 'abook_take_save';
16}
17
18
19function valid_email ($email, $verify)
20{
21 global $abook_take_verify;
22
23 if (eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-wyz][a-z](g|l|m|pa|t|u|v)?$",
24 $email, $check))
25 {
26 if (! $verify)
27 {
28 return TRUE;
29 }
30
31 if (checkdnsrr(substr(strstr($email, '@'), 1), 'ANY'))
32 {
33 return TRUE;
34 }
35 }
36 return FALSE;
37}
38
39
40function abook_take_read_string($str)
41{
42 global $abook_found_email;
43
44 $str = eregi_replace('[^-0-9a-z_.@]', ' ', $str);
45 $str = eregi_replace('[[:space:]]+', ' ', $str);
46 $chances = split(' ', $str);
47 $i = 0;
48 while ($i < count($chances))
49 {
50 if (valid_email($chances[$i], 0) &&
51 ! isset($abook_found_email[$chances[$i]]))
52 {
53 //echo '<option value="' . $chances[$i] . '">' . $chances[$i] .
54 // '</option>' . "\n";
55 echo "<input type=\"hidden\" name=\"email[]\" value=\"$chances[$i]\">\n";
56 $abook_found_email[$chances[$i]] = 1;
57 }
58 $i ++;
59 }
60}
61
62
63function abook_take_read_array($array)
64{
65 $i = 0;
66 while ($i < count($array))
67 {
68 abook_take_read_string($array[$i]);
69 $i ++;
70 }
71}
72
73
74function abook_take_read()
75{
76 global $color, $abook_take_location;
77 global $body, $abook_take_hide, $message, $imapConnection;
78
79 if ($abook_take_hide)
80 return;
81
82 ?>
83 <FORM ACTION="../plugins/abook_take/take.php" METHOD=POST>
84 <table align="<?PHP
85 echo $abook_take_location;
86 ?>" cellpadding=3 cellspacing=0 border=0 bgcolor="<?PHP
87 echo $color[10]
88 ?>">
89 <tr>
90 <td>
91 <table cellpadding=2 cellspacing=1 border=0 bgcolor="<?PHP
92 echo $color[5]
93 ?>">
94 <tr>
95 <td>
96 <?PHP
97 abook_take_read_string($message->header->from);
98 abook_take_read_array($message->header->cc);
99 abook_take_read_array($message->header->reply_to);
100 abook_take_read_array($message->header->to);
101
102
103 $new_body = $body;
104 $pos = strpos($new_body,
105 '">Download this as a file</A></CENTER><BR></SMALL>');
106 if (is_int($pos))
107 {
108 $new_body = substr($new_body, 0, $pos);
109 }
110
111 $trans = get_html_translation_table(HTML_ENTITIES);
112 $trans[' '] = '&nbsp;';
113 $trans = array_flip($trans);
114 $new_body = strtr($new_body, $trans);
115
116 $new_body = urldecode($new_body);
117 $new_body = strip_tags($new_body);
118
119 $new_body = strtr($new_body, "\n", ' ');
120
121 abook_take_read_string($body);
122 ?>
123 <INPUT TYPE="submit" VALUE="Take Address">
124 </td>
125 </tr>
126 </table>
127 </td>
128 </tr>
129 </table>
130 </form>
131 <?PHP
132}
133
134function abook_take_pref()
135{
136 global $username, $data_dir;
137 global $abook_take_hide, $abook_take_location, $abook_take_verify;
138
139 $abook_take_location = getPref($data_dir, $username, 'abook_take_location');
140 if ($abook_take_location == '')
141 $abook_take_location = 'center';
142
143 $abook_take_hide = getPref($data_dir, $username, 'abook_take_hide');
144 $abook_take_verify = getPref($data_dir, $username, 'abook_take_verify');
145}
146
147
148function abook_take_options()
149{
150 global $abook_take_location, $abook_take_hide, $abook_take_verify;
151
152 ?><tr><td align=right nowrap valign="top">Address Book Take:</td>
153 <td><select name="abook_take_abook_take_location">
154 <option value="left"<?PHP
155 if ($abook_take_location == 'left')
156 echo ' SELECTED';
157 ?>>Left aligned</option>
158 <option value="center"<?PHP
159 if ($abook_take_location == 'center')
160 echo ' SELECTED';
161 ?>>Centered</option>
162 <option value="right"<?PHP
163 if ($abook_take_location == 'right')
164 echo ' SELECTED';
165 ?>>Right aligned</option>
166 </select> on the Read screen<br>
167 <input type=checkbox name="abook_take_abook_take_hide"<?PHP
168 if ($abook_take_hide)
169 echo ' CHECKED';
170 ?>> Hide the box<br>
171 <input type=checkbox name="abook_take_abook_take_verify"<?PHP
172 if ($abook_take_verify)
173 echo ' CHECKED';
174 ?>> Try to verify addresses
175 </td></tr><?PHP
176}
177
178
179function abook_take_save()
180{
181 global $username, $data_dir;
182 global $abook_take_abook_take_location;
183 global $abook_take_abook_take_hide;
184 global $abook_take_abook_take_verify;
185
186
187 if (isset($abook_take_abook_take_location))
188 {
189 setPref($data_dir, $username, 'abook_take_location', $abook_take_abook_take_location);
190 }
191 else
192 {
193 setPref($data_dir, $username, 'abook_take_location', 'center');
194 }
195
196 if (isset($abook_take_abook_take_hide))
197 {
198 setPref($data_dir, $username, 'abook_take_hide', '1');
199 }
200 else
201 {
202 setPref($data_dir, $username, 'abook_take_hide', '');
203 }
204
205 if (isset($abook_take_abook_take_verify))
206 {
207 setPref($data_dir, $username, 'abook_take_verify', '1');
208 }
209 else
210 {
211 setPref($data_dir, $username, 'abook_take_verify', '');
212 }
213}
214
215?>